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