Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor/includes/droip/backend/Hooks.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + /**
4 + * Preview script for html markup generator
5 + *
6 + * @package tutor-droip-elements
7 + */
8 +
9 + namespace TutorLMSDroip;
10 +
11 + use Tutor\Ecommerce\CheckoutController;
12 + use TutorLMSDroip\ElementGenerator\CourseMetaGenerator;
13 + use TutorLMSDroip\ElementGenerator\ThumbnailGenerator;
14 + use Tutor\Ecommerce\CartController;
15 + use TutorPro\Subscription\Models\PlanModel;
16 + use TutorPro\Subscription\Subscription;
17 +
18 + if (! defined('ABSPATH')) {
19 + exit; // Exit if accessed directly.
20 + }
21 +
22 + /**
23 + * Class Forntend
24 + */
25 + class Hooks
26 + {
27 +
28 + use CourseMetaGenerator;
29 + use ThumbnailGenerator;
30 +
31 + public function __construct()
32 + {
33 + add_filter('droip_post_types', [$this, 'droip_post_types'], 10, 1);
34 + add_filter('droip_collection_TUTOR_LMS_COURSES', [$this, 'droip_collection_TUTOR_LMS_COURSES'], 10, 2);
35 + add_filter('droip_collection_TUTOR_LMS_CURRICULUM', [$this, 'droip_collection_TUTOR_LMS_CURRICULUM'], 10, 2);
36 + add_filter('droip_collection_TUTOR_LMS_CART', [$this, 'droip_collection_TUTOR_LMS_CART'], 10, 2);
37 + add_filter('droip_collection_TUTOR_LMS_MEMBERSHIP', [$this, 'droip_collection_TUTOR_LMS_MEMBERSHIP'], 10, 2);
38 + add_filter('droip_dynamic_content', [$this, 'droip_dynamic_content'], 10, 2);
39 + add_filter('droip_comment-TUTOR_LMS-tutor_q_and_a', [$this, 'modify_qna_comment_data']);
40 + add_filter('droip_comment-TUTOR_LMS-tutor_course_rating', [$this, 'modify_rating_comment_data']);
41 + add_filter('droip_comment_added-TUTOR_LMS-tutor_q_and_a', [$this, 'qna_comment_added']);
42 + add_filter('droip_comment_added-TUTOR_LMS-tutor_course_rating', [$this, 'rating_comment_added']);
43 + add_filter('droip_visibility_condition_fields', [VisibilityCondition::class, 'visibility_condition_fields'], 10, 2);
44 + add_filter('droip_visibility_condition_check_' . TDE_APP_PREFIX, [VisibilityCondition::class, 'element_visibility_condition_check'], 10, 3);
45 +
46 + add_filter('droip_dynamic_content_fields', [$this, 'modify_droip_dynamic_content_fields'], 10, 2);
47 + add_filter('droip_external_collection_options', [$this, 'modify_external_collection_options'], 10, 2);
48 + add_filter('droip_external_collection_item_type', [$this, 'get_tutor_item_types'], 10, 2);
49 + add_filter('droip_element_generator_radio-button', [$this, 'droip_element_generator_radio_buttons'], 10, 2);
50 + }
51 +
52 + public function modify_droip_dynamic_content_fields($fields, $collection_data)
53 + {
54 + if (isset($collection_data['collectionType'], $collection_data['type']) && $collection_data['collectionType'] === 'posts' && $collection_data['type'] === 'courses') {
55 + if (isset($fields['typeValues'], $fields['typeValues']['content'])) {
56 + foreach ($fields['typeValues']['content'] as $key => $value) {
57 + if ($value['value'] === 'post') {
58 + $fields['typeValues']['content'][$key]['title'] = 'Course';
59 + }
60 + }
61 + }
62 + } else if (isset($collection_data['collectionType'], $collection_data['type']) && $collection_data['collectionType'] === 'TUTOR_LMS_COURSES' && $collection_data['type'] === 'TUTOR_LMS-subscriptions') {
63 + if ($collection_data['elementContentType'] === 'content') {
64 + $fields['typeValues']['content'][] = ['title' => 'Subscription', 'value' => 'TUTOR_LMS-subscriptions'];
65 + $fields['typeValuesAttr']['content']['TUTOR_LMS-subscriptions'] = [
66 + ['title' => 'Plan name', 'value' => 'TUTOR_LMS-subscriptions-plan-name'],
67 + ['title' => 'Plan price', 'value' => 'TUTOR_LMS-subscriptions-plan-price'],
68 + ['title' => 'Plan sale price', 'value' => 'TUTOR_LMS-subscriptions-plan-sale-price'],
69 + ['title' => 'Plan Recurring Interval', 'value' => 'TUTOR_LMS-subscriptions-plan-recurring-interval'],
70 + ['title' => 'Enrollment Fee', 'value' => 'TUTOR_LMS-subscriptions-enrollment-fee'],
71 + ['title' => 'Plan Short Description', 'value' => 'TUTOR_LMS-subscriptions-plan-short-description'],
72 + ];
73 + }
74 + } else if (isset($collection_data['collectionType'], $collection_data['type']) && $collection_data['collectionType'] === 'TUTOR_LMS_MEMBERSHIP' && $collection_data['type'] === 'TUTOR_LMS-membership-plans') {
75 + if ($collection_data['elementContentType'] === 'content') {
76 + $fields['typeValues']['content'][] = ['title' => 'Membership Plan', 'value' => 'TUTOR_LMS-membership-plans'];
77 + $fields['typeValuesAttr']['content']['TUTOR_LMS-membership-plans'] = [
78 + ['title' => 'Plan name', 'value' => 'TUTOR_LMS-membership-plans-plan-name'],
79 + ['title' => 'Plan price', 'value' => 'TUTOR_LMS-membership-plans-plan-price'],
80 + ['title' => 'Plan sale price', 'value' => 'TUTOR_LMS-membership-plans-plan-sale-price'],
81 + ['title' => 'Plan Recurring Interval', 'value' => 'TUTOR_LMS-membership-plans-plan-recurring-interval'],
82 + ['title' => 'Enrollment Fee', 'value' => 'TUTOR_LMS-membership-plans-enrollment-fee'],
83 + ['title' => 'Plan Short Description', 'value' => 'TUTOR_LMS-membership-plans-plan-short-description'],
84 + ['title' => 'Featured Text', 'value' => 'TUTOR_LMS-membership-plans-featured-text'],
85 + ['title' => 'Trial Fee', 'value' => 'TUTOR_LMS-membership-plans-trial-fee'],
86 + ['title' => 'Trial Interval', 'value' => 'TUTOR_LMS-membership-plans-trial-interval'],
87 + ['title' => 'Trial Value', 'value' => 'TUTOR_LMS-membership-plans-trial-value'],
88 +
89 + ];
90 + }
91 +
92 + if (isset($collection_data['elementContentType']) && $collection_data['elementContentType'] === 'anchor') {
93 + $plan_model = new PlanModel();
94 + $active_membership_plans = $plan_model->get_membership_plans(PlanModel::STATUS_ACTIVE);
95 +
96 + if (count($active_membership_plans) > 0) {
97 + $fields['typeValues']['anchor'][] = ['title' => 'Membership', 'value' => 'membership-anchor'];
98 +
99 + // get all active membership plans names
100 + $fields['typeValuesAttr']['anchor']['membership-anchor'] = [['title' => 'Link', 'value' => 'membership-link']];
101 + }
102 + }
103 + } else if (isset($collection_data['collectionType'], $collection_data['type']) && $collection_data['collectionType'] === 'TUTOR_LMS_MEMBERSHIP' && $collection_data['type'] === 'TUTOR_LMS-membership-features') {
104 + if ($collection_data['elementContentType'] === 'content') {
105 + $fields['typeValues']['content'][] = ['title' => 'Membership Features', 'value' => 'TUTOR_LMS-membership-features'];
106 + $fields['typeValuesAttr']['content']['TUTOR_LMS-membership-features'] = [
107 + ['title' => 'Content', 'value' => 'TUTOR_LMS-membership-features-feature-content'],
108 + ];
109 + }
110 + }
111 +
112 + return $fields;
113 + }
114 +
115 + public function modify_external_collection_options($options, $args)
116 + {
117 + $type = $args['type'];
118 + $collectionType = $args['collectionType'];
119 +
120 + $courses_group = [
121 + 'title' => 'Course',
122 + 'value' => 'TUTOR_LMS_COURSES',
123 + 'inherit' => true,
124 + 'default_select_type' => "TUTOR_LMS-topics",
125 + 'group' => [
126 + ['title' => 'Curriculum', 'value' => "TUTOR_LMS-topics", 'itemType' => 'post'],
127 + ['title' => 'Reviews', 'value' => "TUTOR_LMS-tutor_course_rating", 'itemType' => 'comment'],
128 + ['title' => 'Q & A', 'value' => "TUTOR_LMS-tutor_q_and_a", 'itemType' => 'comment'],
129 + ['title' => 'Announcements', 'value' => "TUTOR_LMS-announcements", 'itemType' => 'announcement'],
130 + ['title' => 'Resources', 'value' => "TUTOR_LMS-resources", 'itemType' => 'resources'],
131 + ['title' => 'Gradebooks', 'value' => "TUTOR_LMS-gradebooks", 'itemType' => 'post'],
132 + ['title' => 'Instructors', 'value' => "TUTOR_LMS-instructors", 'itemType' => 'user'],
133 + ['title' => 'Subscriptions', 'value' => "TUTOR_LMS-subscriptions", 'itemType' => 'subscriptions'],
134 + // ['title' => 'Cart', 'value' => "TUTOR_LMS-cart", 'itemType' => 'post'] //temporary commented.
135 + ],
136 + ];
137 +
138 + $curriculum_group = [
139 + 'title' => 'Curriculum',
140 + 'value' => 'TUTOR_LMS_CURRICULUM',
141 + 'inherit' => true,
142 + 'default_select_type' => "TUTOR_LMS-materials",
143 + 'group' => [
144 + ['title' => 'Materials', 'value' => "TUTOR_LMS-materials", 'itemType' => 'material'],
145 + ],
146 + ];
147 +
148 + $cart_group = [
149 + 'title' => 'Course',
150 + 'value' => 'TUTOR_LMS_COURSES',
151 + 'inherit' => true,
152 + 'default_select_type' => "TUTOR_LMS-cart",
153 + 'group' => [
154 + ['title' => 'Cart', 'value' => "TUTOR_LMS-cart", 'itemType' => 'post'],
155 + ],
156 + ];
157 +
158 + $membership_group = [
159 + 'title' => 'Membership',
160 + 'value' => 'TUTOR_LMS_MEMBERSHIP',
161 + 'inherit' => true,
162 + 'default_select_type' => "TUTOR_LMS-membership-plans",
163 + 'group' => [
164 + ['title' => 'Plans', 'value' => "TUTOR_LMS-membership-plans", 'itemType' => 'membership-plan'],
165 + ['title' => 'Features', 'value' => "TUTOR_LMS-membership-features", 'itemType' => 'membership-feature'],
166 + ],
167 + ];
168 +
169 + if ($collectionType === 'posts' && $type === 'courses') {
170 + $options[] = $courses_group;
171 + } else if ($collectionType === 'TUTOR_LMS_COURSES' && $type === 'TUTOR_LMS-topics') {
172 + $options[] = $curriculum_group;
173 + } else {
174 + // $options[] = $cart_group; //temporary commented.
175 + }
176 +
177 + $options[] = $membership_group;
178 +
179 + return $options;
180 + }
181 +
182 + public function get_tutor_item_types($oldItemType, $collectionName)
183 + {
184 + switch ($collectionName) {
185 + case 'TUTOR_LMS-tutor_course_rating':
186 + return 'comment';
187 + case 'TUTOR_LMS-materials':
188 + return 'material';
189 + case 'TUTOR_LMS-tutor_q_and_a':
190 + return 'comment';
191 + case 'TUTOR_LMS-announcements':
192 + return 'announcement';
193 + case 'TUTOR_LMS-resources':
194 + return 'resources';
195 + default:
196 + return $oldItemType;
197 + }
198 + }
199 +
200 + public function modify_rating_comment_data($value)
201 + {
202 + $moderation = tutor_utils()->get_option('enable_course_review_moderation', false, true, true);
203 + $value['comment_agent'] = 'TutorLMSPlugin';
204 + $value['comment_type'] = 'tutor_course_rating';
205 + $value['comment_approved'] = $moderation ? 'hold' : 'approved';
206 + return $value;
207 + }
208 +
209 + public function modify_qna_comment_data($value)
210 + {
211 + $value['comment_agent'] = 'TutorLMSPlugin';
212 + $value['comment_type'] = 'tutor_q_and_a';
213 + $value['comment_approved'] = 'approved';
214 + return $value;
215 + }
216 +
217 + public function rating_comment_added($value)
218 + {
219 + $comment_ID = $value['comment_ID'];
220 + $form_data = $value['form_data'];
221 + $rating = isset($form_data['rating']) ? sanitize_text_field($form_data['rating']) : 0;
222 + if (! $comment_ID) {
223 + return;
224 + }
225 +
226 + global $wpdb;
227 + $rating_info = $wpdb->get_row(
228 + $wpdb->prepare(
229 + "SELECT * FROM {$wpdb->commentmeta}
230 + WHERE comment_id = %d
231 + AND meta_key = 'tutor_rating'; ",
232 + $comment_ID
233 + )
234 + );
235 + if ($rating_info) {
236 + $wpdb->update(
237 + $wpdb->commentmeta,
238 + ['meta_value' => $rating],
239 + [
240 + 'comment_id' => $comment_ID,
241 + 'meta_key' => 'tutor_rating',
242 + ]
243 + );
244 + } else {
245 + $wpdb->insert(
246 + $wpdb->commentmeta,
247 + [
248 + 'comment_id' => $comment_ID,
249 + 'meta_key' => 'tutor_rating',
250 + 'meta_value' => $rating,
251 + ]
252 + );
253 + }
254 + do_action('tutor_after_rating_placed', $comment_ID);
255 + }
256 +
257 + public function qna_comment_added($value)
258 + {
259 + $form_data = $value['form_data'];
260 + $comment_parent = isset($form_data['comment_parent']) ? sanitize_text_field($form_data['comment_parent']) : 0;
261 + if (! $comment_parent) {
262 + return;
263 + }
264 +
265 + global $wpdb;
266 + $parent_q_author_id = $wpdb->get_var(
267 + $wpdb->prepare(
268 + "SELECT user_id
269 + FROM {$wpdb->comments}
270 + WHERE comment_ID = %d
271 + ",
272 + $comment_parent
273 + )
274 + );
275 +
276 + $asker_id = $value['user_id'];
277 + $self = $asker_id == $parent_q_author_id;
278 + update_comment_meta($parent_q_author_id, 'tutor_qna_read' . ($self ? '' : '_' . $asker_id), 0);
279 + }
280 +
281 + public function droip_post_types($post_types)
282 + {
283 + $post_types[] = [
284 + 'title' => 'Course Topics',
285 + 'value' => 'topics',
286 + ];
287 + return $post_types;
288 + }
289 + public function droip_collection_TUTOR_LMS_COURSES($value, $args)
290 + {
291 + $context = isset($args['context']) ? $args['context'] : false;
292 + if ($context && isset($context['collectionType'])) {
293 + $collectionType = $context['collectionType']; // post/tags/users
294 + if ($collectionType === 'post') {
295 + if ($args['name'] === 'TUTOR_LMS-topics') {
296 + $args['post_parent'] = $context['id'];
297 + $args['inherit'] = true;
298 + }
299 + }
300 + }
301 + if ($args['name'] === 'TUTOR_LMS-topics') {
302 + $args['name'] = 'topics';
303 + $args['item_per_page'] = -1;
304 + // $obj = HelperFunctions::get_posts($args);
305 + // $obj['itemType'] = 'post';
306 + // return $obj;
307 + return [
308 + 'data' => tutor_utils()->get_topics($args['post_parent'])->posts,
309 + 'pagination' => null,
310 + 'itemType' => 'post',
311 + ];
312 + } elseif ($args['name'] === 'TUTOR_LMS-tutor_course_rating') {
313 + $reviews = tutor_utils()->get_course_reviews($args['post_parent'], 0, 100, false, ['approved'], get_current_user_id());
314 + $reviews = $this->add_author_image_to_data($reviews);
315 + return [
316 + 'data' => $reviews,
317 + 'pagination' => [],
318 + 'itemType' => 'comment',
319 + ];
320 + } elseif ($args['name'] === 'TUTOR_LMS-materials') {
321 + $topic_contents = tutor_utils()->get_course_contents_by_topic($args['post_parent'], -1);
322 + $obj['data'] = $topic_contents->posts;
323 + $obj['pagination'] = [];
324 + $obj['itemType'] = 'post';
325 + return $obj;
326 + } elseif ($args['name'] === 'TUTOR_LMS-tutor_q_and_a') {
327 + if ($args['post_parent'] == 0) {
328 + return [
329 + 'data' => [],
330 + 'pagination' => [],
331 + 'itemType' => 'comment',
332 + ];
333 + }
334 +
335 + if (isset($args['context']) && isset($args['context']['comment_ID'])) {
336 + $q_id = $args['context']['comment_ID'];
337 + $answer = tutor_utils()->get_qa_answer_by_question($q_id);
338 + $filteredAnswers = array_values(
339 + array_filter(
340 + $answer,
341 + function ($obj) use ($q_id) {
342 + return $obj->comment_ID !== $q_id;
343 + }
344 + )
345 + );
346 + $filteredAnswers = $this->add_author_image_to_data($filteredAnswers);
347 + $filteredAnswers = $this->add_qna_reply_flag($filteredAnswers);
348 + return [
349 + 'data' => $filteredAnswers,
350 + 'pagination' => [],
351 + 'itemType' => 'comment',
352 + ];
353 + }
354 +
355 + $questions = tutor_utils()->get_qa_questions(0, 100, '', null, null, null, null, false, ['course_id' => $args['post_parent']]);
356 + $questions = $this->add_author_image_to_data($questions);
357 + return [
358 + 'data' => $questions,
359 + 'pagination' => [],
360 + 'itemType' => 'comment',
361 + ];
362 + } elseif ($args['name'] === 'TUTOR_LMS-announcements') {
363 + $announcements = tutor_utils()->get_announcements($args['post_parent']);
364 + return [
365 + 'data' => $announcements,
366 + 'pagination' => [],
367 + 'itemType' => 'announcement',
368 + ];
369 + } elseif ($args['name'] === 'TUTOR_LMS-resources') {
370 + $resources = tutor_utils()->get_attachments($args['post_parent']);
371 + return [
372 + 'data' => $resources,
373 + 'pagination' => [],
374 + 'itemType' => 'resources',
375 + ];
376 + } elseif ($args['name'] === 'TUTOR_LMS-instructors') {
377 + $instructors = tutor_utils()->get_instructors_by_course($args['post_parent']);
378 + $instructors = array_map(fn($user) => (array) array_merge((array) $user, [
379 + 'user_url' => get_author_posts_url($user->ID),
380 + 'profile_image' => get_avatar_url($user->ID),
381 + ]), $instructors);
382 +
383 + return [
384 + 'data' => $instructors,
385 + 'pagination' => [],
386 + 'itemType' => 'user',
387 + ];
388 + } elseif ($args['name'] === 'TUTOR_LMS-cart') {
389 + $cart = new CartController();
390 + $cart_items = $cart->get_cart_items();
391 + $courses = isset($cart_items['courses'], $cart_items['courses']['results']) ? $cart_items['courses']['results'] : [];
392 + return [
393 + 'data' => $courses,
394 + 'pagination' => null,
395 + 'itemType' => 'post',
396 + ];
397 + } else if ($args['name'] === 'TUTOR_LMS-subscriptions') {
398 + if (tutor()->has_pro && Subscription::is_enabled()) {
399 + $plan_model = new PlanModel();
400 + $items = $plan_model->get_subscription_plans($args['post_parent'], PlanModel::STATUS_ACTIVE); // get all active subscription plans
401 + return [
402 + 'data' => $items,
403 + 'pagination' => null,
404 + 'itemType' => 'TUTOR_LMS-subscriptions',
405 + ];
406 + }
407 + } else {
408 + return [
409 + 'data' => [],
410 + 'pagination' => [],
411 + 'itemType' => false,
412 + ];
413 + }
414 +
415 + return $value;
416 + }
417 +
418 + public function droip_collection_TUTOR_LMS_CURRICULUM($value, $args)
419 + {
420 + if ($args['name'] === 'TUTOR_LMS-materials' && isset($args['post_parent'])) {
421 + $topic_contents = tutor_utils()->get_course_contents_by_topic($args['post_parent'], -1);
422 + $obj['data'] = $topic_contents->posts;
423 + $obj['pagination'] = [];
424 + $obj['itemType'] = 'post';
425 + return $obj;
426 + } else {
427 + return [
428 + 'data' => [],
429 + 'pagination' => [],
430 + 'itemType' => false,
431 + ];
432 + }
433 +
434 + return $value;
435 + }
436 +
437 + public function droip_collection_TUTOR_LMS_MEMBERSHIP($value, $args)
438 + {
439 + if ($args['name'] === 'TUTOR_LMS-membership-plans') {
440 + $plan_model = new PlanModel();
441 + $active_membership_plans = $plan_model->get_membership_plans(PlanModel::STATUS_ACTIVE);
442 +
443 + return [
444 + 'data' => $active_membership_plans,
445 + 'pagination' => null,
446 + 'itemType' => 'membership-plan',
447 + ];
448 + } elseif ($args['name'] === 'TUTOR_LMS-membership-features' && isset($args['post_parent'])) {
449 + $plan_id = $args['post_parent'];
450 +
451 + if (isset($args['parent_item_type']) && $args['parent_item_type'] === 'membership-plan') {
452 + if (isset($args['parent_item'], $args['parent_item']->id)) {
453 + $plan_id = $args['parent_item']->id;
454 + }
455 + }
456 +
457 + $plan_model = new PlanModel();
458 + $active_membership_plans = $plan_model->get_membership_plans(PlanModel::STATUS_ACTIVE);
459 +
460 + $plan_details = null;
461 + foreach ($active_membership_plans as $plan) {
462 + if ($plan->id === $plan_id) {
463 + $plan_details = $plan;
464 + break;
465 + }
466 + }
467 +
468 + if (! $plan_details) {
469 + return [
470 + 'data' => [],
471 + 'pagination' => [],
472 + 'itemType' => false,
473 + ];
474 + }
475 +
476 + $features = isset($plan_details->description) ? json_decode($plan_details->description, true) : [];
477 +
478 +
479 + return [
480 + 'data' => $features,
481 + 'pagination' => null,
482 + 'itemType' => 'membership-feature',
483 + ];
484 + } else {
485 + return [
486 + 'data' => [],
487 + 'pagination' => [],
488 + 'itemType' => false,
489 + ];
490 + }
491 +
492 + return $value;
493 + }
494 +
495 + public function droip_dynamic_content($value, $args)
496 + {
497 + if (isset($args['dynamicContent'])) {
498 + $dynamicContent = $args['dynamicContent'];
499 +
500 + if ($dynamicContent['type'] === 'course') {
501 + $collectionItem = $args['collectionItem'];
502 + if ($collectionItem && isset($collectionItem['ID'])) {
503 + $course_id = $collectionItem['ID'];
504 + } elseif (isset($args['post_id'])) {
505 + $course_id = $args['post_id'];
506 + }
507 +
508 + if ($dynamicContent['value'] === 'thumbnail_image') {
509 + $tutor_course_img = get_tutor_course_thumbnail_src('post-thumbnail', $course_id);
510 + if ($tutor_course_img) {
511 + return $tutor_course_img;
512 + }
513 + } elseif ($dynamicContent['value'] === 'thumbnail_video') {
514 + $video_info = tutor_utils()->get_video_info($course_id);
515 + $source_key = is_object($video_info) ? 'source_' . $video_info->source : null;
516 + if ($source_key) {
517 + return ['url' => $video_info->$source_key];
518 + }
519 + }
520 + } else if ($dynamicContent['type'] === 'TUTOR_LMS-subscriptions') {
521 + $collectionItem = isset($args['collectionItem']) ? $args['collectionItem'] : false;
522 + $plan_id = false;
523 + if ($collectionItem && isset($collectionItem['id'])) {
524 + $plan_id = $collectionItem['id'];
525 + } elseif (isset($args['options'], $args['options']['TUTOR_LMS-subscriptions'])) {
526 + $plan_id = $args['options']['TUTOR_LMS-subscriptions']->id;
527 + }
528 +
529 + $plan_model = new PlanModel();
530 + $plan_details = $plan_model->get_plan($plan_id);
531 + if (!$plan_details) {
532 + return "No Plan";
533 + }
534 + if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-plan-name') {
535 + if ($plan_details) {
536 + return $plan_details->plan_name;
537 + }
538 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-plan-price') {
539 + if ($plan_details) {
540 + return tutor_get_formatted_price($plan_details->regular_price);
541 + }
542 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-plan-sale-price') {
543 + if ($plan_details) {
544 + return tutor_get_formatted_price($plan_details->sale_price);
545 + }
546 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-plan-recurring-interval') {
547 + if ($plan_details) {
548 + return isset($plan_details->recurring_interval) ? $plan_details->recurring_interval : 'N/A';
549 + }
550 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-enrollment-fee') {
551 + if ($plan_details) {
552 + return tutor_get_formatted_price($plan_details->enrollment_fee);
553 + }
554 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-plan-short-description') {
555 + if ($plan_details) {
556 + return wp_kses_post($plan_details->short_description);
557 + }
558 + }
559 + } else if ($dynamicContent['type'] === 'TUTOR_LMS-membership-plans') {
560 + $collectionItem = isset($args['collectionItem']) ? $args['collectionItem'] : false;
561 + $plan_id = false;
562 +
563 + if ($collectionItem && isset($collectionItem['id'])) {
564 + $plan_id = $collectionItem['id'];
565 + } elseif (isset($args['options'], $args['options']['membership-plan'])) {
566 + $plan_id = $args['options']['membership-plan']->id;
567 + }
568 +
569 + $plan_model = new PlanModel();
570 + $plan_details = $plan_model->get_plan($plan_id);
571 +
572 + if (!$plan_details) {
573 + return "No Plan";
574 + }
575 +
576 + if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-plan-name') {
577 + if ($plan_details) {
578 + return $plan_details->plan_name;
579 + }
580 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-plan-price') {
581 + if ($plan_details) {
582 + return tutor_get_formatted_price($plan_details->regular_price);
583 + }
584 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-plan-sale-price') {
585 + if ($plan_details) {
586 + return tutor_get_formatted_price($plan_details->sale_price);
587 + }
588 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-plan-recurring-interval') {
589 + if ($plan_details) {
590 + return isset($plan_details->recurring_interval) ? $plan_details->recurring_interval : 'N/A';
591 + }
592 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-enrollment-fee') {
593 + if ($plan_details) {
594 + return tutor_get_formatted_price($plan_details->enrollment_fee);
595 + }
596 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-plan-short-description') {
597 + if ($plan_details) {
598 + return wp_kses_post($plan_details->short_description);
599 + }
600 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-featured-text') {
601 + if ($plan_details) {
602 + return sanitize_text_field($plan_details->featured_text);
603 + }
604 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-trial-fee') {
605 + if ($plan_details) {
606 + return tutor_get_formatted_price($plan_details->trial_fee);
607 + }
608 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-trial-interval') {
609 + if ($plan_details) {
610 + return isset($plan_details->trial_interval) ? $plan_details->trial_interval : 'N/A';
611 + }
612 + } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-trial-value') {
613 + if ($plan_details) {
614 + return isset($plan_details->trial_value) ? intval($plan_details->trial_value) : 'N/A';
615 + }
616 + }
617 + } else if ($dynamicContent['type'] === 'TUTOR_LMS-membership-features') {
618 + $collectionItem = isset($args['collectionItem']) ? $args['collectionItem'] : false;
619 + $feature_id = false;
620 +
621 + if ($collectionItem && isset($collectionItem['id'])) {
622 + $feature_id = $collectionItem['id'];
623 + } elseif (isset($args['options'], $args['options']['membership-feature'])) {
624 + $feature_id = $args['options']['membership-feature']['id'];
625 + }
626 +
627 + $plan_model = new PlanModel();
628 + $active_membership_plans = $plan_model->get_membership_plans(PlanModel::STATUS_ACTIVE);
629 +
630 + foreach ($active_membership_plans as $plan) {
631 + $features = json_decode($plan->description, true);
632 + foreach ($features as $feature) {
633 + if ($feature['id'] == $feature_id) {
634 + if ($dynamicContent['value'] === 'TUTOR_LMS-membership-features-feature-content') {
635 + return isset($feature['content']) ? wp_kses_post($feature['content']) : '';
636 + }
637 + }
638 + }
639 + }
640 +
641 + return '';
642 + } else if ($dynamicContent['type'] === 'membership-anchor') {
643 + if ($dynamicContent['value'] === 'membership-link') {
644 + $collectionItem = isset($args['collectionItem']) ? $args['collectionItem'] : false;
645 +
646 + $plan_id = false;
647 + $url = '#';
648 +
649 + if (isset($args['options'], $args['options']['membership-plan'])) {
650 + $plan_id = $args['options']['membership-plan']->id;
651 + $checkout_link = CheckoutController::get_page_url();
652 +
653 + if ($checkout_link) {
654 + $url = add_query_arg('plan', $plan_id, $checkout_link);
655 + }
656 + }
657 +
658 + return $url;
659 + }
660 + }
661 + } elseif (isset($args['settings'])) {
662 + $settings = $args['settings'];
663 + $options = [];
664 + switch ($args['collectionProperties']['type']) {
665 + case 'TUTOR_LMS-tutor_course_rating':
666 + $reviews = tutor_utils()->get_course_reviews($args['collectionItem']['comment_ID'], 0, 100, false, ['approved'], get_current_user_id(), false);
667 + $options['comment'] = count($reviews) > 0 ? $reviews[0] : [];
668 + break;
669 + case 'TUTOR_LMS-materials':
670 + $options['material'] = $args['collectionItem'];
671 + break;
672 + case 'TUTOR_LMS-tutor_q_and_a':
673 + $options['comment'] = tutor_utils()->get_qa_question($args['collectionItem']['comment_ID']);
674 + break;
675 + case 'TUTOR_LMS-announcements':
676 + $options['announcement'] = get_post($args['collectionItem']['ID']);
677 + break;
678 + case 'TUTOR_LMS-resources':
679 + $resource_id = $args['collectionItem']['id'] ?? null;
680 + if ($resource_id) {
681 + $resource = tutor_utils()->get_attachment_data($resource_id);
682 + if ($resource) {
683 + $options['resources'] = $resource;
684 + }
685 + }
686 + break;
687 + case 'TUTOR_LMS-cart':
688 + $cart = new CartController();
689 + $cart_items = $cart->get_cart_items();
690 + $course_id = $args['collectionItem']['ID'];
691 + $options['post'] = [];
692 +
693 + if ($cart_items && isset($cart_items['courses']['results']) && is_array($cart_items['courses']['results'])) {
694 + foreach ($cart_items['courses']['results'] as $course) {
695 + if ($course->ID === $course_id) {
696 + $options['post'] = $course;
697 + break;
698 + }
699 + }
700 + }
701 + default:
702 + break;
703 + }
704 +
705 + $collectionItem = $args['collectionItem'];
706 + if ($collectionItem && isset($collectionItem['ID'])) {
707 + $course_id = $collectionItem['ID'];
708 + } elseif (isset($args['post_id'])) {
709 + $course_id = $args['post_id'];
710 + }
711 +
712 + $is_instructor = false;
713 + if (! $collectionItem && isset($args['templateEditContext']['collectionType'])) {
714 + $is_instructor = $args['templateEditContext']['collectionType'] === 'user';
715 + } else if (
716 + $collectionItem && $collectionItem['collectionType'] === 'users' ||
717 + $args['collectionProperties']['type'] === 'TUTOR_LMS-instructors'
718 + ) {
719 + $is_instructor = true;
720 + }
721 +
722 + if (isset($settings['course_meta_type'])) {
723 + $meta = $this->get_course_meta($settings['course_meta_type'], $course_id, $options, $settings, $is_instructor);
724 + return $this->wrap_if_meta_has_label($meta, $settings);
725 + }
726 + if (isset($settings['thumbnail_type'])) {
727 + return $this->get_course_thumbnail($settings['thumbnail_type'], $settings['thumbnail_type'], $course_id, $options);
728 + }
729 + }
730 + return $value;
731 + }
732 +
733 + public function add_author_image_to_data($list)
734 + {
735 + foreach ($list as $item) {
736 + $item->author_profile_picture = ['src' => get_avatar_url($item->user_id)];
737 + }
738 + return $list;
739 + }
740 +
741 + public function add_qna_reply_flag($list)
742 + {
743 + foreach ($list as $item) {
744 + $item->reply = true;
745 + }
746 + return $list;
747 + }
748 +
749 + public function droip_element_generator_radio_buttons($value, $options)
750 + {
751 + if (isset($options['options'], $options['options']['TUTOR_LMS-subscriptions'])) {
752 +
753 + $course_id = isset($options['options']['post']) ? $options['options']['post']->ID : get_the_ID();
754 + $attributes = isset($options['attributes']) ? $options['attributes'] : '';
755 +
756 + $tag = $options['element']['properties']['tag'] ?? 'div';
757 +
758 + $name = 'name="course_' . $course_id . '_subscription_plan"';
759 +
760 + $extra_attributes = 'data-subscription_id="' . $options['options']['TUTOR_LMS-subscriptions']->id . '"';
761 +
762 +
763 + // Set checked for first item
764 + $checked = '';
765 + if (isset($options['options']['item_index']) && $options['options']['item_index'] === 1) {
766 + $checked = 'checked="checked"';
767 + }
768 +
769 + return "<$tag $name $attributes $extra_attributes $checked />";
770 + }
771 +
772 + return $value;
773 + }
774 + }
775 +