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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / includes / droip / backend / ElementGenerator / ActionsGenerator.php
tutor / includes / droip / backend / ElementGenerator Last commit date
ActionsGenerator.php 9 months ago AddRatingGenerator.php 1 year ago CourseMetaGenerator.php 9 months ago ElementGenerator.php 1 year ago MaterialGenerator.php 1 year ago Preview.php 1 year ago PriceGenerator.php 9 months ago SocialLinkGenerator.php 1 year ago ThumbnailGenerator.php 1 year ago
ActionsGenerator.php
325 lines
1 <?php
2
3 /**
4 * Preview script for html markup generator
5 *
6 * @package tutor-droip-elements
7 */
8
9 namespace TutorLMSDroip\ElementGenerator;
10
11 use TUTOR\Course;
12 use TUTOR_CERT\Certificate;
13 use TutorPro\Subscription\Subscription;
14 use TutorPro\Subscription\Models\PlanModel;
15 use Tutor\Ecommerce\CheckoutController;
16 use TutorPro\GiftCourse\GiftCourse;
17 use TutorPro\Subscription\Settings;
18
19 if (! defined('ABSPATH')) {
20 exit; // Exit if accessed directly.
21 }
22
23 /**
24 * Class ActionsGenerator
25 * This class is used to define all helper functions.
26 *
27 * @package TutorLMSDroip\ElementGenerator
28 */
29 trait ActionsGenerator
30 {
31
32 /**
33 * Generate actionbox markup
34 *
35 * @return string
36 */
37 private function generate_action_markup()
38 {
39 $course_id = isset($this->options['post']) ? $this->options['post']->ID : get_the_ID();
40 $ele_name = $this->element['name'];
41 $entry_box_button_logic = tutor_entry_box_buttons($course_id);
42 $type = isset($this->properties['type']) ? $this->properties['type'] : 'enroll_btn';
43 $extra_attributes = "data-course_id='$course_id' data-action_type='$type'";
44
45 $selling_option = Course::get_selling_option($course_id);
46 if (!$selling_option) {
47 $selling_option = Course::SELLING_OPTION_ALL;
48 }
49
50 switch ($type) {
51 case 'wishlist_btn': {
52 if (! is_user_logged_in()) {
53 return '';
54 }
55 $is_wish_listed = tutor_utils()->is_wishlisted($course_id, get_current_user_id());
56 if ($is_wish_listed) {
57 return '';
58 }
59
60 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
61 }
62 case 'wishlisted_btn': {
63 if (! is_user_logged_in()) {
64 return '';
65 }
66 $is_wish_listed = tutor_utils()->is_wishlisted($course_id, get_current_user_id());
67 if (! $is_wish_listed) {
68 return '';
69 }
70
71 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
72 }
73 }
74
75 $entry_box_button_logic = $this->update_entry_box_button_logic($entry_box_button_logic, $this->options);
76
77 if (! isset($entry_box_button_logic->{'show_' . $type}) || (isset($entry_box_button_logic->{'show_' . $type}) && $entry_box_button_logic->{'show_' . $type} !== true)) {
78 return '';
79 }
80 switch ($type) {
81 case 'enroll_btn': {
82 if (! $entry_box_button_logic->show_enroll_btn) {
83 return '';
84 }
85 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
86 }
87
88 case 'add_to_cart_btn': {
89 $is_course_in_user_cart = tutor_is_item_in_cart($course_id);
90 if ($is_course_in_user_cart) {
91 return '';
92 }
93
94 if ($selling_option === Course::SELLING_OPTION_ALL || $selling_option === Course::SELLING_OPTION_ONE_TIME || $selling_option === Course::SELLING_OPTION_BOTH) {
95 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
96 }
97 return "";
98 }
99
100 case 'remove_from_cart_btn': {
101 $is_course_in_user_cart = tutor_is_item_in_cart($course_id);
102 if (!$is_course_in_user_cart) {
103 return '';
104 }
105 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
106 }
107
108 case 'view_cart_btn': {
109 $is_course_in_user_cart = tutor_is_item_in_cart($course_id);
110 if (! $is_course_in_user_cart) {
111 return '';
112 }
113 $extra_attributes .= " data-cart_url='" . tutor_get_cart_url() . "'";
114 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
115 }
116
117 case 'start_learning_btn': {
118 if (! $entry_box_button_logic->show_start_learning_btn) {
119 return '';
120 }
121 $is_course_completed = tutor_utils()->is_completed_course($course_id, get_current_user_id());
122 if ($is_course_completed) {
123 return '';
124 }
125 $lession_url = tutor_utils()->get_course_first_lesson($course_id);
126 $extra_attributes .= " data-lession_url=$lession_url";
127 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
128 }
129
130 case 'continue_learning_btn': {
131 if (! $entry_box_button_logic->show_continue_learning_btn) {
132 return '';
133 }
134 $is_course_completed = tutor_utils()->is_completed_course($course_id, get_current_user_id());
135 if ($is_course_completed) {
136 return '';
137 }
138 $extra_attributes .= " data-continue_learning_url='" . tutor_utils()->get_course_first_lesson() . "'";
139 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
140 }
141
142 case 'complete_course_btn': {
143 if (! $entry_box_button_logic->show_complete_course_btn) {
144 return '';
145 }
146 $is_course_completed = tutor_utils()->is_completed_course($course_id, get_current_user_id());
147 if ($is_course_completed) {
148 return '';
149 }
150
151 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
152 }
153
154 case 'retake_course_btn': {
155 if ($entry_box_button_logic->show_retake_course_btn || ($entry_box_button_logic->show_certificate_view_btn && function_exists('TUTOR_CERT'))) {
156 $extra_attributes .= " data-continue_learning_url='" . tutor_utils()->get_course_first_lesson() . "'";
157 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
158 }
159
160 return "";
161 }
162 case 'certificate_view_btn': {
163 if (! function_exists('TUTOR_CERT')) {
164 return '';
165 }
166 if (! $entry_box_button_logic->show_certificate_view_btn) {
167 return '';
168 }
169 $is_course_completed = tutor_utils()->is_completed_course($course_id, get_current_user_id());
170
171 if (! $is_course_completed) {
172 return '';
173 }
174 if (! $course_id) {
175 return '';
176 }
177
178 $certificate_url = '';
179 if (tutils()->is_addon_enabled(TUTOR_CERT()->basename)) {
180 $certificate_url = (new Certificate(true))->get_certificate($course_id);
181
182 $extra_attributes .= " data-certificate_url='" . $certificate_url . "'";
183 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
184 }
185
186 return '';
187 }
188
189 case 'subscribe_now_btn': {
190 $checkout_link = CheckoutController::get_page_url();
191
192
193 if (is_user_logged_in()) {
194 $extra_attributes .= " data-checkout_url='" . $checkout_link . "'";
195 } else {
196 $login_url = wp_login_url(wp_get_referer());
197
198 $extra_attributes .= " data-login_url='" . $login_url . "'";
199 }
200
201 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
202 }
203
204 case 'membership_btn': {
205 $pricing_page = Settings::get_pricing_page_url();
206 if ($pricing_page) {
207 $extra_attributes .= " data-pricing_url='" . $pricing_page . "'";
208 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
209 }
210
211 return "";
212 }
213
214 case 'gift_course_btn': {
215 if (is_user_logged_in()) {
216 $extra_attributes .= " data-tutor-modal-target='tutor-gift-this-course-modal'";
217
218 $btn = $this->generate_child_element_with_parent_droip_data($extra_attributes);
219
220 // Capture template output
221 ob_start();
222 tutor_load_template(
223 'single.course.gift-this-course-modal',
224 array('course_id' => $course_id),
225 true
226 );
227
228 $modal_html = ob_get_clean();
229
230 // Return button + modal
231 return $btn . $modal_html;
232 } else {
233 // direct to login page if not logged in
234 $login_url = wp_login_url(wp_get_referer());
235 $extra_attributes .= " data-login_url='" . $login_url . "'";
236 $btn = $this->generate_child_element_with_parent_droip_data($extra_attributes);
237
238 // Return button + modal
239 return $btn;
240 }
241
242 return "";
243 }
244
245 default: {
246 return '';
247 }
248 }
249
250 return '';
251 }
252
253 private function update_entry_box_button_logic($entry_box_button_logic, $options)
254 {
255 $course_id = isset($options['post']) ? $options['post']->ID : get_the_ID();
256
257 $is_paid_course = tutor_utils()->is_course_purchasable($course_id);
258
259 if (isset($options['relation_type']) && $options['relation_type'] === 'TUTOR_LMS_CART') {
260 if ($entry_box_button_logic->show_view_cart_btn) {
261 $entry_box_button_logic->show_remove_from_cart_btn = true;
262 }
263 }
264 if (isset($options['relation_type']) && $options['relation_type'] === 'TUTOR_LMS_CART') {
265 $entry_box_button_logic->show_view_cart_btn = false;
266 }
267
268 if ($is_paid_course) {
269
270 if (tutor()->has_pro && Subscription::is_enabled() && $course_id) {
271
272
273 // Checking is course has subscription plan then show buy now button.
274 $selling_option = Course::get_selling_option($course_id);
275 if (!$selling_option) {
276 $selling_option = Course::SELLING_OPTION_ALL;
277 }
278 if ($selling_option === Course::SELLING_OPTION_SUBSCRIPTION || $selling_option === Course::SELLING_OPTION_BOTH || $selling_option === Course::SELLING_OPTION_ALL) {
279 $plan_model = new PlanModel();
280 $items = $plan_model->get_subscription_plans($course_id, PlanModel::STATUS_ACTIVE);
281
282 if (count($items) > 0) {
283 $entry_box_button_logic->show_subscribe_now_btn = true;
284 }
285 }
286
287 // Checking is course has membership plan enabled
288 $selling_option = Course::get_selling_option($course_id);
289 if (!$selling_option) {
290 $selling_option = Course::SELLING_OPTION_ALL;
291 }
292 if ($selling_option === Course::SELLING_OPTION_MEMBERSHIP || $selling_option === Course::SELLING_OPTION_ALL) {
293 $entry_box_button_logic->show_membership_btn = true;
294 }
295 }
296
297 // Checking is course can be gifted then show gift course button.
298 if (class_exists('\TutorPro\GiftCourse\InitGift') && class_exists('TutorPro\GiftCourse\GiftCourse')) {
299 $init_gift = new \TutorPro\GiftCourse\InitGift();
300 if (tutor()->has_pro && $init_gift->is_enabled() && $course_id) {
301 $can_gift_this_course = GiftCourse::can_gift_course($course_id);
302
303 if ($can_gift_this_course) {
304 $entry_box_button_logic->show_gift_course_btn = true;
305 }
306 }
307 }
308 }
309
310 return $entry_box_button_logic;
311 }
312
313 private function generate_child_element_with_parent_droip_data($extra_attributes)
314 {
315 $children_html = $this->generate_child_elements();
316 // echo "<pre>";var_dump($this->element['parentId'], $this->elements[$this->element['parentId'] ]);die;
317 if (isset($this->elements[$this->element['parentId']])) {
318 $encoded_data = $this->get_all_data_and_styles_from_element_id($this->element['parentId']);
319 $encoded_data = json_encode($encoded_data);
320 $children_html .= "<textarea style='display: none'>$encoded_data</textarea>";
321 }
322 return $this->generate_common_element(false, $children_html, $extra_attributes);
323 }
324 }
325