PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.9.13
Tutor LMS – eLearning and online course solution v3.9.13
3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.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 / Hooks.php
tutor / includes / droip / backend Last commit date
ElementGenerator 2 months ago Ajax.php 2 weeks ago Backend.php 1 year ago Editor.php 1 year ago Frontend.php 1 year ago Helper.php 9 months ago Hooks.php 4 months ago Iframe.php 1 year ago Pages.php 9 months ago VisibilityCondition.php 4 months ago
Hooks.php
903 lines
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 add_filter('droip_import_should_create_page', [$this, 'droip_import_should_create_page'], 10, 2);
52 add_action('droip_import_page_created', [$this, 'droip_import_page_created'], 10, 2);
53
54 // $show = apply_filters('droip_show_custom_section_' . $type, true);
55 add_filter('droip_show_custom_section_header', [$this, 'show_droip_header'], 10, 1);
56 add_filter('droip_show_custom_section_footer', [$this, 'show_droip_footer'], 10, 1);
57 }
58
59 public function show_droip_header($show)
60 {
61 $is_frontend_builder = tutor_utils()->is_tutor_frontend_dashboard( 'create-course' );
62 if ( $is_frontend_builder ) {
63 $show = false;
64 }
65 if( $this->if_spotlight_mode_for_learning_page_enabled() ) {
66 $show = false;
67 }
68 return $show;
69 }
70
71 public function show_droip_footer($show)
72 {
73 $is_frontend_builder = tutor_utils()->is_tutor_frontend_dashboard( 'create-course' );
74 if ( $is_frontend_builder ) {
75 $show = false;
76 }
77 if( $this->if_spotlight_mode_for_learning_page_enabled() ) {
78 $show = false;
79 }
80 return $show;
81 }
82
83 private function if_spotlight_mode_for_learning_page_enabled(){
84 global $wp_query;
85 if($wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && in_array( $wp_query->query_vars['post_type'], ['lesson', 'tutor_quiz', 'tutor_assignments', 'tutor-google-meet', 'tutor_zoom_meeting']) ) {
86 $enable_spotlight_mode = tutor_utils()->get_option( 'enable_spotlight_mode' );
87 if ( $enable_spotlight_mode ) {
88 return true;
89 }
90 }
91
92 return false;
93 }
94
95 public function droip_import_should_create_page($flag, $old_page_data)
96 {
97 if ($old_page_data['post_type'] === 'page') {
98 $page_slug = $old_page_data['post_name'];
99 if(in_array($page_slug, ['instructor-registration', 'student-registration'])){
100 return false;
101 }
102 if($page_slug === 'cart' && get_post(CartController::get_page_id())){
103 return false;
104 }
105 if($page_slug === 'checkout' && get_post(CheckoutController::get_page_id())){
106 return false;
107 }
108
109 $dashboard_page_id = (int) tutor_utils()->dashboard_page_id();
110 if($page_slug === 'dashboard' && get_post($dashboard_page_id)){
111 return false;
112 }
113
114 $certificate_page_id = (int) tutor_utils()->get_option('tutor_certificate_page');
115 if($page_slug === 'tutor-certificate' && get_post($certificate_page_id)){
116 return false;
117 }
118
119 $membership_page_id = (int) tutor_utils()->get_option('membership_pricing_page_id');
120 if($page_slug === 'membership-pricing' && get_post($membership_page_id)){
121 return false;
122 }
123 }
124
125 return $flag;
126 }
127
128 public function droip_import_page_created($new_page_id, $old_page_data)
129 {
130 // Clear Tutor LMS Cache after importing a page
131 if ($old_page_data['post_type'] === 'page') {
132 $page_slug = $old_page_data['post_name'];
133 if($page_slug === 'cart'){
134 tutor_utils()->update_option( CartController::PAGE_ID_OPTION_NAME, $new_page_id );
135 }
136 if($page_slug === 'checkout'){
137 tutor_utils()->update_option( CheckoutController::PAGE_ID_OPTION_NAME, $new_page_id );
138 }
139 if($page_slug === 'dashboard'){
140 tutor_utils()->update_option( 'tutor_dashboard_page_id', $new_page_id );
141 }
142 if($page_slug === 'tutor-certificate'){
143 tutor_utils()->update_option( 'tutor_certificate_page', $new_page_id );
144 }
145 if($page_slug === 'membership-pricing'){
146 tutor_utils()->update_option( 'membership_pricing_page_id', $new_page_id );
147 }
148 }
149 }
150
151 public function modify_droip_dynamic_content_fields($fields, $collection_data)
152 {
153 if (isset($collection_data['collectionType'], $collection_data['type']) && $collection_data['collectionType'] === 'posts' && $collection_data['type'] === 'courses') {
154 if (isset($fields['typeValues'], $fields['typeValues']['content'])) {
155 foreach ($fields['typeValues']['content'] as $key => $value) {
156 if ($value['value'] === 'post') {
157 $fields['typeValues']['content'][$key]['title'] = 'Course';
158 }
159 }
160 }
161 } else if (isset($collection_data['collectionType'], $collection_data['type']) && $collection_data['collectionType'] === 'TUTOR_LMS_COURSES' && $collection_data['type'] === 'TUTOR_LMS-subscriptions') {
162 if ($collection_data['elementContentType'] === 'content') {
163 $fields['typeValues']['content'][] = ['title' => 'Subscription', 'value' => 'TUTOR_LMS-subscriptions'];
164 $fields['typeValuesAttr']['content']['TUTOR_LMS-subscriptions'] = [
165 ['title' => 'Plan name', 'value' => 'TUTOR_LMS-subscriptions-plan-name'],
166 ['title' => 'Plan price', 'value' => 'TUTOR_LMS-subscriptions-plan-price'],
167 ['title' => 'Plan sale price', 'value' => 'TUTOR_LMS-subscriptions-plan-sale-price'],
168 ['title' => 'Plan Recurring Interval', 'value' => 'TUTOR_LMS-subscriptions-plan-recurring-interval'],
169 ['title' => 'Enrollment Fee', 'value' => 'TUTOR_LMS-subscriptions-enrollment-fee'],
170 ['title' => 'Plan Short Description', 'value' => 'TUTOR_LMS-subscriptions-plan-short-description'],
171 ];
172 }
173 } else if (isset($collection_data['collectionType'], $collection_data['type']) && $collection_data['collectionType'] === 'TUTOR_LMS_MEMBERSHIP' && $collection_data['type'] === 'TUTOR_LMS-membership-plans') {
174 if ($collection_data['elementContentType'] === 'content') {
175 $fields['typeValues']['content'][] = ['title' => 'Membership Plan', 'value' => 'TUTOR_LMS-membership-plans'];
176 $fields['typeValuesAttr']['content']['TUTOR_LMS-membership-plans'] = [
177 ['title' => 'Plan name', 'value' => 'TUTOR_LMS-membership-plans-plan-name'],
178 ['title' => 'Plan price', 'value' => 'TUTOR_LMS-membership-plans-plan-price'],
179 ['title' => 'Plan sale price', 'value' => 'TUTOR_LMS-membership-plans-plan-sale-price'],
180 ['title' => 'Plan Recurring Interval', 'value' => 'TUTOR_LMS-membership-plans-plan-recurring-interval'],
181 ['title' => 'Enrollment Fee', 'value' => 'TUTOR_LMS-membership-plans-enrollment-fee'],
182 ['title' => 'Plan Short Description', 'value' => 'TUTOR_LMS-membership-plans-plan-short-description'],
183 ['title' => 'Featured Text', 'value' => 'TUTOR_LMS-membership-plans-featured-text'],
184 ['title' => 'Trial Fee', 'value' => 'TUTOR_LMS-membership-plans-trial-fee'],
185 ['title' => 'Trial Interval', 'value' => 'TUTOR_LMS-membership-plans-trial-interval'],
186 ['title' => 'Trial Value', 'value' => 'TUTOR_LMS-membership-plans-trial-value'],
187
188 ];
189 }
190
191 if (isset($collection_data['elementContentType']) && $collection_data['elementContentType'] === 'anchor') {
192 $plan_model = new PlanModel();
193 $active_membership_plans = $plan_model->get_membership_plans(PlanModel::STATUS_ACTIVE);
194
195 if (count($active_membership_plans) > 0) {
196 $fields['typeValues']['anchor'][] = ['title' => 'Membership', 'value' => 'membership-anchor'];
197
198 // get all active membership plans names
199 $fields['typeValuesAttr']['anchor']['membership-anchor'] = [['title' => 'Link', 'value' => 'membership-link']];
200 }
201 }
202 } else if (isset($collection_data['collectionType'], $collection_data['type']) && $collection_data['collectionType'] === 'TUTOR_LMS_MEMBERSHIP' && $collection_data['type'] === 'TUTOR_LMS-membership-features') {
203 if ($collection_data['elementContentType'] === 'content') {
204 $fields['typeValues']['content'][] = ['title' => 'Membership Features', 'value' => 'TUTOR_LMS-membership-features'];
205 $fields['typeValuesAttr']['content']['TUTOR_LMS-membership-features'] = [
206 ['title' => 'Content', 'value' => 'TUTOR_LMS-membership-features-feature-content'],
207 ];
208 }
209 } else if (isset($collection_data['collectionType']) && $collection_data['collectionType'] === 'user' || $collection_data['collectionType'] === 'users') {
210 if ($collection_data['elementContentType'] === 'anchor') {
211 $fields['typeValuesAttr']['anchor']['author'] = array_merge(
212 $fields['typeValuesAttr']['anchor']['author'],
213 [
214 ['title' => 'Facebook', 'value' => 'TUTOR_LMS-instructor-facebook'],
215 ['title' => 'X (Twitter)', 'value' => 'TUTOR_LMS-instructor-twitter'],
216 ['title' => 'Linkedin', 'value' => 'TUTOR_LMS-instructor-linkedin'],
217 ['title' => 'Website', 'value' => 'TUTOR_LMS-instructor-website'],
218 ['title' => 'Github', 'value' => 'TUTOR_LMS-instructor-github'],
219 ]
220 );
221 }
222 }
223
224 return $fields;
225 }
226
227 public function modify_external_collection_options($options, $args)
228 {
229 $type = $args['type'];
230 $collectionType = $args['collectionType'];
231
232 $courses_group = [
233 'title' => 'Course',
234 'value' => 'TUTOR_LMS_COURSES',
235 'inherit' => true,
236 'default_select_type' => "TUTOR_LMS-topics",
237 'group' => [
238 ['title' => 'Curriculum', 'value' => "TUTOR_LMS-topics", 'itemType' => 'post'],
239 ['title' => 'Reviews', 'value' => "TUTOR_LMS-tutor_course_rating", 'itemType' => 'comment'],
240 ['title' => 'Q & A', 'value' => "TUTOR_LMS-tutor_q_and_a", 'itemType' => 'comment'],
241 ['title' => 'Announcements', 'value' => "TUTOR_LMS-announcements", 'itemType' => 'announcement'],
242 ['title' => 'Resources', 'value' => "TUTOR_LMS-resources", 'itemType' => 'resources'],
243 ['title' => 'Gradebooks', 'value' => "TUTOR_LMS-gradebooks", 'itemType' => 'post'],
244 ['title' => 'Instructors', 'value' => "TUTOR_LMS-instructors", 'itemType' => 'user'],
245 ['title' => 'Subscriptions', 'value' => "TUTOR_LMS-subscriptions", 'itemType' => 'subscriptions'],
246 // ['title' => 'Cart', 'value' => "TUTOR_LMS-cart", 'itemType' => 'post'] //temporary commented.
247 ],
248 ];
249
250 $curriculum_group = [
251 'title' => 'Curriculum',
252 'value' => 'TUTOR_LMS_CURRICULUM',
253 'inherit' => true,
254 'default_select_type' => "TUTOR_LMS-materials",
255 'group' => [
256 ['title' => 'Materials', 'value' => "TUTOR_LMS-materials", 'itemType' => 'material'],
257 ],
258 ];
259
260 $cart_group = [
261 'title' => 'Course',
262 'value' => 'TUTOR_LMS_COURSES',
263 'inherit' => true,
264 'default_select_type' => "TUTOR_LMS-cart",
265 'group' => [
266 ['title' => 'Cart', 'value' => "TUTOR_LMS-cart", 'itemType' => 'post'],
267 ],
268 ];
269
270 $membership_group = [
271 'title' => 'Membership',
272 'value' => 'TUTOR_LMS_MEMBERSHIP',
273 'inherit' => true,
274 'default_select_type' => "TUTOR_LMS-membership-plans",
275 'group' => [
276 ['title' => 'Plans', 'value' => "TUTOR_LMS-membership-plans", 'itemType' => 'membership-plan'],
277 ['title' => 'Features', 'value' => "TUTOR_LMS-membership-features", 'itemType' => 'membership-feature'],
278 ],
279 ];
280
281 if ($collectionType === 'posts' && $type === 'courses') {
282 $options[] = $courses_group;
283 } else if ($collectionType === 'TUTOR_LMS_COURSES' && $type === 'TUTOR_LMS-topics') {
284 $options[] = $curriculum_group;
285 } else {
286 // $options[] = $cart_group; //temporary commented.
287 }
288
289 $options[] = $membership_group;
290
291 return $options;
292 }
293
294 public function get_tutor_item_types($oldItemType, $collectionName)
295 {
296 switch ($collectionName) {
297 case 'TUTOR_LMS-tutor_course_rating':
298 return 'comment';
299 case 'TUTOR_LMS-materials':
300 return 'material';
301 case 'TUTOR_LMS-tutor_q_and_a':
302 return 'comment';
303 case 'TUTOR_LMS-announcements':
304 return 'announcement';
305 case 'TUTOR_LMS-resources':
306 return 'resources';
307 default:
308 return $oldItemType;
309 }
310 }
311
312 public function modify_rating_comment_data($value)
313 {
314 $moderation = tutor_utils()->get_option('enable_course_review_moderation', false, true, true);
315 $value['comment_agent'] = 'TutorLMSPlugin';
316 $value['comment_type'] = 'tutor_course_rating';
317 $value['comment_approved'] = $moderation ? 'hold' : 'approved';
318 return $value;
319 }
320
321 public function modify_qna_comment_data($value)
322 {
323 $value['comment_agent'] = 'TutorLMSPlugin';
324 $value['comment_type'] = 'tutor_q_and_a';
325 $value['comment_approved'] = 'approved';
326 return $value;
327 }
328
329 public function rating_comment_added($value)
330 {
331 $comment_ID = $value['comment_ID'];
332 $form_data = $value['form_data'];
333 $rating = isset($form_data['rating']) ? sanitize_text_field($form_data['rating']) : 0;
334 if (! $comment_ID) {
335 return;
336 }
337
338 global $wpdb;
339 $rating_info = $wpdb->get_row(
340 $wpdb->prepare(
341 "SELECT * FROM {$wpdb->commentmeta}
342 WHERE comment_id = %d
343 AND meta_key = 'tutor_rating'; ",
344 $comment_ID
345 )
346 );
347 if ($rating_info) {
348 $wpdb->update(
349 $wpdb->commentmeta,
350 ['meta_value' => $rating],
351 [
352 'comment_id' => $comment_ID,
353 'meta_key' => 'tutor_rating',
354 ]
355 );
356 } else {
357 $wpdb->insert(
358 $wpdb->commentmeta,
359 [
360 'comment_id' => $comment_ID,
361 'meta_key' => 'tutor_rating',
362 'meta_value' => $rating,
363 ]
364 );
365 }
366 do_action('tutor_after_rating_placed', $comment_ID);
367 }
368
369 public function qna_comment_added($value)
370 {
371 $form_data = $value['form_data'];
372 $comment_parent = isset($form_data['comment_parent']) ? sanitize_text_field($form_data['comment_parent']) : 0;
373 if (! $comment_parent) {
374 return;
375 }
376
377 global $wpdb;
378 $parent_q_author_id = $wpdb->get_var(
379 $wpdb->prepare(
380 "SELECT user_id
381 FROM {$wpdb->comments}
382 WHERE comment_ID = %d
383 ",
384 $comment_parent
385 )
386 );
387
388 $asker_id = $value['user_id'];
389 $self = $asker_id == $parent_q_author_id;
390 update_comment_meta($parent_q_author_id, 'tutor_qna_read' . ($self ? '' : '_' . $asker_id), 0);
391 }
392
393 public function droip_post_types($post_types)
394 {
395 $post_types[] = [
396 'title' => 'Course Topics',
397 'value' => 'topics',
398 ];
399 return $post_types;
400 }
401 public function droip_collection_TUTOR_LMS_COURSES($value, $args)
402 {
403 $context = isset($args['context']) ? $args['context'] : false;
404 if ($context && isset($context['collectionType'])) {
405 $collectionType = $context['collectionType']; // post/tags/users
406 if ($collectionType === 'post') {
407 if ($args['name'] === 'TUTOR_LMS-topics') {
408 $args['post_parent'] = $context['id'];
409 $args['inherit'] = true;
410 }
411 }
412 }
413 if ($args['name'] === 'TUTOR_LMS-topics') {
414 $args['name'] = 'topics';
415 $args['item_per_page'] = -1;
416 // $obj = HelperFunctions::get_posts($args);
417 // $obj['itemType'] = 'post';
418 // return $obj;
419 return [
420 'data' => tutor_utils()->get_topics($args['post_parent'])->posts,
421 'pagination' => null,
422 'itemType' => 'post',
423 ];
424 } elseif ($args['name'] === 'TUTOR_LMS-tutor_course_rating') {
425 $reviews = tutor_utils()->get_course_reviews($args['post_parent'], 0, 100, false, ['approved'], get_current_user_id());
426 $reviews = $this->add_author_image_to_data($reviews);
427 return [
428 'data' => $reviews,
429 'pagination' => [],
430 'itemType' => 'comment',
431 ];
432 } elseif ($args['name'] === 'TUTOR_LMS-materials') {
433 $topic_contents = tutor_utils()->get_course_contents_by_topic($args['post_parent'], -1);
434 $obj['data'] = $topic_contents->posts;
435 $obj['pagination'] = [];
436 $obj['itemType'] = 'post';
437 return $obj;
438 } elseif ($args['name'] === 'TUTOR_LMS-tutor_q_and_a') {
439 if ($args['post_parent'] == 0) {
440 return [
441 'data' => [],
442 'pagination' => [],
443 'itemType' => 'comment',
444 ];
445 }
446
447 if (isset($args['context']) && isset($args['context']['comment_ID'])) {
448 $q_id = $args['context']['comment_ID'];
449 $answer = tutor_utils()->get_qa_answer_by_question($q_id);
450 $filteredAnswers = array_values(
451 array_filter(
452 $answer,
453 function ($obj) use ($q_id) {
454 return $obj->comment_ID !== $q_id;
455 }
456 )
457 );
458 $filteredAnswers = $this->add_author_image_to_data($filteredAnswers);
459 $filteredAnswers = $this->add_qna_reply_flag($filteredAnswers);
460 return [
461 'data' => $filteredAnswers,
462 'pagination' => [],
463 'itemType' => 'comment',
464 ];
465 }
466
467 $questions = tutor_utils()->get_qa_questions(0, 100, '', null, null, null, null, false, ['course_id' => $args['post_parent']]);
468 $questions = $this->add_author_image_to_data($questions);
469 return [
470 'data' => $questions,
471 'pagination' => [],
472 'itemType' => 'comment',
473 ];
474 } elseif ($args['name'] === 'TUTOR_LMS-announcements') {
475 $announcements = tutor_utils()->get_announcements($args['post_parent']);
476 return [
477 'data' => $announcements,
478 'pagination' => [],
479 'itemType' => 'announcement',
480 ];
481 } elseif ($args['name'] === 'TUTOR_LMS-resources') {
482 $resources = tutor_utils()->get_attachments($args['post_parent']);
483 return [
484 'data' => $resources,
485 'pagination' => [],
486 'itemType' => 'resources',
487 ];
488 } elseif ($args['name'] === 'TUTOR_LMS-instructors') {
489 $instructors = tutor_utils()->get_instructors_by_course($args['post_parent']);
490 $instructors = array_map(fn($user) => (array) array_merge((array) $user, [
491 'user_url' => get_author_posts_url($user->ID),
492 'profile_image' => get_avatar_url($user->ID),
493 ]), $instructors);
494
495 return [
496 'data' => $instructors,
497 'pagination' => [],
498 'itemType' => 'user',
499 ];
500 } elseif ($args['name'] === 'TUTOR_LMS-cart') {
501 $cart = new CartController();
502 $cart_items = $cart->get_cart_items();
503 $courses = isset($cart_items['courses'], $cart_items['courses']['results']) ? $cart_items['courses']['results'] : [];
504 return [
505 'data' => $courses,
506 'pagination' => null,
507 'itemType' => 'post',
508 ];
509 } else if ($args['name'] === 'TUTOR_LMS-subscriptions') {
510 if (tutor()->has_pro && Subscription::is_enabled()) {
511 $plan_model = new PlanModel();
512 $items = $plan_model->get_subscription_plans($args['post_parent'], PlanModel::STATUS_ACTIVE); // get all active subscription plans
513 return [
514 'data' => $items,
515 'pagination' => null,
516 'itemType' => 'TUTOR_LMS-subscriptions',
517 ];
518 }
519 } else {
520 return [
521 'data' => [],
522 'pagination' => [],
523 'itemType' => false,
524 ];
525 }
526
527 return $value;
528 }
529
530 public function droip_collection_TUTOR_LMS_CURRICULUM($value, $args)
531 {
532 if ($args['name'] === 'TUTOR_LMS-materials' && isset($args['post_parent'])) {
533 $topic_contents = tutor_utils()->get_course_contents_by_topic($args['post_parent'], -1);
534 $obj['data'] = $topic_contents->posts;
535 $obj['pagination'] = [];
536 $obj['itemType'] = 'post';
537 return $obj;
538 } else {
539 return [
540 'data' => [],
541 'pagination' => [],
542 'itemType' => false,
543 ];
544 }
545
546 return $value;
547 }
548
549 public function droip_collection_TUTOR_LMS_MEMBERSHIP($value, $args)
550 {
551 if ($args['name'] === 'TUTOR_LMS-membership-plans') {
552 $plan_model = new PlanModel();
553 $active_membership_plans = $plan_model->get_membership_plans(PlanModel::STATUS_ACTIVE);
554
555 return [
556 'data' => $active_membership_plans,
557 'pagination' => null,
558 'itemType' => 'membership-plan',
559 ];
560 } elseif ($args['name'] === 'TUTOR_LMS-membership-features' && isset($args['post_parent'])) {
561 $plan_id = $args['post_parent'];
562
563 if (isset($args['parent_item_type']) && $args['parent_item_type'] === 'membership-plan') {
564 if (isset($args['parent_item'], $args['parent_item']->id)) {
565 $plan_id = $args['parent_item']->id;
566 }
567 }
568
569 $plan_model = new PlanModel();
570 $active_membership_plans = $plan_model->get_membership_plans(PlanModel::STATUS_ACTIVE);
571
572 $plan_details = null;
573 foreach ($active_membership_plans as $plan) {
574 if ($plan->id === $plan_id) {
575 $plan_details = $plan;
576 break;
577 }
578 }
579
580 if (! $plan_details) {
581 return [
582 'data' => [],
583 'pagination' => [],
584 'itemType' => false,
585 ];
586 }
587
588 $features = isset($plan_details->description) ? json_decode($plan_details->description, true) : [];
589
590
591 return [
592 'data' => $features,
593 'pagination' => null,
594 'itemType' => 'membership-feature',
595 ];
596 } else {
597 return [
598 'data' => [],
599 'pagination' => [],
600 'itemType' => false,
601 ];
602 }
603
604 return $value;
605 }
606
607 public function droip_dynamic_content($value, $args)
608 {
609 if (isset($args['dynamicContent'])) {
610 $dynamicContent = $args['dynamicContent'];
611
612 if ($dynamicContent['type'] === 'course') {
613 $collectionItem = $args['collectionItem'];
614 if ($collectionItem && isset($collectionItem['ID'])) {
615 $course_id = $collectionItem['ID'];
616 } elseif (isset($args['post_id'])) {
617 $course_id = $args['post_id'];
618 }
619
620 if ($dynamicContent['value'] === 'thumbnail_image') {
621 $tutor_course_img = get_tutor_course_thumbnail_src('post-thumbnail', $course_id);
622 if ($tutor_course_img) {
623 return $tutor_course_img;
624 }
625 } elseif ($dynamicContent['value'] === 'thumbnail_video') {
626 $video_info = tutor_utils()->get_video_info($course_id);
627 $source_key = is_object($video_info) ? 'source_' . $video_info->source : null;
628 if ($source_key) {
629 return ['url' => $video_info->$source_key];
630 }
631 }
632 } else if ($dynamicContent['type'] === 'TUTOR_LMS-subscriptions') {
633 $collectionItem = isset($args['collectionItem']) ? $args['collectionItem'] : false;
634 $plan_id = false;
635 if ($collectionItem && isset($collectionItem['id'])) {
636 $plan_id = $collectionItem['id'];
637 } elseif (isset($args['options'], $args['options']['TUTOR_LMS-subscriptions'])) {
638 $plan_id = $args['options']['TUTOR_LMS-subscriptions']->id;
639 }
640
641 $plan_model = new PlanModel();
642 $plan_details = $plan_model->get_plan($plan_id);
643 if (!$plan_details) {
644 return "No Plan";
645 }
646 if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-plan-name') {
647 if ($plan_details) {
648 return $plan_details->plan_name;
649 }
650 } else if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-plan-price') {
651 if ($plan_details) {
652 return tutor_get_formatted_price($plan_details->regular_price);
653 }
654 } else if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-plan-sale-price') {
655 if ($plan_details) {
656 return tutor_get_formatted_price($plan_details->sale_price);
657 }
658 } else if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-plan-recurring-interval') {
659 if ($plan_details) {
660 return isset($plan_details->recurring_interval) ? $plan_details->recurring_interval : 'N/A';
661 }
662 } else if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-enrollment-fee') {
663 if ($plan_details) {
664 return tutor_get_formatted_price($plan_details->enrollment_fee);
665 }
666 } else if ($dynamicContent['value'] === 'TUTOR_LMS-subscriptions-plan-short-description') {
667 if ($plan_details) {
668 return wp_kses_post($plan_details->short_description);
669 }
670 }
671 } else if ($dynamicContent['type'] === 'TUTOR_LMS-membership-plans') {
672 $collectionItem = isset($args['collectionItem']) ? $args['collectionItem'] : false;
673 $plan_id = false;
674
675 if ($collectionItem && isset($collectionItem['id'])) {
676 $plan_id = $collectionItem['id'];
677 } elseif (isset($args['options'], $args['options']['membership-plan'])) {
678 $plan_id = $args['options']['membership-plan']->id;
679 }
680
681 $plan_model = new PlanModel();
682 $plan_details = $plan_model->get_plan($plan_id);
683
684 if (!$plan_details) {
685 return "No Plan";
686 }
687
688 if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-plan-name') {
689 if ($plan_details) {
690 return $plan_details->plan_name;
691 }
692 } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-plan-price') {
693 if ($plan_details) {
694 return tutor_get_formatted_price($plan_details->regular_price);
695 }
696 } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-plan-sale-price') {
697 if ($plan_details) {
698 return tutor_get_formatted_price($plan_details->sale_price);
699 }
700 } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-plan-recurring-interval') {
701 if ($plan_details) {
702 return isset($plan_details->recurring_interval) ? $plan_details->recurring_interval : 'N/A';
703 }
704 } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-enrollment-fee') {
705 if ($plan_details) {
706 return tutor_get_formatted_price($plan_details->enrollment_fee);
707 }
708 } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-plan-short-description') {
709 if ($plan_details) {
710 return wp_kses_post($plan_details->short_description);
711 }
712 } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-featured-text') {
713 if ($plan_details) {
714 return sanitize_text_field($plan_details->featured_text);
715 }
716 } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-trial-fee') {
717 if ($plan_details) {
718 return tutor_get_formatted_price($plan_details->trial_fee);
719 }
720 } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-trial-interval') {
721 if ($plan_details) {
722 return isset($plan_details->trial_interval) ? $plan_details->trial_interval : 'N/A';
723 }
724 } else if ($dynamicContent['value'] === 'TUTOR_LMS-membership-plans-trial-value') {
725 if ($plan_details) {
726 return isset($plan_details->trial_value) ? intval($plan_details->trial_value) : 'N/A';
727 }
728 }
729 } else if ($dynamicContent['type'] === 'TUTOR_LMS-membership-features') {
730 $collectionItem = isset($args['collectionItem']) ? $args['collectionItem'] : false;
731 $feature_id = false;
732
733 if ($collectionItem && isset($collectionItem['id'])) {
734 $feature_id = $collectionItem['id'];
735 } elseif (isset($args['options'], $args['options']['membership-feature'])) {
736 $feature_id = $args['options']['membership-feature']['id'];
737 }
738
739 $plan_model = new PlanModel();
740 $active_membership_plans = $plan_model->get_membership_plans(PlanModel::STATUS_ACTIVE);
741
742 foreach ($active_membership_plans as $plan) {
743 $features = json_decode($plan->description, true);
744 foreach ($features as $feature) {
745 if ($feature['id'] == $feature_id) {
746 if ($dynamicContent['value'] === 'TUTOR_LMS-membership-features-feature-content') {
747 return isset($feature['content']) ? wp_kses_post($feature['content']) : '';
748 }
749 }
750 }
751 }
752
753 return '';
754 } else if ($dynamicContent['type'] === 'membership-anchor') {
755 if ($dynamicContent['value'] === 'membership-link') {
756 $collectionItem = isset($args['collectionItem']) ? $args['collectionItem'] : false;
757
758 $plan_id = false;
759 $url = '#';
760
761 if (is_user_logged_in() && isset($args['options'], $args['options']['membership-plan'])) {
762 $plan_id = $args['options']['membership-plan']->id;
763 $checkout_link = CheckoutController::get_page_url();
764
765 if ($checkout_link) {
766 $url = add_query_arg('plan', $plan_id, $checkout_link);
767 }
768 } else if (!is_user_logged_in()) {
769 $url = wp_login_url(wp_get_referer());
770 }
771
772 return $url;
773 }
774 } else if ($dynamicContent['type'] === 'author') {
775 $user_id = isset($args['options'], $args['options']['user']) ? $args['options']['user']['ID'] : false;
776
777 if ($dynamicContent['value'] === 'TUTOR_LMS-instructor-facebook') {
778 return get_user_meta($user_id, '_tutor_profile_facebook', true);
779 } else if ($dynamicContent['value'] === 'TUTOR_LMS-instructor-twitter') {
780 return get_user_meta($user_id, '_tutor_profile_twitter', true);
781 } else if ($dynamicContent['value'] === 'TUTOR_LMS-instructor-linkedin') {
782 return get_user_meta($user_id, '_tutor_profile_linkedin', true);
783 } else if ($dynamicContent['value'] === 'TUTOR_LMS-instructor-website') {
784 return get_user_meta($user_id, '_tutor_profile_website', true);
785 } else if ($dynamicContent['value'] === 'TUTOR_LMS-instructor-github') {
786 return get_user_meta($user_id, '_tutor_profile_github', true);
787 }
788 }
789 } elseif (isset($args['settings'])) {
790 $settings = $args['settings'];
791 $options = [];
792 switch ($args['collectionProperties']['type']) {
793 case 'TUTOR_LMS-tutor_course_rating':
794 $reviews = tutor_utils()->get_course_reviews($args['collectionItem']['comment_ID'], 0, 100, false, ['approved'], get_current_user_id(), false);
795 $options['comment'] = count($reviews) > 0 ? $reviews[0] : [];
796 break;
797 case 'TUTOR_LMS-materials':
798 $options['material'] = $args['collectionItem'];
799 break;
800 case 'TUTOR_LMS-tutor_q_and_a':
801 $options['comment'] = tutor_utils()->get_qa_question($args['collectionItem']['comment_ID']);
802 break;
803 case 'TUTOR_LMS-announcements':
804 $options['announcement'] = get_post($args['collectionItem']['ID']);
805 break;
806 case 'TUTOR_LMS-resources':
807 $resource_id = $args['collectionItem']['id'] ?? null;
808 if ($resource_id) {
809 $resource = tutor_utils()->get_attachment_data($resource_id);
810 if ($resource) {
811 $options['resources'] = $resource;
812 }
813 }
814 break;
815 case 'TUTOR_LMS-cart':
816 $cart = new CartController();
817 $cart_items = $cart->get_cart_items();
818 $course_id = $args['collectionItem']['ID'];
819 $options['post'] = [];
820
821 if ($cart_items && isset($cart_items['courses']['results']) && is_array($cart_items['courses']['results'])) {
822 foreach ($cart_items['courses']['results'] as $course) {
823 if ($course->ID === $course_id) {
824 $options['post'] = $course;
825 break;
826 }
827 }
828 }
829 default:
830 break;
831 }
832
833 $collectionItem = $args['collectionItem'];
834 if ($collectionItem && isset($collectionItem['ID'])) {
835 $course_id = $collectionItem['ID'];
836 } elseif (isset($args['post_id'])) {
837 $course_id = $args['post_id'];
838 }
839
840 $is_instructor = false;
841 if (! $collectionItem && isset($args['templateEditContext']['collectionType'])) {
842 $is_instructor = $args['templateEditContext']['collectionType'] === 'user';
843 } else if (
844 $collectionItem && $collectionItem['collectionType'] === 'users' ||
845 $args['collectionProperties']['type'] === 'TUTOR_LMS-instructors'
846 ) {
847 $is_instructor = true;
848 }
849
850 if (isset($settings['course_meta_type'])) {
851 $meta = $this->get_course_meta($settings['course_meta_type'], $course_id, $options, $settings, $is_instructor);
852 return $this->wrap_if_meta_has_label($meta, $settings);
853 }
854 if (isset($settings['thumbnail_type'])) {
855 return $this->get_course_thumbnail($settings['thumbnail_type'], $settings['thumbnail_type'], $course_id, $options);
856 }
857 }
858 return $value;
859 }
860
861 public function add_author_image_to_data($list)
862 {
863 foreach ($list as $item) {
864 $item->author_profile_picture = ['src' => get_avatar_url($item->user_id)];
865 }
866 return $list;
867 }
868
869 public function add_qna_reply_flag($list)
870 {
871 foreach ($list as $item) {
872 $item->reply = true;
873 }
874 return $list;
875 }
876
877 public function droip_element_generator_radio_buttons($value, $options)
878 {
879 if (isset($options['options'], $options['options']['TUTOR_LMS-subscriptions'])) {
880
881 $course_id = isset($options['options']['post']) ? $options['options']['post']->ID : get_the_ID();
882 $attributes = isset($options['attributes']) ? $options['attributes'] : '';
883
884 $tag = $options['element']['properties']['tag'] ?? 'div';
885
886 $name = 'name="course_' . $course_id . '_subscription_plan"';
887
888 $extra_attributes = 'data-subscription_id="' . $options['options']['TUTOR_LMS-subscriptions']->id . '"';
889
890
891 // Set checked for first item
892 $checked = '';
893 if (isset($options['options']['item_index']) && $options['options']['item_index'] === 1) {
894 $checked = 'checked="checked"';
895 }
896
897 return "<$tag $name $attributes $extra_attributes $checked />";
898 }
899
900 return $value;
901 }
902 }
903