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.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 / VisibilityCondition.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
VisibilityCondition.php
408 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\Models\CartModel;
12 use TutorLMSDroip\ElementGenerator\CourseMetaGenerator;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Class Helper
20 * This class is used to define all helper functions.
21 */
22 class VisibilityCondition {
23
24 use CourseMetaGenerator;
25
26 public static function visibility_condition_fields( $conditions, $collection_data ) {
27 $type = $collection_data['type'];
28 $collectionType = $collection_data['collectionType'];
29 if ( $collectionType === 'posts' ) {
30 switch ( $type ) {
31 case 'courses': {
32 $conditions['post'] = array(
33 'title' => 'Course',
34 'fields' => array_merge(
35 $conditions['post']['fields'],
36 array(
37 array(
38 'source' => TDE_APP_PREFIX,
39 'value' => 'is_paid',
40 'title' => 'Paid',
41 'operator_type' => 'boolean_operators',
42 ),
43 array(
44 'source' => TDE_APP_PREFIX,
45 'value' => 'on_sale',
46 'title' => 'On Sale',
47 'operator_type' => 'boolean_operators',
48 ),
49 array(
50 'source' => TDE_APP_PREFIX,
51 'value' => 'average_rating',
52 'title' => 'Rating (Avg.)',
53 'operator_type' => 'numeric_operators',
54 'operand_type' => array_merge(
55 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
56 array(
57 'placeholder' => 'Rating',
58 )
59 ),
60 ),
61 array(
62 'source' => TDE_APP_PREFIX,
63 'value' => 'total_ratings',
64 'title' => 'Total Ratings',
65 'operator_type' => 'numeric_operators',
66 'operand_type' => array_merge(
67 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
68 array(
69 'placeholder' => 'Rating count',
70 )
71 ),
72 ),
73 array(
74 'source' => TDE_APP_PREFIX,
75 'value' => 'enroll_count',
76 'title' => 'Enrollment Count',
77 'operator_type' => 'numeric_operators',
78 'operand_type' => array_merge(
79 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
80 array(
81 'placeholder' => 'Enroll Count',
82 )
83 ),
84 ),
85 array(
86 'source' => TDE_APP_PREFIX,
87 'value' => 'student_state',
88 'title' => 'Student status',
89 'operator_type' => array(
90 array(
91 'title' => '= Equals',
92 'value' => 'user_state-is_equal',
93 ),
94 array(
95 'title' => '≠ Does not equal',
96 'value' => 'user_state-not_equal',
97 ),
98 ),
99 'operand_type' => array_merge(
100 DROIP_PLUGIN_SETTINGS['SELECT'],
101 array(
102 'options' => array(
103 array(
104 'value' => 'logged_in',
105 'title' => 'Logged in',
106 ),
107 array(
108 'value' => 'wishlisted',
109 'title' => 'Wishlisted',
110 ),
111 array(
112 'value' => 'added_in_cart',
113 'title' => 'Added in Cart',
114 ),
115 array(
116 'value' => 'enrolled',
117 'title' => 'Enrolled',
118 ),
119 array(
120 'value' => 'learner',
121 'title' => 'Learner',
122 ),
123 array(
124 'value' => 'can_retake',
125 'title' => 'Can Retake',
126 ),
127 array(
128 'value' => 'completed',
129 'title' => 'Completed',
130 ),
131 ),
132 )
133 ),
134 ),
135 // [
136 // 'source' => TDE_APP_PREFIX,
137 // 'value' => 'user_authored',
138 // 'title' => 'User authored',
139 // 'operator_type' => 'dropdown_operators',
140 // 'operand_type' => array_merge(
141 // DROIP_PLUGIN_SETTINGS['SELECT'],
142 // [
143 // 'options' => [
144 // ['value' => 'no_review', 'title' => 'No Review'],
145 // ['value' => 'current_review', 'title' => 'Current Review'],
146 // ['value' => 'no_question', 'title' => 'No Question'],
147 // ['value' => 'current_question', 'title' => 'Current Question'],
148 // ],
149 // ]
150 // ),
151 // ],
152 array(
153 'source' => TDE_APP_PREFIX,
154 'value' => 'resource_count',
155 'title' => 'Resources',
156 'operator_type' => 'numeric_operators',
157 'operand_type' => array_merge(
158 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
159 array(
160 'placeholder' => 'Resource Count',
161 )
162 ),
163 ),
164 array(
165 'source' => TDE_APP_PREFIX,
166 'value' => 'lesson_count',
167 'title' => 'Lessons',
168 'operator_type' => 'numeric_operators',
169 'operand_type' => array_merge(
170 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
171 array(
172 'placeholder' => 'Lesson Count',
173 )
174 ),
175 ),
176 array(
177 'source' => TDE_APP_PREFIX,
178 'value' => 'quiz_count',
179 'title' => 'Quizzes',
180 'operator_type' => 'numeric_operators',
181 'operand_type' => array_merge(
182 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
183 array(
184 'placeholder' => 'Quiz Count',
185 )
186 ),
187 ),
188 array(
189 'source' => TDE_APP_PREFIX,
190 'value' => 'assignments_count',
191 'title' => 'Assignments',
192 'operator_type' => 'numeric_operators',
193 'operand_type' => array_merge(
194 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
195 array(
196 'placeholder' => 'Assignment Count',
197 )
198 ),
199 ),
200 array(
201 'source' => TDE_APP_PREFIX,
202 'value' => 'is_review_enabled',
203 'title' => 'Review Enabled',
204 'operator_type' => 'boolean_operators',
205 ),
206 array(
207 'source' => TDE_APP_PREFIX,
208 'value' => 'is_qna_enabled',
209 'title' => 'QnA Enabled',
210 'operator_type' => 'boolean_operators',
211 ),
212 array(
213 'source' => TDE_APP_PREFIX,
214 'value' => 'is_certificate_enabled',
215 'title' => 'Certificate Enabled',
216 'operator_type' => 'boolean_operators',
217 ),
218 )
219 ),
220 );
221 }
222 }
223 } elseif ( $collectionType === 'user' ) {
224 switch ( $type ) {
225 case 'courses': {
226 $conditions['user'] = array(
227 'title' => 'Instructor',
228 'fields' => array_merge(
229 $conditions['user']['fields'],
230 array(
231 array(
232 'source' => TDE_APP_PREFIX,
233 'value' => 'instructor_course_count',
234 'title' => 'Course Count',
235 'operator_type' => 'numeric_operators',
236 'operand_type' => array_merge(
237 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
238 array(
239 'placeholder' => 'Course Count',
240 )
241 ),
242 ),
243 array(
244 'source' => TDE_APP_PREFIX,
245 'value' => 'instructor_student_count',
246 'title' => 'Student Count',
247 'operator_type' => 'numeric_operators',
248 'operand_type' => array_merge(
249 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
250 array(
251 'placeholder' => 'Student Count',
252 )
253 ),
254 ),
255 array(
256 'source' => TDE_APP_PREFIX,
257 'value' => 'instructor_rating',
258 'title' => 'Rating',
259 'operator_type' => 'numeric_operators',
260 'operand_type' => array_merge(
261 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
262 array(
263 'placeholder' => 'Rating',
264 )
265 ),
266 ),
267 array(
268 'source' => TDE_APP_PREFIX,
269 'value' => 'instructor_rating_count',
270 'title' => 'Rating Count',
271 'operator_type' => 'numeric_operators',
272 'operand_type' => array_merge(
273 DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'],
274 array(
275 'placeholder' => 'Rating Count',
276 )
277 ),
278 ),
279 )
280 ),
281 );
282 }
283 }
284 }
285
286 return $conditions;
287 }
288
289
290
291 public static function element_visibility_condition_check( $default_value, $condition, $options ) {
292 $source = $condition['source'];
293 $field = $condition['field']['value'];
294 $operator = $condition['operator']['value'];
295 $operand = $condition['operand']['value'];
296
297 $fieldValue = self::get_course_field_value( $field, $options );
298
299 if ( $source === TDE_APP_PREFIX ) {
300 switch ( $operator ) {
301 case 'true': {
302 return (bool) $fieldValue;
303 }
304 case 'false': {
305 return ! $fieldValue;
306 }
307 case 'is_equal': {
308 return $fieldValue == $operand;
309 }
310 case 'not_equal': {
311 return $fieldValue != $operand;
312 }
313 case 'less_than': {
314 return $fieldValue < $operand;
315 }
316 case 'greater_than': {
317 return $fieldValue > $operand;
318 }
319 case 'less_than_or_equal': {
320 return $fieldValue <= $operand;
321 }
322 case 'greater_than_or_equal': {
323 return $fieldValue >= $operand;
324 }
325 case 'user_state-is_equal': {
326 return in_array( $operand, $fieldValue );
327 }
328 case 'user_state-not_equal': {
329 return in_array( $operand, $fieldValue );
330 }
331 }
332 }
333
334 return $default_value;
335 }
336
337
338
339 private static function get_course_field_value( $field, $options ) {
340 $course_id = isset( $options['post'] ) ? $options['post']->ID : get_the_ID();
341 switch ( $field ) {
342 case 'is_paid': {
343 $is_paid_course = tutor_utils()->is_course_purchasable( $course_id );
344 return $is_paid_course;
345 }
346 case 'on_sale': {
347 $course_price = tutor_utils()->get_raw_course_price( $course_id );
348 return $course_price->sale_price != 0;
349 }
350 case 'average_rating': {
351 $average_rating = self::get_course_meta( $field, $course_id, $options );
352 $average_rating = floatval( str_replace( ',', '', $average_rating ) );
353 return $average_rating;
354 }
355 case 'total_ratings':
356 case 'enroll_count':
357 case 'resource_count':
358 case 'lesson_count':
359 case 'quiz_count':
360 case 'assignments_count': {
361 $value = self::get_course_meta( $field, $course_id, $options );
362 return $value;
363 }
364 case 'student_state': {
365 $state = array();
366 $entry_box_logic = tutor_entry_box_buttons( $course_id );
367 if ( is_user_logged_in() ) {
368 $state[] = 'logged_in';
369 if ( tutor_utils()->is_wishlisted( $course_id ) ) {
370 $state[] = 'wishlisted';
371 }
372
373 if ( $entry_box_logic->show_view_cart_btn ) {
374 $state[] = 'added_in_cart';
375 } elseif ( tutor_utils()->is_enrolled( $course_id ) ) {
376 $state[] = 'enrolled';
377 }
378
379 if ( $entry_box_logic->show_continue_learning_btn ) {
380 $state[] = 'learner';
381 } elseif ( tutor_utils()->is_completed_course( $course_id ) ) {
382 $state[] = 'completed';
383 }
384
385 if ( $entry_box_logic->show_retake_course_btn ) {
386 $state[] = 'can_retake';
387 }
388 }
389 return $state;
390 }
391 case 'is_review_enabled': {
392 $review_enabled = (bool) get_tutor_option( 'enable_course_review' );
393 return $review_enabled;
394 }
395 case 'is_qna_enabled': {
396 $enable_q_and_a_on_course = (bool) get_tutor_option( 'enable_q_and_a_on_course' );
397 $disable_qa_for_this_course = get_post_meta( $course_id, '_tutor_enable_qa', true ) != 'yes' ?? false;
398 return ! ( ! $enable_q_and_a_on_course || $disable_qa_for_this_course );
399 }
400 case 'is_certificate_enabled': {
401 $addon_config = tutor_utils()->get_addon_config( 'tutor-pro/addons/tutor-certificate/tutor-certificate.php' );
402 $is_enabled = (bool) tutor_utils()->avalue_dot( 'is_enable', $addon_config );
403 return $is_enabled;
404 }
405 }
406 }
407 }
408