diff --git a/.changelogs/feature_course-level-lesson-drip.yml b/.changelogs/feature_course-level-lesson-drip.yml new file mode 100644 index 0000000000..db57e00f45 --- /dev/null +++ b/.changelogs/feature_course-level-lesson-drip.yml @@ -0,0 +1,3 @@ +significance: minor +type: added +entry: Adds course-level lesson drip settings. diff --git a/assets/js/builder/Schemas/Lesson.js b/assets/js/builder/Schemas/Lesson.js index 55b612ea94..2be8c6f852 100644 --- a/assets/js/builder/Schemas/Lesson.js +++ b/assets/js/builder/Schemas/Lesson.js @@ -87,6 +87,26 @@ define( [], function() { return this.get_available_prereq_options(); }, }, + ], [ + { + label: LLMS.l10n.translate( 'Course Drip Method' ), + id: 'course-drip', + type: 'heading', + condition: function() { + return ( this.get_course() && 'yes' === this.get_course().get( 'lesson_drip' ) && this.get_course().get( 'drip_method' ) ); + }, + detail: LLMS.l10n.translate( 'Drip settings are currently set at the course level, under the Restrictions settings tab. Disable to allow lesson level drip settings.' ) + ' ' + LLMS.l10n.translate( 'Edit Course' ) + '', + }, + ], [ + { + label: LLMS.l10n.translate( 'Course Drip Method' ), + id: 'course-drip', + type: 'heading', + condition: function() { + return ( ! this.get_course() || 'yes' !== this.get_course().get( 'lesson_drip' ) || ! this.get_course().get( 'drip_method' ) ); + }, + detail: LLMS.l10n.translate( 'Drip settings can be set at the course level to release course content at a specified interval, in the Restrictions settings tab.' ) + ' ' + LLMS.l10n.translate( 'Edit Course' ) + '', + }, ], [ { attribute: 'drip_method', @@ -94,6 +114,9 @@ define( [], function() { label: LLMS.l10n.translate( 'Drip Method' ), switch_attribute: 'drip_method', type: 'select', + condition: function() { + return ( ! this.get_course() || 'yes' !== this.get_course().get( 'lesson_drip' ) || ! this.get_course().get( 'drip_method' ) ); + }, options: function() { var options = [ @@ -132,6 +155,10 @@ define( [], function() { { attribute: 'days_before_available', condition: function() { + if ( this.get_course() && 'yes' === this.get_course().get( 'lesson_drip' ) && this.get_course().get( 'drip_method' ) ) { + return false; + } + return ( -1 !== [ 'enrollment', 'start', 'prerequisite' ].indexOf( this.get( 'drip_method' ) ) ); }, id: 'days-before-available', @@ -143,6 +170,10 @@ define( [], function() { attribute: 'date_available', date_format: 'Y-m-d', condition: function() { + if ( this.get_course() && 'yes' === this.get_course().get( 'lesson_drip' ) && this.get_course().get( 'drip_method' ) ) { + return false; + } + return ( 'date' === this.get( 'drip_method' ) ); }, id: 'date-available', @@ -153,6 +184,10 @@ define( [], function() { { attribute: 'time_available', condition: function() { + if ( this.get_course() && 'yes' === this.get_course().get( 'lesson_drip' ) && this.get_course().get( 'drip_method' ) ) { + return false; + } + return ( 'date' === this.get( 'drip_method' ) ); }, datepicker: 'false', diff --git a/assets/js/llms-builder.js b/assets/js/llms-builder.js index eea455aade..3858dacdfa 100644 --- a/assets/js/llms-builder.js +++ b/assets/js/llms-builder.js @@ -3707,6 +3707,28 @@ define( 'Schemas/Lesson',[], function() { return this.get_available_prereq_options(); }, }, + ], [ + { + label: LLMS.l10n.translate( 'Course Drip Method' ), + id: 'course-drip', + type: 'heading', + condition: function() { + return ( this.get_course() && 'yes' === this.get_course().get( 'lesson_drip' ) && this.get_course().get( 'drip_method' ) ); + }, + // TODO: see if we can get rid of this hack. this.get_course() is not available at this point to use window.llms_builder.admin_url. + detail: LLMS.l10n.translate( 'Drip settings are currently set at the course level, under the Restrictions settings tab. Disable to allow lesson level drip settings.' ) + ' ' + LLMS.l10n.translate( 'Edit Course' ) + '', + }, + ], [ + { + label: LLMS.l10n.translate( 'Course Drip Method' ), + id: 'course-drip', + type: 'heading', + condition: function() { + return ( ! this.get_course() || 'yes' !== this.get_course().get( 'lesson_drip' ) || ! this.get_course().get( 'drip_method' ) ); + }, + // TODO: see if we can get rid of this hack. this.get_course() is not available at this point to use window.llms_builder.admin_url. + detail: LLMS.l10n.translate( 'Drip settings can be set at the course level to release course content at a specified interval, in the Restrictions settings tab.' ) + ' ' + LLMS.l10n.translate( 'Edit Course' ) + '', + }, ], [ { attribute: 'drip_method', @@ -3714,6 +3736,9 @@ define( 'Schemas/Lesson',[], function() { label: LLMS.l10n.translate( 'Drip Method' ), switch_attribute: 'drip_method', type: 'select', + condition: function() { + return ( ! this.get_course() || 'yes' !== this.get_course().get( 'lesson_drip' ) || ! this.get_course().get( 'drip_method' ) ); + }, options: function() { var options = [ @@ -3752,6 +3777,10 @@ define( 'Schemas/Lesson',[], function() { { attribute: 'days_before_available', condition: function() { + if ( this.get_course() && 'yes' === this.get_course().get( 'lesson_drip' ) && this.get_course().get( 'drip_method' ) ) { + return false; + } + return ( -1 !== [ 'enrollment', 'start', 'prerequisite' ].indexOf( this.get( 'drip_method' ) ) ); }, id: 'days-before-available', @@ -3763,6 +3792,10 @@ define( 'Schemas/Lesson',[], function() { attribute: 'date_available', date_format: 'Y-m-d', condition: function() { + if ( this.get_course() && 'yes' === this.get_course().get( 'lesson_drip' ) && this.get_course().get( 'drip_method' ) ) { + return false; + } + return ( 'date' === this.get( 'drip_method' ) ); }, id: 'date-available', @@ -3773,6 +3806,10 @@ define( 'Schemas/Lesson',[], function() { { attribute: 'time_available', condition: function() { + if ( this.get_course() && 'yes' === this.get_course().get( 'lesson_drip' ) && this.get_course().get( 'drip_method' ) ) { + return false; + } + return ( 'date' === this.get( 'drip_method' ) ); }, datepicker: 'false', diff --git a/includes/admin/post-types/meta-boxes/class.llms.meta.box.course.options.php b/includes/admin/post-types/meta-boxes/class.llms.meta.box.course.options.php index 45d9251f9a..2470cb3f9f 100644 --- a/includes/admin/post-types/meta-boxes/class.llms.meta.box.course.options.php +++ b/includes/admin/post-types/meta-boxes/class.llms.meta.box.course.options.php @@ -328,7 +328,51 @@ public function get_fields() { 'label' => __( 'Choose Prerequisite Course Track', 'lifterlms' ), 'value' => $course_tracks, ), - + array( + 'type' => 'checkbox', + 'label' => __( 'Enable Lesson Drip', 'lifterlms' ), + 'desc' => __( 'Set global drip restrictions so lesson content becomes available at an interval you define for the course.', 'lifterlms' ), + 'id' => $this->prefix . 'lesson_drip', + 'is_controller' => true, + 'value' => 'yes', + 'class' => '', + 'desc_class' => 'd-3of4 t-3of4 m-1of2', + ), + array( + 'class' => 'llms-select2', + 'controller' => '#' . $this->prefix . 'lesson_drip', + 'controller_value' => 'yes', + 'is_controller' => true, + 'type' => 'select', + 'id' => $this->prefix . 'drip_method', + 'label' => __( 'Drip Method', 'lifterlms' ), + 'value' => array( + array( + 'key' => 'start', + 'title' => __( 'After course start or enrollment', 'lifterlms' ), + ), + ), + ), + array( + 'controller' => '#' . $this->prefix . 'lesson_drip', + 'controller_value' => 'yes', + 'class' => 'input-full', + 'id' => $this->prefix . 'ignore_lessons', + 'label' => __( 'Number of lessons to make immediately available on course start', 'lifterlms' ), + 'type' => 'number', + 'step' => 1, + 'min' => 1, + ), + array( + 'controller' => '#' . $this->prefix . 'lesson_drip', + 'controller_value' => 'yes', + 'class' => 'input-full', + 'id' => $this->prefix . 'days_before_available', + 'label' => __( 'Delay (in days) ', 'lifterlms' ), + 'type' => 'number', + 'step' => 1, + 'min' => 1, + ), array( 'is_controller' => true, 'type' => 'checkbox', diff --git a/includes/admin/post-types/meta-boxes/class.llms.meta.box.lesson.php b/includes/admin/post-types/meta-boxes/class.llms.meta.box.lesson.php index 5863f1353f..c4fe3b02b8 100644 --- a/includes/admin/post-types/meta-boxes/class.llms.meta.box.lesson.php +++ b/includes/admin/post-types/meta-boxes/class.llms.meta.box.lesson.php @@ -73,7 +73,7 @@ public function get_fields() { unset( $methods['start'] ); } - return array( + $fields = array( array( 'title' => __( 'General', 'lifterlms' ), 'fields' => array( @@ -134,44 +134,13 @@ public function get_fields() { ), ), ), - array( + 'drip' => array( 'title' => __( 'Drip Settings', 'lifterlms' ), 'fields' => array( array( - 'class' => 'llms-select2', - 'desc_class' => 'd-all', - 'id' => $this->prefix . 'drip_method', - 'is_controller' => true, - 'label' => __( 'Method', 'lifterlms' ), - 'type' => 'select', - 'value' => $methods, - ), - array( - 'controller' => '#' . $this->prefix . 'drip_method', - 'controller_value' => 'lesson,enrollment,start,prerequisite', - 'class' => 'input-full', - 'id' => $this->prefix . 'days_before_available', - 'label' => __( 'Delay (in days) ', 'lifterlms' ), - 'type' => 'number', - 'step' => 1, - 'min' => 0, - ), - array( - 'controller' => '#' . $this->prefix . 'drip_method', - 'controller_value' => 'date', - 'class' => 'llms-datepicker', - 'id' => $this->prefix . 'date_available', - 'label' => __( 'Date Available', 'lifterlms' ), - 'type' => 'date', - ), - array( - 'controller' => '#' . $this->prefix . 'drip_method', - 'controller_value' => 'date', - 'class' => '', - 'desc' => __( 'Optionally enter a time when the lesson should become available. If no time supplied, lesson will be available at 12:00 AM. Format must be HH:MM AM', 'lifterlms' ), - 'id' => $this->prefix . 'time_available', - 'label' => __( 'Time Available', 'lifterlms' ), - 'type' => 'text', + 'type' => 'custom-html', + 'id' => $this->prefix . 'drip_course_settings_info', + 'value' => $this->get_drip_course_settings_info_html( $course ), ), ), ), @@ -191,8 +160,67 @@ public function get_fields() { ), ), ); + + if ( 'yes' !== $course->get( 'lesson_drip' ) || ! $course->get( 'drip_method' ) ) { + $fields['drip']['fields'][] = array( + 'class' => 'llms-select2', + 'desc_class' => 'd-all', + 'id' => $this->prefix . 'drip_method', + 'is_controller' => true, + 'label' => __( 'Method', 'lifterlms' ), + 'type' => 'select', + 'value' => $methods, + ); + $fields['drip']['fields'][] = array( + 'controller' => '#' . $this->prefix . 'drip_method', + 'controller_value' => 'lesson,enrollment,start,prerequisite', + 'class' => 'input-full', + 'id' => $this->prefix . 'days_before_available', + 'label' => __( 'Delay (in days) ', 'lifterlms' ), + 'type' => 'number', + 'step' => 1, + 'min' => 0, + ); + $fields['drip']['fields'][] = array( + 'controller' => '#' . $this->prefix . 'drip_method', + 'controller_value' => 'date', + 'class' => 'llms-datepicker', + 'id' => $this->prefix . 'date_available', + 'label' => __( 'Date Available', 'lifterlms' ), + 'type' => 'date', + ); + $fields['drip']['fields'][] = array( + 'controller' => '#' . $this->prefix . 'drip_method', + 'controller_value' => 'date', + 'class' => '', + 'desc' => __( 'Optionally enter a time when the lesson should become available. If no time supplied, lesson will be available at 12:00 AM. Format must be HH:MM AM', 'lifterlms' ), + 'id' => $this->prefix . 'time_available', + 'label' => __( 'Time Available', 'lifterlms' ), + 'type' => 'text', + ); + } + + return $fields; } + /** + * Helpful messaging depending on whether the course for this lesson has drip settings enabled or not. + * + * @since [version] + * + * @param LLMS_Course $course Course object. + * @return string + */ + public function get_drip_course_settings_info_html( $course ) { + $output = 'yes' === $course->get( 'lesson_drip' ) && $course->get( 'drip_method' ) ? + __( 'Drip settings are currently set at the course level, under the Restrictions settings tab. If you would like to set individual drip settings for each lesson, you must disable the course level drip settings first.', 'lifterlms' ) + : + __( 'Drip settings can be set at the course level to release course content at a specified interval, in the Restrictions settings tab.', 'lifterlms' ); + + $output .= ' ' . __( 'Edit Course', 'lifterlms' ) . ''; + + return $output; + } } new LLMS_Meta_Box_Lesson(); diff --git a/includes/admin/views/builder/settings-fields.php b/includes/admin/views/builder/settings-fields.php index 71ccbff421..11f36382ce 100644 --- a/includes/admin/views/builder/settings-fields.php +++ b/includes/admin/views/builder/settings-fields.php @@ -138,6 +138,9 @@ class="llms-input standard" {{{ field.label_after }}} <# } #> + <# if ( field.detail ) { #> +