PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.2
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / emails / types / class-lp-email-type-finished-course.php

class-lp-email-type-finished-course.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7.2, at inc/emails/types/class-lp-email-type-finished-course.php

144 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class LP_Email_Type_Finished_Course
5 *
6 * @editor tungnx
7 * @modify 4.1.3
8 * @version 3.0.1
9 */
10 class LP_Email_Type_Finished_Course extends LP_Email {
11 /**
12 * Course ID
13 *
14 * @var int
15 */
16 public $course_id = 0;
17
18 /**
19 * User ID
20 *
21 * @var int
22 */
23 public $user_id = 0;
24
25 /**
26 * User Item ID
27 *
28 * @var int
29 */
30 public $user_item_id = 0;
31
32 /**
33 * LP_Email_Type_Finished_Course constructor.
34 */
35 public function __construct() {
36 parent::__construct();
37
38 $variable_on_email_support = apply_filters(
39 'lp/email/type-finished-course/variables-support',
40 [
41 '{{course_id}}',
42 '{{course_name}}',
43 '{{course_url}}',
44 '{{user_id}}',
45 '{{user_name}}',
46 '{{user_display_name}}',
47 '{{user_email}}',
48 '{{course_grade}}',
49 '{{course_result_percent}}',
50 ]
51 );
52
53 $this->support_variables = array_merge( $this->support_variables, $variable_on_email_support );
54 }
55
56 /**
57 * Check email enable option
58 * Check param valid: 3 params: $course_id, $user_id, $user_item_id
59 * Set values
60 *
61 * @param array $params
62 * @return bool
63 * @throws Exception
64 */
65 protected function check_and_set( array $params ): bool {
66 if ( ! $this->enable ) {
67 return false;
68 }
69
70 if ( count( $params ) < 3 ) {
71 return false;
72 }
73
74 $this->course_id = $params[0];
75 $this->user_id = $params[1];
76 $this->user_item_id = $params[2];
77
78 return true;
79 }
80
81 /**
82 * Trigger email.
83 * Receive 3 params: $course_id, $user_id, $user_item_id
84 *
85 * @param array $params
86 * @throws Exception
87 * @since 4.1.1
88 * @author tungnx
89 */
90 public function handle( array $params ) {
91 if ( ! $this->check_and_set( $params ) ) {
92 return;
93 }
94
95 $this->set_data_content();
96 if ( $this instanceof LP_Email_Finished_Course_Instructor ) {
97 $instructor = learn_press_get_user( get_post_field( 'post_author', $this->course_id ) );
98 if ( $instructor && ! empty( $instructor->get_email() ) ) {
99 $this->set_receive( $instructor->get_email() );
100 }
101 } elseif ( $this instanceof LP_Email_Finished_Course_User ) {
102 $user = learn_press_get_user( $this->user_id );
103 if ( $user && ! empty( $user->get_email() ) ) {
104 $this->set_receive( $user->get_email() );
105 }
106 }
107 $this->send_email();
108 }
109
110 /**
111 * Set variables for content email.
112 * @editor tungnx
113 * @since 4.1.3
114 */
115 public function set_data_content() {
116 $course = learn_press_get_course( $this->course_id );
117 $user = learn_press_get_user( $this->user_id );
118
119 if ( ! $course || ! $user ) {
120 return;
121 }
122
123 $user_course_data = $user->get_course_data( $this->course_id );
124
125 $this->variables = apply_filters(
126 'lp/email/type-finished-course/variables-mapper',
127 [
128 '{{course_id}}' => $this->course_id,
129 '{{course_name}}' => $course->get_title(),
130 '{{course_url}}' => $course->get_permalink(),
131 '{{user_id}}' => $this->user_id,
132 '{{user_name}}' => $user->get_username(),
133 '{{user_display_name}}' => $user->get_display_name(),
134 '{{user_email}}' => $user->get_email(),
135 '{{course_grade}}' => $user_course_data->get_graduation( 'display' ),
136 '{{course_result_percent}}' => $user_course_data->get_percent_result( 2 ),
137 ]
138 );
139
140 $variables_common = $this->get_common_variables( $this->email_format );
141 $this->variables = array_merge( $this->variables, $variables_common );
142 }
143 }
144