diff --git a/.changelogs/issue-3141.yml b/.changelogs/issue-3141.yml new file mode 100644 index 0000000000..577aa32e01 --- /dev/null +++ b/.changelogs/issue-3141.yml @@ -0,0 +1,3 @@ +significance: minor +type: added +entry: "Added unenrollment notification trigger (popup and email) for courses and memberships, disabled by default." diff --git a/includes/notifications/class.llms.notifications.php b/includes/notifications/class.llms.notifications.php index 2e652a851e..c54b6ccf80 100644 --- a/includes/notifications/class.llms.notifications.php +++ b/includes/notifications/class.llms.notifications.php @@ -307,6 +307,7 @@ private function load() { 'section_complete', 'student_welcome', 'subscription_cancelled', + 'unenrollment', 'upcoming_payment_reminder', ); diff --git a/includes/notifications/controllers/class.llms.notification.controller.unenrollment.php b/includes/notifications/controllers/class.llms.notification.controller.unenrollment.php new file mode 100644 index 0000000000..7a6015a1bc --- /dev/null +++ b/includes/notifications/controllers/class.llms.notification.controller.unenrollment.php @@ -0,0 +1,143 @@ +user_id = $user_id; + $this->post_id = $post_id; + $this->course = llms_get_post( $post_id ); + + $this->send(); + + } + + /** + * Takes a subscriber type (student, author, etc) and retrieves a User ID + * + * @param string $subscriber Subscriber type string. + * @return int|false + * @since [version] + */ + protected function get_subscriber( $subscriber ) { + + switch ( $subscriber ) { + + case 'author': + $uid = $this->course->get( 'author' ); + break; + + case 'student': + $uid = $this->user_id; + break; + + default: + $uid = false; + + } + + return $uid; + + } + + /** + * Get the translatable title for the notification + * used on settings screens + * + * @return string + * @since [version] + */ + public function get_title() { + return __( 'Unenrollment', 'lifterlms' ); + } + + /** + * Setup the subscriber options for the notification + * + * All subscribers default to disabled ('no') per the feature request: + * site administrators must opt in to receive unenrollment notifications. + * + * @param string $type Notification type id. + * @return array + * @since [version] + */ + protected function set_subscriber_options( $type ) { + + $options = array(); + + switch ( $type ) { + + case 'basic': + $options[] = $this->get_subscriber_option_array( 'student', 'no' ); + $options[] = $this->get_subscriber_option_array( 'author', 'no' ); + break; + + case 'email': + $options[] = $this->get_subscriber_option_array( 'student', 'no' ); + $options[] = $this->get_subscriber_option_array( 'author', 'no' ); + $options[] = $this->get_subscriber_option_array( 'custom', 'no' ); + break; + + } + + return $options; + + } + +} + +return LLMS_Notification_Controller_Unenrollment::instance(); diff --git a/includes/notifications/views/class.llms.notification.view.unenrollment.php b/includes/notifications/views/class.llms.notification.view.unenrollment.php new file mode 100644 index 0000000000..1c18a70552 --- /dev/null +++ b/includes/notifications/views/class.llms.notification.view.unenrollment.php @@ -0,0 +1,143 @@ + 10000, + /** + * Enables manual dismissal of notifications + */ + 'dismissible' => true, + ); + + /** + * Notification Trigger ID + * + * @var string + */ + public $trigger_id = 'unenrollment'; + + /** + * Setup body content for output + * + * @return string + * @since [version] + */ + protected function set_body() { + if ( 'email' === $this->notification->get( 'type' ) ) { + return sprintf( __( 'You have been unenrolled from %s.', 'lifterlms' ), '{{TITLE}}' ); + } + return sprintf( __( '%1$s has been unenrolled from %2$s.', 'lifterlms' ), '{{STUDENT_NAME}}', '{{TITLE}}' ); + } + + /** + * Setup footer content for output + * + * @return string + * @since [version] + */ + protected function set_footer() { + return ''; + } + + /** + * Setup notification icon for output + * + * @return string + * @since [version] + */ + protected function set_icon() { + return $this->get_icon_default( 'negative' ); + } + + /** + * Setup merge codes that can be used with the notification + * + * @return array + * @since [version] + */ + protected function set_merge_codes() { + return array( + '{{TITLE}}' => __( 'Title', 'lifterlms' ), + '{{TYPE}}' => __( 'Type (Course or Membership)', 'lifterlms' ), + '{{STUDENT_NAME}}' => __( 'Student Name', 'lifterlms' ), + ); + } + + /** + * Replace merge codes with actual values + * + * @param string $code The merge code to get merged data for. + * @return string + * @since [version] + */ + protected function set_merge_data( $code ) { + + switch ( $code ) { + + case '{{TITLE}}': + $code = $this->post->get( 'title' ); + break; + + case '{{TYPE}}': + $code = $this->post->get_post_type_label(); + break; + + case '{{STUDENT_NAME}}': + $code = $this->is_for_self() ? __( 'you', 'lifterlms' ) : $this->user->get_name(); + break; + + } + + return $code; + + } + + /** + * Setup notification subject for output + * + * @return string + * @since [version] + */ + protected function set_subject() { + if ( $this->is_for_self() ) { + return sprintf( __( 'You have been unenrolled from %s', 'lifterlms' ), '{{TITLE}}' ); + } + return sprintf( __( '%1$s unenrolled from %2$s', 'lifterlms' ), '{{STUDENT_NAME}}', '{{TITLE}}' ); + } + + /** + * Setup notification title for output + * + * @return string + * @since [version] + */ + protected function set_title() { + return sprintf( __( '%1$s unenrollment', 'lifterlms' ), '{{TYPE}}' ); + } + +}