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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 5 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
363 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 $extra_attributes .= " data-lession_url=$lession_url";
149 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
150 }
151
152 case 'continue_learning_btn': {
153 if (! $entry_box_button_logic->show_continue_learning_btn) {
154 return '';
155 }
156 $is_course_completed = tutor_utils()->is_completed_course($course_id, get_current_user_id());
157 if ($is_course_completed) {
158 return '';
159 }
160 $extra_attributes .= " data-continue_learning_url='" . tutor_utils()->get_course_first_lesson() . "'";
161 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
162 }
163
164 case 'complete_course_btn': {
165 if (! $entry_box_button_logic->show_complete_course_btn) {
166 return '';
167 }
168 $is_course_completed = tutor_utils()->is_completed_course($course_id, get_current_user_id());
169 if ($is_course_completed) {
170 return '';
171 }
172
173 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
174 }
175
176 case 'retake_course_btn': {
177 if ($entry_box_button_logic->show_retake_course_btn || ($entry_box_button_logic->show_certificate_view_btn && function_exists('TUTOR_CERT'))) {
178 $extra_attributes .= " data-continue_learning_url='" . tutor_utils()->get_course_first_lesson() . "'";
179 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
180 }
181
182 return "";
183 }
184 case 'certificate_view_btn': {
185 if (! function_exists('TUTOR_CERT')) {
186 return '';
187 }
188 if (! $entry_box_button_logic->show_certificate_view_btn) {
189 return '';
190 }
191 $is_course_completed = tutor_utils()->is_completed_course($course_id, get_current_user_id());
192
193 if (! $is_course_completed) {
194 return '';
195 }
196 if (! $course_id) {
197 return '';
198 }
199
200 if (tutils()->is_addon_enabled(TUTOR_CERT()->basename)) {
201 $has_course_certificate_template = (new Certificate(true))->has_course_certificate_template($course_id);
202 if (!$has_course_certificate_template) {
203 return "";
204 }
205
206 $certificate_url = '';
207 $certificate_url = (new Certificate(true))->get_certificate($course_id);
208
209 $extra_attributes .= " data-certificate_url='" . $certificate_url . "'";
210 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
211 }
212
213 return '';
214 }
215
216 case 'subscribe_now_btn': {
217 $checkout_link = CheckoutController::get_page_url();
218
219
220 if (is_user_logged_in()) {
221 $extra_attributes .= " data-checkout_url='" . $checkout_link . "'";
222 } else {
223 $login_url = wp_login_url(wp_get_referer());
224
225 $extra_attributes .= " data-login_url='" . $login_url . "'";
226 }
227
228 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
229 }
230
231 case 'membership_btn': {
232 $pricing_page = Settings::get_pricing_page_url();
233 if ($pricing_page) {
234 $extra_attributes .= " data-pricing_url='" . $pricing_page . "'";
235 // if (is_user_logged_in()) { // removed to always direct to pricing page
236 // } else {
237 // $login_url = wp_login_url(wp_get_referer());
238
239 // $extra_attributes .= " data-login_url='" . $login_url . "'";
240 // }
241
242 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
243 }
244
245 return "";
246 }
247
248 case 'gift_course_btn': {
249 if (is_user_logged_in()) {
250 $modal_id = 'tutor-gift-this-course-modal-' . wp_generate_uuid4();
251 $extra_attributes .= " data-tutor-modal-target='$modal_id'";
252
253 $btn = $this->generate_child_element_with_parent_droip_data($extra_attributes);
254 // Capture template output
255 ob_start();
256 tutor_load_template(
257 'single.course.gift-this-course-modal',
258 array('course_id' => $course_id, 'modal_id' => $modal_id),
259 true
260 );
261
262 $modal_html = ob_get_clean();
263
264 // Return button + modal
265 return $btn . $modal_html;
266 } else {
267 // direct to login page if not logged in
268 $login_url = wp_login_url(wp_get_referer());
269 $extra_attributes .= " data-login_url='" . $login_url . "'";
270 $btn = $this->generate_child_element_with_parent_droip_data($extra_attributes);
271
272 // Return button + modal
273 return $btn;
274 }
275
276 return "";
277 }
278
279 default: {
280 return '';
281 }
282 }
283
284 return '';
285 }
286
287 private function update_entry_box_button_logic($entry_box_button_logic, $options)
288 {
289 $course_id = isset($options['post']) ? $options['post']->ID : get_the_ID();
290
291 $is_paid_course = tutor_utils()->is_course_purchasable($course_id);
292
293 if (isset($options['relation_type']) && $options['relation_type'] === 'TUTOR_LMS_CART') {
294 if ($entry_box_button_logic->show_view_cart_btn) {
295 $entry_box_button_logic->show_remove_from_cart_btn = true;
296 }
297 }
298 if (isset($options['relation_type']) && $options['relation_type'] === 'TUTOR_LMS_CART') {
299 $entry_box_button_logic->show_view_cart_btn = false;
300 }
301
302 // Remove this part. These logic come from tutor_entry_box_buttons function.
303 // if ($is_paid_course) {
304
305 // if (tutor()->has_pro && Subscription::is_enabled() && $course_id) {
306
307 // $plan_model = new PlanModel();
308 // // Checking is course has subscription plan then show buy now button.
309 // $selling_option = Course::get_selling_option($course_id);
310 // if (!$selling_option) {
311 // $selling_option = Course::SELLING_OPTION_ALL;
312 // }
313 // if ($selling_option === Course::SELLING_OPTION_SUBSCRIPTION || $selling_option === Course::SELLING_OPTION_BOTH || $selling_option === Course::SELLING_OPTION_ALL) {
314
315 // $items = $plan_model->get_subscription_plans($course_id, PlanModel::STATUS_ACTIVE);
316
317 // if (count($items) > 0) {
318 // $entry_box_button_logic->show_subscribe_now_btn = true;
319 // }
320 // }
321
322 // // Checking is course has membership plan enabled
323 // $selling_option = Course::get_selling_option($course_id);
324 // if (!$selling_option) {
325 // $selling_option = Course::SELLING_OPTION_ALL;
326 // }
327 // if ($selling_option === Course::SELLING_OPTION_MEMBERSHIP || $selling_option === Course::SELLING_OPTION_ALL) {
328 // $active_membership_plans = $plan_model->get_membership_plans(PlanModel::STATUS_ACTIVE);
329 // if (count($active_membership_plans) > 0) {
330 // $entry_box_button_logic->show_membership_btn = true;
331 // }
332 // }
333 // }
334
335 // // Checking is course can be gifted then show gift course button.
336 // if (class_exists('\TutorPro\GiftCourse\InitGift') && class_exists('TutorPro\GiftCourse\GiftCourse')) {
337 // $init_gift = new \TutorPro\GiftCourse\InitGift();
338 // if (tutor()->has_pro && $init_gift->is_enabled() && $course_id) {
339 // $can_gift_this_course = GiftCourse::can_gift_course($course_id);
340
341 // if ($can_gift_this_course) {
342 // $entry_box_button_logic->show_gift_course_btn = true;
343 // }
344 // }
345 // }
346 // }
347
348 return $entry_box_button_logic;
349 }
350
351 private function generate_child_element_with_parent_droip_data($extra_attributes)
352 {
353 $children_html = $this->generate_child_elements();
354 // echo "<pre>";var_dump($this->element['parentId'], $this->elements[$this->element['parentId'] ]);die;
355 if (isset($this->elements[$this->element['parentId']])) {
356 $encoded_data = $this->get_all_data_and_styles_from_element_id($this->element['parentId']);
357 $encoded_data = json_encode($encoded_data);
358 $children_html .= "<textarea style='display: none'>$encoded_data</textarea>";
359 }
360 return $this->generate_common_element(false, $children_html, $extra_attributes);
361 }
362 }
363