ElementGenerator
7 months ago
Ajax.php
10 months ago
Backend.php
1 year ago
Editor.php
1 year ago
Frontend.php
1 year ago
Helper.php
9 months ago
Hooks.php
7 months ago
Iframe.php
1 year ago
Pages.php
9 months ago
VisibilityCondition.php
7 months ago
VisibilityCondition.php
852 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\Course; |
| 12 | use Tutor\Models\CartModel; |
| 13 | use TUTOR_CERT\Certificate; |
| 14 | use TutorLMSDroip\ElementGenerator\CourseMetaGenerator; |
| 15 | |
| 16 | if (! defined('ABSPATH')) { |
| 17 | exit; // Exit if accessed directly. |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Class Helper |
| 22 | * This class is used to define all helper functions. |
| 23 | */ |
| 24 | class VisibilityCondition |
| 25 | { |
| 26 | |
| 27 | use CourseMetaGenerator; |
| 28 | |
| 29 | public static function visibility_condition_fields($conditions, $collection_data) |
| 30 | { |
| 31 | $type = $collection_data['type']; |
| 32 | $collectionType = $collection_data['collectionType']; |
| 33 | if ($collectionType === 'posts') { |
| 34 | switch ($type) { |
| 35 | case 'courses': { |
| 36 | $conditions = self::get_course_type_conditions($conditions); |
| 37 | break; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | $conditions = self::get_lms_setting_type_conditions($conditions); |
| 42 | } elseif ($collectionType === 'user') { |
| 43 | switch ($type) { |
| 44 | case 'courses': { |
| 45 | $conditions['user'] = array( |
| 46 | 'title' => 'Instructor', |
| 47 | 'fields' => array_merge( |
| 48 | $conditions['user']['fields'], |
| 49 | array( |
| 50 | array( |
| 51 | 'source' => TDE_APP_PREFIX, |
| 52 | 'value' => 'instructor_course_count', |
| 53 | 'title' => 'Course Count', |
| 54 | 'operator_type' => 'numeric_operators', |
| 55 | 'operand_type' => array_merge( |
| 56 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 57 | array( |
| 58 | 'placeholder' => 'Course Count', |
| 59 | ) |
| 60 | ), |
| 61 | ), |
| 62 | array( |
| 63 | 'source' => TDE_APP_PREFIX, |
| 64 | 'value' => 'instructor_student_count', |
| 65 | 'title' => 'Student Count', |
| 66 | 'operator_type' => 'numeric_operators', |
| 67 | 'operand_type' => array_merge( |
| 68 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 69 | array( |
| 70 | 'placeholder' => 'Student Count', |
| 71 | ) |
| 72 | ), |
| 73 | ), |
| 74 | array( |
| 75 | 'source' => TDE_APP_PREFIX, |
| 76 | 'value' => 'instructor_rating', |
| 77 | 'title' => 'Rating', |
| 78 | 'operator_type' => 'numeric_operators', |
| 79 | 'operand_type' => array_merge( |
| 80 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 81 | array( |
| 82 | 'placeholder' => 'Rating', |
| 83 | ) |
| 84 | ), |
| 85 | ), |
| 86 | array( |
| 87 | 'source' => TDE_APP_PREFIX, |
| 88 | 'value' => 'instructor_rating_count', |
| 89 | 'title' => 'Rating Count', |
| 90 | 'operator_type' => 'numeric_operators', |
| 91 | 'operand_type' => array_merge( |
| 92 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 93 | array( |
| 94 | 'placeholder' => 'Rating Count', |
| 95 | ) |
| 96 | ), |
| 97 | ), |
| 98 | ) |
| 99 | ), |
| 100 | ); |
| 101 | } |
| 102 | } |
| 103 | } else { |
| 104 | switch ($type) { |
| 105 | case 'TUTOR_LMS-tutor_course_rating': { |
| 106 | $conditions = self::get_course_type_conditions($conditions); |
| 107 | break; |
| 108 | } |
| 109 | |
| 110 | case 'TUTOR_LMS-subscriptions': { |
| 111 | $conditions = self::get_subscription_type_conditions($conditions); |
| 112 | break; |
| 113 | } |
| 114 | |
| 115 | case 'TUTOR_LMS-membership-plans': { |
| 116 | $conditions = self::get_membership_type_conditions($conditions); |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | case 'TUTOR_LMS-membership-features': { |
| 121 | $conditions = self::get_membership_features_type_conditions($conditions); |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | return $conditions; |
| 128 | } |
| 129 | |
| 130 | private static function get_subscription_type_conditions($conditions) |
| 131 | { |
| 132 | if (!isset($conditions['post']['fields'])) { |
| 133 | $conditions['post']['fields'] = array(); |
| 134 | } |
| 135 | $conditions['post'] = array( |
| 136 | 'title' => 'Subscription', |
| 137 | 'fields' => array_merge( |
| 138 | $conditions['post']['fields'], |
| 139 | array( |
| 140 | |
| 141 | // recurring_interval |
| 142 | array( |
| 143 | 'source' => TDE_APP_PREFIX, |
| 144 | 'value' => 'recurring_interval', |
| 145 | 'title' => 'Recurring Interval', |
| 146 | 'operator_type' => 'dropdown_operators', |
| 147 | 'operand_type' => array_merge( |
| 148 | DROIP_PLUGIN_SETTINGS['SELECT'], |
| 149 | array( |
| 150 | 'options' => array( |
| 151 | array( |
| 152 | 'value' => 'day', |
| 153 | 'title' => 'Day', |
| 154 | ), |
| 155 | array( |
| 156 | 'value' => 'week', |
| 157 | 'title' => 'Week', |
| 158 | ), |
| 159 | array( |
| 160 | 'value' => 'month', |
| 161 | 'title' => 'Month', |
| 162 | ), |
| 163 | array( |
| 164 | 'value' => 'year', |
| 165 | 'title' => 'Year', |
| 166 | ), |
| 167 | ), |
| 168 | ), |
| 169 | ), |
| 170 | ), |
| 171 | |
| 172 | // enrollment_fee |
| 173 | array( |
| 174 | 'source' => TDE_APP_PREFIX, |
| 175 | 'value' => 'enrollment_fee', |
| 176 | 'title' => 'Enrollment Fee', |
| 177 | 'operator_type' => 'numeric_operators', |
| 178 | 'operand_type' => array_merge( |
| 179 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 180 | array( |
| 181 | 'placeholder' => 'Enrollment Fee', |
| 182 | ), |
| 183 | ), |
| 184 | ), |
| 185 | |
| 186 | // provide_certificate DEFAULT 1, -- 0 or 1 |
| 187 | array( |
| 188 | 'source' => TDE_APP_PREFIX, |
| 189 | 'value' => 'provide_certificate', |
| 190 | 'title' => 'Provide Certificate', |
| 191 | 'operator_type' => 'dropdown_operators', |
| 192 | 'operand_type' => array_merge( |
| 193 | DROIP_PLUGIN_SETTINGS['SELECT'], |
| 194 | array( |
| 195 | 'options' => array( |
| 196 | array( |
| 197 | 'value' => '1', |
| 198 | 'title' => 'Yes', |
| 199 | ), |
| 200 | array( |
| 201 | 'value' => '0', |
| 202 | 'title' => 'No', |
| 203 | ), |
| 204 | ), |
| 205 | ) |
| 206 | ), |
| 207 | ), |
| 208 | |
| 209 | // is_featured |
| 210 | array( |
| 211 | 'source' => TDE_APP_PREFIX, |
| 212 | 'value' => 'is_featured', |
| 213 | 'title' => 'Is Featured', |
| 214 | 'operator_type' => 'dropdown_operators', |
| 215 | 'operand_type' => array_merge( |
| 216 | DROIP_PLUGIN_SETTINGS['SELECT'], |
| 217 | array( |
| 218 | 'options' => array( |
| 219 | array( |
| 220 | 'value' => '1', |
| 221 | 'title' => 'Yes', |
| 222 | ), |
| 223 | array( |
| 224 | 'value' => '0', |
| 225 | 'title' => 'No', |
| 226 | ), |
| 227 | ), |
| 228 | ), |
| 229 | ), |
| 230 | ), |
| 231 | |
| 232 | // sale_price |
| 233 | array( |
| 234 | 'source' => TDE_APP_PREFIX, |
| 235 | 'value' => 'sale_price', |
| 236 | 'title' => 'Sale Price', |
| 237 | 'operator_type' => 'boolean_operators', |
| 238 | ), |
| 239 | ), |
| 240 | ), |
| 241 | ); |
| 242 | |
| 243 | return $conditions; |
| 244 | } |
| 245 | |
| 246 | private static function get_membership_type_conditions($conditions) |
| 247 | { |
| 248 | if (!isset($conditions['post']['fields'])) { |
| 249 | $conditions['post']['fields'] = array(); |
| 250 | } |
| 251 | $conditions['post'] = array( |
| 252 | 'title' => 'Membership', |
| 253 | 'fields' => array_merge( |
| 254 | $conditions['post']['fields'], |
| 255 | array( |
| 256 | array( |
| 257 | 'source' => TDE_APP_PREFIX, |
| 258 | 'value' => 'recurring_interval', |
| 259 | 'title' => 'Recurring Interval', |
| 260 | 'operator_type' => 'dropdown_operators', |
| 261 | 'operand_type' => array_merge( |
| 262 | DROIP_PLUGIN_SETTINGS['SELECT'], |
| 263 | array( |
| 264 | 'options' => array( |
| 265 | array( |
| 266 | 'value' => 'day', |
| 267 | 'title' => 'Day', |
| 268 | ), |
| 269 | array( |
| 270 | 'value' => 'week', |
| 271 | 'title' => 'Week', |
| 272 | ), |
| 273 | array( |
| 274 | 'value' => 'month', |
| 275 | 'title' => 'Month', |
| 276 | ), |
| 277 | array( |
| 278 | 'value' => 'year', |
| 279 | 'title' => 'Year', |
| 280 | ), |
| 281 | ), |
| 282 | ), |
| 283 | ), |
| 284 | ), |
| 285 | |
| 286 | // recurring_value |
| 287 | array( |
| 288 | 'source' => TDE_APP_PREFIX, |
| 289 | 'value' => 'recurring_value', |
| 290 | 'title' => 'Recurring Value', |
| 291 | 'operator_type' => 'numeric_operators', |
| 292 | 'operand_type' => array_merge( |
| 293 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 294 | array( |
| 295 | 'placeholder' => 'Recurring Value', |
| 296 | ) |
| 297 | ), |
| 298 | ), |
| 299 | |
| 300 | // enrollment_fee |
| 301 | array( |
| 302 | 'source' => TDE_APP_PREFIX, |
| 303 | 'value' => 'enrollment_fee', |
| 304 | 'title' => 'Has enrollment fee', |
| 305 | 'operator_type' => 'boolean_operators', |
| 306 | ), |
| 307 | |
| 308 | // provide_certificate DEFAULT 1, -- 0 or 1 |
| 309 | array( |
| 310 | 'source' => TDE_APP_PREFIX, |
| 311 | 'value' => 'provide_certificate', |
| 312 | 'title' => 'Provide Certificate', |
| 313 | 'operator_type' => 'boolean_operators', |
| 314 | ), |
| 315 | |
| 316 | // is_featured |
| 317 | array( |
| 318 | 'source' => TDE_APP_PREFIX, |
| 319 | 'value' => 'is_featured', |
| 320 | 'title' => 'Is Featured', |
| 321 | 'operator_type' => 'boolean_operators', |
| 322 | ), |
| 323 | |
| 324 | // sale_price |
| 325 | array( |
| 326 | 'source' => TDE_APP_PREFIX, |
| 327 | 'value' => 'sale_price', |
| 328 | 'title' => 'Offer sale Price', |
| 329 | 'operator_type' => 'boolean_operators', |
| 330 | ), |
| 331 | ), |
| 332 | ), |
| 333 | ); |
| 334 | |
| 335 | return $conditions; |
| 336 | } |
| 337 | |
| 338 | private static function get_membership_features_type_conditions($conditions) |
| 339 | { |
| 340 | if (!isset($conditions['post']['fields'])) { |
| 341 | $conditions['post']['fields'] = array(); |
| 342 | } |
| 343 | $conditions['post'] = array( |
| 344 | 'title' => 'Feature', |
| 345 | 'fields' => array_merge( |
| 346 | $conditions['post']['fields'], |
| 347 | array( |
| 348 | array( |
| 349 | 'source' => TDE_APP_PREFIX, |
| 350 | 'value' => 'icon_type', |
| 351 | 'title' => 'Icon', |
| 352 | 'operator_type' => 'dropdown_operators', |
| 353 | 'operand_type' => array_merge( |
| 354 | DROIP_PLUGIN_SETTINGS['SELECT'], |
| 355 | array( |
| 356 | 'options' => array( |
| 357 | array( |
| 358 | 'value' => 'yes', |
| 359 | 'title' => 'Check', |
| 360 | ), |
| 361 | array( |
| 362 | 'value' => 'no', |
| 363 | 'title' => 'Times', |
| 364 | ), |
| 365 | ), |
| 366 | ), |
| 367 | ), |
| 368 | ), |
| 369 | ), |
| 370 | ), |
| 371 | ); |
| 372 | |
| 373 | return $conditions; |
| 374 | } |
| 375 | |
| 376 | private static function get_course_type_conditions($conditions) |
| 377 | { |
| 378 | if (!isset($conditions['post']['fields'])) { |
| 379 | $conditions['post']['fields'] = array(); |
| 380 | } |
| 381 | $conditions['post'] = array( |
| 382 | 'title' => 'Course', |
| 383 | 'fields' => array_merge( |
| 384 | $conditions['post']['fields'], |
| 385 | array( |
| 386 | array( |
| 387 | 'source' => TDE_APP_PREFIX, |
| 388 | 'value' => 'is_paid', |
| 389 | 'title' => 'Paid', |
| 390 | 'operator_type' => 'boolean_operators', |
| 391 | ), |
| 392 | array( |
| 393 | 'source' => TDE_APP_PREFIX, |
| 394 | 'value' => 'on_sale', |
| 395 | 'title' => 'On Sale', |
| 396 | 'operator_type' => 'boolean_operators', |
| 397 | ), |
| 398 | array( |
| 399 | 'source' => TDE_APP_PREFIX, |
| 400 | 'value' => 'purchase_options', |
| 401 | 'title' => 'Purchase Options', |
| 402 | 'operator_type' => 'dropdown_operators', |
| 403 | 'operand_type' => array_merge( |
| 404 | DROIP_PLUGIN_SETTINGS['SELECT'], |
| 405 | array( |
| 406 | 'options' => array( |
| 407 | array( |
| 408 | 'value' => Course::SELLING_OPTION_ONE_TIME, |
| 409 | 'title' => 'One Time', |
| 410 | ), |
| 411 | array( |
| 412 | 'value' => Course::SELLING_OPTION_SUBSCRIPTION, |
| 413 | 'title' => 'Subscription', |
| 414 | ), |
| 415 | |
| 416 | array( |
| 417 | 'value' => Course::SELLING_OPTION_BOTH, |
| 418 | 'title' => 'Subscription & One-Time', |
| 419 | ), |
| 420 | |
| 421 | array( |
| 422 | 'value' => Course::SELLING_OPTION_MEMBERSHIP, |
| 423 | 'title' => 'Membership', |
| 424 | ), |
| 425 | array( |
| 426 | 'value' => Course::SELLING_OPTION_ALL, |
| 427 | 'title' => 'All', |
| 428 | ), |
| 429 | ), |
| 430 | ) |
| 431 | ), |
| 432 | ), |
| 433 | array( |
| 434 | 'source' => TDE_APP_PREFIX, |
| 435 | 'value' => 'average_rating', |
| 436 | 'title' => 'Rating (Avg.)', |
| 437 | 'operator_type' => 'numeric_operators', |
| 438 | 'operand_type' => array_merge( |
| 439 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 440 | array( |
| 441 | 'placeholder' => 'Rating', |
| 442 | ) |
| 443 | ), |
| 444 | ), |
| 445 | array( |
| 446 | 'source' => TDE_APP_PREFIX, |
| 447 | 'value' => 'total_ratings', |
| 448 | 'title' => 'Total Ratings', |
| 449 | 'operator_type' => 'numeric_operators', |
| 450 | 'operand_type' => array_merge( |
| 451 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 452 | array( |
| 453 | 'placeholder' => 'Rating count', |
| 454 | ) |
| 455 | ), |
| 456 | ), |
| 457 | array( |
| 458 | 'source' => TDE_APP_PREFIX, |
| 459 | 'value' => 'enroll_count', |
| 460 | 'title' => 'Enrollment Count', |
| 461 | 'operator_type' => 'numeric_operators', |
| 462 | 'operand_type' => array_merge( |
| 463 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 464 | array( |
| 465 | 'placeholder' => 'Enroll Count', |
| 466 | ) |
| 467 | ), |
| 468 | ), |
| 469 | array( |
| 470 | 'source' => TDE_APP_PREFIX, |
| 471 | 'value' => 'student_state', |
| 472 | 'title' => 'Student status', |
| 473 | 'operator_type' => array( |
| 474 | array( |
| 475 | 'title' => '= Equals', |
| 476 | 'value' => 'user_state-is_equal', |
| 477 | ), |
| 478 | array( |
| 479 | 'title' => '≠ Does not equal', |
| 480 | 'value' => 'user_state-not_equal', |
| 481 | ), |
| 482 | ), |
| 483 | 'operand_type' => array_merge( |
| 484 | DROIP_PLUGIN_SETTINGS['SELECT'], |
| 485 | array( |
| 486 | 'options' => array( |
| 487 | array( |
| 488 | 'value' => 'logged_in', |
| 489 | 'title' => 'Logged in', |
| 490 | ), |
| 491 | array( |
| 492 | 'value' => 'wishlisted', |
| 493 | 'title' => 'Wishlisted', |
| 494 | ), |
| 495 | array( |
| 496 | 'value' => 'added_in_cart', |
| 497 | 'title' => 'Added in Cart', |
| 498 | ), |
| 499 | array( |
| 500 | 'value' => 'enrolled', |
| 501 | 'title' => 'Enrolled', |
| 502 | ), |
| 503 | array( |
| 504 | 'value' => 'learner', |
| 505 | 'title' => 'Learner', |
| 506 | ), |
| 507 | array( |
| 508 | 'value' => 'can_retake', |
| 509 | 'title' => 'Can Retake', |
| 510 | ), |
| 511 | array( |
| 512 | 'value' => 'completed', |
| 513 | 'title' => 'Completed', |
| 514 | ), |
| 515 | ), |
| 516 | ) |
| 517 | ), |
| 518 | ), |
| 519 | // [ |
| 520 | // 'source' => TDE_APP_PREFIX, |
| 521 | // 'value' => 'user_authored', |
| 522 | // 'title' => 'User authored', |
| 523 | // 'operator_type' => 'dropdown_operators', |
| 524 | // 'operand_type' => array_merge( |
| 525 | // DROIP_PLUGIN_SETTINGS['SELECT'], |
| 526 | // [ |
| 527 | // 'options' => [ |
| 528 | // ['value' => 'no_review', 'title' => 'No Review'], |
| 529 | // ['value' => 'current_review', 'title' => 'Current Review'], |
| 530 | // ['value' => 'no_question', 'title' => 'No Question'], |
| 531 | // ['value' => 'current_question', 'title' => 'Current Question'], |
| 532 | // ], |
| 533 | // ] |
| 534 | // ), |
| 535 | // ], |
| 536 | array( |
| 537 | 'source' => TDE_APP_PREFIX, |
| 538 | 'value' => 'resource_count', |
| 539 | 'title' => 'Resources', |
| 540 | 'operator_type' => 'numeric_operators', |
| 541 | 'operand_type' => array_merge( |
| 542 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 543 | array( |
| 544 | 'placeholder' => 'Resource Count', |
| 545 | ) |
| 546 | ), |
| 547 | ), |
| 548 | array( |
| 549 | 'source' => TDE_APP_PREFIX, |
| 550 | 'value' => 'lesson_count', |
| 551 | 'title' => 'Lessons', |
| 552 | 'operator_type' => 'numeric_operators', |
| 553 | 'operand_type' => array_merge( |
| 554 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 555 | array( |
| 556 | 'placeholder' => 'Lesson Count', |
| 557 | ) |
| 558 | ), |
| 559 | ), |
| 560 | array( |
| 561 | 'source' => TDE_APP_PREFIX, |
| 562 | 'value' => 'quiz_count', |
| 563 | 'title' => 'Quizzes', |
| 564 | 'operator_type' => 'numeric_operators', |
| 565 | 'operand_type' => array_merge( |
| 566 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 567 | array( |
| 568 | 'placeholder' => 'Quiz Count', |
| 569 | ) |
| 570 | ), |
| 571 | ), |
| 572 | array( |
| 573 | 'source' => TDE_APP_PREFIX, |
| 574 | 'value' => 'assignments_count', |
| 575 | 'title' => 'Assignments', |
| 576 | 'operator_type' => 'numeric_operators', |
| 577 | 'operand_type' => array_merge( |
| 578 | DROIP_PLUGIN_SETTINGS['INPUT_NUMBER'], |
| 579 | array( |
| 580 | 'placeholder' => 'Assignment Count', |
| 581 | ) |
| 582 | ), |
| 583 | ), |
| 584 | array( |
| 585 | 'source' => TDE_APP_PREFIX, |
| 586 | 'value' => 'is_review_enabled', |
| 587 | 'title' => 'Review Enabled', |
| 588 | 'operator_type' => 'boolean_operators', |
| 589 | ), |
| 590 | array( |
| 591 | 'source' => TDE_APP_PREFIX, |
| 592 | 'value' => 'is_qna_enabled', |
| 593 | 'title' => 'QnA Enabled', |
| 594 | 'operator_type' => 'boolean_operators', |
| 595 | ), |
| 596 | array( |
| 597 | 'source' => TDE_APP_PREFIX, |
| 598 | 'value' => 'is_certificate_enabled', |
| 599 | 'title' => 'Certificate Enabled', |
| 600 | 'operator_type' => 'boolean_operators', |
| 601 | ), |
| 602 | ) |
| 603 | ), |
| 604 | ); |
| 605 | return $conditions; |
| 606 | } |
| 607 | |
| 608 | private static function get_lms_setting_type_conditions($conditions) |
| 609 | { |
| 610 | if (!isset($conditions['lms-settings']['fields'])) { |
| 611 | $conditions['lms-settings']['fields'] = array(); |
| 612 | } |
| 613 | |
| 614 | $conditions['lms-settings'] = array( |
| 615 | 'title' => 'LMS Settings', |
| 616 | 'fields' => array_merge( |
| 617 | $conditions['lms-settings']['fields'], |
| 618 | array( |
| 619 | array( |
| 620 | 'source' => TDE_APP_PREFIX, |
| 621 | 'value' => 'is_membership_only_mode_enabled', |
| 622 | 'title' => 'Membership-Only Mode', |
| 623 | 'operator_type' => 'boolean_operators', |
| 624 | ) |
| 625 | ) |
| 626 | ), |
| 627 | ); |
| 628 | |
| 629 | return $conditions; |
| 630 | } |
| 631 | |
| 632 | public static function element_visibility_condition_check($default_value, $condition, $options) |
| 633 | { |
| 634 | $source = $condition['source']; |
| 635 | $field = $condition['field']['value']; |
| 636 | $operator = $condition['operator']['value']; |
| 637 | $operand = $condition['operand']['value']; |
| 638 | $field_group = isset($condition['field']['group']) ? $condition['field']['group'] : ''; |
| 639 | |
| 640 | if (isset($options['TUTOR_LMS-subscriptions'])) { |
| 641 | $subscription = (array) $options['TUTOR_LMS-subscriptions']; |
| 642 | $fieldValue = self::get_subscription_field_value($subscription, $field, $options); |
| 643 | } else if (isset($options['membership-plan'], $options['itemType']) && $options['itemType'] === 'membership-plan') { |
| 644 | $membership_plan = (array) $options['membership-plan']; |
| 645 | $fieldValue = self::get_membership_plan_field_value($membership_plan, $field); |
| 646 | } else if (isset($options['membership-feature'], $options['itemType']) && $options['itemType'] === 'membership-feature') { |
| 647 | $membership_feature = (array) $options['membership-feature']; |
| 648 | $fieldValue = self::get_membership_feature_field_value($membership_feature, $field); |
| 649 | } else { |
| 650 | if ($field_group === 'lms-settings') { |
| 651 | $fieldValue = self::get_lms_settings_field_value($field); |
| 652 | } else { |
| 653 | $fieldValue = self::get_course_field_value($field, $options); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | if ($source === TDE_APP_PREFIX) { |
| 658 | switch ($operator) { |
| 659 | case 'true': { |
| 660 | return (bool) $fieldValue; |
| 661 | } |
| 662 | case 'false': { |
| 663 | return ! $fieldValue; |
| 664 | } |
| 665 | case 'is_equal': { |
| 666 | return $fieldValue == $operand; |
| 667 | } |
| 668 | case 'not_equal': { |
| 669 | return $fieldValue != $operand; |
| 670 | } |
| 671 | case 'less_than': { |
| 672 | return $fieldValue < $operand; |
| 673 | } |
| 674 | case 'greater_than': { |
| 675 | return $fieldValue > $operand; |
| 676 | } |
| 677 | case 'less_than_or_equal': { |
| 678 | return $fieldValue <= $operand; |
| 679 | } |
| 680 | case 'greater_than_or_equal': { |
| 681 | return $fieldValue >= $operand; |
| 682 | } |
| 683 | case 'user_state-is_equal': { |
| 684 | return in_array($operand, $fieldValue); |
| 685 | } |
| 686 | case 'user_state-not_equal': { |
| 687 | return !in_array($operand, $fieldValue); |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | return $default_value; |
| 693 | } |
| 694 | |
| 695 | private static function get_membership_feature_field_value($membership_feature, $field) |
| 696 | { |
| 697 | $yes_icon_types = array( |
| 698 | 'tick', |
| 699 | 'tick_circle', |
| 700 | 'tick_circle_fill', |
| 701 | 'plus_square', |
| 702 | 'plus_circle', |
| 703 | 'plus_circle_fill', |
| 704 | 'plus_square_fill', |
| 705 | ); |
| 706 | |
| 707 | $no_icon_types = array( |
| 708 | 'cross', |
| 709 | 'cross_circle', |
| 710 | 'cross_circle_fill', |
| 711 | 'minus_square', |
| 712 | 'minus_circle', |
| 713 | 'minus_circle_fill', |
| 714 | 'minus_square_fill', |
| 715 | ); |
| 716 | |
| 717 | switch ($field) { |
| 718 | case 'icon_type': { |
| 719 | if (in_array($membership_feature['icon'], $yes_icon_types)) { |
| 720 | return 'yes'; |
| 721 | } elseif (in_array($membership_feature['icon'], $no_icon_types)) { |
| 722 | return 'no'; |
| 723 | } |
| 724 | |
| 725 | return null; |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | return isset($membership_feature[$field]) ? $membership_feature[$field] : null; |
| 730 | } |
| 731 | |
| 732 | private static function get_subscription_field_value($subscription, $field, $options) |
| 733 | { |
| 734 | switch ($field) { |
| 735 | case 'sale_price': { |
| 736 | return $subscription['sale_price'] !== '0.00'; |
| 737 | } |
| 738 | } |
| 739 | return isset($subscription[$field]) ? $subscription[$field] : null; |
| 740 | } |
| 741 | |
| 742 | private static function get_membership_plan_field_value($membership_plan, $field) |
| 743 | { |
| 744 | switch ($field) { |
| 745 | case 'enrollment_fee': |
| 746 | case 'sale_price': { |
| 747 | return $membership_plan[$field] !== '0.00'; |
| 748 | } |
| 749 | |
| 750 | case 'is_featured': |
| 751 | case 'provide_certificate': { |
| 752 | return $membership_plan[$field] == '1'; |
| 753 | } |
| 754 | |
| 755 | default: |
| 756 | return isset($membership_plan[$field]) ? $membership_plan[$field] : null; |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | private static function get_course_field_value($field, $options) |
| 761 | { |
| 762 | $course_id = isset($options['post']) ? $options['post']->ID : get_the_ID(); |
| 763 | switch ($field) { |
| 764 | case 'is_paid': { |
| 765 | $is_paid_course = tutor_utils()->is_course_purchasable($course_id); |
| 766 | return $is_paid_course; |
| 767 | } |
| 768 | case 'on_sale': { |
| 769 | $course_price = tutor_utils()->get_raw_course_price($course_id); |
| 770 | return $course_price->sale_price != 0; |
| 771 | } |
| 772 | case 'purchase_options': { |
| 773 | $selling_option = Course::get_selling_option($course_id); |
| 774 | return $selling_option; |
| 775 | } |
| 776 | case 'average_rating': { |
| 777 | $average_rating = self::get_course_meta($field, $course_id, $options); |
| 778 | $average_rating = floatval(str_replace(',', '', $average_rating)); |
| 779 | return $average_rating; |
| 780 | } |
| 781 | case 'total_ratings': |
| 782 | case 'enroll_count': |
| 783 | case 'resource_count': |
| 784 | case 'lesson_count': |
| 785 | case 'quiz_count': |
| 786 | case 'assignments_count': { |
| 787 | $value = self::get_course_meta($field, $course_id, $options); |
| 788 | return $value; |
| 789 | } |
| 790 | case 'student_state': { |
| 791 | $state = array(); |
| 792 | $entry_box_logic = tutor_entry_box_buttons($course_id); |
| 793 | if (is_user_logged_in()) { |
| 794 | $state[] = 'logged_in'; |
| 795 | if (tutor_utils()->is_wishlisted($course_id)) { |
| 796 | $state[] = 'wishlisted'; |
| 797 | } |
| 798 | |
| 799 | if ($entry_box_logic->show_view_cart_btn) { |
| 800 | $state[] = 'added_in_cart'; |
| 801 | } elseif (tutor_utils()->is_enrolled($course_id)) { |
| 802 | $state[] = 'enrolled'; |
| 803 | } |
| 804 | |
| 805 | if ($entry_box_logic->show_continue_learning_btn) { |
| 806 | $state[] = 'learner'; |
| 807 | } elseif (tutor_utils()->is_completed_course($course_id)) { |
| 808 | $state[] = 'completed'; |
| 809 | } |
| 810 | |
| 811 | if ($entry_box_logic->show_retake_course_btn) { |
| 812 | $state[] = 'can_retake'; |
| 813 | } |
| 814 | } |
| 815 | return $state; |
| 816 | } |
| 817 | case 'is_review_enabled': { |
| 818 | $review_enabled = (bool) get_tutor_option('enable_course_review'); |
| 819 | return $review_enabled; |
| 820 | } |
| 821 | case 'is_qna_enabled': { |
| 822 | $enable_q_and_a_on_course = (bool) get_tutor_option('enable_q_and_a_on_course'); |
| 823 | $disable_qa_for_this_course = get_post_meta($course_id, '_tutor_enable_qa', true) != 'yes' ?? false; |
| 824 | return ! (! $enable_q_and_a_on_course || $disable_qa_for_this_course); |
| 825 | } |
| 826 | case 'is_certificate_enabled': { |
| 827 | $addon_config = tutor_utils()->get_addon_config('tutor-pro/addons/tutor-certificate/tutor-certificate.php'); |
| 828 | $is_enabled = (bool) tutor_utils()->avalue_dot('is_enable', $addon_config); |
| 829 | if ($is_enabled) { |
| 830 | $has_course_certificate_template = (new Certificate(true))->has_course_certificate_template($course_id); |
| 831 | return $has_course_certificate_template; |
| 832 | } |
| 833 | return false; |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | private static function get_lms_settings_field_value($field) |
| 839 | { |
| 840 | switch ($field) { |
| 841 | case 'is_membership_only_mode_enabled': { |
| 842 | $is_membership_only_mode_enabled = apply_filters('tutor_membership_only_mode', false); |
| 843 | return $is_membership_only_mode_enabled; |
| 844 | } |
| 845 | |
| 846 | default: { |
| 847 | return null; |
| 848 | } |
| 849 | } |
| 850 | return null; |
| 851 | } |
| 852 | } |