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