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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 / Hooks.php
tutor / includes / droip / backend Last commit date
ElementGenerator 1 year ago Ajax.php 1 year ago Backend.php 1 year ago Editor.php 1 year ago Frontend.php 1 year ago Helper.php 1 year ago Hooks.php 1 year ago Iframe.php 1 year ago Pages.php 1 year ago VisibilityCondition.php 1 year ago
Hooks.php
344 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 TutorLMSDroip\ElementGenerator\CourseMetaGenerator;
12 use TutorLMSDroip\ElementGenerator\ThumbnailGenerator;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Class Forntend
20 */
21 class Hooks {
22
23 use CourseMetaGenerator;
24 use ThumbnailGenerator;
25
26 public function __construct() {
27 add_filter( 'droip_post_types', array( $this, 'droip_post_types' ), 10, 1 );
28 add_filter( 'droip_collection_TUTOR_LMS_COURSES', array( $this, 'droip_collection_TUTOR_LMS_COURSES' ), 10, 2 );
29 add_filter( 'droip_collection_TUTOR_LMS_CURRICULUM', array( $this, 'droip_collection_TUTOR_LMS_CURRICULUM' ), 10, 2 );
30 add_filter( 'droip_dynamic_content', array( $this, 'droip_dynamic_content' ), 10, 2 );
31 add_filter( 'droip_comment-TUTOR_LMS-tutor_q_and_a', array( $this, 'modify_qna_comment_data' ) );
32 add_filter( 'droip_comment-TUTOR_LMS-tutor_course_rating', array( $this, 'modify_rating_comment_data' ) );
33 add_filter( 'droip_comment_added-TUTOR_LMS-tutor_q_and_a', array( $this, 'qna_comment_added' ) );
34 add_filter( 'droip_comment_added-TUTOR_LMS-tutor_course_rating', array( $this, 'rating_comment_added' ) );
35 add_filter( 'droip_visibility_condition_fields', array( VisibilityCondition::class, 'visibility_condition_fields' ), 10, 2 );
36 add_filter( 'droip_visibility_condition_check_' . TDE_APP_PREFIX, array( VisibilityCondition::class, 'element_visibility_condition_check' ), 10, 3 );
37
38 add_filter( 'droip_dynamic_content_fields', array( $this, 'modify_droip_dynamic_content_fields' ), 10, 2 );
39 }
40
41 public function modify_droip_dynamic_content_fields( $fields, $collection_data ) {
42 if ( isset( $collection_data['collectionType'], $collection_data['type'] ) && $collection_data['collectionType'] === 'posts' && $collection_data['type'] === 'courses' ) {
43 if ( isset( $fields['typeValues'], $fields['typeValues']['content'] ) ) {
44 foreach ( $fields['typeValues']['content'] as $key => $value ) {
45 if ( $value['value'] === 'post' ) {
46 $fields['typeValues']['content'][ $key ]['title'] = 'Course';
47 }
48 }
49 }
50 }
51 return $fields;
52 }
53
54 public function modify_rating_comment_data( $value ) {
55 $moderation = tutor_utils()->get_option( 'enable_course_review_moderation', false, true, true );
56 $value['comment_agent'] = 'TutorLMSPlugin';
57 $value['comment_type'] = 'tutor_course_rating';
58 $value['comment_approved'] = $moderation ? 'hold' : 'approved';
59 return $value;
60 }
61
62 public function modify_qna_comment_data( $value ) {
63 $value['comment_agent'] = 'TutorLMSPlugin';
64 $value['comment_type'] = 'tutor_q_and_a';
65 $value['comment_approved'] = 'approved';
66 return $value;
67 }
68
69 public function rating_comment_added( $value ) {
70 $comment_ID = $value['comment_ID'];
71 $form_data = $value['form_data'];
72 $rating = isset( $form_data['rating'] ) ? sanitize_text_field( $form_data['rating'] ) : 0;
73 if ( ! $comment_ID ) {
74 return;
75 }
76
77 global $wpdb;
78 $rating_info = $wpdb->get_row(
79 $wpdb->prepare(
80 "SELECT * FROM {$wpdb->commentmeta}
81 WHERE comment_id = %d
82 AND meta_key = 'tutor_rating'; ",
83 $comment_ID
84 )
85 );
86 if ( $rating_info ) {
87 $wpdb->update(
88 $wpdb->commentmeta,
89 array( 'meta_value' => $rating ),
90 array(
91 'comment_id' => $comment_ID,
92 'meta_key' => 'tutor_rating',
93 )
94 );
95 } else {
96 $wpdb->insert(
97 $wpdb->commentmeta,
98 array(
99 'comment_id' => $comment_ID,
100 'meta_key' => 'tutor_rating',
101 'meta_value' => $rating,
102 )
103 );
104 }
105 do_action( 'tutor_after_rating_placed', $comment_ID );
106 }
107
108 public function qna_comment_added( $value ) {
109 $form_data = $value['form_data'];
110 $comment_parent = isset( $form_data['comment_parent'] ) ? sanitize_text_field( $form_data['comment_parent'] ) : 0;
111 if ( ! $comment_parent ) {
112 return;
113 }
114
115 global $wpdb;
116 $parent_q_author_id = $wpdb->get_var(
117 $wpdb->prepare(
118 "SELECT user_id
119 FROM {$wpdb->comments}
120 WHERE comment_ID = %d
121 ",
122 $comment_parent
123 )
124 );
125
126 $asker_id = $value['user_id'];
127 $self = $asker_id == $parent_q_author_id;
128 update_comment_meta( $parent_q_author_id, 'tutor_qna_read' . ( $self ? '' : '_' . $asker_id ), 0 );
129 }
130
131 public function droip_post_types( $post_types ) {
132 $post_types[] = array(
133 'title' => 'Course Topics',
134 'value' => 'topics',
135 );
136 return $post_types;
137 }
138 public function droip_collection_TUTOR_LMS_COURSES( $value, $args ) {
139 $context = isset( $args['context'] ) ? $args['context'] : false;
140 if ( $context && isset( $context['collectionType'] ) ) {
141 $collectionType = $context['collectionType']; // post/tags/users
142 if ( $collectionType === 'post' ) {
143 if ( $args['name'] === 'TUTOR_LMS-topics' ) {
144 $args['post_parent'] = $context['id'];
145 $args['inherit'] = true;
146 }
147 }
148 }
149 if ( $args['name'] === 'TUTOR_LMS-topics' ) {
150 $args['name'] = 'topics';
151 $args['item_per_page'] = -1;
152 // $obj = HelperFunctions::get_posts($args);
153 // $obj['itemType'] = 'post';
154 // return $obj;
155 return array(
156 'data' => tutor_utils()->get_topics( $args['post_parent'] )->posts,
157 'pagination' => null,
158 'itemType' => 'post',
159 );
160 } elseif ( $args['name'] === 'TUTOR_LMS-tutor_course_rating' ) {
161 $reviews = tutor_utils()->get_course_reviews( $args['post_parent'], 0, 100, false, array( 'approved' ), get_current_user_id() );
162 $reviews = $this->add_author_image_to_data( $reviews );
163 return array(
164 'data' => $reviews,
165 'pagination' => array(),
166 'itemType' => 'comment',
167 );
168 } elseif ( $args['name'] === 'TUTOR_LMS-materials' ) {
169 $topic_contents = tutor_utils()->get_course_contents_by_topic( $args['post_parent'], -1 );
170 $obj['data'] = $topic_contents->posts;
171 $obj['pagination'] = array();
172 $obj['itemType'] = 'post';
173 return $obj;
174 } elseif ( $args['name'] === 'TUTOR_LMS-tutor_q_and_a' ) {
175 if ( $args['post_parent'] == 0 ) {
176 return array(
177 'data' => array(),
178 'pagination' => array(),
179 'itemType' => 'comment',
180 );
181 }
182
183 if ( isset( $args['context'] ) && isset( $args['context']['comment_ID'] ) ) {
184 $q_id = $args['context']['comment_ID'];
185 $answer = tutor_utils()->get_qa_answer_by_question( $q_id );
186 $filteredAnswers = array_values(
187 array_filter(
188 $answer,
189 function ( $obj ) use ( $q_id ) {
190 return $obj->comment_ID !== $q_id;
191 }
192 )
193 );
194 $filteredAnswers = $this->add_author_image_to_data( $filteredAnswers );
195 $filteredAnswers = $this->add_qna_reply_flag( $filteredAnswers );
196 return array(
197 'data' => $filteredAnswers,
198 'pagination' => array(),
199 'itemType' => 'comment',
200 );
201 }
202
203 $questions = tutor_utils()->get_qa_questions( 0, 100, '', null, null, null, null, false, array( 'course_id' => $args['post_parent'] ) );
204 $questions = $this->add_author_image_to_data( $questions );
205 return array(
206 'data' => $questions,
207 'pagination' => array(),
208 'itemType' => 'comment',
209 );
210 } elseif ( $args['name'] === 'TUTOR_LMS-announcements' ) {
211 $announcements = tutor_utils()->get_announcements( $args['post_parent'] );
212 return array(
213 'data' => $announcements,
214 'pagination' => array(),
215 'itemType' => 'announcement',
216 );
217 } elseif ( $args['name'] === 'TUTOR_LMS-resources' ) {
218 $resources = tutor_utils()->get_attachments( $args['post_parent'] );
219 return array(
220 'data' => $resources,
221 'pagination' => array(),
222 'itemType' => 'resources',
223 );
224 } else {
225 return array(
226 'data' => array(),
227 'pagination' => array(),
228 'itemType' => false,
229 );
230 }
231
232 return $value;
233 }
234
235 public function droip_collection_TUTOR_LMS_CURRICULUM( $value, $args ) {
236 if ( $args['name'] === 'TUTOR_LMS-materials' && isset( $args['post_parent'] ) ) {
237 $topic_contents = tutor_utils()->get_course_contents_by_topic( $args['post_parent'], -1 );
238 $obj['data'] = $topic_contents->posts;
239 $obj['pagination'] = array();
240 $obj['itemType'] = 'post';
241 return $obj;
242 } else {
243 return array(
244 'data' => array(),
245 'pagination' => array(),
246 'itemType' => false,
247 );
248 }
249
250 return $value;
251 }
252 public function droip_dynamic_content( $value, $args ) {
253 if ( isset( $args['dynamicContent'] ) ) {
254 $dynamicContent = $args['dynamicContent'];
255 $collectionItem = $args['collectionItem'];
256
257 if ( $collectionItem && isset( $collectionItem['ID'] ) ) {
258 $course_id = $collectionItem['ID'];
259 } elseif ( isset( $args['post_id'] ) ) {
260 $course_id = $args['post_id'];
261 }
262
263 if ( $dynamicContent['type'] === 'course' ) {
264 if ( $dynamicContent['value'] === 'thumbnail_image' ) {
265 $tutor_course_img = get_tutor_course_thumbnail_src( 'post-thumbnail', $course_id );
266 if ( $tutor_course_img ) {
267 return $tutor_course_img;
268 }
269 } elseif ( $dynamicContent['value'] === 'thumbnail_video' ) {
270 $video_info = tutor_utils()->get_video_info( $course_id );
271 $source_key = is_object( $video_info ) ? 'source_' . $video_info->source : null;
272 if ( $source_key ) {
273 return array( 'url' => $video_info->$source_key );
274 }
275 }
276 }
277 } elseif ( isset( $args['settings'] ) ) {
278 $settings = $args['settings'];
279 $options = array();
280 switch ( $args['collectionProperties']['type'] ) {
281 case 'TUTOR_LMS-tutor_course_rating':
282 $reviews = tutor_utils()->get_course_reviews( $args['collectionItem']['comment_ID'], 0, 100, false, array( 'approved' ), get_current_user_id(), false );
283 $options['comment'] = count( $reviews ) > 0 ? $reviews[0] : array();
284 break;
285 case 'TUTOR_LMS-materials':
286 $options['material'] = $args['collectionItem'];
287 break;
288 case 'TUTOR_LMS-tutor_q_and_a':
289 $options['comment'] = tutor_utils()->get_qa_question( $args['collectionItem']['comment_ID'] );
290 break;
291 case 'TUTOR_LMS-announcements':
292 $options['announcement'] = get_post( $args['collectionItem']['ID'] );
293 break;
294 case 'TUTOR_LMS-resources':
295 $resource_id = $args['collectionItem']['id'] ?? null;
296 if ( $resource_id ) {
297 $resource = tutor_utils()->get_attachment_data( $resource_id );
298 if ( $resource ) {
299 $options['resources'] = $resource;
300 }
301 }
302 break;
303 default:
304 break;
305 }
306
307 $collectionItem = $args['collectionItem'];
308 if ( $collectionItem && isset( $collectionItem['ID'] ) ) {
309 $course_id = $collectionItem['ID'];
310 } elseif ( isset( $args['post_id'] ) ) {
311 $course_id = $args['post_id'];
312 }
313
314 $is_instructor = false;
315 if ( ! $collectionItem && isset( $args['templateEditContext']['collectionType'] ) ) {
316 $is_instructor = $args['templateEditContext']['collectionType'] === 'user';
317 }
318
319 if ( isset( $settings['course_meta_type'] ) ) {
320 $meta = $this->get_course_meta( $settings['course_meta_type'], $course_id, $options, $settings, $is_instructor );
321 return $this->wrap_if_meta_has_label( $meta, $settings );
322 }
323 if ( isset( $settings['thumbnail_type'] ) ) {
324 return $this->get_course_thumbnail( $settings['thumbnail_type'], $settings['thumbnail_type'], $course_id, $options );
325 }
326 }
327 return $value;
328 }
329
330 public function add_author_image_to_data( $list ) {
331 foreach ( $list as $item ) {
332 $item->author_profile_picture = array( 'src' => get_avatar_url( $item->user_id ) );
333 }
334 return $list;
335 }
336
337 public function add_qna_reply_flag( $list ) {
338 foreach ( $list as $item ) {
339 $item->reply = true;
340 }
341 return $list;
342 }
343 }
344