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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
333 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 if (tutils()->is_addon_enabled(TUTOR_CERT()->basename)) {
179 $has_course_certificate_template = (new Certificate(true))->has_course_certificate_template($course_id);
180 if (!$has_course_certificate_template) {
181 return "";
182 }
183
184 $certificate_url = '';
185 $certificate_url = (new Certificate(true))->get_certificate($course_id);
186
187 $extra_attributes .= " data-certificate_url='" . $certificate_url . "'";
188 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
189 }
190
191 return '';
192 }
193
194 case 'subscribe_now_btn': {
195 $checkout_link = CheckoutController::get_page_url();
196
197
198 if (is_user_logged_in()) {
199 $extra_attributes .= " data-checkout_url='" . $checkout_link . "'";
200 } else {
201 $login_url = wp_login_url(wp_get_referer());
202
203 $extra_attributes .= " data-login_url='" . $login_url . "'";
204 }
205
206 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
207 }
208
209 case 'membership_btn': {
210 $pricing_page = Settings::get_pricing_page_url();
211 if ($pricing_page) {
212 $extra_attributes .= " data-pricing_url='" . $pricing_page . "'";
213 return $this->generate_child_element_with_parent_droip_data($extra_attributes);
214 }
215
216 return "";
217 }
218
219 case 'gift_course_btn': {
220 if (is_user_logged_in()) {
221 $extra_attributes .= " data-tutor-modal-target='tutor-gift-this-course-modal'";
222
223 $btn = $this->generate_child_element_with_parent_droip_data($extra_attributes);
224
225 // Capture template output
226 ob_start();
227 tutor_load_template(
228 'single.course.gift-this-course-modal',
229 array('course_id' => $course_id),
230 true
231 );
232
233 $modal_html = ob_get_clean();
234
235 // Return button + modal
236 return $btn . $modal_html;
237 } else {
238 // direct to login page if not logged in
239 $login_url = wp_login_url(wp_get_referer());
240 $extra_attributes .= " data-login_url='" . $login_url . "'";
241 $btn = $this->generate_child_element_with_parent_droip_data($extra_attributes);
242
243 // Return button + modal
244 return $btn;
245 }
246
247 return "";
248 }
249
250 default: {
251 return '';
252 }
253 }
254
255 return '';
256 }
257
258 private function update_entry_box_button_logic($entry_box_button_logic, $options)
259 {
260 $course_id = isset($options['post']) ? $options['post']->ID : get_the_ID();
261
262 $is_paid_course = tutor_utils()->is_course_purchasable($course_id);
263
264 if (isset($options['relation_type']) && $options['relation_type'] === 'TUTOR_LMS_CART') {
265 if ($entry_box_button_logic->show_view_cart_btn) {
266 $entry_box_button_logic->show_remove_from_cart_btn = true;
267 }
268 }
269 if (isset($options['relation_type']) && $options['relation_type'] === 'TUTOR_LMS_CART') {
270 $entry_box_button_logic->show_view_cart_btn = false;
271 }
272
273 if ($is_paid_course) {
274
275 if (tutor()->has_pro && Subscription::is_enabled() && $course_id) {
276
277
278 // Checking is course has subscription plan then show buy now button.
279 $selling_option = Course::get_selling_option($course_id);
280 if (!$selling_option) {
281 $selling_option = Course::SELLING_OPTION_ALL;
282 }
283 if ($selling_option === Course::SELLING_OPTION_SUBSCRIPTION || $selling_option === Course::SELLING_OPTION_BOTH || $selling_option === Course::SELLING_OPTION_ALL) {
284 $plan_model = new PlanModel();
285 $items = $plan_model->get_subscription_plans($course_id, PlanModel::STATUS_ACTIVE);
286
287 if (count($items) > 0) {
288 $entry_box_button_logic->show_subscribe_now_btn = true;
289 }
290 }
291
292 // Checking is course has membership plan enabled
293 $selling_option = Course::get_selling_option($course_id);
294 if (!$selling_option) {
295 $selling_option = Course::SELLING_OPTION_ALL;
296 }
297 if ($selling_option === Course::SELLING_OPTION_MEMBERSHIP || $selling_option === Course::SELLING_OPTION_ALL) {
298 $active_membership_plans = $plan_model->get_membership_plans(PlanModel::STATUS_ACTIVE);
299 if (count($active_membership_plans) > 0) {
300 $entry_box_button_logic->show_membership_btn = true;
301 }
302 }
303 }
304
305 // Checking is course can be gifted then show gift course button.
306 if (class_exists('\TutorPro\GiftCourse\InitGift') && class_exists('TutorPro\GiftCourse\GiftCourse')) {
307 $init_gift = new \TutorPro\GiftCourse\InitGift();
308 if (tutor()->has_pro && $init_gift->is_enabled() && $course_id) {
309 $can_gift_this_course = GiftCourse::can_gift_course($course_id);
310
311 if ($can_gift_this_course) {
312 $entry_box_button_logic->show_gift_course_btn = true;
313 }
314 }
315 }
316 }
317
318 return $entry_box_button_logic;
319 }
320
321 private function generate_child_element_with_parent_droip_data($extra_attributes)
322 {
323 $children_html = $this->generate_child_elements();
324 // echo "<pre>";var_dump($this->element['parentId'], $this->elements[$this->element['parentId'] ]);die;
325 if (isset($this->elements[$this->element['parentId']])) {
326 $encoded_data = $this->get_all_data_and_styles_from_element_id($this->element['parentId']);
327 $encoded_data = json_encode($encoded_data);
328 $children_html .= "<textarea style='display: none'>$encoded_data</textarea>";
329 }
330 return $this->generate_common_element(false, $children_html, $extra_attributes);
331 }
332 }
333