AuthController.php
2 years ago
AutomationController.php
3 years ago
EventController.php
3 years ago
EventHelperController.php
3 years ago
GlobalSearchController.php
2 years ago
IntegrationsController.php
3 years ago
OptionController.php
3 years ago
RestController.php
2 years ago
RoutesController.php
3 years ago
SettingsController.php
3 years ago
GlobalSearchController.php
12667 lines
| 1 | <?php |
| 2 | /** |
| 3 | * GlobalSearchController. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category GlobalSearchController |
| 7 | * @package SureTriggers |
| 8 | * @author BSF <username@example.com> |
| 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 10 | * @link https://www.brainstormforce.com/ |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | |
| 14 | namespace SureTriggers\Controllers; |
| 15 | |
| 16 | use DOMDocument; |
| 17 | use FluentCrm\App\Models\CustomContactField; |
| 18 | use FluentCrm\App\Models\Subscriber; |
| 19 | use FluentCrm\App\Models\Tag; |
| 20 | use memberpress\courses\lib as lib; |
| 21 | use memberpress\courses\models as models; |
| 22 | use FluentCrm\Framework\Support\Arr; |
| 23 | use GFCommon; |
| 24 | use GFFormsModel; |
| 25 | use Give_Payment; |
| 26 | use MeprBaseRealGateway; |
| 27 | use MeprOptions; |
| 28 | use OsAgentHelper; |
| 29 | use OsBookingHelper; |
| 30 | use OsCustomerHelper; |
| 31 | use OsServiceHelper; |
| 32 | use PrestoPlayer\Models\Video; |
| 33 | use RGFormsModel; |
| 34 | use SureTriggers\Integrations\AffiliateWP\AffiliateWP; |
| 35 | use SureTriggers\Integrations\EDD\EDD; |
| 36 | use SureTriggers\Integrations\FunnelKitAutomations\FunnelKitAutomations; |
| 37 | use SureTriggers\Integrations\JetpackCRM\JetpackCRM; |
| 38 | use SureTriggers\Integrations\LearnDash\LearnDash; |
| 39 | use SureTriggers\Integrations\LifterLMS\LifterLMS; |
| 40 | use SureTriggers\Integrations\MemberPress\MemberPress; |
| 41 | use SureTriggers\Integrations\MemberPressCourse\MemberPressCourse; |
| 42 | use SureTriggers\Integrations\ModernEventsCalendar\ModernEventsCalendar; |
| 43 | use SureTriggers\Integrations\PeepSo\PeepSo; |
| 44 | use SureTriggers\Integrations\RafflePress\RafflePress; |
| 45 | use SureTriggers\Integrations\RestrictContent\RestrictContent; |
| 46 | use SureTriggers\Integrations\TheEventCalendar\TheEventCalendar; |
| 47 | use SureTriggers\Integrations\WishlistMember\WishlistMember; |
| 48 | use SureTriggers\Integrations\WooCommerce\WooCommerce; |
| 49 | use SureTriggers\Integrations\WordPress\WordPress; |
| 50 | use SureTriggers\Integrations\WpPolls\WpPolls; |
| 51 | use SureTriggers\Models\Utilities; |
| 52 | use SureTriggers\Traits\SingletonLoader; |
| 53 | use Tribe__Tickets__Tickets_Handler; |
| 54 | use WC_Subscription; |
| 55 | use WC_Subscriptions_Product; |
| 56 | use WP_Query; |
| 57 | use WP_Comment_Query; |
| 58 | use WP_REST_Request; |
| 59 | use WP_REST_Response; |
| 60 | use WPForms_Form_Handler; |
| 61 | use CP_V2_Popups; |
| 62 | use Project_Huddle; |
| 63 | use FrmForm; |
| 64 | use Forminator_API; |
| 65 | use SureTriggers\Integrations\LearnPress\LearnPress; |
| 66 | use WC_Customer; |
| 67 | use WC_Booking; |
| 68 | use WC_Bookings_Admin; |
| 69 | use MeprTransaction; |
| 70 | |
| 71 | /** |
| 72 | * GlobalSearchController- Add ajax related functions here. |
| 73 | * |
| 74 | * @category GlobalSearchController |
| 75 | * @package SureTriggers |
| 76 | * @author BSF <username@example.com> |
| 77 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 78 | * @link https://www.brainstormforce.com/ |
| 79 | * @since 1.0.0 |
| 80 | * |
| 81 | * @psalm-suppress UndefinedTrait |
| 82 | */ |
| 83 | class GlobalSearchController { |
| 84 | |
| 85 | use SingletonLoader; |
| 86 | |
| 87 | /** |
| 88 | * Search post by post type. |
| 89 | * |
| 90 | * @param array $data Search Params. |
| 91 | * |
| 92 | * @since 1.0.0 |
| 93 | * |
| 94 | * @return array |
| 95 | */ |
| 96 | public function search_post( $data ) { |
| 97 | $result = []; |
| 98 | $posts = Utilities::find_posts_by_title( $data ); |
| 99 | |
| 100 | foreach ( $posts['results'] as $post ) { |
| 101 | $result[] = [ |
| 102 | 'label' => $post['post_title'], |
| 103 | 'value' => $post['ID'], |
| 104 | ]; |
| 105 | } |
| 106 | |
| 107 | return [ |
| 108 | 'options' => $result, |
| 109 | 'hasMore' => $posts['has_more'], |
| 110 | ]; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Search Course. |
| 115 | * |
| 116 | * @param array $data quesry params. |
| 117 | * |
| 118 | * @return array |
| 119 | * @since 1.0.0 |
| 120 | */ |
| 121 | public function search_ld_course( $data ) { |
| 122 | $courses = get_posts( |
| 123 | [ |
| 124 | |
| 125 | 'post_type' => 'product', |
| 126 | 'meta_key' => '_related_course', |
| 127 | 'post_status' => 'publish', |
| 128 | ] |
| 129 | ); |
| 130 | $options = []; |
| 131 | foreach ( $courses as $course ) { |
| 132 | $options[] = [ |
| 133 | 'label' => $course->post_title, |
| 134 | 'value' => $course->ID, |
| 135 | ]; |
| 136 | } |
| 137 | |
| 138 | return [ |
| 139 | 'options' => $options, |
| 140 | 'hasMore' => false, |
| 141 | ]; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Search achievement by post type. |
| 146 | * |
| 147 | * @param array $data Search Params. |
| 148 | * |
| 149 | * @since 1.0.0 |
| 150 | * |
| 151 | * @return array |
| 152 | */ |
| 153 | public function search_achievements( $data ) { |
| 154 | $post = get_post( $data['dynamic'] ); |
| 155 | $slug = $post->post_name; |
| 156 | |
| 157 | $achievements = get_posts( |
| 158 | [ |
| 159 | 'post_type' => $slug, |
| 160 | 'post_status' => 'publish', |
| 161 | ] |
| 162 | ); |
| 163 | $options = []; |
| 164 | foreach ( $achievements as $achievement ) { |
| 165 | $options[] = [ |
| 166 | 'label' => $achievement->post_title, |
| 167 | 'value' => (string) $achievement->ID, |
| 168 | ]; |
| 169 | } |
| 170 | |
| 171 | return [ |
| 172 | 'options' => $options, |
| 173 | 'hasMore' => false, |
| 174 | ]; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Search Course. |
| 179 | * |
| 180 | * @param array $data quesry params. |
| 181 | * |
| 182 | * @return array |
| 183 | * @since 1.0.0 |
| 184 | */ |
| 185 | public function search_tutor_course( $data ) { |
| 186 | $courses = get_posts( |
| 187 | [ |
| 188 | 'post_type' => tutor()->course_post_type, |
| 189 | 'post_status' => 'publish', |
| 190 | 'numberposts' => '-1', |
| 191 | ] |
| 192 | ); |
| 193 | $options = []; |
| 194 | foreach ( $courses as $course ) { |
| 195 | $options[] = [ |
| 196 | 'label' => $course->post_title, |
| 197 | 'value' => $course->ID, |
| 198 | ]; |
| 199 | } |
| 200 | |
| 201 | return [ |
| 202 | 'options' => $options, |
| 203 | 'hasMore' => false, |
| 204 | ]; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Search Products. |
| 209 | * |
| 210 | * @param array $data quesry params. |
| 211 | * |
| 212 | * @return array |
| 213 | * @since 1.0.0 |
| 214 | */ |
| 215 | public function search_product( $data ) { |
| 216 | $result = []; |
| 217 | $posts = Utilities::find_posts_by_title( $data ); |
| 218 | |
| 219 | foreach ( $posts['results'] as $post ) { |
| 220 | $result[] = [ |
| 221 | 'label' => $post['post_title'], |
| 222 | 'value' => $post['post_title'], |
| 223 | ]; |
| 224 | } |
| 225 | |
| 226 | return [ |
| 227 | 'options' => $result, |
| 228 | 'hasMore' => $posts['has_more'], |
| 229 | ]; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Search Product Categories. |
| 234 | * |
| 235 | * @param array $data Search Params. |
| 236 | * |
| 237 | * @since 1.0.0 |
| 238 | */ |
| 239 | public function search_product_category( $data ) { |
| 240 | if ( ! empty( $data['dynamic'] ) ) { |
| 241 | $taxonomy = $data['dynamic']; |
| 242 | } else { |
| 243 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 244 | } |
| 245 | |
| 246 | $term = $data['term']; |
| 247 | $result = []; |
| 248 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 249 | foreach ( $terms['result'] as $tax_term ) { |
| 250 | $result[] = [ |
| 251 | 'label' => $tax_term->name, |
| 252 | 'value' => $tax_term->name, |
| 253 | ]; |
| 254 | } |
| 255 | |
| 256 | return [ |
| 257 | 'options' => $result, |
| 258 | 'hasMore' => $terms['has_more'], |
| 259 | ]; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Search Product Tags. |
| 264 | * |
| 265 | * @param array $data Search Params. |
| 266 | * |
| 267 | * @since 1.0.0 |
| 268 | */ |
| 269 | public function search_product_tags( $data ) { |
| 270 | if ( ! empty( $data['dynamic'] ) ) { |
| 271 | $taxonomy = $data['dynamic']; |
| 272 | } else { |
| 273 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 274 | } |
| 275 | |
| 276 | $term = $data['term']; |
| 277 | $result = []; |
| 278 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 279 | |
| 280 | foreach ( $terms['result'] as $tax_term ) { |
| 281 | $result[] = [ |
| 282 | 'label' => $tax_term->name, |
| 283 | 'value' => $tax_term->name, |
| 284 | ]; |
| 285 | } |
| 286 | |
| 287 | return [ |
| 288 | 'options' => $result, |
| 289 | 'hasMore' => $terms['has_more'], |
| 290 | ]; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Global ajax search. |
| 295 | * Here you need to add the field action name to work. |
| 296 | * |
| 297 | * @param WP_REST_Request $request Request data. |
| 298 | * |
| 299 | * @return WP_REST_Response |
| 300 | * @since 1.0.0 |
| 301 | */ |
| 302 | public function global_search( $request ) { |
| 303 | $post_type = $request->get_param( 'post_type' ); |
| 304 | $dynamic = $request->get_param( 'dynamic' ); |
| 305 | $search_term = $request->get_param( 'term' ); |
| 306 | $identifier = $request->get_param( 'field_identifier' ); |
| 307 | $page = max( 1, $request->get_param( 'page' ) ); |
| 308 | $taxonomy = $request->get_param( 'taxonomy' ) ? $request->get_param( 'taxonomy' ) : []; |
| 309 | |
| 310 | $filter = $request->get_param( 'filter' ) ? json_decode( stripslashes( $request->get_param( 'filter' ) ), true ) : []; |
| 311 | |
| 312 | $data = [ |
| 313 | 'dynamic' => $dynamic, |
| 314 | 'search_term' => $search_term, |
| 315 | 'page' => $page, |
| 316 | 'taxonomy' => $taxonomy, |
| 317 | 'filter' => $filter, |
| 318 | 'post_type' => $post_type, |
| 319 | ]; |
| 320 | $response = [ |
| 321 | 'hasMore' => false, |
| 322 | 'options' => [], |
| 323 | ]; |
| 324 | |
| 325 | $method_name = 'search_' . $identifier; |
| 326 | |
| 327 | if ( method_exists( $this, $method_name ) ) { |
| 328 | $response = $this->{$method_name}( $data ); |
| 329 | } else { |
| 330 | return RestController::error_message( 'Invalid field Identifier param.' ); |
| 331 | } |
| 332 | |
| 333 | return RestController::success_message( $response ); |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Search Taxonomy Terms. |
| 338 | * |
| 339 | * @param array $data Search Params. |
| 340 | * |
| 341 | * @since 1.0.0 |
| 342 | * |
| 343 | * @return array |
| 344 | */ |
| 345 | public function search_term( $data ) { |
| 346 | if ( ! empty( $data['dynamic'] ) ) { |
| 347 | $taxonomy = $data['dynamic']; |
| 348 | } else { |
| 349 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 350 | } |
| 351 | |
| 352 | $term = $data['term']; |
| 353 | $result = []; |
| 354 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 355 | foreach ( $terms['result'] as $tax_term ) { |
| 356 | $result[] = [ |
| 357 | 'label' => $tax_term->name, |
| 358 | 'value' => $tax_term->term_id, |
| 359 | ]; |
| 360 | } |
| 361 | |
| 362 | return [ |
| 363 | 'options' => $result, |
| 364 | 'hasMore' => $terms['has_more'], |
| 365 | ]; |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Search users. |
| 370 | * |
| 371 | * @param array $data Search Params. |
| 372 | * |
| 373 | * @since 1.0.0 |
| 374 | * |
| 375 | * @return array |
| 376 | */ |
| 377 | public function search_user( $data ) { |
| 378 | $result = []; |
| 379 | $page = $data['page']; |
| 380 | $users = Utilities::get_users( $data, $page ); |
| 381 | |
| 382 | if ( is_array( $users['results'] ) ) { |
| 383 | foreach ( $users['results'] as $user ) { |
| 384 | $result[] = [ |
| 385 | 'label' => $user->user_login, |
| 386 | 'value' => $user->ID, |
| 387 | ]; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | return [ |
| 392 | 'options' => $result, |
| 393 | 'hasMore' => $users['has_more'], |
| 394 | ]; |
| 395 | |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Search WPForm fields. |
| 400 | * |
| 401 | * @param array $data Search Params. |
| 402 | * |
| 403 | * @since 1.0.0 |
| 404 | * |
| 405 | * @return array |
| 406 | */ |
| 407 | public function search_pluggable_wpform_fields( $data ) { |
| 408 | $result = []; |
| 409 | $page = $data['page']; |
| 410 | $form_id = absint( $data['dynamic'] ); |
| 411 | $wpform_fields = Utilities::get_wpform_fields( $data['search_term'], $page, $form_id ); |
| 412 | |
| 413 | if ( is_array( $wpform_fields['results'] ) ) { |
| 414 | foreach ( $wpform_fields['results'] as $field ) { |
| 415 | $result[] = [ |
| 416 | 'label' => $field['label'], |
| 417 | 'value' => '{' . $field['id'] . '}', |
| 418 | ]; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | return [ |
| 423 | 'options' => $result, |
| 424 | 'hasMore' => $wpform_fields['has_more'], |
| 425 | ]; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Prepare variable products. |
| 430 | * |
| 431 | * @param array $data data. |
| 432 | * |
| 433 | * @return array |
| 434 | */ |
| 435 | public function search_variable_products( $data ) { |
| 436 | $products = Utilities::get_variable_products( $data['search_term'], $data['page'] ); |
| 437 | $options = []; |
| 438 | |
| 439 | foreach ( $products['result'] as $product ) { |
| 440 | $options[] = [ |
| 441 | 'label' => $product->get_title(), |
| 442 | 'value' => (string) $product->get_id(), |
| 443 | ]; |
| 444 | } |
| 445 | |
| 446 | return [ |
| 447 | 'options' => $options, |
| 448 | 'hasMore' => $products['has_more'], |
| 449 | ]; |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Prepare variable products. |
| 454 | * |
| 455 | * @param array $data data. |
| 456 | * |
| 457 | * @return array |
| 458 | */ |
| 459 | public function search_product_variations( $data ) { |
| 460 | $variations = Utilities::get_product_variations( $data['dynamic'] ); |
| 461 | $options = []; |
| 462 | |
| 463 | foreach ( $variations['result'] as $product ) { |
| 464 | $options[] = [ |
| 465 | 'label' => ! empty( $product->post_excerpt ) ? $product->post_excerpt : $product->post_title, |
| 466 | 'value' => (string) $product->ID, |
| 467 | ]; |
| 468 | } |
| 469 | |
| 470 | return [ |
| 471 | 'options' => $options, |
| 472 | 'hasMore' => $variations['has_more'], |
| 473 | ]; |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Search WooCommerce Subscriptions. |
| 478 | * |
| 479 | * @param array $data Search Params. |
| 480 | * |
| 481 | * @since 1.0.0 |
| 482 | * |
| 483 | * @return array |
| 484 | */ |
| 485 | public function search_subscription_variation( $data ) { |
| 486 | $subscription_products = Utilities::get_subscription_variation( $data['search_term'], $data['page'] ); |
| 487 | $result = []; |
| 488 | |
| 489 | if ( ! function_exists( 'wc_get_products' ) ) { |
| 490 | return $result; |
| 491 | } |
| 492 | |
| 493 | foreach ( $subscription_products['result'] as $post ) { |
| 494 | if ( $data['search_term'] ) { |
| 495 | if ( false !== stripos( $post->get_title(), $data['search_term'] ) ) { |
| 496 | $result[] = [ |
| 497 | 'label' => $post->get_title(), |
| 498 | 'value' => (string) $post->get_id(), |
| 499 | ]; |
| 500 | } |
| 501 | } else { |
| 502 | $result[] = [ |
| 503 | 'label' => $post->get_title(), |
| 504 | 'value' => (string) $post->get_id(), |
| 505 | ]; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | return [ |
| 510 | 'options' => $result, |
| 511 | 'hasMore' => $subscription_products['has_more'], |
| 512 | ]; |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Prepare WooCommerce Payment Methods. |
| 517 | * |
| 518 | * @param array $data Search Params. |
| 519 | * @return array[] |
| 520 | */ |
| 521 | public function search_woo_payment_methods( $data ) { |
| 522 | $payment_methods = WC()->payment_gateways->get_available_payment_gateways(); |
| 523 | $options = []; |
| 524 | |
| 525 | if ( ! empty( $payment_methods ) ) { |
| 526 | foreach ( $payment_methods as $payment ) { |
| 527 | $options[] = [ |
| 528 | 'label' => $payment->title, |
| 529 | 'value' => $payment->id, |
| 530 | ]; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | return [ |
| 535 | 'options' => $options, |
| 536 | 'hasMore' => false, |
| 537 | ]; |
| 538 | } |
| 539 | |
| 540 | /** |
| 541 | * Prepare WooCommerce Order Status List. |
| 542 | * |
| 543 | * @param array $data Search Params. |
| 544 | * @return array[] |
| 545 | */ |
| 546 | public function search_woo_order_status_list( $data ) { |
| 547 | $order_status = wc_get_order_statuses(); |
| 548 | $options = []; |
| 549 | |
| 550 | if ( ! empty( $order_status ) ) { |
| 551 | foreach ( $order_status as $key => $status ) { |
| 552 | $options[] = [ |
| 553 | 'label' => $status, |
| 554 | 'value' => $key, |
| 555 | ]; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | return [ |
| 560 | 'options' => $options, |
| 561 | 'hasMore' => false, |
| 562 | ]; |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * Prepare WooCommerce Country List. |
| 567 | * |
| 568 | * @param array $data Search Params. |
| 569 | * @return array[] |
| 570 | */ |
| 571 | public function search_woo_country_list( $data ) { |
| 572 | $countries = WC()->countries->get_countries(); |
| 573 | $options = []; |
| 574 | |
| 575 | if ( ! empty( $countries ) ) { |
| 576 | foreach ( $countries as $key => $country ) { |
| 577 | $options[] = [ |
| 578 | 'label' => $country, |
| 579 | 'value' => $key, |
| 580 | ]; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | return [ |
| 585 | 'options' => $options, |
| 586 | 'hasMore' => false, |
| 587 | ]; |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Prepare WooCommerce Country States List. |
| 592 | * |
| 593 | * @param array $data Search Params. |
| 594 | * @return array[] |
| 595 | */ |
| 596 | public function search_woo_country_state_list( $data ) { |
| 597 | if ( ! empty( $data['dynamic']['shipping_country'] ) ) { |
| 598 | $cc = $data['dynamic']['shipping_country']; |
| 599 | } else { |
| 600 | $cc = $data['dynamic']; |
| 601 | } |
| 602 | |
| 603 | $states = WC()->countries->get_states( $cc ); |
| 604 | |
| 605 | $options = []; |
| 606 | if ( ! empty( $states ) ) { |
| 607 | foreach ( $states as $key => $state ) { |
| 608 | $options[] = [ |
| 609 | 'label' => $state, |
| 610 | 'value' => $key, |
| 611 | ]; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | return [ |
| 616 | 'options' => $options, |
| 617 | 'hasMore' => false, |
| 618 | ]; |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * Get Memberpress gatways (payment methods) for subscription. |
| 623 | * |
| 624 | * @param array $data QueryParams. |
| 625 | * |
| 626 | * @return array |
| 627 | * @since 1.0.0 |
| 628 | */ |
| 629 | public function search_memberpress_gayways( $data ) { |
| 630 | $mp_options = MeprOptions::fetch(); |
| 631 | |
| 632 | $pms = array_keys( $mp_options->integrations ); |
| 633 | $gateways = []; |
| 634 | |
| 635 | foreach ( $pms as $pm_id ) { |
| 636 | $obj = $mp_options->payment_method( $pm_id ); |
| 637 | if ( $obj instanceof MeprBaseRealGateway ) { |
| 638 | $gateways[] = [ |
| 639 | 'label' => sprintf( '%1$s (%2$s)', $obj->label, $obj->name ), |
| 640 | 'value' => $obj->id, |
| 641 | ]; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | return [ |
| 646 | 'options' => $gateways, |
| 647 | 'hasMore' => false, |
| 648 | ]; |
| 649 | } |
| 650 | |
| 651 | /** |
| 652 | * Prepare roles. |
| 653 | * |
| 654 | * @param array $data data. |
| 655 | * |
| 656 | * @return array |
| 657 | */ |
| 658 | public function search_roles( $data ) { |
| 659 | $roles = wp_roles()->roles; |
| 660 | $options = []; |
| 661 | foreach ( $roles as $role => $details ) { |
| 662 | |
| 663 | $options[] = [ |
| 664 | 'label' => $details['name'], |
| 665 | 'value' => $role, |
| 666 | ]; |
| 667 | |
| 668 | } |
| 669 | |
| 670 | return [ |
| 671 | 'options' => $options, |
| 672 | 'hasMore' => false, |
| 673 | ]; |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * Fetch operators. |
| 678 | * |
| 679 | * @return array |
| 680 | */ |
| 681 | public function search_condition_operators() { |
| 682 | return [ |
| 683 | 'options' => EventHelperController::get_instance()->prepare_operators(), |
| 684 | 'hasMore' => false, |
| 685 | ]; |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * Prepare post types. |
| 690 | * |
| 691 | * @param array $data data. |
| 692 | * |
| 693 | * @return array |
| 694 | */ |
| 695 | public function search_post_types( $data ) { |
| 696 | $post_types = get_post_types( [ 'public' => true ], 'object' ); |
| 697 | $post_types = apply_filters( 'suretriggers_post_types', $post_types ); |
| 698 | if ( isset( $post_types['attachment'] ) ) { |
| 699 | unset( $post_types['attachment'] ); |
| 700 | } |
| 701 | |
| 702 | $options = []; |
| 703 | foreach ( $post_types as $post_type => $details ) { |
| 704 | $options[] = [ |
| 705 | 'label' => $details->label, |
| 706 | 'value' => $post_type, |
| 707 | ]; |
| 708 | } |
| 709 | |
| 710 | return [ |
| 711 | 'options' => $options, |
| 712 | 'hasMore' => false, |
| 713 | ]; |
| 714 | } |
| 715 | |
| 716 | /** |
| 717 | * Get post statuses. |
| 718 | * |
| 719 | * @param array $data data. |
| 720 | * |
| 721 | * @return array |
| 722 | */ |
| 723 | public function search_post_statuses( $data ) { |
| 724 | $post_statuses = get_post_stati( [], 'objects' ); |
| 725 | $post_statuses = apply_filters( 'suretriggers_post_types', $post_statuses ); |
| 726 | $options = []; |
| 727 | |
| 728 | foreach ( $post_statuses as $post_status => $details ) { |
| 729 | if ( 'woocommerce' === $details->label_count['domain'] ) { |
| 730 | $options[] = [ |
| 731 | 'label' => 'WooCommerce - ' . $details->label, |
| 732 | 'value' => $post_status, |
| 733 | ]; |
| 734 | } else { |
| 735 | $options[] = [ |
| 736 | 'label' => $details->label, |
| 737 | 'value' => $post_status, |
| 738 | ]; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | return [ |
| 743 | 'options' => $options, |
| 744 | 'hasMore' => false, |
| 745 | ]; |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * Get Taxonomies. |
| 750 | * |
| 751 | * @param array $data data. |
| 752 | * |
| 753 | * @return array |
| 754 | */ |
| 755 | public function search_taxonomy_list( $data ) { |
| 756 | $taxonomies = get_taxonomies( [ 'public' => true ], 'objects' ); |
| 757 | $options = []; |
| 758 | $options[0] = [ |
| 759 | 'label' => 'Any Taxonomy', |
| 760 | 'value' => -1, |
| 761 | ]; |
| 762 | |
| 763 | foreach ( $taxonomies as $taxonomy => $taxonomy_obj ) { |
| 764 | $options[] = [ |
| 765 | 'label' => $taxonomy_obj->label, |
| 766 | 'value' => $taxonomy_obj->name, |
| 767 | ]; |
| 768 | } |
| 769 | |
| 770 | return [ |
| 771 | 'options' => $options, |
| 772 | 'hasMore' => false, |
| 773 | ]; |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * Get WPForms. |
| 778 | * |
| 779 | * @param array $data data. |
| 780 | * |
| 781 | * @return array |
| 782 | */ |
| 783 | public function search_wp_forms( $data ) { |
| 784 | if ( ! class_exists( 'WPForms_Form_Handler' ) ) { |
| 785 | return; |
| 786 | } |
| 787 | |
| 788 | $wpforms = new WPForms_Form_Handler(); |
| 789 | $forms = $wpforms->get( '', [ 'orderby' => 'title' ] ); |
| 790 | $options = []; |
| 791 | |
| 792 | if ( ! empty( $forms ) ) { |
| 793 | foreach ( $forms as $form ) { |
| 794 | $options[] = [ |
| 795 | 'label' => $form->post_title, |
| 796 | 'value' => $form->ID, |
| 797 | ]; |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | return [ |
| 802 | 'options' => $options, |
| 803 | 'hasMore' => false, |
| 804 | ]; |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * Get Gravity Forms. |
| 809 | * |
| 810 | * @param array $data data. |
| 811 | * |
| 812 | * @return array |
| 813 | */ |
| 814 | public function search_gravity_forms( $data ) { |
| 815 | if ( ! class_exists( 'GFFormsModel' ) ) { |
| 816 | return; |
| 817 | } |
| 818 | |
| 819 | $forms = GFFormsModel::get_forms(); |
| 820 | $options = []; |
| 821 | |
| 822 | if ( ! empty( $forms ) ) { |
| 823 | foreach ( $forms as $form ) { |
| 824 | $options[] = [ |
| 825 | 'label' => $form->title, |
| 826 | 'value' => $form->id, |
| 827 | ]; |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | return [ |
| 832 | 'options' => $options, |
| 833 | 'hasMore' => false, |
| 834 | ]; |
| 835 | } |
| 836 | |
| 837 | /** |
| 838 | * Get tag & contact details. |
| 839 | * |
| 840 | * @param array $data data. |
| 841 | * |
| 842 | * @return array |
| 843 | */ |
| 844 | public function search_pluggables_fluentcrm_contact_added_to_tags( $data ) { |
| 845 | $context = []; |
| 846 | $pluggable_data = []; |
| 847 | $tag_id = $data['filter']; |
| 848 | |
| 849 | if ( $tag_id > 0 ) { |
| 850 | $tags = Tag::where( 'id', $tag_id )->first(); |
| 851 | } else { |
| 852 | $tags = Tag::orderBy( 'id', 'DESC' )->first(); |
| 853 | } |
| 854 | $contact = Subscriber::orderBy( 'id', 'DESC' )->first(); |
| 855 | if ( $contact ) { |
| 856 | $pluggable_data['contact'] = $contact; |
| 857 | $context['tag_id'] = $tag_id; |
| 858 | $pluggable_data['tag'] = $tags; |
| 859 | $context['response_type'] = 'live'; |
| 860 | } else { |
| 861 | $pluggable_data['conatct']['full_name'] = 'Test User'; |
| 862 | $pluggable_data['conatct']['first_name'] = 'Test'; |
| 863 | $pluggable_data['conatct']['last_name'] = 'User'; |
| 864 | $pluggable_data['conatct']['company_id'] = 112; |
| 865 | $pluggable_data['conatct']['email'] = 'testuser@gmail.com'; |
| 866 | $pluggable_data['conatct']['address_line_1'] = '33, Vincent Road'; |
| 867 | $pluggable_data['conatct']['address_line_2'] = 'Chicago Street'; |
| 868 | $pluggable_data['conatct']['postal_code'] = '212342'; |
| 869 | $pluggable_data['conatct']['city'] = 'New York City'; |
| 870 | $pluggable_data['conatct']['state'] = 'New York'; |
| 871 | $pluggable_data['conatct']['country'] = 'USA'; |
| 872 | $pluggable_data['conatct']['phone'] = '9992191911'; |
| 873 | $pluggable_data['conatct']['status'] = 'subscribed'; |
| 874 | $pluggable_data['conatct']['contact_type'] = 'lead'; |
| 875 | $pluggable_data['conatct']['source'] = ''; |
| 876 | $pluggable_data['conatct']['date_of_birth'] = '2022-11-09'; |
| 877 | $context['tag_id'] = 1; |
| 878 | $pluggable_data['tag'] = |
| 879 | [ |
| 880 | 'id' => '1', |
| 881 | 'title' => 'new', |
| 882 | 'slug' => 'new', |
| 883 | 'description' => null, |
| 884 | 'created_at' => '2023-01-19 10:23:23', |
| 885 | 'updated_at' => '2023-01-19 10:23:23', |
| 886 | 'pivot' => [ |
| 887 | 'subscriber_id' => '1', |
| 888 | 'object_id' => '1', |
| 889 | 'object_type' => 'FluentCrm\\App\\Models\\Tag', |
| 890 | 'created_at' => '2023-01-19 10:42:55', |
| 891 | 'updated_at' => '2023-01-19 10:42:55', |
| 892 | |
| 893 | ], |
| 894 | ]; |
| 895 | $context['response_type'] = 'sample'; |
| 896 | } |
| 897 | |
| 898 | $context['pluggable_data'] = $pluggable_data; |
| 899 | return $context; |
| 900 | } |
| 901 | |
| 902 | /** |
| 903 | * Get FluentCRM contact details. |
| 904 | * |
| 905 | * @param array $data data. |
| 906 | * |
| 907 | * @return array |
| 908 | */ |
| 909 | public function search_pluggables_fluentcrm_contact_added( $data ) { |
| 910 | $context = []; |
| 911 | $pluggable_data = []; |
| 912 | |
| 913 | $contact = Subscriber::orderBy( 'id', 'DESC' )->first(); |
| 914 | if ( $contact ) { |
| 915 | /** |
| 916 | * |
| 917 | * Ignore line |
| 918 | * |
| 919 | * @phpstan-ignore-next-line |
| 920 | */ |
| 921 | $subscriber = Subscriber::with( [ 'tags', 'lists' ] )->find( $contact->id ); |
| 922 | $customer_fields = $subscriber->custom_fields(); |
| 923 | $pluggable_data['contact']['details'] = $subscriber; |
| 924 | $pluggable_data['contact']['custom'] = $customer_fields; |
| 925 | $context['response_type'] = 'live'; |
| 926 | } else { |
| 927 | $pluggable_data['contact']['details']['full_name'] = 'Test User'; |
| 928 | $pluggable_data['contact']['details']['first_name'] = 'Test'; |
| 929 | $pluggable_data['contact']['details']['last_name'] = 'User'; |
| 930 | $pluggable_data['contact']['details']['company_id'] = 112; |
| 931 | $pluggable_data['contact']['details']['email'] = 'testuser@gmail.com'; |
| 932 | $pluggable_data['contact']['details']['address_line_1'] = '33, Vincent Road'; |
| 933 | $pluggable_data['contact']['details']['address_line_2'] = 'Chicago Street'; |
| 934 | $pluggable_data['contact']['details']['postal_code'] = '212342'; |
| 935 | $pluggable_data['contact']['details']['city'] = 'New York City'; |
| 936 | $pluggable_data['contact']['details']['state'] = 'New York'; |
| 937 | $pluggable_data['contact']['details']['country'] = 'USA'; |
| 938 | $pluggable_data['contact']['details']['phone'] = '9992191911'; |
| 939 | $pluggable_data['contact']['details']['status'] = 'subscribed'; |
| 940 | $pluggable_data['contact']['details']['contact_type'] = 'lead'; |
| 941 | $pluggable_data['contact']['details']['source'] = ''; |
| 942 | $pluggable_data['contact']['details']['date_of_birth'] = '2022-11-09'; |
| 943 | $context['response_type'] = 'sample'; |
| 944 | } |
| 945 | |
| 946 | $context['pluggable_data'] = $pluggable_data; |
| 947 | return $context; |
| 948 | } |
| 949 | |
| 950 | /** |
| 951 | * Get Divi Forms. |
| 952 | * |
| 953 | * @param array $data data. |
| 954 | * |
| 955 | * @return array |
| 956 | */ |
| 957 | public function search_divi_forms( $data ) { |
| 958 | $form_posts = Utilities::get_divi_forms(); |
| 959 | $options = []; |
| 960 | |
| 961 | if ( empty( $form_posts ) ) { |
| 962 | return [ |
| 963 | 'options' => [], |
| 964 | 'hasMore' => false, |
| 965 | ]; |
| 966 | } |
| 967 | |
| 968 | foreach ( $form_posts as $form_post ) { |
| 969 | $pattern_regex = '/\[et_pb_contact_form(.*?)](.+?)\[\/et_pb_contact_form]/'; |
| 970 | preg_match_all( $pattern_regex, $form_post['post_content'], $forms, PREG_SET_ORDER ); |
| 971 | if ( empty( $forms ) ) { |
| 972 | continue; |
| 973 | } |
| 974 | |
| 975 | $count = 0; |
| 976 | |
| 977 | foreach ( $forms as $form ) { |
| 978 | $pattern_form = get_shortcode_regex( [ 'et_pb_contact_form' ] ); |
| 979 | preg_match_all( "/$pattern_form/", $form[0], $forms_extracted, PREG_SET_ORDER ); |
| 980 | |
| 981 | if ( empty( $forms_extracted ) ) { |
| 982 | continue; |
| 983 | } |
| 984 | |
| 985 | foreach ( $forms_extracted as $form_extracted ) { |
| 986 | $form_attrs = shortcode_parse_atts( $form_extracted[3] ); |
| 987 | $form_id = isset( $form_attrs['_unique_id'] ) ? $form_attrs['_unique_id'] : ''; |
| 988 | if ( empty( $form_id ) ) { |
| 989 | continue; |
| 990 | } |
| 991 | $form_id = sprintf( '%d-%s', $form_post['ID'], $form_id ); |
| 992 | $form_title = isset( $form_attrs['title'] ) ? $form_attrs['title'] : ''; |
| 993 | $form_title = sprintf( '%s %s', $form_post['post_title'], $form_title ); |
| 994 | $options[] = [ |
| 995 | 'label' => $form_title, |
| 996 | 'value' => $form_id, |
| 997 | ]; |
| 998 | } |
| 999 | $count++; |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | return [ |
| 1004 | 'options' => $options, |
| 1005 | 'hasMore' => false, |
| 1006 | ]; |
| 1007 | } |
| 1008 | |
| 1009 | /** |
| 1010 | * Get Comment Pluggable data. |
| 1011 | * |
| 1012 | * @param array $data data. |
| 1013 | * |
| 1014 | * @return array |
| 1015 | */ |
| 1016 | public function search_pluggables_wp_insert_comment( $data ) { |
| 1017 | $context = []; |
| 1018 | $post_data = []; |
| 1019 | $args = [ |
| 1020 | 'number' => '1', |
| 1021 | 'status' => 'approve', |
| 1022 | 'post_type' => $data['filter']['post_type']['value'], |
| 1023 | ]; |
| 1024 | |
| 1025 | if ( isset( $data['filter']['post']['value'] ) ) { |
| 1026 | $post_id = $data['filter']['post']['value']; |
| 1027 | if ( $post_id > 0 ) { |
| 1028 | $args['post_id'] = $post_id; |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | $comments = get_comments( $args ); |
| 1033 | if ( empty( $comments ) ) { |
| 1034 | unset( $args['post_id'] ); |
| 1035 | $comments = get_comments( $args ); |
| 1036 | } |
| 1037 | $context['context_data'] = $data; |
| 1038 | $context['context_args'] = $args; |
| 1039 | if ( ! empty( $comments ) ) { |
| 1040 | foreach ( $comments as $comment ) : |
| 1041 | if ( is_object( $comment ) ) { |
| 1042 | $comment = get_object_vars( $comment ); |
| 1043 | } |
| 1044 | if ( is_array( $comment ) && isset( $comment['comment_post_ID'] ) ) { |
| 1045 | $post = get_post( absint( $comment['comment_post_ID'] ) ); |
| 1046 | if ( is_object( $post ) ) { |
| 1047 | if ( property_exists( $post, 'ID' ) || property_exists( $post, 'post_author' ) || property_exists( $post, 'post_title' ) ) { |
| 1048 | $post_id = $post->ID; |
| 1049 | $postauthor = (int) $post->post_author; |
| 1050 | if ( is_array( $comment ) ) { |
| 1051 | $context['pluggable_data'] = [ |
| 1052 | 'post' => $post_id, |
| 1053 | 'post_title' => $post->post_title, |
| 1054 | 'post_author' => get_the_author_meta( 'display_name', $postauthor ), |
| 1055 | 'post_link' => get_the_permalink( $post_id ), |
| 1056 | 'comment_id' => $comment['comment_ID'], |
| 1057 | 'comment' => $comment['comment_content'], |
| 1058 | 'comment_author' => $comment['comment_author'], |
| 1059 | 'comment_author_email' => $comment['comment_author_email'], |
| 1060 | 'comment_date' => $comment['comment_date'], |
| 1061 | ]; |
| 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | } |
| 1066 | if ( is_array( $comment ) && isset( $comment['comment_author_email'] ) ) { |
| 1067 | $user_email = $comment['comment_author_email']; |
| 1068 | /** |
| 1069 | * |
| 1070 | * Ignore line |
| 1071 | * |
| 1072 | * @phpstan-ignore-next-line |
| 1073 | */ |
| 1074 | $user = get_user_by( 'email', $user_email ); |
| 1075 | if ( $user ) { |
| 1076 | $context['pluggable_data']['wp_user_id'] = $user->ID; |
| 1077 | $context['pluggable_data']['user_login'] = $user->user_login; |
| 1078 | $context['pluggable_data']['display_name'] = $user->display_name; |
| 1079 | $context['pluggable_data']['user_firstname'] = $user->user_firstname; |
| 1080 | $context['pluggable_data']['user_lastname'] = $user->user_lastname; |
| 1081 | $context['pluggable_data']['user_email'] = $user->user_email; |
| 1082 | $context['pluggable_data']['user_role'] = $user->roles; |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | $context['response_type'] = 'live'; |
| 1087 | endforeach; |
| 1088 | } else { |
| 1089 | $sample_comment = [ |
| 1090 | 'post' => 100, |
| 1091 | 'post_title' => 'Sample Post', |
| 1092 | 'comment_id' => 101, |
| 1093 | 'comment' => 'Sample Comment', |
| 1094 | ]; |
| 1095 | $sample_comment['wp_user_id'] = 7; |
| 1096 | $sample_comment['user_login'] = 'testuser@gmail.com'; |
| 1097 | $sample_comment['display_name'] = 'Test User'; |
| 1098 | $sample_comment['user_firstname'] = 'Test'; |
| 1099 | $sample_comment['user_lastname'] = 'User'; |
| 1100 | $sample_comment['user_email'] = 'testuser@gmail.com'; |
| 1101 | $sample_comment['user_role'] = [ 'Subscriber' ]; |
| 1102 | |
| 1103 | $context['pluggable_data'] = $sample_comment; |
| 1104 | $context['response_type'] = 'sample'; |
| 1105 | } |
| 1106 | return $context; |
| 1107 | } |
| 1108 | |
| 1109 | /** |
| 1110 | * User reset password. |
| 1111 | * |
| 1112 | * @param array $data data. |
| 1113 | * @return array |
| 1114 | */ |
| 1115 | public function search_pluggables_user_reset_password( $data ) { |
| 1116 | $user_context = $this->search_pluggables_add_user_role( $data ); |
| 1117 | $user_context['pluggable_data']['new_password'] = '***password***'; |
| 1118 | return $user_context; |
| 1119 | } |
| 1120 | |
| 1121 | /** |
| 1122 | * User pluggable data. |
| 1123 | * |
| 1124 | * @param array $data data. |
| 1125 | * @return array |
| 1126 | */ |
| 1127 | public function search_pluggables_add_user_role( $data ) { |
| 1128 | $context = []; |
| 1129 | $args = [ |
| 1130 | 'order' => 'DESC', |
| 1131 | 'number' => 1, |
| 1132 | 'orderby' => 'ID', |
| 1133 | ]; |
| 1134 | |
| 1135 | if ( isset( $data['filter']['role']['value'] ) ) { |
| 1136 | $role = $data['filter']['role']['value']; |
| 1137 | $args['role'] = $role; |
| 1138 | } |
| 1139 | if ( isset( $data['filter']['new_role']['value'] ) ) { |
| 1140 | $role = $data['filter']['new_role']['value']; |
| 1141 | $args['role'] = $role; |
| 1142 | } |
| 1143 | |
| 1144 | $users = get_users( $args ); |
| 1145 | |
| 1146 | if ( isset( $data['filter']['meta_key']['value'] ) ) { |
| 1147 | $meta_key = $data['filter']['meta_key']['value']; |
| 1148 | $args['st_meta_key'] = $meta_key; |
| 1149 | } |
| 1150 | |
| 1151 | if ( isset( $data['filter']['profile_field']['value'] ) ) { |
| 1152 | $meta_key = $data['filter']['profile_field']['value']; |
| 1153 | $args['profile_field'] = $meta_key; |
| 1154 | } |
| 1155 | |
| 1156 | if ( ! empty( $users ) ) { |
| 1157 | $user = $users[0]; |
| 1158 | $pluggable_data = []; |
| 1159 | $pluggable_data['wp_user_id'] = $user->ID; |
| 1160 | $pluggable_data['user_login'] = $user->user_login; |
| 1161 | $pluggable_data['display_name'] = $user->display_name; |
| 1162 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 1163 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 1164 | $pluggable_data['user_email'] = $user->user_email; |
| 1165 | $pluggable_data['user_role'] = $user->roles; |
| 1166 | if ( isset( $args['st_meta_key'] ) ) { |
| 1167 | $pluggable_data['meta_key'] = $args['st_meta_key']; |
| 1168 | $pluggable_data['meta_value'] = get_user_meta( $user->ID, $args['st_meta_key'], true ); |
| 1169 | } |
| 1170 | if ( isset( $args['profile_field'] ) ) { |
| 1171 | $userdata = get_userdata( $user->ID ); |
| 1172 | $userdata = json_decode( wp_json_encode( $userdata->data ), true ); |
| 1173 | |
| 1174 | $pluggable_data['profile_field'] = $args['profile_field']; |
| 1175 | $pluggable_data['profile_field_value'] = $userdata[ $args['profile_field'] ]; |
| 1176 | } |
| 1177 | $context['pluggable_data'] = $pluggable_data; |
| 1178 | $context['response_type'] = 'live'; |
| 1179 | } else { |
| 1180 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 1181 | $context['pluggable_data'] = [ |
| 1182 | 'wp_user_id' => 1, |
| 1183 | 'user_login' => 'admin', |
| 1184 | 'display_name' => 'Test User', |
| 1185 | 'user_firstname' => 'Test', |
| 1186 | 'user_lastname' => 'User', |
| 1187 | 'user_email' => 'testuser@gmail.com', |
| 1188 | 'user_role' => [ $role ], |
| 1189 | ]; |
| 1190 | if ( isset( $args['st_meta_key'] ) ) { |
| 1191 | $context['pluggable_data']['meta_key'] = $args['st_meta_key']; |
| 1192 | $context['pluggable_data']['meta_value'] = 'test meta value'; |
| 1193 | } |
| 1194 | if ( isset( $args['profile_field'] ) ) { |
| 1195 | $context['pluggable_data']['profile_field'] = $args['profile_field']; |
| 1196 | $context['pluggable_data']['profile_field_value'] = 'Profile Field Value'; |
| 1197 | } |
| 1198 | $context['response_type'] = 'sample'; |
| 1199 | } |
| 1200 | return $context; |
| 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * User pluggable data. |
| 1205 | * |
| 1206 | * @param array $data data. |
| 1207 | * @return array |
| 1208 | */ |
| 1209 | public function search_pluggables_last_user_login( $data ) { |
| 1210 | $context = []; |
| 1211 | $args = [ |
| 1212 | 'orderby' => 'meta_value', |
| 1213 | 'meta_key' => 'st_last_login', |
| 1214 | 'order' => 'DESC', |
| 1215 | 'number' => 1, |
| 1216 | ]; |
| 1217 | $users = get_users( $args ); |
| 1218 | |
| 1219 | if ( ! empty( $users ) ) { |
| 1220 | $user = $users[0]; |
| 1221 | $pluggable_data = []; |
| 1222 | $pluggable_data['wp_user_id'] = $user->ID; |
| 1223 | $pluggable_data['user_login'] = $user->user_login; |
| 1224 | $pluggable_data['display_name'] = $user->display_name; |
| 1225 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 1226 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 1227 | $pluggable_data['user_email'] = $user->user_email; |
| 1228 | $pluggable_data['user_role'] = $user->roles; |
| 1229 | |
| 1230 | $context['pluggable_data'] = $pluggable_data; |
| 1231 | $context['response_type'] = 'live'; |
| 1232 | } else { |
| 1233 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 1234 | $context['pluggable_data'] = [ |
| 1235 | 'wp_user_id' => 1, |
| 1236 | 'user_login' => 'admin', |
| 1237 | 'display_name' => 'Test User', |
| 1238 | 'user_firstname' => 'Test', |
| 1239 | 'user_lastname' => 'User', |
| 1240 | 'user_email' => 'testuser@gmail.com', |
| 1241 | 'user_role' => [ $role ], |
| 1242 | ]; |
| 1243 | $context['response_type'] = 'sample'; |
| 1244 | } |
| 1245 | return $context; |
| 1246 | } |
| 1247 | |
| 1248 | /** |
| 1249 | * Donation pluggable data. |
| 1250 | * |
| 1251 | * @param array $data data. |
| 1252 | * @return array |
| 1253 | */ |
| 1254 | public function search_pluggables_wordpress_post( $data ) { |
| 1255 | $context = []; |
| 1256 | $args = [ |
| 1257 | 'post_type' => 'any', |
| 1258 | 'posts_per_page' => 1, |
| 1259 | 'orderby' => 'modified', |
| 1260 | 'order' => 'DESC', |
| 1261 | ]; |
| 1262 | |
| 1263 | if ( isset( $data['filter']['post_type']['value'] ) ) { |
| 1264 | $post_type = $data['filter']['post_type']['value']; |
| 1265 | $args['post_type'] = $post_type; |
| 1266 | } |
| 1267 | |
| 1268 | if ( isset( $data['filter']['status']['value'] ) ) { |
| 1269 | $post_status = $data['filter']['status']['value']; |
| 1270 | $args['post_status'] = $post_status; |
| 1271 | } |
| 1272 | |
| 1273 | if ( isset( $data['filter']['post_status']['value'] ) ) { |
| 1274 | $post_status = $data['filter']['post_status']['value']; |
| 1275 | $args['post_status'] = $post_status; |
| 1276 | } |
| 1277 | |
| 1278 | if ( isset( $data['filter']['post']['value'] ) ) { |
| 1279 | $post_id = $data['filter']['post']['value']; |
| 1280 | if ( $post_id > 0 ) { |
| 1281 | $args['p'] = $post_id; |
| 1282 | unset( $args['post_status'] ); |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | $posts = get_posts( $args ); |
| 1287 | if ( ! empty( $posts ) ) { |
| 1288 | $context['pluggable_data'] = $posts[0]; |
| 1289 | $custom_metas = get_post_meta( $posts[0]->ID ); |
| 1290 | if ( property_exists( $context['pluggable_data'], 'post' ) ) { |
| 1291 | $context['pluggable_data']->post = $posts[0]->ID; |
| 1292 | } |
| 1293 | if ( is_object( $context['pluggable_data'] ) ) { |
| 1294 | $context['pluggable_data'] = get_object_vars( $context['pluggable_data'] ); |
| 1295 | } |
| 1296 | $context['pluggable_data']['custom_metas'] = $custom_metas; |
| 1297 | $context['response_type'] = 'live'; |
| 1298 | } else { |
| 1299 | $context['pluggable_data'] = [ |
| 1300 | 'ID' => 557, |
| 1301 | 'post' => 557, |
| 1302 | 'post_author' => 1, |
| 1303 | 'post_date' => '2022-11-18 12:18:14', |
| 1304 | 'post_date_gmt' => '2022-11-18 12:18:14', |
| 1305 | 'post_content' => 'Test Post Content', |
| 1306 | 'post_title' => 'Test Post', |
| 1307 | 'post_excerpt' => '', |
| 1308 | 'post_status' => $args['post_status'], |
| 1309 | 'comment_status' => 'open', |
| 1310 | 'ping_status' => 'open', |
| 1311 | 'post_password' => '', |
| 1312 | 'post_name' => 'test-post', |
| 1313 | 'to_ping' => '', |
| 1314 | 'pinged' => '', |
| 1315 | 'post_modified' => '2022-11-18 12:18:14', |
| 1316 | 'post_modified_gmt' => '2022-11-18 12:18:14', |
| 1317 | 'post_content_filtered' => '', |
| 1318 | 'post_parent' => 0, |
| 1319 | 'guid' => 'https://abc.com/test-post/', |
| 1320 | 'menu_order' => 0, |
| 1321 | 'post_type' => 'post', |
| 1322 | 'post_mime_type' => '', |
| 1323 | 'comment_count' => 0, |
| 1324 | 'filter' => 'raw', |
| 1325 | ]; |
| 1326 | $context['response_type'] = 'sample'; |
| 1327 | } |
| 1328 | |
| 1329 | return $context; |
| 1330 | } |
| 1331 | |
| 1332 | /** |
| 1333 | * Donation pluggable data |
| 1334 | * |
| 1335 | * @param array $data data. |
| 1336 | * @return array |
| 1337 | */ |
| 1338 | public function search_pluggables_givewp_donation_via_form( $data ) { |
| 1339 | global $wpdb; |
| 1340 | $context = []; |
| 1341 | $pluggable_data = []; |
| 1342 | |
| 1343 | $payment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type=%s ORDER BY id DESC LIMIT 1", 'give_payment' ) ); |
| 1344 | |
| 1345 | if ( ! empty( $payment ) ) { |
| 1346 | $payment = new Give_Payment( $payment->ID ); |
| 1347 | $address_data = $payment->address; |
| 1348 | |
| 1349 | $pluggable_data['first_name'] = $payment->first_name; |
| 1350 | $pluggable_data['last_name'] = $payment->last_name; |
| 1351 | $pluggable_data['email'] = $payment->email; |
| 1352 | $pluggable_data['currency'] = $payment->currency; |
| 1353 | $pluggable_data['donated_amount'] = $payment->subtotal; |
| 1354 | $pluggable_data['donation_amount'] = $payment->subtotal; |
| 1355 | $pluggable_data['form_id'] = (int) $payment->form_id; |
| 1356 | $pluggable_data['form_title'] = $payment->form_title; |
| 1357 | $pluggable_data['name_title_prefix'] = $payment->title_prefix; |
| 1358 | $pluggable_data['date'] = $payment->date; |
| 1359 | |
| 1360 | if ( is_array( $address_data ) ) { |
| 1361 | $pluggable_data['address_line_1'] = $address_data['line1']; |
| 1362 | $pluggable_data['address_line_2'] = $address_data['line2']; |
| 1363 | $pluggable_data['city'] = $address_data['city']; |
| 1364 | $pluggable_data['state'] = $address_data['state']; |
| 1365 | $pluggable_data['zip'] = $address_data['zip']; |
| 1366 | $pluggable_data['country'] = $address_data['country']; |
| 1367 | } |
| 1368 | $donor_comment = give_get_donor_donation_comment( $payment->ID, $payment->donor_id ); |
| 1369 | $pluggable_data['comment'] = isset( $doner['comment_content'] ) ? $donor_comment : ''; |
| 1370 | $context['response_type'] = 'live'; |
| 1371 | } else { |
| 1372 | $pluggable_data['first_name'] = 'Test'; |
| 1373 | $pluggable_data['last_name'] = 'User'; |
| 1374 | $pluggable_data['email'] = 'testuser@gmail.com'; |
| 1375 | $pluggable_data['currency'] = 'USD'; |
| 1376 | $pluggable_data['donated_amount'] = 100; |
| 1377 | $pluggable_data['donation_amount'] = 100; |
| 1378 | $pluggable_data['form_id'] = 23; |
| 1379 | $pluggable_data['form_title'] = 'Test Donation'; |
| 1380 | $pluggable_data['name_title_prefix'] = 'Mr'; |
| 1381 | $pluggable_data['date'] = '2022-11-07 16:06:05'; |
| 1382 | $pluggable_data['address_line_1'] = '33, Vincent Road'; |
| 1383 | $pluggable_data['address_line_2'] = 'Chicago Street'; |
| 1384 | $pluggable_data['city'] = 'New York City'; |
| 1385 | $pluggable_data['state'] = 'New York'; |
| 1386 | $pluggable_data['zip'] = '223131'; |
| 1387 | $pluggable_data['country'] = 'USA'; |
| 1388 | $pluggable_data['comment'] = 'Test Comment'; |
| 1389 | $context['response_type'] = 'sample'; |
| 1390 | } |
| 1391 | |
| 1392 | $context['pluggable_data'] = $pluggable_data; |
| 1393 | return $context; |
| 1394 | } |
| 1395 | |
| 1396 | /** |
| 1397 | * Search Divi Form fields. |
| 1398 | * |
| 1399 | * @param array $data Search Params. |
| 1400 | * |
| 1401 | * @since 1.0.0 |
| 1402 | * |
| 1403 | * @return array |
| 1404 | */ |
| 1405 | public function search_pluggable_divi_form_fields( $data ) { |
| 1406 | $result = []; |
| 1407 | $form_id = absint( $data['dynamic'] ); |
| 1408 | $form_posts = Utilities::get_divi_forms(); |
| 1409 | |
| 1410 | if ( empty( $form_posts ) ) { |
| 1411 | return [ |
| 1412 | 'options' => [], |
| 1413 | 'hasMore' => false, |
| 1414 | ]; |
| 1415 | } |
| 1416 | $fields = []; |
| 1417 | foreach ( $form_posts as $form_post ) { |
| 1418 | $pattern_regex = '/\[et_pb_contact_form(.*?)](.+?)\[\/et_pb_contact_form]/'; |
| 1419 | preg_match_all( $pattern_regex, $form_post['post_content'], $forms, PREG_SET_ORDER ); |
| 1420 | if ( empty( $forms ) ) { |
| 1421 | continue; |
| 1422 | } |
| 1423 | |
| 1424 | $count = 0; |
| 1425 | |
| 1426 | foreach ( $forms as $form ) { |
| 1427 | $pattern = get_shortcode_regex( [ 'et_pb_contact_field' ] ); |
| 1428 | |
| 1429 | preg_match_all( "/$pattern/", $form[0], $contact_fields, PREG_SET_ORDER ); |
| 1430 | |
| 1431 | if ( empty( $contact_fields ) ) { |
| 1432 | return $fields; |
| 1433 | } |
| 1434 | |
| 1435 | foreach ( $contact_fields as $contact_field ) { |
| 1436 | $contact_field_attrs = shortcode_parse_atts( $contact_field[3] ); |
| 1437 | $field_id = strtolower( self::array_get( $contact_field_attrs, 'field_id' ) ); |
| 1438 | $fields[] = [ |
| 1439 | 'field_title' => self::array_get( $contact_field_attrs, 'field_title', __( 'No title', 'suretriggers' ) ), |
| 1440 | 'field_id' => $field_id, |
| 1441 | ]; |
| 1442 | } |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | if ( ! empty( $fields ) ) { |
| 1447 | foreach ( $fields as $field ) { |
| 1448 | $result[] = [ |
| 1449 | 'label' => $field['field_title'], |
| 1450 | 'value' => '{' . $field['field_id'] . '}', |
| 1451 | ]; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | return [ |
| 1456 | 'options' => $result, |
| 1457 | 'hasMore' => false, |
| 1458 | ]; |
| 1459 | } |
| 1460 | |
| 1461 | /** |
| 1462 | * Pseudo function copied from Divi |
| 1463 | * |
| 1464 | * @param array $array An array which contains value located at `$address`. |
| 1465 | * @param string|array $address The location of the value within `$array` (dot notation). |
| 1466 | * @param mixed $default Value to return if not found. Default is an empty string. |
| 1467 | * |
| 1468 | * @return mixed The value, if found, otherwise $default. |
| 1469 | */ |
| 1470 | public static function array_get( $array, $address, $default = '' ) { |
| 1471 | $keys = is_array( $address ) ? $address : explode( '.', $address ); |
| 1472 | $value = $array; |
| 1473 | |
| 1474 | foreach ( $keys as $key ) { |
| 1475 | if ( ! empty( $key ) && isset( $key[0] ) && '[' === $key[0] ) { |
| 1476 | $index = substr( $key, 1, -1 ); |
| 1477 | |
| 1478 | if ( is_numeric( $index ) ) { |
| 1479 | $key = (int) $index; |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | if ( ! isset( $value[ $key ] ) ) { |
| 1484 | return $default; |
| 1485 | } |
| 1486 | |
| 1487 | $value = $value[ $key ]; |
| 1488 | } |
| 1489 | |
| 1490 | return $value; |
| 1491 | } |
| 1492 | |
| 1493 | /** |
| 1494 | * Get UAG Forms. |
| 1495 | * |
| 1496 | * @param array $data data. |
| 1497 | * |
| 1498 | * @return array |
| 1499 | */ |
| 1500 | public function search_spectra_forms( $data ) { |
| 1501 | $form_posts = Utilities::get_uag_forms(); |
| 1502 | |
| 1503 | $options = []; |
| 1504 | if ( empty( $form_posts ) ) { |
| 1505 | return [ |
| 1506 | 'options' => [], |
| 1507 | 'hasMore' => false, |
| 1508 | ]; |
| 1509 | } |
| 1510 | |
| 1511 | foreach ( $form_posts as $form_post ) { |
| 1512 | $blocks = parse_blocks( $form_post['post_content'] ); |
| 1513 | $i = 1; |
| 1514 | foreach ( $blocks as $key => $block ) { |
| 1515 | if ( 'uagb/forms' === $block['blockName'] ) { |
| 1516 | $options[] = [ |
| 1517 | 'label' => $form_post['post_title'] . ' (Form ' . ( $i ) . ')', |
| 1518 | 'value' => $block['attrs']['block_id'], |
| 1519 | ]; |
| 1520 | $i++; |
| 1521 | } elseif ( 'uagb/forms' !== $block['blockName'] && isset( $block['innerBlocks'] ) ) { |
| 1522 | foreach ( $block['innerBlocks'] as $element ) { |
| 1523 | if ( is_array( $element ) && isset( $element['blockName'] ) && 'uagb/forms' === $element['blockName'] ) { |
| 1524 | $options[] = [ |
| 1525 | 'label' => $form_post['post_title'] . ' (Form ' . ( $i ) . ')', |
| 1526 | 'value' => $element['attrs']['block_id'], |
| 1527 | ]; |
| 1528 | $i++; |
| 1529 | } elseif ( is_array( $element ) && isset( $element['innerBlocks'] ) ) { |
| 1530 | foreach ( $element['innerBlocks'] as $inner_block ) { |
| 1531 | if ( isset( $inner_block['blockName'] ) && 'uagb/forms' === $inner_block['blockName'] ) { |
| 1532 | $options[] = [ |
| 1533 | 'label' => $form_post['post_title'] . ' (Form ' . ( $i ) . ')', |
| 1534 | 'value' => $inner_block['attrs']['block_id'], |
| 1535 | ]; |
| 1536 | $i++; |
| 1537 | } |
| 1538 | } |
| 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | return [ |
| 1546 | 'options' => $options, |
| 1547 | 'hasMore' => false, |
| 1548 | ]; |
| 1549 | } |
| 1550 | |
| 1551 | /** |
| 1552 | * Check array recursive. |
| 1553 | * |
| 1554 | * @param array $array Array. |
| 1555 | * @param string $value search params. |
| 1556 | * @since 1.0.0 |
| 1557 | * |
| 1558 | * @return array|void |
| 1559 | */ |
| 1560 | public static function get_column_by_value( $array, $value ) { |
| 1561 | |
| 1562 | foreach ( $array as $key => $sub_array ) { |
| 1563 | |
| 1564 | if ( is_array( $sub_array ) ) { |
| 1565 | $result = self::get_column_by_value( $sub_array, $value ); |
| 1566 | if ( null !== $result ) { |
| 1567 | return $key; |
| 1568 | } |
| 1569 | } else { |
| 1570 | return $key; |
| 1571 | } |
| 1572 | } |
| 1573 | return null; |
| 1574 | |
| 1575 | } |
| 1576 | |
| 1577 | |
| 1578 | /** |
| 1579 | * Search UAG Form fields. |
| 1580 | * |
| 1581 | * @param array $data Search Params. |
| 1582 | * |
| 1583 | * @since 1.0.0 |
| 1584 | * |
| 1585 | * @return array |
| 1586 | */ |
| 1587 | public function search_spectraform_fields( $data ) { |
| 1588 | $result = []; |
| 1589 | $form_id = absint( $data['dynamic'] ); |
| 1590 | $form_posts = Utilities::get_uag_forms(); |
| 1591 | |
| 1592 | if ( empty( $form_posts ) ) { |
| 1593 | return [ |
| 1594 | 'options' => [], |
| 1595 | 'hasMore' => false, |
| 1596 | ]; |
| 1597 | } |
| 1598 | |
| 1599 | foreach ( $form_posts as $form_post ) { |
| 1600 | $blocks = parse_blocks( $form_post['post_content'] ); |
| 1601 | |
| 1602 | foreach ( $blocks as $block ) { |
| 1603 | if ( (int) $block['attrs']['block_id'] === $form_id ) { |
| 1604 | $doc = new DOMDocument(); |
| 1605 | $rendered_block = render_block( $block ); |
| 1606 | $doc->loadHTML( $rendered_block ); |
| 1607 | $child_node_list = $doc->getElementsByTagName( 'div' ); |
| 1608 | for ( $i = 0; $i < $child_node_list->length; $i++ ) { |
| 1609 | $temp = $child_node_list->item( $i ); |
| 1610 | if ( $temp && stripos( $temp->getAttribute( 'class' ), 'uagb-forms-input-label' ) !== false ) { |
| 1611 | $nodes[] = $temp; |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | foreach ( $nodes as $node ) { |
| 1616 | $result[] = [ |
| 1617 | 'label' => $node->textContent, //phpcs:ignore |
| 1618 | 'value' => $node->textContent, //phpcs:ignore |
| 1619 | ]; |
| 1620 | } |
| 1621 | } |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | return [ |
| 1626 | 'options' => $result, |
| 1627 | 'hasMore' => false, |
| 1628 | ]; |
| 1629 | } |
| 1630 | |
| 1631 | /** |
| 1632 | * Search forms of MetForms. |
| 1633 | * |
| 1634 | * @param array $data data. |
| 1635 | * @return array |
| 1636 | */ |
| 1637 | public function search_met_forms( $data ) { |
| 1638 | $args = [ |
| 1639 | 'post_type' => 'metform-form', |
| 1640 | 'post_status' => 'publish', |
| 1641 | 'numberposts' => -1, |
| 1642 | ]; |
| 1643 | |
| 1644 | $forms = get_posts( $args ); |
| 1645 | |
| 1646 | $options = []; |
| 1647 | |
| 1648 | if ( ! empty( $forms ) ) { |
| 1649 | foreach ( $forms as $form ) { |
| 1650 | $options[] = [ |
| 1651 | 'label' => $form->post_title, |
| 1652 | 'value' => $form->ID, |
| 1653 | ]; |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | return [ |
| 1658 | 'options' => $options, |
| 1659 | 'hasMore' => false, |
| 1660 | ]; |
| 1661 | } |
| 1662 | |
| 1663 | /** |
| 1664 | * Search forms of Ninja Forms. |
| 1665 | * |
| 1666 | * @param array $data data. |
| 1667 | * @return array |
| 1668 | */ |
| 1669 | public function search_ninja_forms( $data ) { |
| 1670 | $options = []; |
| 1671 | |
| 1672 | if ( function_exists( 'Ninja_Forms' ) ) { |
| 1673 | foreach ( Ninja_Forms()->form()->get_forms() as $form ) { |
| 1674 | $options[] = [ |
| 1675 | 'label' => $form->get_setting( 'title' ), |
| 1676 | 'value' => $form->get_id(), |
| 1677 | ]; |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | return [ |
| 1682 | 'options' => $options, |
| 1683 | 'hasMore' => false, |
| 1684 | ]; |
| 1685 | } |
| 1686 | |
| 1687 | /** |
| 1688 | * Search forms of Pie Forms. |
| 1689 | * |
| 1690 | * @param array $data data. |
| 1691 | * @return array |
| 1692 | */ |
| 1693 | public function search_pie_forms( $data ) { |
| 1694 | global $wpdb; |
| 1695 | $options = []; |
| 1696 | |
| 1697 | if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'pf_forms' ) ) ) { |
| 1698 | |
| 1699 | $results = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'pf_forms WHERE post_status = "published"' ); |
| 1700 | |
| 1701 | if ( $results ) { |
| 1702 | foreach ( $results as $result ) { |
| 1703 | $options[] = [ |
| 1704 | 'label' => $result->form_title, |
| 1705 | 'value' => $result->id, |
| 1706 | ]; |
| 1707 | } |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | return [ |
| 1712 | 'options' => $options, |
| 1713 | 'hasMore' => false, |
| 1714 | ]; |
| 1715 | } |
| 1716 | |
| 1717 | /** |
| 1718 | * Get Fluent Forms. |
| 1719 | * |
| 1720 | * @param array $data data. |
| 1721 | * |
| 1722 | * @return array |
| 1723 | */ |
| 1724 | public function search_fluent_forms( $data ) { |
| 1725 | |
| 1726 | if ( ! function_exists( 'wpFluent' ) ) { |
| 1727 | return [ |
| 1728 | 'options' => [], |
| 1729 | 'hasMore' => false, |
| 1730 | ]; |
| 1731 | } |
| 1732 | |
| 1733 | $forms = wpFluent()->table( 'fluentform_forms' ) |
| 1734 | ->select( [ 'id', 'title' ] ) |
| 1735 | ->orderBy( 'id', 'DESC' ) |
| 1736 | ->get(); |
| 1737 | |
| 1738 | $options = []; |
| 1739 | if ( ! empty( $forms ) ) { |
| 1740 | foreach ( $forms as $form ) { |
| 1741 | $options[] = [ |
| 1742 | 'label' => $form->title, |
| 1743 | 'value' => $form->id, |
| 1744 | ]; |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | return [ |
| 1749 | 'options' => $options, |
| 1750 | 'hasMore' => false, |
| 1751 | ]; |
| 1752 | |
| 1753 | } |
| 1754 | |
| 1755 | /** |
| 1756 | * Get Fluent Forms. |
| 1757 | * |
| 1758 | * @param array $data data. |
| 1759 | * |
| 1760 | * @return array |
| 1761 | */ |
| 1762 | public function search_bricks_builder_forms( $data ) { |
| 1763 | $bricks_theme = wp_get_theme( 'bricks' ); |
| 1764 | if ( ! $bricks_theme->exists() ) { |
| 1765 | return [ |
| 1766 | 'options' => [], |
| 1767 | 'hasMore' => false, |
| 1768 | ]; |
| 1769 | } |
| 1770 | |
| 1771 | $args = [ |
| 1772 | 'post_type' => 'bricks_template', |
| 1773 | 'post_status' => 'publish', |
| 1774 | 'posts_per_page' => -1, |
| 1775 | ]; |
| 1776 | |
| 1777 | $templates = get_posts( $args ); |
| 1778 | |
| 1779 | $options = []; |
| 1780 | if ( ! empty( $templates ) ) { |
| 1781 | foreach ( $templates as $template ) { |
| 1782 | $fetch_content = get_post_meta( $template->ID, BRICKS_DB_PAGE_CONTENT, true ); |
| 1783 | if ( is_array( $fetch_content ) ) { |
| 1784 | foreach ( $fetch_content as $content ) { |
| 1785 | if ( 'form' === $content['name'] ) { |
| 1786 | $options[] = [ |
| 1787 | 'label' => $template->post_title . ' - ' . ( isset( $content['label'] ) ? $content['label'] : 'Form' ), |
| 1788 | 'value' => $content['id'], |
| 1789 | ]; |
| 1790 | } |
| 1791 | } |
| 1792 | } |
| 1793 | } |
| 1794 | } |
| 1795 | |
| 1796 | return [ |
| 1797 | 'options' => $options, |
| 1798 | 'hasMore' => false, |
| 1799 | ]; |
| 1800 | |
| 1801 | } |
| 1802 | |
| 1803 | /** |
| 1804 | * Bricks builder form fields. |
| 1805 | * |
| 1806 | * @param array $data data. |
| 1807 | * @return array |
| 1808 | */ |
| 1809 | public function search_pluggable_bricks_builder_form_fields( $data ) { |
| 1810 | $result = []; |
| 1811 | $fields = []; |
| 1812 | $form_id_str = $data['dynamic']; |
| 1813 | $ids = explode( '_', $form_id_str ); |
| 1814 | $post_id = $ids[0]; |
| 1815 | $form_id = $ids[1]; |
| 1816 | $fetch_content = get_post_meta( $post_id, BRICKS_DB_PAGE_CONTENT, true ); |
| 1817 | if ( is_array( $fetch_content ) ) { |
| 1818 | foreach ( $fetch_content as $content ) { |
| 1819 | if ( 'form' === $content['name'] && $form_id === $content['id'] ) { |
| 1820 | $fields = $content['settings']['fields']; |
| 1821 | break; |
| 1822 | } |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | if ( ! empty( $fields ) ) { |
| 1827 | foreach ( $fields as $field ) { |
| 1828 | $result[] = [ |
| 1829 | 'label' => $field['label'], |
| 1830 | 'value' => '{' . strtolower( $field['label'] ) . '}', |
| 1831 | ]; |
| 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | return [ |
| 1836 | 'options' => $result, |
| 1837 | 'hasMore' => false, |
| 1838 | ]; |
| 1839 | } |
| 1840 | |
| 1841 | /** |
| 1842 | * Get fluent form fields |
| 1843 | * |
| 1844 | * @param array $data Data array. |
| 1845 | * |
| 1846 | * @return array |
| 1847 | */ |
| 1848 | public function search_pluggable_fluent_form_fields( $data ) { |
| 1849 | $result = []; |
| 1850 | $form_id = absint( $data['dynamic'] ); |
| 1851 | |
| 1852 | $fluentform_fields = Utilities::get_fluentform_fields( $data['search_term'], -1, $form_id ); |
| 1853 | |
| 1854 | if ( is_array( $fluentform_fields['results'] ) ) { |
| 1855 | foreach ( $fluentform_fields['results'] as $field ) { |
| 1856 | $result[] = [ |
| 1857 | 'label' => $field['text'], |
| 1858 | 'value' => "{{$field['value']}}", |
| 1859 | ]; |
| 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | $result[] = [ |
| 1864 | 'value' => '{form_id}', |
| 1865 | 'label' => 'Form ID', |
| 1866 | ]; |
| 1867 | |
| 1868 | $result[] = [ |
| 1869 | 'value' => '{form_title}', |
| 1870 | 'label' => 'Form Title', |
| 1871 | ]; |
| 1872 | $result[] = [ |
| 1873 | 'value' => '{entry_id}', |
| 1874 | 'label' => 'Entry ID', |
| 1875 | ]; |
| 1876 | |
| 1877 | $result[] = [ |
| 1878 | 'value' => '{entry_source_url}', |
| 1879 | 'label' => 'Entry Source URL', |
| 1880 | ]; |
| 1881 | |
| 1882 | $result[] = [ |
| 1883 | 'value' => '{submission_date}', |
| 1884 | 'label' => 'Submission Date', |
| 1885 | ]; |
| 1886 | |
| 1887 | $result[] = [ |
| 1888 | 'value' => '{user_ip}', |
| 1889 | 'label' => 'User IP', |
| 1890 | ]; |
| 1891 | |
| 1892 | return [ |
| 1893 | 'options' => $result, |
| 1894 | 'hasMore' => false, |
| 1895 | ]; |
| 1896 | } |
| 1897 | |
| 1898 | /** |
| 1899 | * Search Gravity Form fields. |
| 1900 | * |
| 1901 | * @param array $data Search Params. |
| 1902 | * |
| 1903 | * @since 1.0.0 |
| 1904 | */ |
| 1905 | public function search_gform_fields( $data ) { |
| 1906 | if ( ! class_exists( 'RGFormsModel' ) ) { |
| 1907 | return [ |
| 1908 | 'options' => [], |
| 1909 | 'hasMore' => false, |
| 1910 | ]; |
| 1911 | } |
| 1912 | $result = []; |
| 1913 | $page = $data['page']; |
| 1914 | $form_id = absint( $data['dynamic'] ); |
| 1915 | |
| 1916 | $form = RGFormsModel::get_form_meta( $form_id ); |
| 1917 | |
| 1918 | if ( is_array( $form['fields'] ) ) { |
| 1919 | foreach ( $form['fields'] as $field ) { |
| 1920 | if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { |
| 1921 | foreach ( $field['inputs'] as $input ) { |
| 1922 | if ( ! isset( $input['isHidden'] ) || ( isset( $input['isHidden'] ) && ! $input['isHidden'] ) ) { |
| 1923 | $result[] = [ |
| 1924 | 'value' => $input['id'], |
| 1925 | 'label' => GFCommon::get_label( $field, $input['id'] ), |
| 1926 | ]; |
| 1927 | } |
| 1928 | } |
| 1929 | } elseif ( ! rgar( $field, 'displayOnly' ) ) { |
| 1930 | $result[] = [ |
| 1931 | 'value' => $field['id'], |
| 1932 | 'label' => GFCommon::get_label( $field ), |
| 1933 | ]; |
| 1934 | } |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | return [ |
| 1939 | 'options' => $result, |
| 1940 | 'hasMore' => false, |
| 1941 | ]; |
| 1942 | |
| 1943 | } |
| 1944 | |
| 1945 | /** |
| 1946 | * Search Gravity Form fields. |
| 1947 | * |
| 1948 | * @param array $data Search Params. |
| 1949 | * |
| 1950 | * @since 1.0.0 |
| 1951 | */ |
| 1952 | public function search_pluggable_gravity_form_fields( $data ) { |
| 1953 | if ( ! class_exists( 'RGFormsModel' ) ) { |
| 1954 | return [ |
| 1955 | 'options' => [], |
| 1956 | 'hasMore' => false, |
| 1957 | ]; |
| 1958 | } |
| 1959 | $result = []; |
| 1960 | $form_id = absint( $data['dynamic'] ); |
| 1961 | |
| 1962 | $form = RGFormsModel::get_form_meta( $form_id ); |
| 1963 | |
| 1964 | if ( is_array( $form['fields'] ) ) { |
| 1965 | foreach ( $form['fields'] as $field ) { |
| 1966 | if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { |
| 1967 | foreach ( $field['inputs'] as $input ) { |
| 1968 | if ( ! isset( $input['isHidden'] ) || ( isset( $input['isHidden'] ) && ! $input['isHidden'] ) ) { |
| 1969 | $result[] = [ |
| 1970 | 'value' => '{' . $input['id'] . '}', |
| 1971 | 'label' => GFCommon::get_label( $field, $input['id'] ), |
| 1972 | ]; |
| 1973 | } |
| 1974 | } |
| 1975 | } elseif ( ! rgar( $field, 'displayOnly' ) ) { |
| 1976 | $result[] = [ |
| 1977 | 'value' => '{' . $field['id'] . '}', |
| 1978 | 'label' => GFCommon::get_label( $field ), |
| 1979 | ]; |
| 1980 | } |
| 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | $result[] = [ |
| 1985 | 'value' => '{gravity_form}', |
| 1986 | 'label' => 'Form ID', |
| 1987 | ]; |
| 1988 | $result[] = [ |
| 1989 | 'value' => '{form_title}', |
| 1990 | 'label' => 'Form Title', |
| 1991 | ]; |
| 1992 | $result[] = [ |
| 1993 | 'value' => '{entry_id}', |
| 1994 | 'label' => 'Entry ID', |
| 1995 | ]; |
| 1996 | $result[] = [ |
| 1997 | 'value' => '{user_ip}', |
| 1998 | 'label' => 'User IP', |
| 1999 | ]; |
| 2000 | $result[] = [ |
| 2001 | 'value' => '{entry_source_url}', |
| 2002 | 'label' => 'Entry Source URL', |
| 2003 | ]; |
| 2004 | $result[] = [ |
| 2005 | 'value' => '{entry_submission_date}', |
| 2006 | 'label' => 'Entry Submission Date', |
| 2007 | ]; |
| 2008 | |
| 2009 | return [ |
| 2010 | 'options' => $result, |
| 2011 | 'hasMore' => false, |
| 2012 | ]; |
| 2013 | |
| 2014 | } |
| 2015 | |
| 2016 | /** |
| 2017 | * Prepare fluentcrm lists. |
| 2018 | * |
| 2019 | * @param array $data Search Params. |
| 2020 | * |
| 2021 | * @return array[] |
| 2022 | */ |
| 2023 | public function search_fluentcrm_lists( $data ) { |
| 2024 | |
| 2025 | $list_api = FluentCrmApi( 'lists' ); |
| 2026 | $all_lists = $list_api->all(); |
| 2027 | $options = []; |
| 2028 | |
| 2029 | if ( ! empty( $all_lists ) ) { |
| 2030 | foreach ( $all_lists as $list ) { |
| 2031 | $options[] = [ |
| 2032 | 'label' => $list->title, |
| 2033 | 'value' => $list->id, |
| 2034 | ]; |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | return [ |
| 2039 | 'options' => $options, |
| 2040 | 'hasMore' => false, |
| 2041 | ]; |
| 2042 | } |
| 2043 | |
| 2044 | /** |
| 2045 | * Prepare fluentcrm contact status. |
| 2046 | * |
| 2047 | * @param array $data Search Params. |
| 2048 | * |
| 2049 | * @return array[] |
| 2050 | */ |
| 2051 | public function search_fluentcrm_contact_status( $data ) { |
| 2052 | |
| 2053 | $options = [ |
| 2054 | [ |
| 2055 | 'label' => __( 'Subscribed', 'suretriggers' ), |
| 2056 | 'value' => 'subscribed', |
| 2057 | ], |
| 2058 | [ |
| 2059 | 'label' => __( 'Pending', 'suretriggers' ), |
| 2060 | 'value' => 'pending', |
| 2061 | ], |
| 2062 | [ |
| 2063 | 'label' => __( 'Unsubscribed', 'suretriggers' ), |
| 2064 | 'value' => 'unsubscribed', |
| 2065 | ], |
| 2066 | [ |
| 2067 | 'label' => __( 'Bounced', 'suretriggers' ), |
| 2068 | 'value' => 'bounced', |
| 2069 | ], |
| 2070 | [ |
| 2071 | 'label' => __( 'Complained', 'suretriggers' ), |
| 2072 | 'value' => 'complained', |
| 2073 | ], |
| 2074 | ]; |
| 2075 | |
| 2076 | return [ |
| 2077 | 'options' => $options, |
| 2078 | 'hasMore' => false, |
| 2079 | ]; |
| 2080 | } |
| 2081 | |
| 2082 | /** |
| 2083 | * Prepare fluentcrm contact status. |
| 2084 | * |
| 2085 | * @param array $data Search Params. |
| 2086 | * |
| 2087 | * @return array[] |
| 2088 | */ |
| 2089 | public function search_fluentcrm_fetch_custom_fields( $data ) { |
| 2090 | |
| 2091 | $options = [ |
| 2092 | [ |
| 2093 | 'label' => __( 'Yes', 'suretriggers' ), |
| 2094 | 'value' => 'true', |
| 2095 | ], |
| 2096 | [ |
| 2097 | 'label' => __( 'No', 'suretriggers' ), |
| 2098 | 'value' => 'false', |
| 2099 | ], |
| 2100 | ]; |
| 2101 | |
| 2102 | return [ |
| 2103 | 'options' => $options, |
| 2104 | 'hasMore' => false, |
| 2105 | ]; |
| 2106 | } |
| 2107 | |
| 2108 | /** |
| 2109 | * Prepare fluentcrm tags. |
| 2110 | * |
| 2111 | * @param array $data Search Params. |
| 2112 | * |
| 2113 | * @return array[] |
| 2114 | */ |
| 2115 | public function search_fluentcrm_tags( $data ) { |
| 2116 | |
| 2117 | $tag_api = FluentCrmApi( 'tags' ); |
| 2118 | $all_tags = $tag_api->all(); |
| 2119 | $options = []; |
| 2120 | |
| 2121 | if ( ! empty( $all_tags ) ) { |
| 2122 | foreach ( $all_tags as $tag ) { |
| 2123 | $options[] = [ |
| 2124 | 'label' => $tag->title, |
| 2125 | 'value' => $tag->id, |
| 2126 | ]; |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | return [ |
| 2131 | 'options' => $options, |
| 2132 | 'hasMore' => false, |
| 2133 | ]; |
| 2134 | } |
| 2135 | |
| 2136 | /** |
| 2137 | * Prepare JetpackCRM Contact tags. |
| 2138 | * |
| 2139 | * @param array $data Search Params. |
| 2140 | * |
| 2141 | * @return array |
| 2142 | */ |
| 2143 | public function search_jetpack_crm_contact_tags( $data ) { |
| 2144 | |
| 2145 | if ( ! function_exists( 'zeroBSCRM_getCustomerTags' ) ) { |
| 2146 | return []; |
| 2147 | } |
| 2148 | |
| 2149 | $all_tags = zeroBSCRM_getCustomerTags(); |
| 2150 | $options = []; |
| 2151 | |
| 2152 | if ( ! empty( $all_tags ) ) { |
| 2153 | foreach ( $all_tags as $tag ) { |
| 2154 | $options[] = [ |
| 2155 | 'label' => $tag['name'], |
| 2156 | 'value' => $tag['id'], |
| 2157 | ]; |
| 2158 | } |
| 2159 | } |
| 2160 | |
| 2161 | return [ |
| 2162 | 'options' => $options, |
| 2163 | 'hasMore' => false, |
| 2164 | ]; |
| 2165 | } |
| 2166 | |
| 2167 | /** |
| 2168 | * Prepare JetpackCRM Company tags. |
| 2169 | * |
| 2170 | * @param array $data Search Params. |
| 2171 | * |
| 2172 | * @return array |
| 2173 | */ |
| 2174 | public function search_jetpack_crm_company_tags( $data ) { |
| 2175 | |
| 2176 | if ( ! defined( 'ZBS_TYPE_COMPANY' ) ) { |
| 2177 | return []; |
| 2178 | } |
| 2179 | |
| 2180 | global $wpdb; |
| 2181 | $all_tags = $wpdb->get_results( $wpdb->prepare( "SELECT `ID`,`zbstag_name` FROM `{$wpdb->prefix}zbs_tags` WHERE zbstag_objtype = %d", ZBS_TYPE_COMPANY ) ); |
| 2182 | |
| 2183 | $options = []; |
| 2184 | if ( ! empty( $all_tags ) ) { |
| 2185 | foreach ( $all_tags as $tag ) { |
| 2186 | $options[] = [ |
| 2187 | 'label' => $tag->zbstag_name, |
| 2188 | 'value' => $tag->ID, |
| 2189 | ]; |
| 2190 | } |
| 2191 | } |
| 2192 | |
| 2193 | return [ |
| 2194 | 'options' => $options, |
| 2195 | 'hasMore' => false, |
| 2196 | ]; |
| 2197 | } |
| 2198 | |
| 2199 | /** |
| 2200 | * Prepare JetpackCRM Companies list. |
| 2201 | * |
| 2202 | * @param array $data Search Params. |
| 2203 | * |
| 2204 | * @return array |
| 2205 | */ |
| 2206 | public function search_jetpack_crm_companies_list( $data ) { |
| 2207 | |
| 2208 | if ( ! function_exists( 'zeroBS_getCompanies' ) ) { |
| 2209 | return []; |
| 2210 | } |
| 2211 | |
| 2212 | $all_companies = zeroBS_getCompanies(); |
| 2213 | $options = []; |
| 2214 | |
| 2215 | if ( ! empty( $all_companies ) ) { |
| 2216 | foreach ( $all_companies as $company ) { |
| 2217 | $options[] = [ |
| 2218 | 'label' => $company['name'], |
| 2219 | 'value' => $company['id'], |
| 2220 | ]; |
| 2221 | } |
| 2222 | } |
| 2223 | |
| 2224 | return [ |
| 2225 | 'options' => $options, |
| 2226 | 'hasMore' => false, |
| 2227 | ]; |
| 2228 | } |
| 2229 | |
| 2230 | /** |
| 2231 | * Prepare JetpackCRM contact status. |
| 2232 | * |
| 2233 | * @param array $data Search Params. |
| 2234 | * |
| 2235 | * @return array |
| 2236 | */ |
| 2237 | public function search_jetpack_crm_contact_statuses( $data ) { |
| 2238 | |
| 2239 | $options = [ |
| 2240 | [ |
| 2241 | 'label' => __( 'Lead', 'suretriggers' ), |
| 2242 | 'value' => 'Lead', |
| 2243 | ], |
| 2244 | [ |
| 2245 | 'label' => __( 'Customer', 'suretriggers' ), |
| 2246 | 'value' => 'Customer', |
| 2247 | ], |
| 2248 | [ |
| 2249 | 'label' => __( 'Refused', 'suretriggers' ), |
| 2250 | 'value' => 'Refused', |
| 2251 | ], |
| 2252 | [ |
| 2253 | 'label' => __( 'Blacklisted', 'suretriggers' ), |
| 2254 | 'value' => 'Blacklisted', |
| 2255 | ], |
| 2256 | [ |
| 2257 | 'label' => __( 'Cancelled by Customer', 'suretriggers' ), |
| 2258 | 'value' => 'Cancelled by Customer', |
| 2259 | ], |
| 2260 | [ |
| 2261 | 'label' => __( 'Cancelled by Us (Pre-Quote)', 'suretriggers' ), |
| 2262 | 'value' => 'Cancelled by Us (Pre-Quote)', |
| 2263 | ], |
| 2264 | [ |
| 2265 | 'label' => __( 'Cancelled by Us (Post-Quote)', 'suretriggers' ), |
| 2266 | 'value' => 'Cancelled by Us (Post-Quote)', |
| 2267 | ], |
| 2268 | ]; |
| 2269 | |
| 2270 | return [ |
| 2271 | 'options' => $options, |
| 2272 | 'hasMore' => false, |
| 2273 | ]; |
| 2274 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * Prepare FunnelKit Automations' lists. |
| 2278 | * |
| 2279 | * @param array $data Search Params. |
| 2280 | * |
| 2281 | * @return array |
| 2282 | */ |
| 2283 | public function search_funnel_kit_automations_lists( $data ) { |
| 2284 | |
| 2285 | if ( ! class_exists( 'BWFCRM_Lists' ) ) { |
| 2286 | return []; |
| 2287 | } |
| 2288 | |
| 2289 | $bwfcrm_lists = \BWFCRM_Lists::get_lists(); |
| 2290 | |
| 2291 | $options = []; |
| 2292 | |
| 2293 | foreach ( $bwfcrm_lists as $list ) { |
| 2294 | $options[] = [ |
| 2295 | 'label' => $list['name'], |
| 2296 | 'value' => $list['ID'], |
| 2297 | ]; |
| 2298 | } |
| 2299 | |
| 2300 | return [ |
| 2301 | 'options' => $options, |
| 2302 | 'hasMore' => false, |
| 2303 | ]; |
| 2304 | } |
| 2305 | |
| 2306 | /** |
| 2307 | * Prepare FunnelKit Automations' tags. |
| 2308 | * |
| 2309 | * @param array $data Search Params. |
| 2310 | * |
| 2311 | * @return array |
| 2312 | */ |
| 2313 | public function search_funnel_kit_automations_tags( $data ) { |
| 2314 | |
| 2315 | if ( ! class_exists( 'BWFCRM_Tag' ) ) { |
| 2316 | return []; |
| 2317 | } |
| 2318 | |
| 2319 | $bwfcrm_tags = \BWFCRM_Tag::get_tags(); |
| 2320 | |
| 2321 | $options = []; |
| 2322 | |
| 2323 | foreach ( $bwfcrm_tags as $tag ) { |
| 2324 | $options[] = [ |
| 2325 | 'label' => $tag['name'], |
| 2326 | 'value' => $tag['ID'], |
| 2327 | ]; |
| 2328 | } |
| 2329 | |
| 2330 | return [ |
| 2331 | 'options' => $options, |
| 2332 | 'hasMore' => false, |
| 2333 | ]; |
| 2334 | } |
| 2335 | |
| 2336 | /** |
| 2337 | * Prepare Wishlist Memberlists level. |
| 2338 | * |
| 2339 | * @param array $data Search Params. |
| 2340 | * |
| 2341 | * @return array[] |
| 2342 | */ |
| 2343 | public function search_wishlistmember_lists( $data ) { |
| 2344 | |
| 2345 | $wlm_levels = wlmapi_get_levels(); |
| 2346 | $options = []; |
| 2347 | |
| 2348 | if ( ! empty( $wlm_levels ) ) { |
| 2349 | foreach ( $wlm_levels['levels']['level'] as $list ) { |
| 2350 | if ( isset( $list['name'] ) && ! empty( $list['name'] ) ) { |
| 2351 | $options[] = [ |
| 2352 | 'label' => $list['name'], |
| 2353 | 'value' => (string) $list['id'], |
| 2354 | ]; |
| 2355 | } |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | return [ |
| 2360 | 'options' => $options, |
| 2361 | 'hasMore' => false, |
| 2362 | ]; |
| 2363 | } |
| 2364 | |
| 2365 | /** |
| 2366 | * Prepare elementor popups. |
| 2367 | * |
| 2368 | * @param array $data Search Params. |
| 2369 | * |
| 2370 | * @return array[] |
| 2371 | */ |
| 2372 | public function search_elementor_popups( $data ) { |
| 2373 | |
| 2374 | $posts = get_posts( |
| 2375 | [ |
| 2376 | 'post_type' => 'elementor_library', |
| 2377 | 'orderby' => 'title', |
| 2378 | 'order' => 'ASC', |
| 2379 | 'post_status' => 'publish', |
| 2380 | 'meta_query' => [ |
| 2381 | [ |
| 2382 | 'key' => '_elementor_template_type', |
| 2383 | 'value' => 'popup', |
| 2384 | 'compare' => '=', |
| 2385 | ], |
| 2386 | ], |
| 2387 | ] |
| 2388 | ); |
| 2389 | |
| 2390 | $options = []; |
| 2391 | if ( ! empty( $posts ) ) { |
| 2392 | foreach ( $posts as $post ) { |
| 2393 | $options[] = [ |
| 2394 | 'label' => $post->post_title, |
| 2395 | 'value' => $post->ID, |
| 2396 | ]; |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | return [ |
| 2401 | 'options' => $options, |
| 2402 | 'hasMore' => false, |
| 2403 | ]; |
| 2404 | } |
| 2405 | |
| 2406 | /** |
| 2407 | * Prepare givewp forms. |
| 2408 | * |
| 2409 | * @param array $data Search Params. |
| 2410 | * |
| 2411 | * @return array[] |
| 2412 | */ |
| 2413 | public function search_givewp_forms( $data ) { |
| 2414 | |
| 2415 | $posts = get_posts( |
| 2416 | [ |
| 2417 | 'post_type' => 'give_forms', |
| 2418 | 'orderby' => 'title', |
| 2419 | 'order' => 'ASC', |
| 2420 | 'post_status' => 'publish', |
| 2421 | ] |
| 2422 | ); |
| 2423 | |
| 2424 | $options = []; |
| 2425 | if ( ! empty( $posts ) ) { |
| 2426 | foreach ( $posts as $post ) { |
| 2427 | $options[] = [ |
| 2428 | 'label' => $post->post_title, |
| 2429 | 'value' => $post->ID, |
| 2430 | ]; |
| 2431 | } |
| 2432 | } |
| 2433 | |
| 2434 | return [ |
| 2435 | 'options' => $options, |
| 2436 | 'hasMore' => false, |
| 2437 | ]; |
| 2438 | } |
| 2439 | |
| 2440 | /** |
| 2441 | * Prepare buddyboss group users. |
| 2442 | * |
| 2443 | * @param array $data Search Params. |
| 2444 | * |
| 2445 | * @return array[] |
| 2446 | */ |
| 2447 | public function search_bb_group_users( $data ) { |
| 2448 | $options = []; |
| 2449 | |
| 2450 | $group_id = $data['dynamic']; |
| 2451 | $admins = groups_get_group_admins( $group_id ); |
| 2452 | |
| 2453 | if ( ! empty( $admins ) ) { |
| 2454 | foreach ( $admins as $admin ) { |
| 2455 | $admin_user = get_user_by( 'id', $admin->user_id ); |
| 2456 | $options[] = [ |
| 2457 | 'label' => $admin_user->display_name, |
| 2458 | 'value' => $admin_user->ID, |
| 2459 | ]; |
| 2460 | } |
| 2461 | } |
| 2462 | |
| 2463 | $members = groups_get_group_members( [ 'group_id' => $group_id ] ); |
| 2464 | |
| 2465 | if ( isset( $members['members'] ) && ! empty( $members['members'] ) ) { |
| 2466 | foreach ( $members['members'] as $member ) { |
| 2467 | $options[] = [ |
| 2468 | 'label' => $member->display_name, |
| 2469 | 'value' => $member->ID, |
| 2470 | ]; |
| 2471 | } |
| 2472 | } |
| 2473 | return [ |
| 2474 | 'options' => $options, |
| 2475 | 'hasMore' => false, |
| 2476 | ]; |
| 2477 | } |
| 2478 | |
| 2479 | /** |
| 2480 | * Prepare buddyboss groups. |
| 2481 | * |
| 2482 | * @param array $data Search Params. |
| 2483 | * |
| 2484 | * @return array[] |
| 2485 | */ |
| 2486 | public function search_buddyboss_groups( $data ) { |
| 2487 | global $wpdb; |
| 2488 | |
| 2489 | $options = []; |
| 2490 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups" ); |
| 2491 | if ( ! empty( $groups ) ) { |
| 2492 | foreach ( $groups as $group ) { |
| 2493 | $options[] = [ |
| 2494 | 'label' => $group->name, |
| 2495 | 'value' => $group->id, |
| 2496 | ]; |
| 2497 | } |
| 2498 | } |
| 2499 | return [ |
| 2500 | 'options' => $options, |
| 2501 | 'hasMore' => false, |
| 2502 | ]; |
| 2503 | } |
| 2504 | |
| 2505 | /** |
| 2506 | * Prepare buddyboss public groups. |
| 2507 | * |
| 2508 | * @param array $data Search Params. |
| 2509 | * |
| 2510 | * @return array[] |
| 2511 | */ |
| 2512 | public function search_buddyboss_public_groups( $data ) { |
| 2513 | $options = []; |
| 2514 | $groups = groups_get_groups(); |
| 2515 | if ( isset( $groups['groups'] ) && ! empty( $groups['groups'] ) ) { |
| 2516 | foreach ( $groups['groups'] as $group ) { |
| 2517 | if ( 'public' === $group->status ) { |
| 2518 | $options[] = [ |
| 2519 | 'label' => $group->name, |
| 2520 | 'value' => $group->id, |
| 2521 | ]; |
| 2522 | } |
| 2523 | } |
| 2524 | } |
| 2525 | return [ |
| 2526 | 'options' => $options, |
| 2527 | 'hasMore' => false, |
| 2528 | ]; |
| 2529 | } |
| 2530 | |
| 2531 | /** |
| 2532 | * Prepare buddyboss profile types list. |
| 2533 | * |
| 2534 | * @param array $data Search Params. |
| 2535 | * |
| 2536 | * @return array[] |
| 2537 | */ |
| 2538 | public function search_bb_profile_type_list( $data ) { |
| 2539 | $options = []; |
| 2540 | |
| 2541 | if ( function_exists( 'bp_get_active_member_types' ) ) { |
| 2542 | $types = bp_get_active_member_types( |
| 2543 | [ |
| 2544 | 'fields' => '*', |
| 2545 | ] |
| 2546 | ); |
| 2547 | if ( $types ) { |
| 2548 | foreach ( $types as $type ) { |
| 2549 | $options[] = [ |
| 2550 | 'label' => $type->post_title, |
| 2551 | 'value' => $type->ID, |
| 2552 | ]; |
| 2553 | } |
| 2554 | } |
| 2555 | } |
| 2556 | |
| 2557 | /** |
| 2558 | * |
| 2559 | * Ignore line |
| 2560 | * |
| 2561 | * @phpstan-ignore-next-line |
| 2562 | */ |
| 2563 | return [ |
| 2564 | 'options' => $options, |
| 2565 | 'hasMore' => false, |
| 2566 | ]; |
| 2567 | } |
| 2568 | |
| 2569 | /** |
| 2570 | * Prepare elementor forms. |
| 2571 | * |
| 2572 | * @param array $data Search Params. |
| 2573 | * |
| 2574 | * @return array[] |
| 2575 | */ |
| 2576 | public function search_elementor_forms( $data ) { |
| 2577 | |
| 2578 | $elementor_forms = Utilities::get_elementor_forms(); |
| 2579 | |
| 2580 | $options = []; |
| 2581 | if ( ! empty( $elementor_forms ) ) { |
| 2582 | foreach ( $elementor_forms as $key => $value ) { |
| 2583 | $options[] = [ |
| 2584 | 'label' => $value, |
| 2585 | 'value' => $key, |
| 2586 | ]; |
| 2587 | } |
| 2588 | } |
| 2589 | |
| 2590 | return [ |
| 2591 | 'options' => $options, |
| 2592 | 'hasMore' => false, |
| 2593 | ]; |
| 2594 | } |
| 2595 | |
| 2596 | /** |
| 2597 | * Prepare elementor forms. |
| 2598 | * |
| 2599 | * @param array $data Search Params. |
| 2600 | * |
| 2601 | * @return array[] |
| 2602 | */ |
| 2603 | public function search_new_elementor_forms( $data ) { |
| 2604 | |
| 2605 | global $wpdb; |
| 2606 | $elementor_forms = []; |
| 2607 | $post_metas = $wpdb->get_results( |
| 2608 | $wpdb->prepare( |
| 2609 | "SELECT pm.post_id, pm.meta_value |
| 2610 | FROM $wpdb->postmeta pm |
| 2611 | LEFT JOIN $wpdb->posts p |
| 2612 | ON p.ID = pm.post_id |
| 2613 | WHERE p.post_type IS NOT NULL |
| 2614 | AND p.post_status = %s |
| 2615 | AND pm.meta_key = %s |
| 2616 | AND pm.`meta_value` LIKE %s", |
| 2617 | 'publish', |
| 2618 | '_elementor_data', |
| 2619 | '%%form_fields%%' |
| 2620 | ) |
| 2621 | ); |
| 2622 | |
| 2623 | if ( ! empty( $post_metas ) ) { |
| 2624 | foreach ( $post_metas as $post_meta ) { |
| 2625 | /** |
| 2626 | * |
| 2627 | * Ignore line |
| 2628 | * |
| 2629 | * @phpstan-ignore-next-line |
| 2630 | */ |
| 2631 | $inner_forms = Utilities::search_elementor_forms( json_decode( $post_meta->meta_value ) ); |
| 2632 | if ( ! empty( $inner_forms ) ) { |
| 2633 | foreach ( $inner_forms as $form ) { |
| 2634 | /** |
| 2635 | * |
| 2636 | * Ignore line |
| 2637 | * |
| 2638 | * @phpstan-ignore-next-line |
| 2639 | */ |
| 2640 | $elementor_forms[ $post_meta->post_id . '_' . $form->id ] = $form->settings->form_name . ' (' . $form->id . ')'; |
| 2641 | } |
| 2642 | } |
| 2643 | } |
| 2644 | } |
| 2645 | |
| 2646 | $options = []; |
| 2647 | if ( ! empty( $elementor_forms ) ) { |
| 2648 | foreach ( $elementor_forms as $key => $value ) { |
| 2649 | $options[] = [ |
| 2650 | 'label' => $value, |
| 2651 | 'value' => $key, |
| 2652 | ]; |
| 2653 | } |
| 2654 | } |
| 2655 | |
| 2656 | /** |
| 2657 | * |
| 2658 | * Ignore line |
| 2659 | * |
| 2660 | * @phpstan-ignore-next-line |
| 2661 | */ |
| 2662 | return [ |
| 2663 | 'options' => $options, |
| 2664 | 'hasMore' => false, |
| 2665 | ]; |
| 2666 | } |
| 2667 | |
| 2668 | /** |
| 2669 | * Prepare elementor form fields. |
| 2670 | * |
| 2671 | * @param array $data Search Params. |
| 2672 | * |
| 2673 | * @return array[] |
| 2674 | */ |
| 2675 | public function search_pluggable_elementor_form_fields( $data ) { |
| 2676 | $result = []; |
| 2677 | $form_id = absint( $data['dynamic'] ); |
| 2678 | $elementor_form_fields = ( new Utilities() )->get_elementor_form_fields( $data ); |
| 2679 | $options = []; |
| 2680 | if ( ! empty( $elementor_form_fields ) ) { |
| 2681 | foreach ( $elementor_form_fields as $key => $value ) { |
| 2682 | $options[] = [ |
| 2683 | 'label' => $value, |
| 2684 | 'value' => '{' . $key . '}', |
| 2685 | ]; |
| 2686 | } |
| 2687 | } |
| 2688 | |
| 2689 | return [ |
| 2690 | 'options' => $options, |
| 2691 | 'hasMore' => false, |
| 2692 | ]; |
| 2693 | } |
| 2694 | |
| 2695 | /** |
| 2696 | * Get all events |
| 2697 | * |
| 2698 | * @param array $data Data array. |
| 2699 | * |
| 2700 | * @return array |
| 2701 | */ |
| 2702 | public function search_event_calendar_event( $data ) { |
| 2703 | $page = $data['page']; |
| 2704 | $limit = Utilities::get_search_page_limit(); |
| 2705 | $offset = $limit * ( $page - 1 ); |
| 2706 | |
| 2707 | $posts = get_posts( |
| 2708 | [ |
| 2709 | 'post_type' => 'tribe_events', |
| 2710 | 'orderby' => 'title', |
| 2711 | 'order' => 'ASC', |
| 2712 | 'post_status' => 'publish', |
| 2713 | 'posts_per_page' => $limit, |
| 2714 | 'offset' => $offset, |
| 2715 | ] |
| 2716 | ); |
| 2717 | |
| 2718 | $options = []; |
| 2719 | if ( ! empty( $posts ) ) { |
| 2720 | foreach ( $posts as $post ) { |
| 2721 | $options[] = [ |
| 2722 | 'label' => $post->post_title, |
| 2723 | 'value' => $post->ID, |
| 2724 | ]; |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | $count = count( $options ); |
| 2729 | |
| 2730 | return [ |
| 2731 | 'options' => $options, |
| 2732 | 'hasMore' => $count > $limit && $count > $offset, |
| 2733 | ]; |
| 2734 | } |
| 2735 | |
| 2736 | /** |
| 2737 | * Prepare rsvp event calendar events. |
| 2738 | * |
| 2739 | * @param array $data Search Params. |
| 2740 | * |
| 2741 | * @return array[] |
| 2742 | */ |
| 2743 | public function search_event_calendar_rsvp_event( $data ) { |
| 2744 | |
| 2745 | $posts = get_posts( |
| 2746 | [ |
| 2747 | 'post_type' => 'tribe_events', |
| 2748 | 'orderby' => 'title', |
| 2749 | 'order' => 'ASC', |
| 2750 | 'post_status' => 'publish', |
| 2751 | ] |
| 2752 | ); |
| 2753 | |
| 2754 | $options = []; |
| 2755 | if ( ! empty( $posts ) ) { |
| 2756 | $ticket_handler = new Tribe__Tickets__Tickets_Handler(); |
| 2757 | foreach ( $posts as $post ) { |
| 2758 | |
| 2759 | $get_rsvp_ticket = $ticket_handler->get_event_rsvp_tickets( $post->ID ); |
| 2760 | |
| 2761 | if ( ! empty( $get_rsvp_ticket ) ) { |
| 2762 | $options[] = [ |
| 2763 | 'label' => $post->post_title, |
| 2764 | 'value' => $post->ID, |
| 2765 | ]; |
| 2766 | } |
| 2767 | } |
| 2768 | } |
| 2769 | |
| 2770 | return [ |
| 2771 | 'options' => $options, |
| 2772 | 'hasMore' => false, |
| 2773 | ]; |
| 2774 | } |
| 2775 | |
| 2776 | /** |
| 2777 | * Prepare Restrict Content Membership Level. |
| 2778 | * |
| 2779 | * @param array $data Search Params. |
| 2780 | * |
| 2781 | * @return array[] |
| 2782 | */ |
| 2783 | public function search_restrictcontent_membership_level( $data ) { |
| 2784 | |
| 2785 | $rcp_memberships = rcp_get_membership_levels(); |
| 2786 | $options = []; |
| 2787 | |
| 2788 | if ( ! empty( $rcp_memberships ) ) { |
| 2789 | foreach ( $rcp_memberships as $list ) { |
| 2790 | $options[] = [ |
| 2791 | 'label' => ucfirst( $list->name ), |
| 2792 | 'value' => $list->id, |
| 2793 | ]; |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | return [ |
| 2798 | 'options' => $options, |
| 2799 | 'hasMore' => false, |
| 2800 | ]; |
| 2801 | } |
| 2802 | |
| 2803 | /** |
| 2804 | * Prepare Restrict Content Customer. |
| 2805 | * |
| 2806 | * @param array $data Search Params. |
| 2807 | * |
| 2808 | * @return array[] |
| 2809 | */ |
| 2810 | public function search_restrictcontent_customer( $data ) { |
| 2811 | |
| 2812 | $rcp_users = rcp_get_memberships(); |
| 2813 | $options = []; |
| 2814 | |
| 2815 | if ( ! empty( $rcp_users ) ) { |
| 2816 | foreach ( $rcp_users as $list ) { |
| 2817 | $user = get_user_by( 'ID', $list->get_user_id() ); |
| 2818 | $user_label = $user->user_email; |
| 2819 | |
| 2820 | if ( $user->display_name !== $user->user_email ) { |
| 2821 | $user_label .= ' (' . $user->display_name . ')'; |
| 2822 | } |
| 2823 | |
| 2824 | $options[] = [ |
| 2825 | 'label' => $user_label, |
| 2826 | 'value' => $list->get_customer_id(), |
| 2827 | ]; |
| 2828 | } |
| 2829 | } |
| 2830 | |
| 2831 | return [ |
| 2832 | 'options' => $options, |
| 2833 | 'hasMore' => false, |
| 2834 | ]; |
| 2835 | } |
| 2836 | |
| 2837 | |
| 2838 | /** |
| 2839 | * Fetch the Presto Player video List. |
| 2840 | * |
| 2841 | * @param array $data Search Params. |
| 2842 | * |
| 2843 | * @return array[] |
| 2844 | */ |
| 2845 | public function search_ap_presto_player_video_list( $data ) { |
| 2846 | |
| 2847 | $videos = ( new Video() )->all(); |
| 2848 | $options = []; |
| 2849 | if ( ! empty( $videos ) ) { |
| 2850 | foreach ( $videos as $video ) { |
| 2851 | $options[] = [ |
| 2852 | 'label' => $video->__get( 'title' ), |
| 2853 | 'value' => (string) $video->__get( 'id' ), |
| 2854 | ]; |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | return [ |
| 2859 | 'options' => $options, |
| 2860 | 'hasMore' => false, |
| 2861 | ]; |
| 2862 | } |
| 2863 | |
| 2864 | /** |
| 2865 | * Presto Player Video percentage. |
| 2866 | * |
| 2867 | * @param array $data Search Params. |
| 2868 | * |
| 2869 | * @return array[] |
| 2870 | */ |
| 2871 | public function search_prestoplayer_video_percent( $data ) { |
| 2872 | |
| 2873 | $percents = [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ]; |
| 2874 | $options = []; |
| 2875 | |
| 2876 | foreach ( $percents as $percent ) { |
| 2877 | $options[] = [ |
| 2878 | 'label' => $percent . '%', |
| 2879 | 'value' => (string) $percent, |
| 2880 | ]; |
| 2881 | } |
| 2882 | |
| 2883 | return [ |
| 2884 | 'options' => $options, |
| 2885 | 'hasMore' => false, |
| 2886 | ]; |
| 2887 | } |
| 2888 | |
| 2889 | /** |
| 2890 | * Get user profile field options. |
| 2891 | * |
| 2892 | * @return array |
| 2893 | * @since 1.0.0 |
| 2894 | */ |
| 2895 | public function search_user_field_options() { |
| 2896 | |
| 2897 | $options = apply_filters( |
| 2898 | 'sure_trigger_get_user_field_options', |
| 2899 | [ |
| 2900 | [ |
| 2901 | 'label' => __( 'User Name', 'suretriggers' ), |
| 2902 | 'value' => 'user_login', |
| 2903 | ], |
| 2904 | [ |
| 2905 | 'label' => __( 'User Email', 'suretriggers' ), |
| 2906 | 'value' => 'user_email', |
| 2907 | ], |
| 2908 | [ |
| 2909 | 'label' => __( 'Display Name', 'suretriggers' ), |
| 2910 | 'value' => 'display_name', |
| 2911 | ], |
| 2912 | [ |
| 2913 | 'label' => __( 'User Password', 'suretriggers' ), |
| 2914 | 'value' => 'user_pass', |
| 2915 | ], |
| 2916 | [ |
| 2917 | 'label' => __( 'Website', 'suretriggers' ), |
| 2918 | 'value' => 'user_url', |
| 2919 | ], |
| 2920 | ] |
| 2921 | ); |
| 2922 | |
| 2923 | return [ |
| 2924 | 'options' => $options, |
| 2925 | 'hasMore' => false, |
| 2926 | ]; |
| 2927 | } |
| 2928 | |
| 2929 | /** |
| 2930 | * Get user post field options. |
| 2931 | * |
| 2932 | * @return array |
| 2933 | * @since 1.0.0 |
| 2934 | */ |
| 2935 | public function search_post_field_options() { |
| 2936 | |
| 2937 | return [ |
| 2938 | 'options' => [ |
| 2939 | [ |
| 2940 | 'label' => __( 'Type', 'suretriggers' ), |
| 2941 | 'value' => 'post_type', |
| 2942 | 'dynamic_field' => [ |
| 2943 | 'type' => 'select-creatable', |
| 2944 | 'ajaxIdentifier' => 'post_types', |
| 2945 | ], |
| 2946 | ], |
| 2947 | [ |
| 2948 | 'label' => __( 'Status', 'suretriggers' ), |
| 2949 | 'value' => 'post_status', |
| 2950 | 'dynamic_field' => [ |
| 2951 | 'type' => 'select-async', |
| 2952 | 'ajaxIdentifier' => 'post_statuses', |
| 2953 | ], |
| 2954 | ], |
| 2955 | [ |
| 2956 | 'label' => __( 'Author', 'suretriggers' ), |
| 2957 | 'value' => 'post_author', |
| 2958 | 'dynamic_field' => [ |
| 2959 | 'type' => 'select-async', |
| 2960 | 'ajaxIdentifier' => 'user', |
| 2961 | ], |
| 2962 | ], |
| 2963 | [ |
| 2964 | 'label' => __( 'Title', 'suretriggers' ), |
| 2965 | 'value' => 'post_title', |
| 2966 | 'dynamic_field' => [ |
| 2967 | 'type' => 'select-creatable', |
| 2968 | ], |
| 2969 | ], |
| 2970 | [ |
| 2971 | 'label' => __( 'Slug', 'suretriggers' ), |
| 2972 | 'value' => 'post_slug', |
| 2973 | 'dynamic_field' => [ |
| 2974 | 'type' => 'select-creatable', |
| 2975 | ], |
| 2976 | ], |
| 2977 | [ |
| 2978 | 'label' => __( 'Content', 'suretriggers' ), |
| 2979 | 'value' => 'post_content', |
| 2980 | 'dynamic_field' => [ |
| 2981 | 'type' => 'html-editor', |
| 2982 | ], |
| 2983 | ], |
| 2984 | ], |
| 2985 | 'hasMore' => false, |
| 2986 | ]; |
| 2987 | } |
| 2988 | |
| 2989 | /** |
| 2990 | * Bricksbuilder grouped data. |
| 2991 | * |
| 2992 | * @param array $data data. |
| 2993 | * @return array |
| 2994 | */ |
| 2995 | public function search_bb_groups( $data ) { |
| 2996 | |
| 2997 | global $wpdb; |
| 2998 | $options = []; |
| 2999 | |
| 3000 | if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'bp_groups' ) ) ) { |
| 3001 | |
| 3002 | $results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s', $wpdb->prefix . 'bp_groups' ) ); |
| 3003 | |
| 3004 | if ( $results ) { |
| 3005 | foreach ( $results as $result ) { |
| 3006 | $options[] = [ |
| 3007 | 'label' => $result->name, |
| 3008 | 'value' => $result->id, |
| 3009 | ]; |
| 3010 | } |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | return [ |
| 3015 | 'options' => $options, |
| 3016 | 'hasMore' => false, |
| 3017 | ]; |
| 3018 | } |
| 3019 | |
| 3020 | /** |
| 3021 | * Search forms. |
| 3022 | * |
| 3023 | * @return array |
| 3024 | */ |
| 3025 | public function search_bb_forums() { |
| 3026 | $options = []; |
| 3027 | $allowed_atatus = [ 'publish', 'private' ]; |
| 3028 | $forum_args = [ |
| 3029 | 'post_type' => bbp_get_forum_post_type(), |
| 3030 | 'posts_per_page' => -1, |
| 3031 | 'orderby' => 'title', |
| 3032 | 'order' => 'ASC', |
| 3033 | 'post_status' => 'any', |
| 3034 | ]; |
| 3035 | $forums = get_posts( $forum_args ); |
| 3036 | |
| 3037 | if ( ! empty( $forums ) ) { |
| 3038 | foreach ( $forums as $forum ) { |
| 3039 | if ( in_array( $forum->post_status, $allowed_atatus, true ) ) { |
| 3040 | $options[] = [ |
| 3041 | 'label' => $forum->post_title, |
| 3042 | 'value' => $forum->ID, |
| 3043 | ]; |
| 3044 | } |
| 3045 | } |
| 3046 | } |
| 3047 | return [ |
| 3048 | 'options' => $options, |
| 3049 | 'hasMore' => false, |
| 3050 | ]; |
| 3051 | } |
| 3052 | |
| 3053 | /** |
| 3054 | * Search Affiliate WP Referral Type. |
| 3055 | * |
| 3056 | * @return array |
| 3057 | */ |
| 3058 | public function search_affwp_referral_type() { |
| 3059 | $options = []; |
| 3060 | |
| 3061 | if ( ! function_exists( 'affiliate_wp' ) ) { |
| 3062 | return []; |
| 3063 | } |
| 3064 | |
| 3065 | $types = affiliate_wp()->referrals->types_registry->get_types(); |
| 3066 | if ( ! empty( $types ) ) { |
| 3067 | foreach ( $types as $type_id => $type ) { |
| 3068 | $options[] = [ |
| 3069 | 'label' => $type['label'], |
| 3070 | 'value' => $type_id, |
| 3071 | ]; |
| 3072 | } |
| 3073 | } |
| 3074 | return [ |
| 3075 | 'options' => $options, |
| 3076 | 'hasMore' => false, |
| 3077 | ]; |
| 3078 | } |
| 3079 | |
| 3080 | /** |
| 3081 | * Search Affiliate WP Referral Status. |
| 3082 | * |
| 3083 | * @return array |
| 3084 | */ |
| 3085 | public function search_affwp_referral_status() { |
| 3086 | $options = []; |
| 3087 | |
| 3088 | if ( ! function_exists( 'affwp_get_affiliate_statuses' ) ) { |
| 3089 | return []; |
| 3090 | } |
| 3091 | |
| 3092 | $statuses = affwp_get_affiliate_statuses(); |
| 3093 | if ( ! empty( $statuses ) ) { |
| 3094 | foreach ( $statuses as $key => $status ) { |
| 3095 | $options[] = [ |
| 3096 | 'label' => $status, |
| 3097 | 'value' => $key, |
| 3098 | ]; |
| 3099 | } |
| 3100 | } |
| 3101 | return [ |
| 3102 | 'options' => $options, |
| 3103 | 'hasMore' => false, |
| 3104 | ]; |
| 3105 | } |
| 3106 | |
| 3107 | /** |
| 3108 | * Search Affiliate WP Affiliates list. |
| 3109 | * |
| 3110 | * @return array |
| 3111 | */ |
| 3112 | public function search_affwp_affiliates_list() { |
| 3113 | $options = []; |
| 3114 | |
| 3115 | global $wpdb; |
| 3116 | $affiliates = $wpdb->get_results( "SELECT affiliate_id FROM {$wpdb->prefix}affiliate_wp_affiliates" ); |
| 3117 | |
| 3118 | if ( ! function_exists( 'affwp_get_affiliate_name' ) ) { |
| 3119 | return []; |
| 3120 | } |
| 3121 | |
| 3122 | if ( ! empty( $affiliates ) ) { |
| 3123 | foreach ( $affiliates as $affiliate ) { |
| 3124 | $options[] = [ |
| 3125 | 'label' => affwp_get_affiliate_name( $affiliate->affiliate_id ), |
| 3126 | 'value' => $affiliate->affiliate_id, |
| 3127 | ]; |
| 3128 | } |
| 3129 | } |
| 3130 | return [ |
| 3131 | 'options' => $options, |
| 3132 | 'hasMore' => false, |
| 3133 | ]; |
| 3134 | } |
| 3135 | |
| 3136 | /** |
| 3137 | * Search Affiliate WP Affiliates list. |
| 3138 | * |
| 3139 | * @return array |
| 3140 | */ |
| 3141 | public function search_affwp_affiliates_rate_type() { |
| 3142 | $options = []; |
| 3143 | |
| 3144 | if ( ! function_exists( 'affwp_get_affiliate_rate_types' ) ) { |
| 3145 | return []; |
| 3146 | } |
| 3147 | |
| 3148 | $rate_types = affwp_get_affiliate_rate_types(); |
| 3149 | |
| 3150 | if ( ! empty( $rate_types ) ) { |
| 3151 | foreach ( $rate_types as $key => $rate_type ) { |
| 3152 | $options[] = [ |
| 3153 | 'label' => $rate_type, |
| 3154 | 'value' => $key, |
| 3155 | ]; |
| 3156 | } |
| 3157 | } |
| 3158 | return [ |
| 3159 | 'options' => $options, |
| 3160 | 'hasMore' => false, |
| 3161 | ]; |
| 3162 | } |
| 3163 | |
| 3164 | /** |
| 3165 | * Get last data for trigger. |
| 3166 | * |
| 3167 | * @param array $data data. |
| 3168 | * @return array |
| 3169 | */ |
| 3170 | public function search_affiliate_wp_triggers_last_data( $data ) { |
| 3171 | global $wpdb; |
| 3172 | |
| 3173 | $context = []; |
| 3174 | $context['response_type'] = 'sample'; |
| 3175 | |
| 3176 | $user_data = WordPress::get_sample_user_context(); |
| 3177 | |
| 3178 | $affiliate_data = [ |
| 3179 | 'affiliate_id' => 1, |
| 3180 | 'rest_id' => '', |
| 3181 | 'user_id' => 1, |
| 3182 | 'rate' => '', |
| 3183 | 'rate_type' => '', |
| 3184 | 'flat_rate_basis' => '', |
| 3185 | 'payment_email' => 'admin@gmail.com', |
| 3186 | 'status' => 'active', |
| 3187 | 'earnings' => 0, |
| 3188 | 'unpaid_earnings' => 0, |
| 3189 | 'referrals' => 0, |
| 3190 | 'visits' => 0, |
| 3191 | 'date_registered' => '2023-01-18 13:35:22', |
| 3192 | 'dynamic_coupon' => 'KDJSKS', |
| 3193 | ]; |
| 3194 | |
| 3195 | $referral_data = [ |
| 3196 | 'referral_id' => 1, |
| 3197 | 'affiliate_id' => 1, |
| 3198 | 'visit_id' => 0, |
| 3199 | 'rest_id' => '', |
| 3200 | 'customer_id' => 0, |
| 3201 | 'parent_id' => 0, |
| 3202 | 'description' => 'Testing', |
| 3203 | 'status' => 'unpaid', |
| 3204 | 'amount' => '12.00', |
| 3205 | 'currency' => '', |
| 3206 | 'custom' => 'custom', |
| 3207 | 'context' => '', |
| 3208 | 'campaign' => '', |
| 3209 | 'reference' => 'Reference', |
| 3210 | 'products' => '', |
| 3211 | 'date' => '2023-01-18 16:36:59', |
| 3212 | 'type' => 'opt-in', |
| 3213 | 'payout_id' => 0, |
| 3214 | ]; |
| 3215 | |
| 3216 | if ( ! function_exists( 'affwp_get_dynamic_affiliate_coupons' ) || ! function_exists( 'affwp_get_affiliate' ) || ! function_exists( 'affwp_get_referral' ) ) { |
| 3217 | return []; |
| 3218 | } |
| 3219 | |
| 3220 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3221 | |
| 3222 | if ( in_array( $term, [ 'affiliate_approved', 'affiliate_awaiting_approval' ], true ) ) { |
| 3223 | $status = 'affiliate_approved' === $term ? 'active' : 'pending'; |
| 3224 | $affiliate = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_affiliates WHERE affiliate_id = ( SELECT max(affiliate_id) FROM {$wpdb->prefix}affiliate_wp_affiliates )" ); |
| 3225 | |
| 3226 | if ( ! empty( $affiliate ) ) { |
| 3227 | $affiliate = affwp_get_affiliate( $affiliate->affiliate_id ); |
| 3228 | $affiliate_data = get_object_vars( $affiliate ); |
| 3229 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 3230 | $context['response_type'] = 'live'; |
| 3231 | } |
| 3232 | $affiliate_data['status'] = $status; |
| 3233 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data ); |
| 3234 | |
| 3235 | } elseif ( 'affiliate_makes_referral' == $term ) { |
| 3236 | $type = isset( $data['dynamic'] ) ? $data['dynamic'] : ''; |
| 3237 | $referral = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}affiliate_wp_referrals WHERE referral_id = ( SELECT max(referral_id) FROM {$wpdb->prefix}affiliate_wp_referrals ) AND sale = %s", $type ) ); |
| 3238 | |
| 3239 | if ( ! empty( $referral ) ) { |
| 3240 | $referral = affwp_get_referral( $referral->referral_id ); |
| 3241 | $affiliate = affwp_get_affiliate( $referral->affiliate_id ); |
| 3242 | $affiliate_data = get_object_vars( $affiliate ); |
| 3243 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 3244 | $referral_data = get_object_vars( $referral ); |
| 3245 | $context['response_type'] = 'live'; |
| 3246 | } |
| 3247 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data, $referral_data ); |
| 3248 | } elseif ( 'affiliate_wc_product_purchased' == $term ) { |
| 3249 | $product = isset( $data['dynamic'] ) ? $data['dynamic'] : ''; |
| 3250 | $referral = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_referrals WHERE context = 'woocommerce' ORDER BY referral_id DESC LIMIT 1" ); |
| 3251 | |
| 3252 | if ( ! empty( $referral ) ) { |
| 3253 | $referral = affwp_get_referral( $referral->referral_id ); |
| 3254 | $affiliate = affwp_get_affiliate( $referral->affiliate_id ); |
| 3255 | $affiliate_data = get_object_vars( $affiliate ); |
| 3256 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 3257 | $referral_data = get_object_vars( $referral ); |
| 3258 | $context['response_type'] = 'live'; |
| 3259 | } |
| 3260 | $dynamic_coupons = affwp_get_dynamic_affiliate_coupons( $referral->affiliate_id, false ); |
| 3261 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data, $referral_data, $dynamic_coupons ); |
| 3262 | if ( ! empty( $referral ) && function_exists( 'wc_get_order' ) ) { |
| 3263 | $order_id = $referral->reference; |
| 3264 | $order = wc_get_order( $order_id ); |
| 3265 | $items = $order->get_items(); |
| 3266 | foreach ( $items as $item ) { |
| 3267 | $context['pluggable_data']['product'] = $item['product_id']; |
| 3268 | } |
| 3269 | } else { |
| 3270 | $context['pluggable_data']['product'] = 1; |
| 3271 | } |
| 3272 | } elseif ( 'affiliate_edd_product_purchased' == $term ) { |
| 3273 | $product = isset( $data['dynamic'] ) ? $data['dynamic'] : ''; |
| 3274 | $referral = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_referrals WHERE context = 'edd' ORDER BY referral_id DESC LIMIT 1" ); |
| 3275 | |
| 3276 | if ( ! empty( $referral ) ) { |
| 3277 | $referral = affwp_get_referral( $referral->referral_id ); |
| 3278 | $affiliate = affwp_get_affiliate( $referral->affiliate_id ); |
| 3279 | $affiliate_data = get_object_vars( $affiliate ); |
| 3280 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 3281 | $referral_data = get_object_vars( $referral ); |
| 3282 | $context['response_type'] = 'live'; |
| 3283 | } |
| 3284 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data, $referral_data ); |
| 3285 | if ( ! empty( $referral ) && function_exists( 'edd_get_payment' ) ) { |
| 3286 | $dynamic_coupons = affwp_get_dynamic_affiliate_coupons( $referral->affiliate_id, false ); |
| 3287 | $edd_payment_id = $referral->reference; |
| 3288 | $payment = edd_get_payment( $edd_payment_id ); |
| 3289 | $cart_details = $payment->cart_details; |
| 3290 | $payment = get_object_vars( $payment ); |
| 3291 | $context['pluggable_data'] = array_merge( $context['pluggable_data'], $dynamic_coupons, $payment ); |
| 3292 | foreach ( $cart_details as $detail ) { |
| 3293 | $context['pluggable_data']['product'] = $detail['id']; |
| 3294 | } |
| 3295 | } else { |
| 3296 | $context['pluggable_data']['product'] = 1; |
| 3297 | } |
| 3298 | } elseif ( 'affiliate_mb_product_purchased' == $term ) { |
| 3299 | $product = isset( $data['dynamic'] ) ? $data['dynamic'] : ''; |
| 3300 | $referral = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_referrals WHERE context = 'memberpress' ORDER BY referral_id DESC LIMIT 1" ); |
| 3301 | |
| 3302 | if ( ! empty( $referral ) && class_exists( '\MeprTransaction' ) ) { |
| 3303 | $referral = affwp_get_referral( $referral->referral_id ); |
| 3304 | $reference_id = $referral->reference; |
| 3305 | $transaction = new MeprTransaction( $reference_id ); |
| 3306 | $user_id = $transaction->user_id; |
| 3307 | $affiliate = affwp_get_affiliate( $referral->affiliate_id ); |
| 3308 | $affiliate_data = get_object_vars( $affiliate ); |
| 3309 | $user_data = WordPress::get_user_context( $user_id ); |
| 3310 | $referral_data = get_object_vars( $referral ); |
| 3311 | $context['response_type'] = 'live'; |
| 3312 | } |
| 3313 | $dynamic_coupons = affwp_get_dynamic_affiliate_coupons( $referral->affiliate_id, false ); |
| 3314 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data, $referral_data, $dynamic_coupons ); |
| 3315 | if ( ! empty( $referral ) && class_exists( '\MeprTransaction' ) ) { |
| 3316 | $membership_id = $wpdb->get_var( |
| 3317 | $wpdb->prepare( |
| 3318 | "SELECT product_id FROM |
| 3319 | {$wpdb->prefix}mepr_transactions WHERE id = %d", |
| 3320 | $referral->reference |
| 3321 | ) |
| 3322 | ); |
| 3323 | $context['pluggable_data']['product'] = $membership_id; |
| 3324 | $context['pluggable_data']['product_name'] = get_the_title( $membership_id ); |
| 3325 | } else { |
| 3326 | $context['pluggable_data']['product'] = 1; |
| 3327 | $context['pluggable_data']['product_name'] = 'membership1'; |
| 3328 | } |
| 3329 | } elseif ( 'affiliate_referral_paid' == $term ) { |
| 3330 | $type = isset( $data['filter']['type']['value'] ) ? $data['filter']['type']['value'] : ''; |
| 3331 | $referral = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}affiliate_wp_referrals WHERE type = %s AND status = 'paid'", $type ) ); |
| 3332 | |
| 3333 | if ( ! empty( $referral ) ) { |
| 3334 | $referral = affwp_get_referral( $referral->referral_id ); |
| 3335 | $affiliate = affwp_get_affiliate( $referral->affiliate_id ); |
| 3336 | $affiliate_data = get_object_vars( $affiliate ); |
| 3337 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 3338 | $referral_data = get_object_vars( $referral ); |
| 3339 | $context['response_type'] = 'live'; |
| 3340 | } |
| 3341 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data, $referral_data ); |
| 3342 | } elseif ( 'affiliate_referral_rejected' == $term ) { |
| 3343 | $type = isset( $data['filter']['type']['value'] ) ? $data['filter']['type']['value'] : ''; |
| 3344 | $referral = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}affiliate_wp_referrals WHERE type = %s AND status = 'rejected'", $type ) ); |
| 3345 | if ( ! empty( $referral ) ) { |
| 3346 | $referral = affwp_get_referral( $referral->referral_id ); |
| 3347 | $affiliate = affwp_get_affiliate( $referral->affiliate_id ); |
| 3348 | $affiliate_data = get_object_vars( $affiliate ); |
| 3349 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 3350 | $referral_data = get_object_vars( $referral ); |
| 3351 | $context['response_type'] = 'live'; |
| 3352 | } |
| 3353 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data, $referral_data ); |
| 3354 | } else { |
| 3355 | $referral = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_referrals WHERE referral_id = ( SELECT max(referral_id) FROM {$wpdb->prefix}affiliate_wp_referrals )" ); |
| 3356 | |
| 3357 | if ( ! empty( $referral ) ) { |
| 3358 | $referral = affwp_get_referral( $referral->referral_id ); |
| 3359 | $affiliate = affwp_get_affiliate( $referral->affiliate_id ); |
| 3360 | $affiliate_data = get_object_vars( $affiliate ); |
| 3361 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 3362 | $referral_data = get_object_vars( $referral ); |
| 3363 | $context['response_type'] = 'live'; |
| 3364 | } |
| 3365 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data, $referral_data ); |
| 3366 | } |
| 3367 | |
| 3368 | return $context; |
| 3369 | } |
| 3370 | |
| 3371 | /** |
| 3372 | * Get last data for trigger. |
| 3373 | * |
| 3374 | * @param array $data data. |
| 3375 | * @return array |
| 3376 | */ |
| 3377 | public function search_jetpack_crm_triggers_last_data( $data ) { |
| 3378 | |
| 3379 | if ( ! function_exists( 'zeroBS_getCompanyCount' ) || ! function_exists( 'zeroBS_getCustomerCount' ) || ! function_exists( 'zeroBS_getQuoteCount' ) ) { |
| 3380 | return []; |
| 3381 | } |
| 3382 | |
| 3383 | global $wpdb; |
| 3384 | |
| 3385 | $context = []; |
| 3386 | $context['response_type'] = 'sample'; |
| 3387 | |
| 3388 | $company_id = [ 'company_id' => 1 ]; |
| 3389 | $contact_id = [ 'contact_id' => 1 ]; |
| 3390 | $quote_id = [ 'quote_id' => 1 ]; |
| 3391 | $event_id = [ 'event_id' => 1 ]; |
| 3392 | $invoice_id = [ 'invoice_id' => 1 ]; |
| 3393 | $transaction_id = [ 'transaction_id' => 1 ]; |
| 3394 | |
| 3395 | $company = [ |
| 3396 | 'company_id' => 1, |
| 3397 | 'company_status' => 'Lead', |
| 3398 | 'company_name' => 'Example Company', |
| 3399 | 'company_email' => 'info@example.com', |
| 3400 | 'main_address_line_1' => '123 Main Street', |
| 3401 | 'main_address_line_2' => 'Suite 456', |
| 3402 | 'main_address_city' => 'New York', |
| 3403 | 'main_address_state' => 'NY', |
| 3404 | 'main_address_postal_code' => '10001', |
| 3405 | 'main_address_country' => 'United States', |
| 3406 | 'second_address_line_1' => '789 Second Avenue', |
| 3407 | 'second_address_line_2' => 'Floor 10', |
| 3408 | 'second_address_city' => 'Los Angeles', |
| 3409 | 'second_address_state' => 'CA', |
| 3410 | 'second_address_postal_code' => '90001', |
| 3411 | 'second_address_country' => 'United States', |
| 3412 | 'main_telephone' => '+1 123-456-7890', |
| 3413 | 'secondary_telephone' => '+1 987-654-3210', |
| 3414 | ]; |
| 3415 | |
| 3416 | $contact = [ |
| 3417 | 'contact_id' => 1, |
| 3418 | 'status' => 'Lead', |
| 3419 | 'prefix' => 'Mr.', |
| 3420 | 'full_name' => 'John Doe', |
| 3421 | 'first_name' => 'John', |
| 3422 | 'last_name' => 'Doe', |
| 3423 | 'email' => 'johndoe@example.com', |
| 3424 | 'main_address_line_1' => '123 Main Street', |
| 3425 | 'main_address_line_2' => 'Suite 456', |
| 3426 | 'main_address_city' => 'New York', |
| 3427 | 'main_address_state' => 'NY', |
| 3428 | 'main_address_postal_code' => '10001', |
| 3429 | 'main_address_country' => 'United States', |
| 3430 | 'second_address_line_1' => '789 Second Avenue', |
| 3431 | 'second_address_line_2' => 'Floor 10', |
| 3432 | 'second_address_city' => 'Los Angeles', |
| 3433 | 'second_address_state' => 'CA', |
| 3434 | 'second_address_postal_code' => '90001', |
| 3435 | 'second_address_country' => 'United States', |
| 3436 | 'home_telephone' => '+1 123-456-7890', |
| 3437 | 'work_telephone' => '+1 987-654-3210', |
| 3438 | 'mobile_telephone' => '+1 555-555-5555', |
| 3439 | ]; |
| 3440 | |
| 3441 | $quote = [ |
| 3442 | 'quote_id' => 1, |
| 3443 | 'contact_id' => 2, |
| 3444 | 'contact_email' => 'john@example.com', |
| 3445 | 'contact_name' => 'John Doe', |
| 3446 | 'status' => '<strong>Created, not yet accepted</strong>', |
| 3447 | 'title' => 'Sample Quote', |
| 3448 | 'value' => 1000, |
| 3449 | 'date' => '2023-05-23', |
| 3450 | 'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', |
| 3451 | 'notes' => 'Additional notes about the quote.', |
| 3452 | ]; |
| 3453 | |
| 3454 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3455 | |
| 3456 | switch ( $term ) { |
| 3457 | case 'company_created': |
| 3458 | if ( zeroBS_getCompanyCount() > 0 ) { |
| 3459 | $company_data = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}zbs_companies WHERE ID = ( SELECT max(ID) FROM {$wpdb->prefix}zbs_companies )" ); |
| 3460 | $company = JetpackCRM::get_company_context( $company_data->ID ); |
| 3461 | $context['response_type'] = 'live'; |
| 3462 | } |
| 3463 | $context['pluggable_data'] = $company; |
| 3464 | break; |
| 3465 | case 'company_deleted': |
| 3466 | $context['pluggable_data'] = $company_id; |
| 3467 | break; |
| 3468 | case 'contact_created': |
| 3469 | if ( zeroBS_getCustomerCount() > 0 ) { |
| 3470 | $contact_data = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}zbs_contacts WHERE ID = ( SELECT max(ID) FROM {$wpdb->prefix}zbs_contacts )" ); |
| 3471 | $contact = JetpackCRM::get_contact_context( $contact_data->ID ); |
| 3472 | $context['response_type'] = 'live'; |
| 3473 | } |
| 3474 | $context['pluggable_data'] = $contact; |
| 3475 | break; |
| 3476 | case 'contact_deleted': |
| 3477 | $context['pluggable_data'] = $contact_id; |
| 3478 | break; |
| 3479 | case 'event_deleted': |
| 3480 | $context['pluggable_data'] = $event_id; |
| 3481 | break; |
| 3482 | case 'invoice_deleted': |
| 3483 | $context['pluggable_data'] = $invoice_id; |
| 3484 | break; |
| 3485 | case 'quote_accepted': |
| 3486 | case 'quote_created': |
| 3487 | if ( zeroBS_getQuoteCount() > 0 ) { |
| 3488 | $quote_data = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}zbs_quotes WHERE ID = ( SELECT max(ID) FROM {$wpdb->prefix}zbs_quotes )" ); |
| 3489 | $quote = JetpackCRM::get_quote_context( $quote_data->ID ); |
| 3490 | $context['response_type'] = 'live'; |
| 3491 | } |
| 3492 | $context['pluggable_data'] = $quote; |
| 3493 | break; |
| 3494 | case 'quote_deleted': |
| 3495 | $context['pluggable_data'] = $quote_id; |
| 3496 | break; |
| 3497 | case 'transaction_deleted': |
| 3498 | $context['pluggable_data'] = $transaction_id; |
| 3499 | break; |
| 3500 | } |
| 3501 | |
| 3502 | return $context; |
| 3503 | } |
| 3504 | |
| 3505 | /** |
| 3506 | * Get last data for trigger. |
| 3507 | * |
| 3508 | * @param array $data data. |
| 3509 | * @return array |
| 3510 | */ |
| 3511 | public function search_funnel_kit_automations_triggers_last_data( $data ) { |
| 3512 | |
| 3513 | if ( ! class_exists( 'BWFCRM_Contact' ) || ! class_exists( 'BWFCRM_Lists' ) || ! class_exists( 'BWFCRM_Tag' ) ) { |
| 3514 | return []; |
| 3515 | } |
| 3516 | |
| 3517 | $context = []; |
| 3518 | $context['response_type'] = 'sample'; |
| 3519 | |
| 3520 | $contact = [ |
| 3521 | 'contact_id' => '1', |
| 3522 | 'wpid' => '0', |
| 3523 | 'uid' => '9e74246335fd81b1c4a9123842c12549', |
| 3524 | 'email' => 'johndoe@example.com', |
| 3525 | 'first_name' => 'John', |
| 3526 | 'last_name' => 'Doe', |
| 3527 | 'contact_no' => '+1 555-555-5555', |
| 3528 | 'state' => 'NY', |
| 3529 | 'country' => 'United States', |
| 3530 | 'timezone' => 'New York', |
| 3531 | 'creation_date' => '2023-05-29 15:26:03', |
| 3532 | 'last_modified' => '2023-05-29 17:08:30', |
| 3533 | 'source' => '', |
| 3534 | 'type' => 'Los Angeles', |
| 3535 | 'status' => '0', |
| 3536 | 'tags' => '["1"]', |
| 3537 | 'lists' => '["2","1"]', |
| 3538 | ]; |
| 3539 | |
| 3540 | $list = [ |
| 3541 | 'list_id' => 1, |
| 3542 | 'list_name' => 'Sample List', |
| 3543 | ]; |
| 3544 | |
| 3545 | $tag = [ |
| 3546 | 'tag_id' => 1, |
| 3547 | 'tag_name' => 'Sample Tag', |
| 3548 | ]; |
| 3549 | |
| 3550 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3551 | |
| 3552 | $recent_contacts = \BWFCRM_Contact::get_recent_contacts( 0, 1, [] ); |
| 3553 | $contact_email = count( $recent_contacts['contacts'] ) > 0 && isset( $recent_contacts['contacts'][0]['email'] ) ? $recent_contacts['contacts'][0]['email'] : ''; |
| 3554 | |
| 3555 | $real_contact = false; |
| 3556 | if ( ! empty( $contact_email ) ) { |
| 3557 | $contact_obj = \BWFCRM_Contact::get_contacts( $contact_email, 0, 1, [], [], OBJECT ); |
| 3558 | |
| 3559 | if ( isset( $contact_obj['contacts'][0] ) ) { |
| 3560 | $contact = FunnelKitAutomations::get_contact_context( $contact_obj['contacts'][0]->contact ); |
| 3561 | $real_contact = true; |
| 3562 | } |
| 3563 | } |
| 3564 | |
| 3565 | if ( 'contact_added_to_list' === $term || 'contact_removed_from_list' === $term ) { |
| 3566 | $list_id = (int) ( isset( $data['filter']['list_id']['value'] ) ? $data['filter']['list_id']['value'] : '-1' ); |
| 3567 | |
| 3568 | if ( -1 === $list_id ) { |
| 3569 | $lists = \BWFCRM_Lists::get_lists( [], '', 0, 1 ); |
| 3570 | $list_id = count( $lists ) > 0 ? $lists[0]['ID'] : -1; |
| 3571 | } |
| 3572 | |
| 3573 | |
| 3574 | if ( -1 !== $list_id ) { |
| 3575 | $list = FunnelKitAutomations::get_list_context( $list_id ); |
| 3576 | $context['response_type'] = $real_contact ? 'live' : 'sample'; |
| 3577 | } |
| 3578 | |
| 3579 | $context['pluggable_data'] = array_merge( $list, $contact ); |
| 3580 | } else { |
| 3581 | $tag_id = (int) ( isset( $data['filter']['tag_id']['value'] ) ? $data['filter']['tag_id']['value'] : '-1' ); |
| 3582 | |
| 3583 | if ( -1 === $tag_id ) { |
| 3584 | $tags = \BWFCRM_Tag::get_tags( [], '', 0, 1 ); |
| 3585 | $tag_id = count( $tags ) > 0 ? $tags[0]['ID'] : -1; |
| 3586 | } |
| 3587 | |
| 3588 | |
| 3589 | if ( -1 !== $tag_id ) { |
| 3590 | $tag = FunnelKitAutomations::get_tag_context( $tag_id ); |
| 3591 | $context['response_type'] = $real_contact ? 'live' : 'sample'; |
| 3592 | } |
| 3593 | |
| 3594 | $context['pluggable_data'] = array_merge( $tag, $contact ); |
| 3595 | } |
| 3596 | |
| 3597 | return $context; |
| 3598 | } |
| 3599 | |
| 3600 | /** |
| 3601 | * Get last data for trigger. |
| 3602 | * |
| 3603 | * @param array $data data. |
| 3604 | * @return array |
| 3605 | */ |
| 3606 | public function search_edd_triggers_last_data( $data ) { |
| 3607 | global $wpdb; |
| 3608 | $context = []; |
| 3609 | $context['response_type'] = 'sample'; |
| 3610 | $context['pluggable_data'] = []; |
| 3611 | $order_data = [ |
| 3612 | 'order_id' => 187, |
| 3613 | 'customer_email' => 'john_doe@bsf.io', |
| 3614 | 'customer_id' => 2, |
| 3615 | 'user_id' => 1, |
| 3616 | 'customer_first_name' => 'Sure', |
| 3617 | 'customer_last_name' => 'Dev', |
| 3618 | 'ordered_items' => 'Price with license — Price one', |
| 3619 | 'currency' => 'USD', |
| 3620 | 'status' => 'complete', |
| 3621 | 'discount_codes' => '', |
| 3622 | 'order_discounts' => 0.00, |
| 3623 | 'order_subtotal' => 12.00, |
| 3624 | 'order_tax' => 0.00, |
| 3625 | 'order_total' => 12.00, |
| 3626 | 'payment_method' => 'manual', |
| 3627 | 'purchase_key' => 'd797b9576a3895e7424bae2417ed87df', |
| 3628 | 'ordered_items_ids' => 17250, |
| 3629 | 'download_id' => 17250, |
| 3630 | 'license_key' => 'f7736093411cfaed18b56ec60227117b', |
| 3631 | 'license_key_expire_date' => '1697524076', |
| 3632 | 'license_key_status' => 'inactive', |
| 3633 | ]; |
| 3634 | |
| 3635 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3636 | $download_id = isset( $data['filter']['download_id']['value'] ) ? $data['filter']['download_id']['value'] : 0; |
| 3637 | if ( 'order_created' === $term || 'order_one_product' === $term ) { |
| 3638 | $order_data['purchase_key'] = '06d3b7d923ca922dc889354f9bc33fbb'; |
| 3639 | |
| 3640 | $args = [ |
| 3641 | 'number' => 1, |
| 3642 | 'status' => [ 'complete', 'refunded', 'partially_refunded', 'renewal' ], |
| 3643 | ]; |
| 3644 | if ( $download_id > 0 ) { |
| 3645 | $args['download'] = $download_id; |
| 3646 | } |
| 3647 | $payments = edd_get_payments( $args ); |
| 3648 | if ( count( $payments ) > 0 ) { |
| 3649 | $order_data = EDD::get_product_purchase_context( $payments[0], $term, $download_id ); |
| 3650 | |
| 3651 | $context['response_type'] = 'live'; |
| 3652 | } else { |
| 3653 | if ( 'order_one_product' === $term ) { |
| 3654 | $order_data['price_id'] = 1; |
| 3655 | } |
| 3656 | } |
| 3657 | } elseif ( 'stripe_payment_refunded' === $term ) { |
| 3658 | $args = [ |
| 3659 | 'number' => 1, |
| 3660 | 'status' => 'complete', |
| 3661 | 'type' => 'refund', |
| 3662 | ]; |
| 3663 | $payments = edd_get_payments( $args ); |
| 3664 | |
| 3665 | if ( count( $payments ) > 0 ) { |
| 3666 | $order_data = EDD::get_purchase_refund_context( $payments[0] ); |
| 3667 | $context['response_type'] = 'live'; |
| 3668 | } |
| 3669 | } else { |
| 3670 | $status = isset( $data['post_type'] ) ? $data['post_type'] : ''; |
| 3671 | if ( ! empty( $status ) ) { |
| 3672 | if ( $download_id > 0 ) { |
| 3673 | $licesnses = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_licenses WHERE status= %s AND download_id=%d ORDER BY id DESC", $status, $download_id ) ); |
| 3674 | } else { |
| 3675 | $licesnses = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_licenses WHERE status= %s ORDER BY id DESC", $status ) ); |
| 3676 | } |
| 3677 | } else { |
| 3678 | if ( $download_id > 0 ) { |
| 3679 | $licesnses = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_licenses WHERE download_id=%d ORDER BY id DESC", $download_id ) ); |
| 3680 | } else { |
| 3681 | $licesnses = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}edd_licenses ORDER BY id DESC" ); |
| 3682 | } |
| 3683 | } |
| 3684 | if ( ! empty( $licesnses ) ) { |
| 3685 | $order_data = EDD::edd_get_license_data( $licesnses->id, $licesnses->download_id, $licesnses->payment_id ); |
| 3686 | $context['response_type'] = 'live'; |
| 3687 | } else { |
| 3688 | $order_data = [ |
| 3689 | 'ID' => 1, |
| 3690 | 'key' => '23232323232', |
| 3691 | 'customer_email' => 'suretest@example.com', |
| 3692 | 'customer_name' => 'Sure Test', |
| 3693 | 'product_id' => 1, |
| 3694 | 'download_id' => 1, |
| 3695 | 'product_name' => 'Test', |
| 3696 | 'activation_limit' => 2, |
| 3697 | 'activation_count' => 1, |
| 3698 | 'activated_urls' => 'https://example.com', |
| 3699 | 'expiration' => '1686297914', |
| 3700 | 'is_lifetime' => '0', |
| 3701 | 'status' => $status, |
| 3702 | ]; |
| 3703 | |
| 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | $context['pluggable_data'] = $order_data; |
| 3708 | return $context; |
| 3709 | } |
| 3710 | |
| 3711 | /** |
| 3712 | * Get last data for trigger. |
| 3713 | * |
| 3714 | * @param array $data data. |
| 3715 | * @return array |
| 3716 | */ |
| 3717 | public function search_presto_player_triggers_last_data( $data ) { |
| 3718 | $context = []; |
| 3719 | $context['response_type'] = 'sample'; |
| 3720 | |
| 3721 | $user_data = WordPress::get_sample_user_context(); |
| 3722 | |
| 3723 | $video_data = [ |
| 3724 | 'pp_video' => '1', |
| 3725 | 'pp_video_percentage' => '100', |
| 3726 | 'video_id' => '1', |
| 3727 | 'video_title' => 'SureTriggers Is Here 🎉 The Easiest Automation Builder WordPress Websites & Apps', |
| 3728 | 'video_type' => 'youtube', |
| 3729 | 'video_external_id' => '-cYbNYgylLs', |
| 3730 | 'video_attachment_id' => '0', |
| 3731 | 'video_post_id' => '127', |
| 3732 | 'video_src' => 'https://www.youtube.com/watch?v=-cYbNYgylLs', |
| 3733 | 'video_created_by' => '1', |
| 3734 | 'video_created_at' => '2022-11-10 00:28:25', |
| 3735 | 'video_updated_at' => '2022-11-10 00:34:40', |
| 3736 | 'video_deleted_at' => '', |
| 3737 | ]; |
| 3738 | |
| 3739 | $videos = ( new Video() )->all(); |
| 3740 | |
| 3741 | if ( count( $videos ) > 0 ) { |
| 3742 | $video_id = '-1' === $data['filter']['pp_video']['value'] ? $videos[0]->id : $data['filter']['pp_video']['value']; |
| 3743 | $video_data = ( new Video( $video_id ) )->toArray(); |
| 3744 | $video_data['pp_video'] = $video_id; |
| 3745 | $video_data['pp_video_percentage'] = isset( $data['filter']['pp_video_percentage']['value'] ) ? $data['filter']['pp_video_percentage']['value'] : '100'; |
| 3746 | $user_data = WordPress::get_user_context( $video_data['created_by'] ); |
| 3747 | |
| 3748 | $context['response_type'] = 'live'; |
| 3749 | } |
| 3750 | |
| 3751 | $context['pluggable_data'] = array_merge( $user_data, $video_data ); |
| 3752 | |
| 3753 | return $context; |
| 3754 | } |
| 3755 | |
| 3756 | /** |
| 3757 | * Get last data for trigger. |
| 3758 | * |
| 3759 | * @param array $data data. |
| 3760 | * @return array |
| 3761 | */ |
| 3762 | public function search_member_press_triggers_last_data( $data ) { |
| 3763 | global $wpdb; |
| 3764 | |
| 3765 | $context = []; |
| 3766 | $context['response_type'] = 'sample'; |
| 3767 | |
| 3768 | $user_data = WordPress::get_sample_user_context(); |
| 3769 | |
| 3770 | $membership_data = [ |
| 3771 | 'membership_id' => '190', |
| 3772 | 'membership_title' => 'Sample Membership', |
| 3773 | 'amount' => '12.00', |
| 3774 | 'total' => '12.00', |
| 3775 | 'tax_amount' => '0.00', |
| 3776 | 'tax_rate' => '0.00', |
| 3777 | 'trans_num' => 't_63a03f3334f44', |
| 3778 | 'status' => 'complete', |
| 3779 | 'subscription_id' => '0', |
| 3780 | 'membership_url' => site_url() . '/register/premium/', |
| 3781 | 'membership_featured_image_id' => '521', |
| 3782 | 'membership_featured_image_url' => SURE_TRIGGERS_URL . 'assets/images/sample.svg', |
| 3783 | ]; |
| 3784 | |
| 3785 | $membership_id = (int) ( isset( $data['filter']['membership_id']['value'] ) ? $data['filter']['membership_id']['value'] : '-1' ); |
| 3786 | |
| 3787 | if ( $membership_id > 0 ) { |
| 3788 | |
| 3789 | $subscription = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mepr_transactions WHERE product_id= %s ORDER BY id DESC LIMIT 1", $membership_id ) ); |
| 3790 | } else { |
| 3791 | $subscription = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mepr_transactions ORDER BY id DESC LIMIT 1" ); |
| 3792 | } |
| 3793 | |
| 3794 | if ( ! empty( $subscription ) ) { |
| 3795 | $membership_data = MemberPress::get_membership_context( $subscription ); |
| 3796 | $user_data = WordPress::get_user_context( $subscription->user_id ); |
| 3797 | |
| 3798 | $context['response_type'] = 'live'; |
| 3799 | } |
| 3800 | |
| 3801 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 3802 | |
| 3803 | return $context; |
| 3804 | } |
| 3805 | |
| 3806 | /** |
| 3807 | * Get last data for trigger. |
| 3808 | * |
| 3809 | * @param array $data data. |
| 3810 | * @return array |
| 3811 | */ |
| 3812 | public function search_wishlist_member_triggers_last_data( $data ) { |
| 3813 | global $wpdb; |
| 3814 | |
| 3815 | $context = []; |
| 3816 | $context['response_type'] = 'sample'; |
| 3817 | |
| 3818 | $user_data = WordPress::get_sample_user_context(); |
| 3819 | |
| 3820 | $membership_data = [ |
| 3821 | 'membership_level_id' => '1', |
| 3822 | 'membership_level_name' => 'Sample Membership Level', |
| 3823 | ]; |
| 3824 | |
| 3825 | $membership_level_id = (int) ( isset( $data['filter']['membership_level_id']['value'] ) ? $data['filter']['membership_level_id']['value'] : '-1' ); |
| 3826 | |
| 3827 | if ( $membership_level_id > 0 ) { |
| 3828 | $membership = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wlm_userlevels WHERE level_id= %s ORDER BY id DESC LIMIT 1", $membership_level_id ) ); |
| 3829 | } else { |
| 3830 | $membership = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}wlm_userlevels ORDER BY id DESC LIMIT 1" ); |
| 3831 | } |
| 3832 | if ( ! empty( $membership ) ) { |
| 3833 | $membership_data = WishlistMember::get_membership_detail_context( (int) $membership->level_id ); |
| 3834 | $user_data = WordPress::get_user_context( $membership->user_id ); |
| 3835 | |
| 3836 | $context['response_type'] = 'live'; |
| 3837 | } |
| 3838 | |
| 3839 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 3840 | |
| 3841 | return $context; |
| 3842 | } |
| 3843 | |
| 3844 | /** |
| 3845 | * Get last data for trigger. |
| 3846 | * |
| 3847 | * @param array $data data. |
| 3848 | * @return array |
| 3849 | */ |
| 3850 | public function search_peepso_triggers_last_data( $data ) { |
| 3851 | global $wpdb; |
| 3852 | |
| 3853 | $context = []; |
| 3854 | $context['response_type'] = 'sample'; |
| 3855 | |
| 3856 | $user_data = WordPress::get_sample_user_context(); |
| 3857 | |
| 3858 | $post_data = [ |
| 3859 | 'post_id' => '1', |
| 3860 | 'activity_id' => '2', |
| 3861 | 'post_author' => '1', |
| 3862 | 'post_content' => 'New sample post...!', |
| 3863 | 'post_title' => 'Sample Post', |
| 3864 | 'post_excerpt' => 'sample', |
| 3865 | 'post_status' => 'publish', |
| 3866 | 'post_type' => 'peepso-post', |
| 3867 | ]; |
| 3868 | |
| 3869 | $post = $wpdb->get_row( "SELECT act_id, act_owner_id, act_external_id FROM {$wpdb->prefix}peepso_activities ORDER BY act_id DESC LIMIT 1" ); |
| 3870 | |
| 3871 | if ( ! empty( $post ) ) { |
| 3872 | $post_data = PeepSo::get_pp_activity_context( (int) $post->act_external_id, (int) $post->act_id ); |
| 3873 | $user_data = WordPress::get_user_context( $post->act_owner_id ); |
| 3874 | |
| 3875 | $context['response_type'] = 'live'; |
| 3876 | } |
| 3877 | |
| 3878 | $context['pluggable_data'] = array_merge( $user_data, $post_data ); |
| 3879 | |
| 3880 | return $context; |
| 3881 | } |
| 3882 | |
| 3883 | /** |
| 3884 | * Get last data for trigger |
| 3885 | * |
| 3886 | * @param array $data data. |
| 3887 | * @return array |
| 3888 | */ |
| 3889 | public function search_restrict_content_pro_triggers_last_data( $data ) { |
| 3890 | $context = []; |
| 3891 | $context['response_type'] = 'sample'; |
| 3892 | |
| 3893 | $user_data = WordPress::get_sample_user_context(); |
| 3894 | |
| 3895 | $membership_data = [ |
| 3896 | 'membership_level_id' => '190', |
| 3897 | 'membership_level' => 'Sample Membership', |
| 3898 | 'membership_initial_payment' => '0.00', |
| 3899 | 'membership_recurring_payment' => '0.00', |
| 3900 | 'membership_expiry_date' => 'January 22, 2023', |
| 3901 | ]; |
| 3902 | |
| 3903 | $customer_id = (int) ( isset( $data['filter']['membership_customer_id']['value'] ) ? $data['filter']['membership_customer_id']['value'] : '-1' ); |
| 3904 | $membership_id = (int) ( isset( $data['filter']['membership_level_id']['value'] ) ? $data['filter']['membership_level_id']['value'] : '-1' ); |
| 3905 | |
| 3906 | $args = [ |
| 3907 | 'status' => 'expired', |
| 3908 | 'number' => 1, |
| 3909 | 'orderby' => 'id', |
| 3910 | ]; |
| 3911 | |
| 3912 | if ( -1 !== $customer_id ) { |
| 3913 | $args['customer_id'] = $customer_id; |
| 3914 | } |
| 3915 | |
| 3916 | if ( -1 !== $membership_id ) { |
| 3917 | $args['object_id'] = $membership_id; |
| 3918 | } |
| 3919 | |
| 3920 | $memberships = rcp_get_memberships( $args ); |
| 3921 | if ( count( $memberships ) > 0 ) { |
| 3922 | $membership_data = RestrictContent::get_rcp_membership_detail_context( $memberships[0] ); |
| 3923 | $user_data = WordPress::get_user_context( $memberships[0]->get_user_id() ); |
| 3924 | |
| 3925 | $context['response_type'] = 'live'; |
| 3926 | } |
| 3927 | |
| 3928 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 3929 | |
| 3930 | return $context; |
| 3931 | } |
| 3932 | |
| 3933 | /** |
| 3934 | * Get last data for trigger |
| 3935 | * |
| 3936 | * @param array $data data. |
| 3937 | * @return array |
| 3938 | */ |
| 3939 | public function search_events_calendar_triggers_last_data( $data ) { |
| 3940 | $context = []; |
| 3941 | $context['response_type'] = 'sample'; |
| 3942 | |
| 3943 | $event_data = [ |
| 3944 | 'event_id' => 1, |
| 3945 | 'event' => [ |
| 3946 | 'ID' => 58, |
| 3947 | 'post_author' => 1, |
| 3948 | 'post_date' => '2023-01-19 09:27:58', |
| 3949 | 'post_date_gmt' => '2023-01-19 09:27:58', |
| 3950 | 'post_content' => '', |
| 3951 | 'post_title' => 'New event', |
| 3952 | 'post_excerpt' => '', |
| 3953 | 'post_status' => 'publish', |
| 3954 | 'comment_status' => 'open', |
| 3955 | 'ping_status' => 'closed', |
| 3956 | 'post_password' => '', |
| 3957 | 'post_name' => 'new-event', |
| 3958 | 'to_ping' => '', |
| 3959 | 'pinged' => '', |
| 3960 | 'post_modified' => '2023-01-19 09:44:25', |
| 3961 | 'post_modified_gmt' => '2023-01-19 09:44:25', |
| 3962 | 'post_content_filtered' => '', |
| 3963 | 'post_parent' => 0, |
| 3964 | 'guid' => 'http://connector.com/?post_type=tribe_events&p=58', |
| 3965 | 'menu_order' => -1, |
| 3966 | 'post_type' => 'tribe_events', |
| 3967 | 'post_mime_type' => '', |
| 3968 | 'comment_count' => 0, |
| 3969 | 'filter' => 'raw', |
| 3970 | ], |
| 3971 | 'attendies' => [ |
| 3972 | 'order_id' => 68, |
| 3973 | 'purchaser_name' => 'John Doe', |
| 3974 | 'purchaser_email' => 'john@test.com', |
| 3975 | 'provider' => 'Tribe__Tickets__RSVP', |
| 3976 | 'provider_slug' => 'rsvp', |
| 3977 | 'purchase_time' => '2023-01-19 09:48:43', |
| 3978 | 'optout' => 1, |
| 3979 | 'ticket' => 'Prime', |
| 3980 | 'attendee_id' => 68, |
| 3981 | 'security' => '2cefc3b53e', |
| 3982 | 'product_id' => 65, |
| 3983 | 'check_in' => '', |
| 3984 | 'order_status' => 'yes', |
| 3985 | 'order_status_label' => 'Going', |
| 3986 | 'user_id' => 1, |
| 3987 | 'ticket_sent' => 1, |
| 3988 | 'event_id' => 58, |
| 3989 | 'ticket_name' => 'Prime', |
| 3990 | 'holder_name' => 'John Doe', |
| 3991 | 'holder_email' => 'john@test.com', |
| 3992 | 'ticket_id' => 68, |
| 3993 | 'qr_ticket_id' => 68, |
| 3994 | 'security_code' => '2cefc3b53e', |
| 3995 | 'attendee_meta' => '', |
| 3996 | 'is_subscribed' => '', |
| 3997 | 'is_purchaser' => 1, |
| 3998 | 'ticket_exists' => 1, |
| 3999 | ], |
| 4000 | ]; |
| 4001 | |
| 4002 | $event_id = (int) ( isset( $data['filter']['event_id']['value'] ) ? $data['filter']['event_id']['value'] : '-1' ); |
| 4003 | |
| 4004 | $args = [ |
| 4005 | 'post_type' => 'tribe_rsvp_attendees', |
| 4006 | 'orderby' => 'ID', |
| 4007 | 'order' => 'DESC', |
| 4008 | 'post_status' => 'publish', |
| 4009 | 'numberposts' => 1, |
| 4010 | ]; |
| 4011 | |
| 4012 | if ( -1 !== $event_id ) { |
| 4013 | $args['meta_query'] = [ |
| 4014 | [ |
| 4015 | 'key' => '_tribe_rsvp_event', |
| 4016 | 'value' => $event_id, |
| 4017 | ], |
| 4018 | ]; |
| 4019 | } |
| 4020 | |
| 4021 | $attendees = get_posts( $args ); |
| 4022 | |
| 4023 | if ( count( $attendees ) > 0 ) { |
| 4024 | $attendee = $attendees[0]; |
| 4025 | $attendee_id = $attendee->ID; |
| 4026 | |
| 4027 | $product_id = get_post_meta( $attendee_id, '_tribe_rsvp_product', true ); |
| 4028 | $order_id = get_post_meta( $attendee_id, '_tribe_rsvp_order', true ); |
| 4029 | |
| 4030 | $event_context = TheEventCalendar::get_event_context( $product_id, $order_id ); |
| 4031 | |
| 4032 | if ( ! empty( $event_context ) ) { |
| 4033 | $event_data = $event_context; |
| 4034 | $context['response_type'] = 'live'; |
| 4035 | } |
| 4036 | } |
| 4037 | |
| 4038 | $context['pluggable_data'] = $event_data; |
| 4039 | |
| 4040 | return $context; |
| 4041 | } |
| 4042 | |
| 4043 | /** |
| 4044 | * Get last data for trigger |
| 4045 | * |
| 4046 | * @param array $data data. |
| 4047 | * @return array |
| 4048 | */ |
| 4049 | public function search_woo_commerce_triggers_last_data( $data ) { |
| 4050 | $context = []; |
| 4051 | $context['response_type'] = 'sample'; |
| 4052 | $context['pluggable_data'] = []; |
| 4053 | $user_data = WordPress::get_sample_user_context(); |
| 4054 | |
| 4055 | $product_data['product'] = [ |
| 4056 | 'id' => '169', |
| 4057 | 'name' => 'Sample Product', |
| 4058 | 'description' => 'This is description of sample product.', |
| 4059 | 'short_description' => 'This is short description of sample product.', |
| 4060 | 'image_url' => SURE_TRIGGERS_URL . 'assets/images/sample.svg', |
| 4061 | 'slug' => 'sample-product', |
| 4062 | 'status' => 'publish', |
| 4063 | 'type' => 'simple', |
| 4064 | 'price' => '89', |
| 4065 | 'featured' => '0', |
| 4066 | 'sku' => 'hoodie-blue-sm', |
| 4067 | 'regular_price' => '90', |
| 4068 | 'sale_price' => '89', |
| 4069 | 'total_sales' => '21', |
| 4070 | 'category' => 'Uncategorized', |
| 4071 | 'tags' => 'sample, new, 2022', |
| 4072 | ]; |
| 4073 | |
| 4074 | $comment_data = [ |
| 4075 | 'comment_id' => '1', |
| 4076 | 'comment' => 'This is a sample comment..!', |
| 4077 | 'comment_author' => 'testsure', |
| 4078 | 'comment_date' => '2023-06-23 10:10:40', |
| 4079 | 'comment_author_email' => 'testsure@example.com', |
| 4080 | ]; |
| 4081 | |
| 4082 | $order_data = [ |
| 4083 | 'order_id' => '500', |
| 4084 | 'total_order_value' => '45', |
| 4085 | 'currency' => 'USD', |
| 4086 | 'shipping_total' => '5', |
| 4087 | 'order_payment_method' => 'cod', |
| 4088 | 'billing_firstname' => 'John', |
| 4089 | 'billing_lastname' => 'Doe', |
| 4090 | 'billing_company' => 'BSF', |
| 4091 | 'billing_address_1' => '1004 Beaumont', |
| 4092 | 'billing_address_2' => '', |
| 4093 | 'billing_city' => 'Casper', |
| 4094 | 'billing_state' => 'Wyoming', |
| 4095 | 'billing_postcode' => '82601', |
| 4096 | 'billing_country' => 'US', |
| 4097 | 'billing_email' => 'john_doe@bsf.io', |
| 4098 | 'billing_phone' => '(307) 7626541', |
| 4099 | 'shipping_firstname' => 'John', |
| 4100 | 'shipping_lastname' => 'Doe', |
| 4101 | 'shipping_company' => 'BSF', |
| 4102 | 'shipping_address_1' => '1004 Beaumont', |
| 4103 | 'shipping_address_2' => '', |
| 4104 | 'shipping_city' => 'Casper', |
| 4105 | 'shipping_state' => 'Wyoming', |
| 4106 | 'shipping_postcode' => '82601', |
| 4107 | 'shipping_country' => 'US', |
| 4108 | 'coupon_codes' => 'e3mstekq, f24sjakb', |
| 4109 | 'total_items_in_order' => '1', |
| 4110 | 'user_id' => '1', |
| 4111 | ]; |
| 4112 | |
| 4113 | $variation_data = [ |
| 4114 | 'product_variation_id' => '626', |
| 4115 | 'product_variation' => 'Color: Silver', |
| 4116 | ]; |
| 4117 | |
| 4118 | $order_sample_data = json_decode( '{"id":37,"parent_id":0,"status":"processing","currency":"USD","version":"7.3.0","prices_include_tax":false,"date_created":{"date":"2023-01-18 08:00:49.000000","timezone_type":1,"timezone":"+00:00"},"date_modified":{"date":"2023-01-18 08:00:50.000000","timezone_type":1,"timezone":"+00:00"},"discount_total":"0","discount_tax":"0","shipping_total":"0","shipping_tax":"0","cart_tax":"0","total":"22.00","total_tax":"0","customer_id":1,"order_key":"wc_order_VdLfjJ9vP7pDs","billing":{"first_name":"John","last_name":"Rana","company":"","address_1":"test","address_2":"","city":"Mohali","state":"AL","postcode":"12344","country":"US","email":"test@example.com","phone":"13232323"},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","phone":""},"payment_method":"cod","payment_method_title":"Cash on delivery","transaction_id":"","customer_ip_address":"::1","customer_user_agent":"Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/108.0.0.0 Safari\/537.36","created_via":"checkout","customer_note":"","date_completed":null,"date_paid":null,"cart_hash":"10b8e2799df0f88e1506edc0f3ed99c9","order_stock_reduced":true,"download_permissions_granted":true,"new_order_email_sent":true,"recorded_sales":true,"recorded_coupon_usage_counts":true,"number":"37","meta_data":[{"id":204,"key":"is_vat_exempt","value":"no"}],"line_items":{"id":"2, 3","order_id":"37, 37","name":"Variable product - Red, Test product","product_id":"34, 31","variation_id":"35, 0","quantity":"1, 1","tax_class":", ","subtotal":"12, 10","subtotal_tax":"0, 0","total":"12, 10","total_tax":"0, 0","taxes":", ","meta_data":", "},"tax_lines":[],"shipping_lines":[],"fee_lines":[],"coupon_lines":[],"products":[{"id":2,"order_id":37,"name":"Variable product - Red","product_id":34,"variation_id":35,"quantity":1,"tax_class":"","subtotal":"12","subtotal_tax":"0","total":"12","total_tax":"0","taxes":{"total":[],"subtotal":[]},"meta_data":{"19":{"key":"color","value":"Red","display_key":"Color","display_value":"<p>Red<\/p>\n"}}},{"id":3,"order_id":37,"name":"Test product","product_id":31,"variation_id":0,"quantity":1,"tax_class":"","subtotal":"10","subtotal_tax":"0","total":"10","total_tax":"0","taxes":{"total":[],"subtotal":[]},"meta_data":[]}],"quantity":"1, 1","wp_user_id":1,"user_login":"john","display_name":"john smith","user_firstname":"John","user_lastname":"Smith","user_email":"test@example.com","user_role":["subscriber"]}', true ); //phpcs:ignore |
| 4119 | |
| 4120 | $product_id = (int) ( isset( $data['filter']['product_id']['value'] ) ? $data['filter']['product_id']['value'] : -1 ); |
| 4121 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 4122 | |
| 4123 | $order_status = ( isset( $data['filter']['to_status']['value'] ) ? $data['filter']['to_status']['value'] : -1 ); |
| 4124 | $order_note_type = ( isset( $data['filter']['note_type']['value'] ) ? $data['filter']['note_type']['value'] : -1 ); |
| 4125 | |
| 4126 | if ( in_array( $term, [ 'product_added_to_cart', 'product_viewed' ], true ) ) { |
| 4127 | if ( -1 === $product_id ) { |
| 4128 | $args = [ |
| 4129 | 'post_type' => 'product', |
| 4130 | 'orderby' => 'ID', |
| 4131 | 'order' => 'DESC', |
| 4132 | 'post_status' => 'publish', |
| 4133 | 'numberposts' => 1, |
| 4134 | ]; |
| 4135 | $products = get_posts( $args ); |
| 4136 | |
| 4137 | if ( count( $products ) > 0 ) { |
| 4138 | $product_id = $products[0]->ID; |
| 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | if ( -1 !== $product_id ) { |
| 4143 | $post = get_post( $product_id ); |
| 4144 | $user_data = WordPress::get_user_context( $post->post_author ); |
| 4145 | $product_data['product_id'] = $product_id; |
| 4146 | $product_data['product'] = WooCommerce::get_product_context( $product_id ); |
| 4147 | $terms = get_the_terms( $product_id, 'product_cat' ); |
| 4148 | if ( ! empty( $terms ) && is_array( $terms ) && isset( $terms[0] ) ) { |
| 4149 | $cat_name = []; |
| 4150 | foreach ( $terms as $cat ) { |
| 4151 | $cat_name[] = $cat->name; |
| 4152 | } |
| 4153 | $product_data['product']['category'] = implode( ', ', $cat_name ); |
| 4154 | } |
| 4155 | $terms_tags = get_the_terms( $product_id, 'product_tag' ); |
| 4156 | if ( ! empty( $terms_tags ) && is_array( $terms_tags ) && isset( $terms_tags[0] ) ) { |
| 4157 | $tag_name = []; |
| 4158 | foreach ( $terms_tags as $tag ) { |
| 4159 | $tag_name[] = $tag->name; |
| 4160 | } |
| 4161 | $product_data['product']['tag'] = implode( ', ', $tag_name ); |
| 4162 | } |
| 4163 | unset( $product_data['product']['id'] ); //phpcs:ignore |
| 4164 | $context['response_type'] = 'live'; |
| 4165 | } |
| 4166 | |
| 4167 | if ( 'product_added_to_cart' === $term ) { |
| 4168 | $product_data['product_quantity'] = 1; |
| 4169 | } |
| 4170 | |
| 4171 | $context['pluggable_data'] = array_merge( $product_data, $user_data ); |
| 4172 | |
| 4173 | } elseif ( 'product_reviewed' === $term ) { |
| 4174 | $comment_args = [ |
| 4175 | 'number' => 1, |
| 4176 | 'type' => 'review', |
| 4177 | 'orderby' => 'comment_ID', |
| 4178 | 'post_id' => -1 !== $product_id ? $product_id : 0, |
| 4179 | ]; |
| 4180 | |
| 4181 | $comments = get_comments( $comment_args ); |
| 4182 | |
| 4183 | if ( count( $comments ) > 0 ) { |
| 4184 | $comment = $comments[0]; |
| 4185 | $comment_data = [ |
| 4186 | 'comment_id' => $comment->comment_ID, |
| 4187 | 'comment' => $comment->comment_content, |
| 4188 | 'comment_author' => $comment->comment_author, |
| 4189 | 'comment_date' => $comment->comment_date, |
| 4190 | 'comment_author_email' => $comment->comment_author_email, |
| 4191 | ]; |
| 4192 | $product_data = WooCommerce::get_product_context( $comment->comment_post_ID ); |
| 4193 | if ( is_object( $comment ) ) { |
| 4194 | $terms = get_the_terms( (int) $comment->comment_post_ID, 'product_cat' ); |
| 4195 | if ( ! empty( $terms ) && is_array( $terms ) && isset( $terms[0] ) ) { |
| 4196 | $cat_name = []; |
| 4197 | foreach ( $terms as $cat ) { |
| 4198 | $cat_name[] = $cat->name; |
| 4199 | } |
| 4200 | $product_data['product']['category'] = implode( ', ', $cat_name ); |
| 4201 | } |
| 4202 | $terms_tags = get_the_terms( (int) $comment->comment_post_ID, 'product_tag' ); |
| 4203 | if ( ! empty( $terms_tags ) && is_array( $terms_tags ) && isset( $terms_tags[0] ) ) { |
| 4204 | $tag_name = []; |
| 4205 | foreach ( $terms_tags as $tag ) { |
| 4206 | $tag_name[] = $tag->name; |
| 4207 | } |
| 4208 | $product_data['product']['tag'] = implode( ', ', $tag_name ); |
| 4209 | } |
| 4210 | } |
| 4211 | $user_data = WordPress::get_user_context( $comment->user_id ); |
| 4212 | $context['response_type'] = 'live'; |
| 4213 | } |
| 4214 | |
| 4215 | $context['pluggable_data'] = array_merge( $product_data, $user_data, $comment_data ); |
| 4216 | |
| 4217 | } elseif ( 'product_purchased' === $term ) { |
| 4218 | $order_id = 0; |
| 4219 | $product_data['quantity'] = '1'; |
| 4220 | if ( -1 !== $product_id ) { |
| 4221 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 4222 | if ( count( $order_ids ) > 0 ) { |
| 4223 | $order_id = $order_ids[0]; |
| 4224 | } |
| 4225 | } else { |
| 4226 | $orders = wc_get_orders( [ 'numberposts' => 1 ] ); |
| 4227 | if ( count( $orders ) > 0 ) { |
| 4228 | $order_id = $orders[0]->get_id(); |
| 4229 | } |
| 4230 | } |
| 4231 | |
| 4232 | if ( 0 !== $order_id ) { |
| 4233 | $order = wc_get_order( $order_id ); |
| 4234 | |
| 4235 | if ( $order ) { |
| 4236 | $user_id = $order->get_customer_id(); |
| 4237 | $items = $order->get_items(); |
| 4238 | |
| 4239 | $product_ids = []; |
| 4240 | |
| 4241 | $iteration = 0; |
| 4242 | foreach ( $items as $item ) { |
| 4243 | if ( method_exists( $item, 'get_product_id' ) ) { |
| 4244 | $item_id = $item->get_product_id(); |
| 4245 | if ( -1 === $product_id && 0 === $iteration ) { |
| 4246 | $product_ids[] = $item_id; |
| 4247 | break; |
| 4248 | } elseif ( $item_id === $product_id ) { |
| 4249 | $product_ids[] = $item_id; |
| 4250 | break; |
| 4251 | } |
| 4252 | } |
| 4253 | |
| 4254 | $iteration++; |
| 4255 | } |
| 4256 | $order_data = WooCommerce::get_order_context( $order_id ); |
| 4257 | $user_data = WordPress::get_user_context( $user_id ); |
| 4258 | $order_data['total_items_in_order'] = count( $product_ids ); |
| 4259 | $product_data = []; |
| 4260 | foreach ( $product_ids as $key => $product_id ) { |
| 4261 | $product_data[ 'product' . $key ] = WooCommerce::get_product_context( $product_id ); |
| 4262 | $terms = get_the_terms( $product_id, 'product_cat' ); |
| 4263 | if ( ! empty( $terms ) && is_array( $terms ) && isset( $terms[0] ) ) { |
| 4264 | $cat_name = []; |
| 4265 | foreach ( $terms as $cat ) { |
| 4266 | $cat_name[] = $cat->name; |
| 4267 | } |
| 4268 | $product_data[ 'product' . $key ]['category'] = implode( ', ', $cat_name ); |
| 4269 | } |
| 4270 | $terms_tags = get_the_terms( $product_id, 'product_tag' ); |
| 4271 | if ( ! empty( $terms_tags ) && is_array( $terms_tags ) && isset( $terms_tags[0] ) ) { |
| 4272 | $tag_name = []; |
| 4273 | foreach ( $terms_tags as $tag ) { |
| 4274 | $tag_name[] = $tag->name; |
| 4275 | } |
| 4276 | $product_data[ 'product' . $key ]['tag'] = implode( ', ', $tag_name ); |
| 4277 | } |
| 4278 | $product = wc_get_product( $product_id ); |
| 4279 | /** |
| 4280 | * |
| 4281 | * Ignore line |
| 4282 | * |
| 4283 | * @phpstan-ignore-next-line |
| 4284 | */ |
| 4285 | if ( $product->is_downloadable() ) { |
| 4286 | /** |
| 4287 | * |
| 4288 | * Ignore line |
| 4289 | * |
| 4290 | * @phpstan-ignore-next-line |
| 4291 | */ |
| 4292 | foreach ( $product->get_downloads() as $key_download_id => $download ) { |
| 4293 | $download_name = $download->get_name(); |
| 4294 | $download_link = $download->get_file(); |
| 4295 | $download_id = $download->get_id(); |
| 4296 | $download_type = $download->get_file_type(); |
| 4297 | $download_ext = $download->get_file_extension(); |
| 4298 | $product_data[ 'product' . $key ]['download'] = [ |
| 4299 | 'download_name' => $download_name, |
| 4300 | 'download_link' => $download_link, |
| 4301 | 'download_id' => $download_id, |
| 4302 | 'download_type' => $download_type, |
| 4303 | 'download_ext' => $download_ext, |
| 4304 | ]; |
| 4305 | } |
| 4306 | } |
| 4307 | } |
| 4308 | $context['response_type'] = 'live'; |
| 4309 | } |
| 4310 | } |
| 4311 | |
| 4312 | $context['pluggable_data'] = array_merge( $order_data, $product_data, $user_data ); |
| 4313 | |
| 4314 | } elseif ( 'variable_product_purchased' === $term ) { |
| 4315 | $product_variation_id = (int) ( isset( $data['filter']['product_variation_id']['value'] ) ? $data['filter']['product_variation_id']['value'] : -1 ); |
| 4316 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 4317 | |
| 4318 | foreach ( $order_ids as $order_id ) { |
| 4319 | $order = wc_get_order( $order_id ); |
| 4320 | |
| 4321 | if ( $order ) { |
| 4322 | $user_id = $order->get_customer_id(); |
| 4323 | $items = $order->get_items(); |
| 4324 | $product_variations = []; |
| 4325 | |
| 4326 | $iteration = 0; |
| 4327 | foreach ( $items as $item ) { |
| 4328 | if ( method_exists( $item, 'get_variation_id' ) ) { |
| 4329 | $variation_id = $item->get_variation_id(); |
| 4330 | if ( -1 === $product_variation_id && 0 === $iteration ) { |
| 4331 | $product_variations[] = $variation_id; |
| 4332 | break; |
| 4333 | } elseif ( $variation_id === $product_variation_id ) { |
| 4334 | $product_variations[] = $variation_id; |
| 4335 | break; |
| 4336 | } |
| 4337 | } |
| 4338 | |
| 4339 | $iteration++; |
| 4340 | } |
| 4341 | |
| 4342 | if ( count( $product_variations ) > 0 ) { |
| 4343 | $product_data = WooCommerce::get_product_context( $product_variation_id ); |
| 4344 | $order_data = WooCommerce::get_order_context( $order_id ); |
| 4345 | $user_data = WordPress::get_user_context( $user_id ); |
| 4346 | $variation_data = [ |
| 4347 | 'product_variation_id' => $product_variations[0], |
| 4348 | 'product_variation' => get_the_excerpt( $product_variations[0] ), |
| 4349 | ]; |
| 4350 | |
| 4351 | $context['response_type'] = 'live'; |
| 4352 | break; |
| 4353 | } |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | $context['pluggable_data'] = array_merge( $order_data, $user_data, $variation_data ); |
| 4358 | |
| 4359 | } elseif ( 'variable_subscription_purchased' === $term ) { |
| 4360 | $product_data['quantity'] = '1'; |
| 4361 | $product_data['product_name'] = 'Sample Product'; |
| 4362 | $product_data['billing_period'] = '2021-2022'; |
| 4363 | |
| 4364 | $context['pluggable_data'] = array_merge( $order_data, $product_data, $user_data ); |
| 4365 | |
| 4366 | $subscription_order_id = 0; |
| 4367 | $order_ids = []; |
| 4368 | |
| 4369 | if ( -1 !== $product_id ) { |
| 4370 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 4371 | |
| 4372 | } else { |
| 4373 | $orders = wc_get_orders( [] ); |
| 4374 | if ( count( $orders ) > 0 ) { |
| 4375 | $order_ids[] = $orders[0]->get_id(); |
| 4376 | } |
| 4377 | } |
| 4378 | |
| 4379 | foreach ( $order_ids as $order_id ) { |
| 4380 | $query_args = [ |
| 4381 | 'post_type' => 'shop_subscription', |
| 4382 | 'orderby' => 'ID', |
| 4383 | 'order' => 'DESC', |
| 4384 | 'post_status' => 'wc-active', |
| 4385 | 'posts_per_page' => 1, |
| 4386 | 'post_parent' => $order_id, |
| 4387 | ]; |
| 4388 | $query_result = new WP_Query( $query_args ); |
| 4389 | $subscription_orders = $query_result->get_posts(); |
| 4390 | |
| 4391 | if ( count( $subscription_orders ) > 0 ) { |
| 4392 | $subscription_order_id = $subscription_orders[0]->ID; |
| 4393 | break; |
| 4394 | } |
| 4395 | } |
| 4396 | |
| 4397 | if ( 0 !== $subscription_order_id ) { |
| 4398 | $subscription = wcs_get_subscription( $subscription_order_id ); |
| 4399 | if ( $subscription instanceof WC_Subscription ) { |
| 4400 | $last_order_id = $subscription->get_last_order(); |
| 4401 | if ( ! empty( $last_order_id ) && $last_order_id === $subscription->get_parent_id() ) { |
| 4402 | $user_id = wc_get_order( $last_order_id )->get_customer_id(); |
| 4403 | $items = $subscription->get_items(); |
| 4404 | |
| 4405 | foreach ( $items as $item ) { |
| 4406 | $product = $item->get_product(); |
| 4407 | if ( class_exists( '\WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) { |
| 4408 | if ( $product->is_type( [ 'subscription', 'subscription_variation', 'variable-subscription' ] ) ) { |
| 4409 | |
| 4410 | $product_data = WooCommerce::get_variable_subscription_product_context( $item, $last_order_id ); |
| 4411 | $user_data = WordPress::get_user_context( $user_id ); |
| 4412 | |
| 4413 | $context['response_type'] = 'live'; |
| 4414 | $context['pluggable_data'] = array_merge( $product_data, $user_data ); |
| 4415 | } |
| 4416 | } |
| 4417 | } |
| 4418 | } |
| 4419 | } |
| 4420 | } |
| 4421 | } elseif ( 'order_created' === $term ) { |
| 4422 | $orders = wc_get_orders( [ 'numberposts' => 1 ] ); |
| 4423 | $order_id = ''; |
| 4424 | if ( count( $orders ) > 0 ) { |
| 4425 | $order_id = $orders[0]->get_id(); |
| 4426 | $order = wc_get_order( $order_id ); |
| 4427 | $user_id = $order->get_customer_id(); |
| 4428 | $order_sample_data = array_merge( |
| 4429 | WooCommerce::get_order_context( $order_id ), |
| 4430 | WordPress::get_user_context( $user_id ) |
| 4431 | ); |
| 4432 | $context['response_type'] = 'live'; |
| 4433 | } |
| 4434 | |
| 4435 | $context['pluggable_data'] = $order_sample_data; |
| 4436 | |
| 4437 | } elseif ( 'order_status_changed' === $term ) { |
| 4438 | if ( -1 == $order_status ) { |
| 4439 | $args = [ |
| 4440 | 'numberposts' => 1, |
| 4441 | 'orderby' => 'date', |
| 4442 | 'order' => 'DESC', |
| 4443 | ]; |
| 4444 | } else { |
| 4445 | $args = [ |
| 4446 | 'status' => [ $order_status ], |
| 4447 | 'numberposts' => 1, |
| 4448 | 'orderby' => 'date', |
| 4449 | 'order' => 'DESC', |
| 4450 | ]; |
| 4451 | } |
| 4452 | $orders = wc_get_orders( $args ); |
| 4453 | $order_id = ''; |
| 4454 | if ( count( $orders ) > 0 ) { |
| 4455 | $order_id = $orders[0]->get_id(); |
| 4456 | $order = wc_get_order( $order_id ); |
| 4457 | $user_id = $order->get_customer_id(); |
| 4458 | $order_sample_data = array_merge( |
| 4459 | WooCommerce::get_order_context( $order_id ), |
| 4460 | WordPress::get_user_context( $user_id ) |
| 4461 | ); |
| 4462 | $context['response_type'] = 'live'; |
| 4463 | } |
| 4464 | $context['pluggable_data'] = $order_sample_data; |
| 4465 | } elseif ( 'order_note_added' === $term ) { |
| 4466 | global $wpdb; |
| 4467 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}comments WHERE comment_type ='order_note' ORDER BY comment_ID DESC LIMIT 1" ); |
| 4468 | $order_id = ''; |
| 4469 | if ( ! empty( $result ) ) { |
| 4470 | $order_id = $result[0]->comment_post_ID; |
| 4471 | $order = wc_get_order( $order_id ); |
| 4472 | if ( ! empty( $order ) ) { |
| 4473 | $user_id = $order->get_customer_id(); |
| 4474 | $order_sample_data = array_merge( |
| 4475 | WooCommerce::get_order_context( $order_id ), |
| 4476 | WordPress::get_user_context( $user_id ) |
| 4477 | ); |
| 4478 | if ( -1 == $order_note_type ) { |
| 4479 | $args = [ |
| 4480 | 'order_id' => $order_id, |
| 4481 | 'limit' => 1, |
| 4482 | ]; |
| 4483 | } else { |
| 4484 | $args = [ |
| 4485 | 'order_id' => $order_id, |
| 4486 | 'type' => $order_note_type, |
| 4487 | 'limit' => 1, |
| 4488 | ]; |
| 4489 | } |
| 4490 | |
| 4491 | $notes = wc_get_order_notes( $args ); |
| 4492 | if ( ! empty( $notes ) ) { |
| 4493 | $order_sample_data['note'] = [ |
| 4494 | 'id' => $notes[0]->id, |
| 4495 | 'date' => $notes[0]->date_created, |
| 4496 | 'author' => $notes[0]->added_by, |
| 4497 | 'content' => $notes[0]->content, |
| 4498 | ]; |
| 4499 | } else { |
| 4500 | $order_sample_data['note'] = [ |
| 4501 | 'id' => '1', |
| 4502 | 'date' => [ |
| 4503 | 'date' => '2023-06-23 10:10:40', |
| 4504 | 'timezone_type' => 1, |
| 4505 | 'timezone' => '+00:00', |
| 4506 | ], |
| 4507 | 'author' => 'admin', |
| 4508 | 'content' => 'new note', |
| 4509 | ]; |
| 4510 | } |
| 4511 | $order_sample_data['note_type'] = $order_note_type; |
| 4512 | $context['response_type'] = 'live'; |
| 4513 | } |
| 4514 | } else { |
| 4515 | $order_sample_data['note'] = [ |
| 4516 | 'id' => '1', |
| 4517 | 'date' => [ |
| 4518 | 'date' => '2023-06-23 10:10:40', |
| 4519 | 'timezone_type' => 1, |
| 4520 | 'timezone' => '+00:00', |
| 4521 | ], |
| 4522 | 'author' => 'admin', |
| 4523 | 'content' => 'new note', |
| 4524 | ]; |
| 4525 | $order_sample_data['note_type'] = 'customer'; |
| 4526 | } |
| 4527 | $context['pluggable_data'] = $order_sample_data; |
| 4528 | } elseif ( 'order_paid' === $term ) { |
| 4529 | $args = [ |
| 4530 | 'status' => [ 'completed' ], |
| 4531 | 'numberposts' => 1, |
| 4532 | ]; |
| 4533 | $orders = wc_get_orders( $args ); |
| 4534 | $order_id = ''; |
| 4535 | if ( count( $orders ) > 0 ) { |
| 4536 | $order_id = $orders[0]->get_id(); |
| 4537 | $order = wc_get_order( $order_id ); |
| 4538 | $user_id = $order->get_customer_id(); |
| 4539 | $order_sample_data = array_merge( |
| 4540 | WooCommerce::get_order_context( $order_id ), |
| 4541 | WordPress::get_user_context( $user_id ) |
| 4542 | ); |
| 4543 | $context['response_type'] = 'live'; |
| 4544 | } |
| 4545 | $context['pluggable_data'] = $order_sample_data; |
| 4546 | } |
| 4547 | |
| 4548 | return $context; |
| 4549 | } |
| 4550 | |
| 4551 | /** |
| 4552 | * Search LMS data. |
| 4553 | * |
| 4554 | * @param array $data data. |
| 4555 | * @return array |
| 4556 | */ |
| 4557 | public function search_lifter_lms_last_data( $data ) { |
| 4558 | global $wpdb; |
| 4559 | $post_type = $data['post_type']; |
| 4560 | $meta_key = '_is_complete'; |
| 4561 | $trigger = $data['search_term']; |
| 4562 | $context = []; |
| 4563 | if ( 'lifterlms_purchase_course' === $trigger ) { |
| 4564 | $product_type = 'course'; |
| 4565 | $post_id = $data['filter']['course_id']['value']; |
| 4566 | } elseif ( 'lifterlms_purchase_membership' === $trigger ) { |
| 4567 | $product_type = 'membership'; |
| 4568 | $post_id = $data['filter']['membership_id']['value']; |
| 4569 | } elseif ( 'lifterlms_lesson_completed' === $trigger ) { |
| 4570 | $post_id = $data['filter']['lesson']['value']; |
| 4571 | } elseif ( 'lifterlms_course_completed' === $trigger ) { |
| 4572 | $post_id = $data['filter']['course']['value']; |
| 4573 | } |
| 4574 | |
| 4575 | $where = 'postmeta.post_id = "' . $post_id . '" AND'; |
| 4576 | |
| 4577 | if ( 'llms_order' === $post_type ) { |
| 4578 | if ( -1 === $post_id ) { |
| 4579 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID=postmeta.post_id WHERE posts.post_type ='llms_order' AND posts.post_status= 'llms-completed' AND postmeta.meta_value=%s AND postmeta.meta_key= '_llms_product_type'", $product_type ) ); |
| 4580 | } else { |
| 4581 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID=postmeta.post_id WHERE posts.post_type ='llms_order' AND posts.post_status= 'llms-completed' AND postmeta.meta_value=%s AND postmeta.meta_key= '_llms_product_id'", $post_id ) ); |
| 4582 | } |
| 4583 | } else { |
| 4584 | if ( -1 === $post_id ) { |
| 4585 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}lifterlms_user_postmeta as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.post_id WHERE postmeta.meta_value='yes' AND postmeta.meta_key=%s AND posts.post_type=%s", $meta_key, $post_type ) ); |
| 4586 | } else { |
| 4587 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}lifterlms_user_postmeta as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.post_id WHERE postmeta.post_id = %s AND postmeta.meta_value='yes' AND postmeta.meta_key=%s AND posts.post_type=%s", $post_id, $meta_key, $post_type ) ); |
| 4588 | } |
| 4589 | } |
| 4590 | |
| 4591 | $response = []; |
| 4592 | if ( ! empty( $result ) ) { |
| 4593 | $result_post_id = $result[0]->post_id; |
| 4594 | $result_user_id = $result[0]->user_id; |
| 4595 | |
| 4596 | switch ( $trigger ) { |
| 4597 | case 'lifterlms_lesson_completed': |
| 4598 | $context = array_merge( |
| 4599 | WordPress::get_user_context( $result_user_id ), |
| 4600 | LifterLMS::get_lms_lesson_context( $result_post_id ) |
| 4601 | ); |
| 4602 | |
| 4603 | $context['course'] = get_the_title( get_post_meta( $result_post_id, '_llms_parent_course', true ) ); |
| 4604 | if ( '' !== ( get_post_meta( $result_post_id, '_llms_parent_section', true ) ) ) { |
| 4605 | $context['parent_section'] = get_the_title( get_post_meta( $result_post_id, '_llms_parent_section', true ) ); |
| 4606 | } |
| 4607 | break; |
| 4608 | case 'lifterlms_course_completed': |
| 4609 | $context = array_merge( |
| 4610 | WordPress::get_user_context( $result_user_id ), |
| 4611 | LifterLMS::get_lms_course_context( $result_post_id ) |
| 4612 | ); |
| 4613 | break; |
| 4614 | case 'lifterlms_purchase_course': |
| 4615 | $user_id = get_post_meta( $result_post_id, '_llms_user_id', true ); |
| 4616 | $context['course_id'] = get_post_meta( $result_post_id, '_llms_product_id', true ); |
| 4617 | $context['course_name'] = get_post_meta( $result_post_id, '_llms_product_title', true ); |
| 4618 | $context['course_amount'] = get_post_meta( $result_post_id, '_llms_original_total', true ); |
| 4619 | $context['currency'] = get_post_meta( $result_post_id, '_llms_currency', true ); |
| 4620 | $context ['order'] = WordPress::get_post_context( $result_post_id ); |
| 4621 | $context['order_type'] = get_post_meta( $result_post_id, '_llms_order_type', true ); |
| 4622 | $context['trial_offer'] = get_post_meta( $result_post_id, '_llms_trial_offer', true ); |
| 4623 | $context['billing_frequency'] = get_post_meta( $result_post_id, '_llms_billing_frequency', true ); |
| 4624 | $context = array_merge( $context, WordPress::get_user_context( $user_id ) ); |
| 4625 | break; |
| 4626 | case 'lifterlms_purchase_membership': |
| 4627 | $user_id = get_post_meta( $result_post_id, '_llms_user_id', true ); |
| 4628 | $context['membership_id'] = get_post_meta( $result_post_id, '_llms_product_id', true ); |
| 4629 | $context['membership_name'] = get_post_meta( $result_post_id, '_llms_product_title', true ); |
| 4630 | $context['membership_amount'] = get_post_meta( $result_post_id, '_llms_original_total', true ); |
| 4631 | $context['currency'] = get_post_meta( $result_post_id, '_llms_currency', true ); |
| 4632 | $context ['order'] = WordPress::get_post_context( $result_post_id ); |
| 4633 | $context['order_type'] = get_post_meta( $result_post_id, '_llms_order_type', true ); |
| 4634 | $context['trial_offer'] = get_post_meta( $result_post_id, '_llms_trial_offer', true ); |
| 4635 | $context['billing_frequency'] = get_post_meta( $result_post_id, '_llms_billing_frequency', true ); |
| 4636 | $context = array_merge( $context, WordPress::get_user_context( $user_id ) ); |
| 4637 | break; |
| 4638 | default: |
| 4639 | return; |
| 4640 | |
| 4641 | } |
| 4642 | $response['pluggable_data'] = $context; |
| 4643 | $response['response_type'] = 'live'; |
| 4644 | |
| 4645 | } |
| 4646 | |
| 4647 | return $response; |
| 4648 | |
| 4649 | } |
| 4650 | |
| 4651 | /** |
| 4652 | * Search SM data. |
| 4653 | * |
| 4654 | * @param array $data data. |
| 4655 | * @return array |
| 4656 | */ |
| 4657 | public function search_suremember_last_data( $data ) { |
| 4658 | global $wpdb; |
| 4659 | $post_type = $data['post_type']; |
| 4660 | $meta_key = '_is_complete'; |
| 4661 | $trigger = $data['search_term']; |
| 4662 | $post_id = $data['filter']['group_id']['value']; |
| 4663 | |
| 4664 | if ( 'suremember_updated_group' === $trigger ) { |
| 4665 | if ( -1 === $post_id ) { |
| 4666 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts WHERE posts.post_type=%s", $post_type ) ); |
| 4667 | } else { |
| 4668 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts WHERE posts.ID=%s AND posts.post_type=%s", $post_id, $post_type ) ); |
| 4669 | } |
| 4670 | } else { |
| 4671 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usermeta as usermeta WHERE usermeta.meta_key = %s", 'suremembers_user_access_group_' . $post_id ) ); |
| 4672 | } |
| 4673 | |
| 4674 | $response = []; |
| 4675 | |
| 4676 | if ( ! empty( $result ) ) { |
| 4677 | $context = []; |
| 4678 | switch ( $trigger ) { |
| 4679 | case 'suremember_updated_group': |
| 4680 | $group_id = $result[0]->ID; |
| 4681 | $suremembers_post['rules'] = get_post_meta( $group_id, 'suremembers_plan_include', true ); |
| 4682 | $suremembers_post['exclude'] = get_post_meta( $group_id, 'suremembers_plan_exclude', true ); //phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude |
| 4683 | $suremembers_post['suremembers_user_roles'] = get_post_meta( $group_id, 'suremembers_user_roles', true ); |
| 4684 | $suremembers_post['title'] = get_the_title( $group_id ); |
| 4685 | $suremembers_post['restrict'] = get_post_meta( $group_id, 'suremembers_plan_rules', true )['restrict']; |
| 4686 | $context['group'] = array_merge( WordPress::get_post_context( $group_id ), $suremembers_post ); |
| 4687 | $context['group_id'] = $group_id; |
| 4688 | unset( $context['group']['ID'] ); |
| 4689 | $response['pluggable_data'] = $context; |
| 4690 | $response['response_type'] = 'live'; |
| 4691 | break; |
| 4692 | case 'suremember_user_added_in_group': |
| 4693 | foreach ( $result as $res ) { |
| 4694 | $meta_value = unserialize( $res->meta_value ); |
| 4695 | if ( 'active' === $meta_value['status'] ) { |
| 4696 | $context = WordPress::get_user_context( $res->user_id ); |
| 4697 | $context['group'] = WordPress::get_post_context( $post_id ); |
| 4698 | $response['pluggable_data'] = $context; |
| 4699 | $response['response_type'] = 'live'; |
| 4700 | } |
| 4701 | } |
| 4702 | break; |
| 4703 | case 'suremember_user_removed_from_group': |
| 4704 | foreach ( $result as $res ) { |
| 4705 | $meta_value = unserialize( $res->meta_value ); |
| 4706 | if ( 'revoked' === $meta_value['status'] ) { |
| 4707 | $context = WordPress::get_user_context( $res->user_id ); |
| 4708 | $context['group'] = WordPress::get_post_context( $post_id ); |
| 4709 | $response['pluggable_data'] = $context; |
| 4710 | $response['response_type'] = 'live'; |
| 4711 | } |
| 4712 | } |
| 4713 | break; |
| 4714 | default: |
| 4715 | return; |
| 4716 | |
| 4717 | } |
| 4718 | } |
| 4719 | |
| 4720 | return $response; |
| 4721 | |
| 4722 | } |
| 4723 | |
| 4724 | /** |
| 4725 | * Search CartFlows data. |
| 4726 | * |
| 4727 | * @param array $data data. |
| 4728 | * @return array |
| 4729 | */ |
| 4730 | public function search_cartflows_last_data( $data ) { |
| 4731 | global $wpdb; |
| 4732 | $trigger = $data['search_term']; |
| 4733 | $context = []; |
| 4734 | if ( 'cartflows_offer_accepted' === $trigger ) { |
| 4735 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID=postmeta.post_id WHERE posts.post_type ='shop_order' AND postmeta.meta_value='upsell' AND postmeta.meta_key= '_cartflows_offer_type'" ); |
| 4736 | } |
| 4737 | $response = []; |
| 4738 | if ( ! empty( $result ) ) { |
| 4739 | $context = []; |
| 4740 | $order_upsell_id = $result[0]->post_id; |
| 4741 | $step_id = get_post_meta( $order_upsell_id, '_cartflows_offer_step_id', true ); |
| 4742 | $order_id = get_post_meta( $order_upsell_id, '_cartflows_offer_parent_id', true ); |
| 4743 | $order = wc_get_order( $order_id ); |
| 4744 | $upsell_order = wc_get_order( $order_upsell_id ); |
| 4745 | $variation_id = $upsell_order->get_items()[0]['product_id']; |
| 4746 | $input_qty = $upsell_order->get_items()[0]['quantity']; |
| 4747 | $offer_product = wcf_pro()->utils->get_offer_data( $step_id, $variation_id, $input_qty, $order_id ); |
| 4748 | $user_id = get_post_meta( $order_upsell_id, '_customer_user', true ); |
| 4749 | $context = WordPress::get_user_context( $user_id ); |
| 4750 | $context['order'] = $order->get_data(); |
| 4751 | $context['upsell'] = $offer_product; |
| 4752 | $response['pluggable_data'] = $context; |
| 4753 | $response['response_type'] = 'live'; |
| 4754 | } |
| 4755 | |
| 4756 | return $response; |
| 4757 | |
| 4758 | } |
| 4759 | |
| 4760 | |
| 4761 | /** |
| 4762 | * Fetch user context. |
| 4763 | * |
| 4764 | * @param int $initiator_id initiator id. |
| 4765 | * @param int $friend_id friend id. |
| 4766 | * @return array |
| 4767 | */ |
| 4768 | public function get_user_context( $initiator_id, $friend_id ) { |
| 4769 | $context = WordPress::get_user_context( $initiator_id ); |
| 4770 | |
| 4771 | $friend_context = WordPress::get_user_context( $friend_id ); |
| 4772 | |
| 4773 | $avatar = get_avatar_url( $initiator_id ); |
| 4774 | |
| 4775 | $context['avatar_url'] = ( $avatar ) ? $avatar : ''; |
| 4776 | |
| 4777 | $context['friend_id'] = $friend_id; |
| 4778 | $context['friend_first_name'] = $friend_context['user_firstname']; |
| 4779 | $context['friend_last_name'] = $friend_context['user_lastname']; |
| 4780 | $context['friend_email'] = $friend_context['user_email']; |
| 4781 | |
| 4782 | $friend_avatar = get_avatar_url( $friend_id ); |
| 4783 | $context['friend_avatar_url'] = $friend_avatar; |
| 4784 | return $context; |
| 4785 | } |
| 4786 | |
| 4787 | /** |
| 4788 | * Search BP data. |
| 4789 | * |
| 4790 | * @param array $data data. |
| 4791 | * @return array |
| 4792 | */ |
| 4793 | public function search_pluggables_bp_friendships( $data ) { |
| 4794 | global $wpdb, $bp; |
| 4795 | $context = []; |
| 4796 | $sample['pluggable_data'] = [ |
| 4797 | 'wp_user_id' => 4, |
| 4798 | 'user_login' => 'katy1ßßßß', |
| 4799 | 'display_name' => 'Katy Smith', |
| 4800 | 'user_firstname' => 'Katy', |
| 4801 | 'user_lastname' => 'Smith', |
| 4802 | 'user_email' => 'katy1@gmail.com', |
| 4803 | 'user_role' => [ 'subscriber' ], |
| 4804 | 'avatar_url' => 'http://pqr.com/avatar', |
| 4805 | 'friend_id' => 1, |
| 4806 | 'friend_first_name' => 'John', |
| 4807 | 'friend_last_name' => 'Wick', |
| 4808 | 'friend_email' => 'john@gmail.com', |
| 4809 | 'friend_avatar_url' => 'http://abc.com/avatar', |
| 4810 | ]; |
| 4811 | $sample['response_type'] = 'sample'; |
| 4812 | |
| 4813 | $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}bp_friends'" ); |
| 4814 | if ( $table_exists ) { |
| 4815 | $friendships = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_friends LIMIT 1" ); |
| 4816 | if ( ! empty( $friendships ) ) { |
| 4817 | $friendship = $friendships[0]; |
| 4818 | $initiator_id = $friendship->initiator_user_id; |
| 4819 | $friend_user_id = $friendship->friend_user_id; |
| 4820 | $context['pluggable_data'] = $this->get_user_context( $initiator_id, $friend_user_id ); |
| 4821 | $context['response_type'] = 'live'; |
| 4822 | } else { |
| 4823 | $context = $sample; |
| 4824 | } |
| 4825 | } else { |
| 4826 | $context = $sample; |
| 4827 | } |
| 4828 | |
| 4829 | |
| 4830 | return $context; |
| 4831 | } |
| 4832 | |
| 4833 | /** |
| 4834 | * Search Buddyboss profile types data. |
| 4835 | * |
| 4836 | * @param array $data data. |
| 4837 | * @return array |
| 4838 | */ |
| 4839 | public function search_pluggables_bp_profile_types( $data ) { |
| 4840 | global $wpdb, $bp; |
| 4841 | $context = []; |
| 4842 | $sample['pluggable_data'] = [ |
| 4843 | 'wp_user_id' => 4, |
| 4844 | 'user_login' => 'katy1ßßßß', |
| 4845 | 'display_name' => 'Katy Smith', |
| 4846 | 'user_firstname' => 'Katy', |
| 4847 | 'user_lastname' => 'Smith', |
| 4848 | 'user_email' => 'katy1@gmail.com', |
| 4849 | 'user_role' => [ 'subscriber' ], |
| 4850 | 'bb_profile_type' => '10', |
| 4851 | 'bb_profile_type_name' => 'student', |
| 4852 | ]; |
| 4853 | $sample['response_type'] = 'sample'; |
| 4854 | |
| 4855 | $post_id = $data['filter']['bb_profile_type']['value']; |
| 4856 | $get_existing = get_post_meta( $post_id, '_bp_member_type_key', true ); |
| 4857 | |
| 4858 | $type_term = get_term_by( |
| 4859 | 'name', |
| 4860 | /** |
| 4861 | * |
| 4862 | * Ignore line |
| 4863 | * |
| 4864 | * @phpstan-ignore-next-line |
| 4865 | */ |
| 4866 | $get_existing, |
| 4867 | 'bp_member_type' |
| 4868 | ); |
| 4869 | |
| 4870 | $results = $wpdb->get_results( |
| 4871 | $wpdb->prepare( |
| 4872 | "SELECT u.ID FROM {$wpdb->prefix}users u INNER JOIN {$wpdb->prefix}term_relationships r |
| 4873 | ON u.ID = r.object_id WHERE u.user_status = 0 AND |
| 4874 | r.term_taxonomy_id = %d ORDER BY RAND() LIMIT 1", |
| 4875 | /** |
| 4876 | * |
| 4877 | * Ignore line |
| 4878 | * |
| 4879 | * @phpstan-ignore-next-line |
| 4880 | */ |
| 4881 | $type_term->term_id |
| 4882 | ) |
| 4883 | ); |
| 4884 | |
| 4885 | if ( ! empty( $results ) ) { |
| 4886 | $user = $results[0]; |
| 4887 | $context['pluggable_data'] = WordPress::get_user_context( $user->ID ); |
| 4888 | $context['pluggable_data']['bb_profile_type'] = $post_id; |
| 4889 | $context['pluggable_data']['bb_profile_type_name'] = get_post_meta( $post_id, '_bp_member_type_label_singular_name', true ); |
| 4890 | $context['response_type'] = 'live'; |
| 4891 | } else { |
| 4892 | $context = $sample; |
| 4893 | } |
| 4894 | |
| 4895 | return $context; |
| 4896 | } |
| 4897 | /** |
| 4898 | * Search BP data. |
| 4899 | * |
| 4900 | * @param array $data data. |
| 4901 | * @return array |
| 4902 | */ |
| 4903 | public function search_pluggables_bp_groups( $data ) { |
| 4904 | global $wpdb, $bp; |
| 4905 | $context = []; |
| 4906 | $group_data = []; |
| 4907 | $args = [ |
| 4908 | 'orderby' => 'user_nicename', |
| 4909 | 'order' => 'ASC', |
| 4910 | 'number' => 1, |
| 4911 | ]; |
| 4912 | |
| 4913 | $users = get_users( $args ); |
| 4914 | |
| 4915 | if ( isset( $data['filter']['group_id']['value'] ) ) { |
| 4916 | $group_id = $data['filter']['group_id']['value']; |
| 4917 | $args['group_id'] = $group_id; |
| 4918 | if ( $group_id > 0 ) { |
| 4919 | $group = groups_get_group( $group_id ); |
| 4920 | $group_data['group_id'] = ( property_exists( $group, 'id' ) ) ? (int) $group->id : ''; |
| 4921 | $group_data['group_name'] = ( property_exists( $group, 'name' ) ) ? $group->name : ''; |
| 4922 | $group_data['group_description'] = ( property_exists( $group, 'description' ) ) ? $group->description : ''; |
| 4923 | } else { |
| 4924 | $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}bp_groups'" ); |
| 4925 | if ( $table_exists ) { |
| 4926 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups LIMIT 1" ); |
| 4927 | $context['groups'] = $groups; |
| 4928 | if ( ! empty( $groups ) ) { |
| 4929 | foreach ( $groups as $group ) { |
| 4930 | $group_data['group_id'] = $group->id; |
| 4931 | $group_data['group_name'] = $group->name; |
| 4932 | $group_data['group_description'] = $group->description; |
| 4933 | } |
| 4934 | } |
| 4935 | } |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | if ( ! empty( $users ) ) { |
| 4940 | $user = $users[0]; |
| 4941 | $pluggable_data = $group_data; |
| 4942 | |
| 4943 | $avatar = get_avatar_url( $user->ID ); |
| 4944 | $pluggable_data['wp_user_id'] = $user->ID; |
| 4945 | $pluggable_data['avatar_url'] = ( $avatar ) ? $avatar : ''; |
| 4946 | $pluggable_data['user_login'] = $user->user_login; |
| 4947 | $pluggable_data['display_name'] = $user->display_name; |
| 4948 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 4949 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 4950 | $pluggable_data['user_email'] = $user->user_email; |
| 4951 | $pluggable_data['user_role'] = $user->roles; |
| 4952 | $context['pluggable_data'] = $pluggable_data; |
| 4953 | $context['response_type'] = 'live'; |
| 4954 | } else { |
| 4955 | $context['pluggable_data'] = [ |
| 4956 | 'wp_user_id' => 1, |
| 4957 | 'user_login' => 'admin', |
| 4958 | 'display_name' => 'Test User', |
| 4959 | 'user_firstname' => 'Test', |
| 4960 | 'user_lastname' => 'User', |
| 4961 | 'user_email' => 'testuser@gmail.com', |
| 4962 | 'user_role' => [ 'subscriber' ], |
| 4963 | 'group_id' => 112, |
| 4964 | 'group_name' => 'Test Group', |
| 4965 | 'group_description' => 'Test Group Description', |
| 4966 | ]; |
| 4967 | $context['response_type'] = 'sample'; |
| 4968 | } |
| 4969 | |
| 4970 | return $context; |
| 4971 | } |
| 4972 | |
| 4973 | /** |
| 4974 | * Search complete courses. |
| 4975 | * |
| 4976 | * @param array $data data. |
| 4977 | * @return array |
| 4978 | */ |
| 4979 | public function search_pluggables_complete_course( $data ) { |
| 4980 | global $wpdb; |
| 4981 | $context = []; |
| 4982 | |
| 4983 | if ( isset( $data['filter']['sfwd_course_id']['value'] ) ) { |
| 4984 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 4985 | } |
| 4986 | if ( -1 === $course_id ) { |
| 4987 | $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='course' AND activity.activity_status= %d AND activity.course_id= %d", 1, $course_id ) ); |
| 4988 | } else { |
| 4989 | $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='course' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d", 1, $course_id, $course_id ) ); |
| 4990 | } |
| 4991 | |
| 4992 | if ( ! empty( $courses ) ) { |
| 4993 | $course = $courses[0]; |
| 4994 | $course_data['course_name'] = $course->post_title; |
| 4995 | $course_data['sfwd_course_id'] = $course->ID; |
| 4996 | $course_data['course_url'] = get_permalink( $course->ID ); |
| 4997 | $course_data['course_featured_image_id'] = get_post_meta( $course->ID, '_thumbnail_id', true ); |
| 4998 | $course_data['course_featured_image_url'] = get_the_post_thumbnail_url( $course->ID ); |
| 4999 | $context['response_type'] = 'live'; |
| 5000 | } else { |
| 5001 | $course_data['course_name'] = 'Test Course'; |
| 5002 | $course_data['sfwd_course_id'] = 112; |
| 5003 | $course_data['course_url'] = 'https://abc.com/test-course'; |
| 5004 | $course_data['course_featured_image_id'] = 113; |
| 5005 | $course_data['course_featured_image_url'] = 'https://pqr.com/test-course-img'; |
| 5006 | $context['response_type'] = 'sample'; |
| 5007 | } |
| 5008 | |
| 5009 | $users_data = $this->search_pluggables_add_user_role( [] ); |
| 5010 | $user_data = $users_data['pluggable_data']; |
| 5011 | |
| 5012 | $context['pluggable_data'] = array_merge( $course_data, $user_data ); |
| 5013 | return $context; |
| 5014 | } |
| 5015 | |
| 5016 | /** |
| 5017 | * Search lessons. |
| 5018 | * |
| 5019 | * @param array $data data. |
| 5020 | * @return array |
| 5021 | */ |
| 5022 | public function search_pluggables_complete_lesson( $data ) { |
| 5023 | global $wpdb; |
| 5024 | $context = []; |
| 5025 | |
| 5026 | if ( isset( $data['filter']['sfwd_lesson_id']['value'] ) ) { |
| 5027 | $lesson_id = $data['filter']['sfwd_lesson_id']['value']; |
| 5028 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 5029 | } |
| 5030 | $course = get_post( $course_id ); |
| 5031 | $pluggable_data = LearnDash::get_course_context( $course ); |
| 5032 | |
| 5033 | if ( -1 === $lesson_id ) { |
| 5034 | $lessons = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='lesson' AND activity.activity_status= %d AND activity.course_id= %d", 1, $course_id ) ); |
| 5035 | } else { |
| 5036 | $lessons = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='lesson' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d", 1, $lesson_id, $course_id ) ); |
| 5037 | } |
| 5038 | |
| 5039 | if ( ! empty( $lessons ) ) { |
| 5040 | $lesson = $lessons[0]; |
| 5041 | |
| 5042 | $pluggable_data = WordPress::get_user_context( $lesson->user_id ); |
| 5043 | $pluggable_data['lesson_name'] = $lesson->post_title; |
| 5044 | $pluggable_data['sfwd_lesson_id'] = $lesson->ID; |
| 5045 | $pluggable_data['lesson_url'] = get_permalink( $lesson->ID ); |
| 5046 | $pluggable_data['lesson_featured_image_id'] = get_post_meta( $lesson->ID, '_thumbnail_id', true ); |
| 5047 | $pluggable_data['lesson_featured_image_url'] = get_the_post_thumbnail_url( $lesson->ID ); |
| 5048 | $context['response_type'] = 'live'; |
| 5049 | } else { |
| 5050 | $pluggable_data = WordPress::get_sample_user_context(); |
| 5051 | $pluggable_data['lesson_name'] = 'Test Lesson'; |
| 5052 | $pluggable_data['sfwd_lesson_id'] = 114; |
| 5053 | $pluggable_data['lesson_url'] = 'https://abc.com/test-lesson'; |
| 5054 | $pluggable_data['lesson_featured_image_id'] = 116; |
| 5055 | $pluggable_data['lesson_featured_image_url'] = 'https://pqr.com/test-lesson-img'; |
| 5056 | $context['response_type'] = 'sample'; |
| 5057 | } |
| 5058 | |
| 5059 | $context['pluggable_data'] = $pluggable_data; |
| 5060 | return $context; |
| 5061 | } |
| 5062 | |
| 5063 | /** |
| 5064 | * Search topics. |
| 5065 | * |
| 5066 | * @param array $data data. |
| 5067 | * @return array |
| 5068 | */ |
| 5069 | public function search_pluggables_complete_topic( $data ) { |
| 5070 | global $wpdb; |
| 5071 | $context = []; |
| 5072 | |
| 5073 | if ( isset( $data['filter']['sfwd_topic_id']['value'] ) ) { |
| 5074 | $topic_id = $data['filter']['sfwd_topic_id']['value']; |
| 5075 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 5076 | } |
| 5077 | $course = get_post( $course_id ); |
| 5078 | $pluggable_data = LearnDash::get_course_context( $course ); |
| 5079 | |
| 5080 | if ( -1 === $topic_id ) { |
| 5081 | $topics = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='topic' AND activity.activity_status= %d AND activity.course_id= %d", 1, $course_id ) ); |
| 5082 | } else { |
| 5083 | $topics = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='topic' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d", 1, $topic_id, $course_id ) ); |
| 5084 | } |
| 5085 | |
| 5086 | if ( ! empty( $topics ) ) { |
| 5087 | $topic = $topics[0]; |
| 5088 | $pluggable_data = WordPress::get_user_context( $topics[0]->user_id ); |
| 5089 | $pluggable_data['topic_name'] = $topic->post_title; |
| 5090 | $pluggable_data['sfwd_topic_id'] = $topic->ID; |
| 5091 | $pluggable_data['topic_url'] = get_permalink( $topic->ID ); |
| 5092 | $pluggable_data['topic_featured_image_id'] = get_post_meta( $topic->ID, '_thumbnail_id', true ); |
| 5093 | $pluggable_data['topic_featured_image_url'] = get_the_post_thumbnail_url( $topic->ID ); |
| 5094 | $context['response_type'] = 'live'; |
| 5095 | } else { |
| 5096 | $pluggable_data = WordPress::get_sample_user_context(); |
| 5097 | $pluggable_data['topic_name'] = 'Test Topic'; |
| 5098 | $pluggable_data['sfwd_topic_id'] = 117; |
| 5099 | $pluggable_data['topic_url'] = 'https://abc.com/test-topic'; |
| 5100 | $pluggable_data['topic_featured_image_id'] = 118; |
| 5101 | $pluggable_data['topic_featured_image_url'] = 'https://pqr.com/test-topic-img'; |
| 5102 | $context['response_type'] = 'sample'; |
| 5103 | } |
| 5104 | |
| 5105 | $context['pluggable_data'] = $pluggable_data; |
| 5106 | return $context; |
| 5107 | } |
| 5108 | |
| 5109 | /** |
| 5110 | * Search purchase courses. |
| 5111 | * |
| 5112 | * @param array $data data. |
| 5113 | * @return array |
| 5114 | */ |
| 5115 | public function search_pluggables_purchase_course( $data ) { |
| 5116 | $context = []; |
| 5117 | $context['response_type'] = 'sample'; |
| 5118 | |
| 5119 | $purchase_data = [ |
| 5120 | 'course_product_id' => '1', |
| 5121 | 'course_product_name' => 'Sample Course', |
| 5122 | 'currency' => 'USD', |
| 5123 | 'total_amount' => '100', |
| 5124 | 'first_name' => 'John', |
| 5125 | 'last_name' => 'Doe', |
| 5126 | 'email' => 'john_doe@bsf.io', |
| 5127 | 'phone' => '+923007626541', |
| 5128 | ]; |
| 5129 | |
| 5130 | $product_id = (int) ( isset( $data['filter']['course_product_id']['value'] ) ? $data['filter']['course_product_id']['value'] : '-1' ); |
| 5131 | $order_id = 0; |
| 5132 | |
| 5133 | if ( -1 !== $product_id ) { |
| 5134 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 5135 | |
| 5136 | if ( count( $order_ids ) > 0 ) { |
| 5137 | $order_id = $order_ids[0]; |
| 5138 | } |
| 5139 | } else { |
| 5140 | $orders = wc_get_orders( [] ); |
| 5141 | if ( count( $orders ) > 0 ) { |
| 5142 | foreach ( $orders as $order ) { |
| 5143 | $items = $order->get_items(); |
| 5144 | |
| 5145 | if ( count( $items ) > 1 ) { |
| 5146 | continue; |
| 5147 | } |
| 5148 | |
| 5149 | foreach ( $items as $item ) { |
| 5150 | if ( method_exists( $item, 'get_product_id' ) ) { |
| 5151 | $product_id = $item->get_product_id(); |
| 5152 | if ( ! empty( get_post_meta( $item->get_product_id(), '_related_course', true ) ) ) { |
| 5153 | $order_id = $order->get_id(); |
| 5154 | break; |
| 5155 | } |
| 5156 | } |
| 5157 | } |
| 5158 | } |
| 5159 | } |
| 5160 | } |
| 5161 | |
| 5162 | if ( 0 !== $order_id ) { |
| 5163 | $order = wc_get_order( $order_id ); |
| 5164 | |
| 5165 | if ( $order ) { |
| 5166 | |
| 5167 | $purchase_data = LearnDash::get_purchase_course_context( $order ); |
| 5168 | |
| 5169 | $context['response_type'] = 'live'; |
| 5170 | } |
| 5171 | } |
| 5172 | |
| 5173 | $context['pluggable_data'] = $purchase_data; |
| 5174 | |
| 5175 | return $context; |
| 5176 | } |
| 5177 | |
| 5178 | /** |
| 5179 | * Fetch BB templates. |
| 5180 | * |
| 5181 | * @return array |
| 5182 | */ |
| 5183 | public function get_beaver_builder_templates() { |
| 5184 | $allowed_types = [ 'subscribe-form', 'contact-form' ]; |
| 5185 | $templates = []; |
| 5186 | $all_templates = get_posts( |
| 5187 | [ |
| 5188 | 'post_type' => 'fl-builder-template', |
| 5189 | 'meta_key' => '_fl_builder_data', |
| 5190 | 'posts_per_page' => -1, |
| 5191 | ] |
| 5192 | ); |
| 5193 | $posts = get_posts( |
| 5194 | [ |
| 5195 | 'post_type' => 'any', |
| 5196 | 'meta_key' => '_fl_builder_data', |
| 5197 | 'posts_per_page' => -1, |
| 5198 | ] |
| 5199 | ); |
| 5200 | $posts = array_merge( $all_templates, $posts ); |
| 5201 | |
| 5202 | if ( ! empty( $posts ) ) { |
| 5203 | foreach ( $posts as $post ) { |
| 5204 | $meta = get_post_meta( $post->ID, '_fl_builder_data', true ); |
| 5205 | foreach ( (array) $meta as $node_id => $node ) { |
| 5206 | if ( isset( $node->type ) && 'module' === $node->type ) { |
| 5207 | $settings = $node->settings; |
| 5208 | if ( in_array( $settings->type, $allowed_types, true ) ) { |
| 5209 | $label = $post->post_title; |
| 5210 | if ( '' !== $settings->node_label ) { |
| 5211 | $label .= ' - ' . $settings->node_label; |
| 5212 | } |
| 5213 | $templates[] = [ |
| 5214 | 'label' => $label, |
| 5215 | 'value' => $node_id, |
| 5216 | ]; |
| 5217 | } |
| 5218 | } |
| 5219 | } |
| 5220 | } |
| 5221 | } |
| 5222 | return $templates; |
| 5223 | } |
| 5224 | |
| 5225 | /** |
| 5226 | * Search beaver builder forms. |
| 5227 | * |
| 5228 | * @param array $data data. |
| 5229 | * @return array |
| 5230 | */ |
| 5231 | public function search_beaver_builder_forms( $data ) { |
| 5232 | $templates = $this->get_beaver_builder_templates(); |
| 5233 | return [ |
| 5234 | 'options' => $templates, |
| 5235 | 'hasMore' => false, |
| 5236 | ]; |
| 5237 | } |
| 5238 | |
| 5239 | /** |
| 5240 | * Search fluentcrm fields. |
| 5241 | * |
| 5242 | * @param array $data data. |
| 5243 | * @return array |
| 5244 | */ |
| 5245 | public function search_fluentcrm_custom_fields( $data ) { |
| 5246 | $context = []; |
| 5247 | $custom_fields = ( new CustomContactField() )->getGlobalFields()['fields']; |
| 5248 | $context['fields'] = $custom_fields; |
| 5249 | return $context; |
| 5250 | } |
| 5251 | |
| 5252 | /** |
| 5253 | * Fetch WP JOB Manager Last Data. |
| 5254 | * |
| 5255 | * @param array $data data. |
| 5256 | * @return array |
| 5257 | */ |
| 5258 | public function search_wp_job_manger_last_data( $data ) { |
| 5259 | global $wpdb; |
| 5260 | $job_type = $data['filter']['job_type']['value']; |
| 5261 | $args = [ |
| 5262 | 'posts_per_page' => 1, |
| 5263 | 'post_type' => 'job_listing', |
| 5264 | 'orderby' => 'id', |
| 5265 | 'order' => 'DESC', |
| 5266 | ]; |
| 5267 | |
| 5268 | if ( -1 !== $job_type ) { |
| 5269 | $args['tax_query'] = [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query |
| 5270 | [ |
| 5271 | 'taxonomy' => 'job_listing_type', |
| 5272 | 'field' => 'term_id', |
| 5273 | 'terms' => $job_type, |
| 5274 | ], |
| 5275 | ]; |
| 5276 | } |
| 5277 | $posts = get_posts( $args ); |
| 5278 | if ( empty( $posts ) ) { |
| 5279 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"ID":145,"wpjob_author":"1","wpjob_date":"2023-01-22 17:38:03","wpjob_date_gmt":"2023-01-22 17:38:03","wpjob_content":"","wpjob_title":"PHP Developer","wpjob_excerpt":"","wpjob_status":"publish","comment_status":"closed","ping_status":"closed","wpjob_password":"","wpjob_name":"project-manager","to_ping":"","pinged":"","wpjob_modified":"2023-01-23 03:23:35","wpjob_modified_gmt":"2023-01-23 03:23:35","wpjob_content_filtered":"","wpjob_parent":0,"guid":"http:\/\/connector.com\/?post_type=job_listing&p=145","menu_order":-1,"wpjob_type":"job_listing","wpjob_mime_type":"","comment_count":"0","filter":"raw","_filled":["0"],"_featured":["1"],"_tribe_ticket_capacity":["0"],"_tribe_ticket_version":["5.5.6"],"_edit_lock":["1674444219:1"],"_job_expires":["2023-02-21"],"_tracked_submitted":["1674409083"],"_edit_last":["1"],"_job_location":[""],"_application":["johnsmith@bexample.com"],"_company_name":["test"],"_company_website":[""],"_company_tagline":[""],"_company_twitter":[""],"_company_video":[""],"_remote_position":["1"],"_llms_reviews_enabled":[""],"_llms_display_reviews":[""],"_llms_num_reviews":["0"],"_llms_multiple_reviews_disabled":[""],"wp_user_id":1,"user_login":"john","display_name":"john","user_firstname":"john","user_lastname":"smith","user_email":"johnsmith@bexample.com","user_role":["administrator","subscriber","tutor_instructor"]}}', true ); |
| 5280 | return $context; |
| 5281 | } |
| 5282 | |
| 5283 | $post = $posts[0]; |
| 5284 | $post_content = WordPress::get_post_context( $post->ID ); |
| 5285 | $post_meta = WordPress::get_post_meta( $post->ID ); |
| 5286 | $job_data = array_merge( $post_content, $post_meta, WordPress::get_user_context( $post->post_author ) ); |
| 5287 | foreach ( $job_data as $key => $job ) { |
| 5288 | $newkey = str_replace( 'post', 'wpjob', $key ); |
| 5289 | unset( $job_data[ $key ] ); |
| 5290 | $job_data[ $newkey ] = $job; |
| 5291 | } |
| 5292 | $context['response_type'] = 'live'; |
| 5293 | $context['pluggable_data'] = $job_data; |
| 5294 | return $context; |
| 5295 | |
| 5296 | } |
| 5297 | |
| 5298 | /** |
| 5299 | * Get Amelia Appointment Category. |
| 5300 | * |
| 5301 | * @param array $data data. |
| 5302 | * |
| 5303 | * @return array |
| 5304 | */ |
| 5305 | public function search_amelia_category_list( $data ) { |
| 5306 | |
| 5307 | global $wpdb; |
| 5308 | |
| 5309 | $page = $data['page']; |
| 5310 | $limit = Utilities::get_search_page_limit(); |
| 5311 | $offset = $limit * ( $page - 1 ); |
| 5312 | |
| 5313 | $categories = $wpdb->get_results( |
| 5314 | $wpdb->prepare( |
| 5315 | "SELECT SQL_CALC_FOUND_ROWS id, name FROM {$wpdb->prefix}amelia_categories WHERE status = %s ORDER BY name ASC LIMIT %d OFFSET %d", |
| 5316 | [ 'visible', $limit, $offset ] |
| 5317 | ), |
| 5318 | OBJECT |
| 5319 | ); |
| 5320 | |
| 5321 | $categories_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 5322 | |
| 5323 | $options = []; |
| 5324 | if ( ! empty( $categories ) ) { |
| 5325 | foreach ( $categories as $category ) { |
| 5326 | $options[] = [ |
| 5327 | 'label' => $category->name, |
| 5328 | 'value' => $category->id, |
| 5329 | ]; |
| 5330 | } |
| 5331 | } |
| 5332 | |
| 5333 | return [ |
| 5334 | 'options' => $options, |
| 5335 | 'hasMore' => $categories_count > $limit && $categories_count > $offset, |
| 5336 | ]; |
| 5337 | |
| 5338 | } |
| 5339 | |
| 5340 | /** |
| 5341 | * Get Amelia Appointment Services. |
| 5342 | * |
| 5343 | * @param array $data data. |
| 5344 | * |
| 5345 | * @return array |
| 5346 | */ |
| 5347 | public function search_amelia_service_list( $data ) { |
| 5348 | |
| 5349 | global $wpdb; |
| 5350 | |
| 5351 | $page = $data['page']; |
| 5352 | $limit = Utilities::get_search_page_limit(); |
| 5353 | $offset = $limit * ( $page - 1 ); |
| 5354 | |
| 5355 | $services = $wpdb->get_results( |
| 5356 | $wpdb->prepare( |
| 5357 | "SELECT SQL_CALC_FOUND_ROWS id, name FROM {$wpdb->prefix}amelia_services |
| 5358 | WHERE categoryId = %d AND status = %s |
| 5359 | ORDER BY name ASC LIMIT %d OFFSET %d", |
| 5360 | [ $data['dynamic'], 'visible', $limit, $offset ] |
| 5361 | ), |
| 5362 | OBJECT |
| 5363 | ); |
| 5364 | |
| 5365 | $services_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 5366 | |
| 5367 | $options = []; |
| 5368 | if ( ! empty( $services ) ) { |
| 5369 | foreach ( $services as $category ) { |
| 5370 | $options[] = [ |
| 5371 | 'label' => $category->name, |
| 5372 | 'value' => $category->id, |
| 5373 | ]; |
| 5374 | } |
| 5375 | } |
| 5376 | |
| 5377 | return [ |
| 5378 | 'options' => $options, |
| 5379 | 'hasMore' => $services_count > $limit && $services_count > $offset, |
| 5380 | ]; |
| 5381 | |
| 5382 | } |
| 5383 | |
| 5384 | /** |
| 5385 | * Get Amelia Events. |
| 5386 | * |
| 5387 | * @param array $data data. |
| 5388 | * |
| 5389 | * @return array |
| 5390 | */ |
| 5391 | public function search_amelia_events_list( $data ) { |
| 5392 | |
| 5393 | global $wpdb; |
| 5394 | |
| 5395 | $page = $data['page']; |
| 5396 | $limit = Utilities::get_search_page_limit(); |
| 5397 | $offset = $limit * ( $page - 1 ); |
| 5398 | |
| 5399 | $events = $wpdb->get_results( |
| 5400 | $wpdb->prepare( |
| 5401 | "SELECT SQL_CALC_FOUND_ROWS id, name from {$wpdb->prefix}amelia_events WHERE status = %s ORDER BY name ASC LIMIT %d OFFSET %d", |
| 5402 | [ 'approved', $limit, $offset ] |
| 5403 | ), |
| 5404 | OBJECT |
| 5405 | ); |
| 5406 | |
| 5407 | $list_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 5408 | |
| 5409 | $options = []; |
| 5410 | if ( ! empty( $events ) ) { |
| 5411 | foreach ( $events as $event ) { |
| 5412 | $options[] = [ |
| 5413 | 'label' => $event->name, |
| 5414 | 'value' => $event->id, |
| 5415 | ]; |
| 5416 | } |
| 5417 | } |
| 5418 | |
| 5419 | return [ |
| 5420 | 'options' => $options, |
| 5421 | 'hasMore' => $list_count > $limit && $list_count > $offset, |
| 5422 | ]; |
| 5423 | |
| 5424 | } |
| 5425 | |
| 5426 | /** |
| 5427 | * Get last data for trigger. |
| 5428 | * |
| 5429 | * @param array $data data. |
| 5430 | * @return array |
| 5431 | */ |
| 5432 | public function search_amelia_appointment_booked_triggers_last_data( $data ) { |
| 5433 | global $wpdb; |
| 5434 | |
| 5435 | $context = []; |
| 5436 | |
| 5437 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 5438 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 5439 | |
| 5440 | if ( -1 === $appointment_service ) { |
| 5441 | // If service exists as per category selected. |
| 5442 | $service_exist = $wpdb->get_row( |
| 5443 | $wpdb->prepare( |
| 5444 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 5445 | [ $appointment_category ] |
| 5446 | ), |
| 5447 | ARRAY_A |
| 5448 | ); |
| 5449 | |
| 5450 | if ( empty( $service_exist ) ) { |
| 5451 | $result = []; |
| 5452 | } else { |
| 5453 | $result = $wpdb->get_row( |
| 5454 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments )', |
| 5455 | ARRAY_A |
| 5456 | ); |
| 5457 | } |
| 5458 | } else { |
| 5459 | $result = $wpdb->get_row( |
| 5460 | $wpdb->prepare( |
| 5461 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments ) AND appointments.serviceId = %d', |
| 5462 | [ $appointment_service ] |
| 5463 | ), |
| 5464 | ARRAY_A |
| 5465 | ); |
| 5466 | } |
| 5467 | |
| 5468 | if ( ! empty( $result ) ) { |
| 5469 | |
| 5470 | $payment_result = $wpdb->get_row( |
| 5471 | $wpdb->prepare( |
| 5472 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 5473 | [ $result['id'] ] |
| 5474 | ), |
| 5475 | ARRAY_A |
| 5476 | ); |
| 5477 | |
| 5478 | $customer_result = $wpdb->get_row( |
| 5479 | $wpdb->prepare( |
| 5480 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 5481 | [ $result['customerId'] ] |
| 5482 | ), |
| 5483 | ARRAY_A |
| 5484 | ); |
| 5485 | |
| 5486 | $service_result = $wpdb->get_row( |
| 5487 | $wpdb->prepare( |
| 5488 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 5489 | [ $result['serviceId'] ] |
| 5490 | ), |
| 5491 | ARRAY_A |
| 5492 | ); |
| 5493 | |
| 5494 | $category_result = $wpdb->get_row( |
| 5495 | $wpdb->prepare( |
| 5496 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 5497 | [ $service_result['categoryId'] ] |
| 5498 | ), |
| 5499 | ARRAY_A |
| 5500 | ); |
| 5501 | |
| 5502 | if ( $result['couponId'] ) { |
| 5503 | $coupon_result = $wpdb->get_row( |
| 5504 | $wpdb->prepare( |
| 5505 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 5506 | [ $result['couponId'] ] |
| 5507 | ), |
| 5508 | ARRAY_A |
| 5509 | ); |
| 5510 | } else { |
| 5511 | $coupon_result = []; |
| 5512 | } |
| 5513 | |
| 5514 | if ( ! empty( $result['customFields'] ) ) { |
| 5515 | $custom_fields = json_decode( $result['customFields'], true ); |
| 5516 | |
| 5517 | $fields_arr = []; |
| 5518 | foreach ( (array) $custom_fields as $fields ) { |
| 5519 | if ( is_array( $fields ) ) { |
| 5520 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 5521 | } |
| 5522 | } |
| 5523 | unset( $result['customFields'] ); |
| 5524 | } else { |
| 5525 | $fields_arr = []; |
| 5526 | } |
| 5527 | |
| 5528 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 5529 | $context['response_type'] = 'live'; |
| 5530 | } else { |
| 5531 | |
| 5532 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id":"1","status":"visible","bookingStart":"2023-02-28 13:00:00","bookingEnd":"2023-02-28 14:00:00","notifyParticipants":"1","serviceId":"4","packageId":null,"providerId":"2","locationId":null,"internalNotes":"","googleCalendarEventId":null,"googleMeetUrl":null,"outlookCalendarEventId":null,"zoomMeeting":null,"lessonSpace":null,"parentId":null,"appointmentId":"1","customerId":"1","price":"15","persons":"1","couponId":null,"token":"02cf0988c6","info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"1 (234) 789\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":"3600","created":"2023-02-08 11:16:03","actionsCompleted":"1","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","customerBookingId":"103","amount":"0","dateTime":"2023-02-28 13:00:00","gateway":"onSite","gatewayTitle":"","data":"","packageCustomerId":null,"entity":"appointment","wcOrderId":null,"type":"customer","externalId":"89","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"1 (234) 789","gender":null,"note":null,"description":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"zoomUserId":null,"countryPhoneIso":"us","translations":"{\"defaultLanguage\":\"en_US\"}","timeZone":null,"serviceName":"demo service","serviceDescription":"","categoryId":"2","categoryName":"New Category1"}}', true ); |
| 5533 | } |
| 5534 | |
| 5535 | return $context; |
| 5536 | } |
| 5537 | |
| 5538 | /** |
| 5539 | * Get last data for trigger. |
| 5540 | * |
| 5541 | * @param array $data data. |
| 5542 | * @return array |
| 5543 | */ |
| 5544 | public function search_amelia_new_event_attendee_triggers_last_data( $data ) { |
| 5545 | global $wpdb; |
| 5546 | |
| 5547 | $context = []; |
| 5548 | |
| 5549 | $event_selected = $data['filter']['amelia_events_list']['value']; |
| 5550 | |
| 5551 | if ( -1 === $event_selected ) { |
| 5552 | $result = $wpdb->get_row( |
| 5553 | 'SELECT * |
| 5554 | FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer |
| 5555 | INNER JOIN ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods as event_period |
| 5556 | ON customer.id = event_period.customerBookingId |
| 5557 | WHERE event_period.customerBookingId = ( Select max(customerBookingId) From ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods )', |
| 5558 | ARRAY_A |
| 5559 | ); |
| 5560 | } else { |
| 5561 | $result = $wpdb->get_row( |
| 5562 | $wpdb->prepare( |
| 5563 | 'SELECT * |
| 5564 | FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer |
| 5565 | INNER JOIN ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods as event_period |
| 5566 | ON customer.id = event_period.customerBookingId |
| 5567 | WHERE event_period.customerBookingId = ( Select max(customerBookingId) From ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods ) AND eventPeriodId = %d', |
| 5568 | [ $event_selected ] |
| 5569 | ), |
| 5570 | ARRAY_A |
| 5571 | ); |
| 5572 | } |
| 5573 | |
| 5574 | if ( ! empty( $result ) ) { |
| 5575 | |
| 5576 | $event = $wpdb->get_row( |
| 5577 | $wpdb->prepare( |
| 5578 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_events WHERE id = %d', |
| 5579 | [ $result['eventPeriodId'] ] |
| 5580 | ), |
| 5581 | ARRAY_A |
| 5582 | ); |
| 5583 | |
| 5584 | $customer_result = $wpdb->get_row( |
| 5585 | $wpdb->prepare( |
| 5586 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 5587 | [ $result['customerId'] ] |
| 5588 | ), |
| 5589 | ARRAY_A |
| 5590 | ); |
| 5591 | |
| 5592 | if ( $result['couponId'] ) { |
| 5593 | $coupon_result = $wpdb->get_row( |
| 5594 | $wpdb->prepare( |
| 5595 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 5596 | [ $result['couponId'] ] |
| 5597 | ), |
| 5598 | ARRAY_A |
| 5599 | ); |
| 5600 | } else { |
| 5601 | $coupon_result = []; |
| 5602 | } |
| 5603 | |
| 5604 | if ( ! empty( $result['customFields'] ) ) { |
| 5605 | $custom_fields = json_decode( $result['customFields'], true ); |
| 5606 | |
| 5607 | $fields_arr = []; |
| 5608 | foreach ( (array) $custom_fields as $fields ) { |
| 5609 | if ( is_array( $fields ) ) { |
| 5610 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 5611 | } |
| 5612 | } |
| 5613 | unset( $result['customFields'] ); |
| 5614 | } else { |
| 5615 | $fields_arr = []; |
| 5616 | } |
| 5617 | |
| 5618 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $event, $customer_result, $coupon_result ); |
| 5619 | $context['response_type'] = 'live'; |
| 5620 | } else { |
| 5621 | |
| 5622 | $context = json_decode( '{"response_type":"sample","pluggable_data":{""id":"1","appointmentId":null,"customerId":"1","status":"visible","price":"10","persons":"1","couponId":null,"token":"6485b07ce9","info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"+213551223123\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":null,"created":"2023-02-02 06:35:18","actionsCompleted":"1","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","customerBookingId":"105","eventPeriodId":"5","parentId":null,"name":"Testing Event 5","bookingOpens":null,"bookingCloses":"2023-02-09 08:00:00","bookingOpensRec":"same","bookingClosesRec":"same","ticketRangeRec":"calculate","recurringCycle":null,"recurringOrder":null,"recurringInterval":null,"recurringMonthly":null,"monthlyDate":null,"monthlyOnRepeat":null,"monthlyOnDay":null,"recurringUntil":null,"maxCapacity":"12","maxCustomCapacity":null,"maxExtraPeople":null,"locationId":null,"customLocation":"test","description":null,"color":"#1788FB","show":"1","notifyParticipants":"1","settings":"{\"payments\":{\"onSite\":true,\"payPal\":{\"enabled\":false},\"stripe\":{\"enabled\":false},\"mollie\":{\"enabled\":false},\"razorpay\":{\"enabled\":false}},\"general\":{\"minimumTimeRequirementPriorToCanceling\":null,\"redirectUrlAfterAppointment\":null},\"zoom\":{\"enabled\":false},\"lessonSpace\":{\"enabled\":false}}","zoomUserId":null,"bringingAnyone":"1","bookMultipleTimes":"1","translations":"{\"defaultLanguage\":\"en_US\"}","depositPayment":"disabled","depositPerPerson":"1","fullPayment":"0","deposit":"0","customPricing":"0","organizerId":"2","closeAfterMin":null,"closeAfterMinBookings":"0","type":"customer","externalId":"91","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"+213551223123","gender":null,"note":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"countryPhoneIso":"dz","timeZone":null}}', true ); |
| 5623 | } |
| 5624 | |
| 5625 | return $context; |
| 5626 | } |
| 5627 | |
| 5628 | /** |
| 5629 | * Get last data for trigger. |
| 5630 | * |
| 5631 | * @param array $data data. |
| 5632 | * @return array |
| 5633 | */ |
| 5634 | public function search_amelia_appointment_rescheduled_triggers_last_data( $data ) { |
| 5635 | global $wpdb; |
| 5636 | |
| 5637 | $context = []; |
| 5638 | |
| 5639 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 5640 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 5641 | |
| 5642 | if ( -1 === $appointment_service ) { |
| 5643 | // If service exists as per category selected. |
| 5644 | $service_exist = $wpdb->get_row( |
| 5645 | $wpdb->prepare( |
| 5646 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 5647 | [ $appointment_category ] |
| 5648 | ), |
| 5649 | ARRAY_A |
| 5650 | ); |
| 5651 | |
| 5652 | if ( empty( $service_exist ) ) { |
| 5653 | $result = []; |
| 5654 | } else { |
| 5655 | $result = $wpdb->get_row( |
| 5656 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments )', |
| 5657 | ARRAY_A |
| 5658 | ); |
| 5659 | } |
| 5660 | } else { |
| 5661 | $result = $wpdb->get_row( |
| 5662 | $wpdb->prepare( |
| 5663 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments ) AND appointments.serviceId = %d', |
| 5664 | [ $appointment_service ] |
| 5665 | ), |
| 5666 | ARRAY_A |
| 5667 | ); |
| 5668 | } |
| 5669 | |
| 5670 | if ( ! empty( $result ) ) { |
| 5671 | |
| 5672 | $payment_result = $wpdb->get_row( |
| 5673 | $wpdb->prepare( |
| 5674 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 5675 | [ $result['id'] ] |
| 5676 | ), |
| 5677 | ARRAY_A |
| 5678 | ); |
| 5679 | |
| 5680 | $customer_result = $wpdb->get_row( |
| 5681 | $wpdb->prepare( |
| 5682 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 5683 | [ $result['customerId'] ] |
| 5684 | ), |
| 5685 | ARRAY_A |
| 5686 | ); |
| 5687 | |
| 5688 | $service_result = $wpdb->get_row( |
| 5689 | $wpdb->prepare( |
| 5690 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 5691 | [ $result['serviceId'] ] |
| 5692 | ), |
| 5693 | ARRAY_A |
| 5694 | ); |
| 5695 | |
| 5696 | $category_result = $wpdb->get_row( |
| 5697 | $wpdb->prepare( |
| 5698 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 5699 | [ $service_result['categoryId'] ] |
| 5700 | ), |
| 5701 | ARRAY_A |
| 5702 | ); |
| 5703 | |
| 5704 | if ( $result['couponId'] ) { |
| 5705 | $coupon_result = $wpdb->get_row( |
| 5706 | $wpdb->prepare( |
| 5707 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 5708 | [ $result['couponId'] ] |
| 5709 | ), |
| 5710 | ARRAY_A |
| 5711 | ); |
| 5712 | } else { |
| 5713 | $coupon_result = []; |
| 5714 | } |
| 5715 | |
| 5716 | if ( ! empty( $result['customFields'] ) ) { |
| 5717 | $custom_fields = json_decode( $result['customFields'], true ); |
| 5718 | |
| 5719 | $fields_arr = []; |
| 5720 | foreach ( (array) $custom_fields as $fields ) { |
| 5721 | if ( is_array( $fields ) ) { |
| 5722 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 5723 | } |
| 5724 | } |
| 5725 | unset( $result['customFields'] ); |
| 5726 | } else { |
| 5727 | $fields_arr = []; |
| 5728 | } |
| 5729 | |
| 5730 | $appointment_data['isRescheduled'] = '1'; |
| 5731 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $appointment_data, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 5732 | $context['response_type'] = 'live'; |
| 5733 | } else { |
| 5734 | |
| 5735 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id":"1","status":"visible","bookingStart":"2023-02-28 15:30:00","bookingEnd":"2023-02-28 16:30:00","notifyParticipants":"1","serviceId":"4","packageId":null,"providerId":"2","locationId":null,"internalNotes":"","googleCalendarEventId":null,"googleMeetUrl":null,"outlookCalendarEventId":null,"zoomMeeting":null,"lessonSpace":null,"parentId":null,"appointmentId":"54","customerId":"1","price":"15","persons":"1","couponId":null,"token":"02cf0988c6","info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"1 (234) 789\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":"3600","created":"2023-02-08 11:16:03","actionsCompleted":"1","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","isRescheduled":"1","customerBookingId":"103","amount":"0","dateTime":"2023-02-28 15:30:00","gateway":"onSite","gatewayTitle":"","data":"","packageCustomerId":null,"entity":"appointment","wcOrderId":null,"type":"customer","externalId":"89","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"1 (234) 789","gender":null,"note":null,"description":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"zoomUserId":null,"countryPhoneIso":"us","translations":"{\"defaultLanguage\":\"en_US\"}","timeZone":null,"serviceName":"demo service","serviceDescription":"","categoryId":"2","categoryName":"New Category1"}}', true ); |
| 5736 | } |
| 5737 | |
| 5738 | return $context; |
| 5739 | } |
| 5740 | |
| 5741 | |
| 5742 | /** |
| 5743 | * Get last data for trigger. |
| 5744 | * |
| 5745 | * @param array $data data. |
| 5746 | * @return array |
| 5747 | */ |
| 5748 | public function search_amelia_appointment_cancelled_triggers_last_data( $data ) { |
| 5749 | global $wpdb; |
| 5750 | |
| 5751 | $context = []; |
| 5752 | |
| 5753 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 5754 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 5755 | |
| 5756 | if ( -1 === $appointment_service ) { |
| 5757 | // If service exists as per category selected. |
| 5758 | $service_exist = $wpdb->get_row( |
| 5759 | $wpdb->prepare( |
| 5760 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 5761 | [ $appointment_category ] |
| 5762 | ), |
| 5763 | ARRAY_A |
| 5764 | ); |
| 5765 | |
| 5766 | if ( empty( $service_exist ) ) { |
| 5767 | $result = []; |
| 5768 | } else { |
| 5769 | $result = $wpdb->get_row( |
| 5770 | $wpdb->prepare( |
| 5771 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE appointments.status = %s order by RAND() DESC LIMIT 1', |
| 5772 | [ 'canceled' ] |
| 5773 | ), |
| 5774 | ARRAY_A |
| 5775 | ); |
| 5776 | } |
| 5777 | } else { |
| 5778 | $result = $wpdb->get_row( |
| 5779 | $wpdb->prepare( |
| 5780 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE appointments.status = %s AND appointments.serviceId = %d order by RAND() DESC LIMIT 1', |
| 5781 | [ 'canceled', $appointment_service ] |
| 5782 | ), |
| 5783 | ARRAY_A |
| 5784 | ); |
| 5785 | } |
| 5786 | |
| 5787 | if ( ! empty( $result ) ) { |
| 5788 | |
| 5789 | $payment_result = $wpdb->get_row( |
| 5790 | $wpdb->prepare( |
| 5791 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 5792 | [ $result['id'] ] |
| 5793 | ), |
| 5794 | ARRAY_A |
| 5795 | ); |
| 5796 | |
| 5797 | $customer_result = $wpdb->get_row( |
| 5798 | $wpdb->prepare( |
| 5799 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 5800 | [ $result['customerId'] ] |
| 5801 | ), |
| 5802 | ARRAY_A |
| 5803 | ); |
| 5804 | |
| 5805 | $service_result = $wpdb->get_row( |
| 5806 | $wpdb->prepare( |
| 5807 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 5808 | [ $result['serviceId'] ] |
| 5809 | ), |
| 5810 | ARRAY_A |
| 5811 | ); |
| 5812 | |
| 5813 | $category_result = $wpdb->get_row( |
| 5814 | $wpdb->prepare( |
| 5815 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 5816 | [ $service_result['categoryId'] ] |
| 5817 | ), |
| 5818 | ARRAY_A |
| 5819 | ); |
| 5820 | |
| 5821 | if ( $result['couponId'] ) { |
| 5822 | $coupon_result = $wpdb->get_row( |
| 5823 | $wpdb->prepare( |
| 5824 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 5825 | [ $result['couponId'] ] |
| 5826 | ), |
| 5827 | ARRAY_A |
| 5828 | ); |
| 5829 | } else { |
| 5830 | $coupon_result = []; |
| 5831 | } |
| 5832 | |
| 5833 | if ( ! empty( $result['customFields'] ) ) { |
| 5834 | $custom_fields = json_decode( $result['customFields'], true ); |
| 5835 | |
| 5836 | $fields_arr = []; |
| 5837 | foreach ( (array) $custom_fields as $fields ) { |
| 5838 | if ( is_array( $fields ) ) { |
| 5839 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 5840 | } |
| 5841 | } |
| 5842 | unset( $result['customFields'] ); |
| 5843 | } else { |
| 5844 | $fields_arr = []; |
| 5845 | } |
| 5846 | |
| 5847 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 5848 | $context['response_type'] = 'live'; |
| 5849 | } else { |
| 5850 | |
| 5851 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id":"1","status":"visible","bookingStart":"2023-02-28 15:30:00","bookingEnd":"2023-02-28 16:30:00","notifyParticipants":"1","serviceId":"4","packageId":null,"providerId":"2","locationId":null,"internalNotes":"","googleCalendarEventId":null,"googleMeetUrl":null,"outlookCalendarEventId":null,"zoomMeeting":null,"lessonSpace":null,"parentId":null,"appointmentId":"54","customerId":"1","price":"15","persons":"1","couponId":null,"token":"02cf0988c6","info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"1 (234) 789\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":"3600","created":"2023-02-08 11:16:03","actionsCompleted":"1","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","customerBookingId":"103","amount":"0","dateTime":"2023-02-28 15:30:00","gateway":"onSite","gatewayTitle":"","data":"","packageCustomerId":null,"entity":"appointment","wcOrderId":null,"type":"customer","externalId":"89","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"1 (234) 789","gender":null,"note":null,"description":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"zoomUserId":null,"countryPhoneIso":"us","translations":"{\"defaultLanguage\":\"en_US\"}","timeZone":null,"serviceName":"demo service","serviceDescription":"","categoryId":"2","categoryName":"New Category1"}}', true ); |
| 5852 | } |
| 5853 | |
| 5854 | return $context; |
| 5855 | } |
| 5856 | |
| 5857 | /** |
| 5858 | * Get MailPoet Forms. |
| 5859 | * |
| 5860 | * @param array $data data. |
| 5861 | * |
| 5862 | * @return array |
| 5863 | */ |
| 5864 | public function search_mailpoet_forms( $data ) { |
| 5865 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5866 | return; |
| 5867 | } |
| 5868 | |
| 5869 | global $wpdb; |
| 5870 | |
| 5871 | $page = $data['page']; |
| 5872 | $limit = Utilities::get_search_page_limit(); |
| 5873 | $offset = $limit * ( $page - 1 ); |
| 5874 | |
| 5875 | $forms = $wpdb->get_results( |
| 5876 | $wpdb->prepare( |
| 5877 | 'SELECT SQL_CALC_FOUND_ROWS * FROM ' . $wpdb->prefix . 'mailpoet_forms WHERE `deleted_at` IS NULL AND `status` = %s ORDER BY id LIMIT %d OFFSET %d', |
| 5878 | [ 'enabled', $limit, $offset ] |
| 5879 | ) |
| 5880 | ); |
| 5881 | |
| 5882 | $form_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 5883 | |
| 5884 | $options = []; |
| 5885 | |
| 5886 | if ( ! empty( $forms ) ) { |
| 5887 | if ( is_array( $forms ) ) { |
| 5888 | foreach ( $forms as $form ) { |
| 5889 | $options[] = [ |
| 5890 | 'label' => $form->name, |
| 5891 | 'value' => $form->id, |
| 5892 | ]; |
| 5893 | } |
| 5894 | } |
| 5895 | } |
| 5896 | |
| 5897 | return [ |
| 5898 | 'options' => $options, |
| 5899 | 'hasMore' => $form_count > $limit && $form_count > $offset, |
| 5900 | ]; |
| 5901 | |
| 5902 | } |
| 5903 | |
| 5904 | /** |
| 5905 | * Get MailPoet List. |
| 5906 | * |
| 5907 | * @param array $data data. |
| 5908 | * |
| 5909 | * @return array |
| 5910 | */ |
| 5911 | public function search_mailpoet_list( $data ) { |
| 5912 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5913 | return; |
| 5914 | } |
| 5915 | |
| 5916 | $mailpoet = \MailPoet\API\API::MP( 'v1' ); |
| 5917 | $lists = $mailpoet->getLists(); |
| 5918 | |
| 5919 | $options = []; |
| 5920 | |
| 5921 | if ( ! empty( $lists ) ) { |
| 5922 | if ( is_array( $lists ) ) { |
| 5923 | foreach ( $lists as $list ) { |
| 5924 | $options[] = [ |
| 5925 | 'label' => $list['name'], |
| 5926 | 'value' => $list['id'], |
| 5927 | ]; |
| 5928 | } |
| 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | return [ |
| 5933 | 'options' => $options, |
| 5934 | 'hasMore' => false, |
| 5935 | ]; |
| 5936 | } |
| 5937 | |
| 5938 | /** |
| 5939 | * Get MailPoet Subscriber Status. |
| 5940 | * |
| 5941 | * @param array $data data. |
| 5942 | * |
| 5943 | * @return array |
| 5944 | */ |
| 5945 | public function search_mailpoet_subscriber_status( $data ) { |
| 5946 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5947 | return; |
| 5948 | } |
| 5949 | |
| 5950 | $subscriber_status = [ |
| 5951 | 'subscribed' => 'Subscribed', |
| 5952 | 'unconfirmed' => 'Unconfirmed', |
| 5953 | 'unsubscribed' => 'Unsubscribed', |
| 5954 | 'inactive' => 'Inactive', |
| 5955 | 'bounced' => 'Bounced', |
| 5956 | ]; |
| 5957 | |
| 5958 | $options = []; |
| 5959 | foreach ( $subscriber_status as $key => $status ) { |
| 5960 | $options[] = [ |
| 5961 | 'label' => $status, |
| 5962 | 'value' => $key, |
| 5963 | ]; |
| 5964 | } |
| 5965 | |
| 5966 | return [ |
| 5967 | 'options' => $options, |
| 5968 | 'hasMore' => false, |
| 5969 | ]; |
| 5970 | } |
| 5971 | |
| 5972 | /** |
| 5973 | * Get MailPoet Subscribers. |
| 5974 | * |
| 5975 | * @param array $data data. |
| 5976 | * |
| 5977 | * @return array |
| 5978 | */ |
| 5979 | public function search_mailpoet_subscribers( $data ) { |
| 5980 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5981 | return; |
| 5982 | } |
| 5983 | |
| 5984 | global $wpdb; |
| 5985 | |
| 5986 | $page = $data['page']; |
| 5987 | $limit = Utilities::get_search_page_limit(); |
| 5988 | $offset = $limit * ( $page - 1 ); |
| 5989 | |
| 5990 | $subscribers = $wpdb->get_results( |
| 5991 | $wpdb->prepare( |
| 5992 | 'SELECT SQL_CALC_FOUND_ROWS id,email FROM ' . $wpdb->prefix . 'mailpoet_subscribers ORDER BY id DESC LIMIT %d OFFSET %d', |
| 5993 | [ $limit, $offset ] |
| 5994 | ) |
| 5995 | ); |
| 5996 | |
| 5997 | $subscribers_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 5998 | |
| 5999 | $options = []; |
| 6000 | |
| 6001 | if ( ! empty( $subscribers ) ) { |
| 6002 | if ( is_array( $subscribers ) ) { |
| 6003 | foreach ( $subscribers as $subscriber ) { |
| 6004 | $options[] = [ |
| 6005 | 'label' => $subscriber->email, |
| 6006 | 'value' => $subscriber->id, |
| 6007 | ]; |
| 6008 | } |
| 6009 | } |
| 6010 | } |
| 6011 | |
| 6012 | return [ |
| 6013 | 'options' => $options, |
| 6014 | 'hasMore' => $subscribers_count > $limit && $subscribers_count > $offset, |
| 6015 | ]; |
| 6016 | } |
| 6017 | |
| 6018 | /** |
| 6019 | * Get ConvertPro Forms. |
| 6020 | * |
| 6021 | * @param array $data data. |
| 6022 | * |
| 6023 | * @return array |
| 6024 | */ |
| 6025 | public function search_convertpro_form_list( $data ) { |
| 6026 | if ( ! class_exists( '\Cp_V2_Loader' ) ) { |
| 6027 | return; |
| 6028 | } |
| 6029 | |
| 6030 | $cp_popups_inst = CP_V2_Popups::get_instance(); |
| 6031 | $popups = $cp_popups_inst->get_all(); |
| 6032 | |
| 6033 | $form_count = count( $popups ); |
| 6034 | |
| 6035 | $page = $data['page']; |
| 6036 | $limit = Utilities::get_search_page_limit(); |
| 6037 | $offset = $limit * ( $page - 1 ); |
| 6038 | |
| 6039 | $options = []; |
| 6040 | |
| 6041 | if ( ! empty( $popups ) ) { |
| 6042 | if ( is_array( $popups ) ) { |
| 6043 | foreach ( $popups as $form ) { |
| 6044 | $options[] = [ |
| 6045 | 'label' => $form->post_title, |
| 6046 | 'value' => $form->ID, |
| 6047 | ]; |
| 6048 | } |
| 6049 | } |
| 6050 | } |
| 6051 | |
| 6052 | return [ |
| 6053 | 'options' => $options, |
| 6054 | 'hasMore' => $form_count > $limit && $form_count > $offset, |
| 6055 | ]; |
| 6056 | |
| 6057 | } |
| 6058 | |
| 6059 | /** |
| 6060 | * Get ProjectHuddle Websites. |
| 6061 | * |
| 6062 | * @param array $data data. |
| 6063 | * |
| 6064 | * @return array |
| 6065 | */ |
| 6066 | public function search_project_huddle_websites( $data ) { |
| 6067 | |
| 6068 | $sites = new WP_Query( |
| 6069 | [ |
| 6070 | 'post_type' => 'ph-website', |
| 6071 | 'posts_per_page' => - 1, |
| 6072 | 'fields' => 'ids', |
| 6073 | ] |
| 6074 | ); |
| 6075 | |
| 6076 | $site_ids = (array) $sites->posts; |
| 6077 | |
| 6078 | $options = []; |
| 6079 | if ( ! empty( $site_ids ) ) { |
| 6080 | if ( is_array( $site_ids ) ) { |
| 6081 | foreach ( $site_ids as $site_id ) { |
| 6082 | $options[] = [ |
| 6083 | 'label' => get_the_title( $site_id ), |
| 6084 | 'value' => $site_id, |
| 6085 | ]; |
| 6086 | } |
| 6087 | } |
| 6088 | } |
| 6089 | return [ |
| 6090 | 'options' => $options, |
| 6091 | 'hasMore' => false, |
| 6092 | ]; |
| 6093 | |
| 6094 | } |
| 6095 | |
| 6096 | /** |
| 6097 | * Get last data for trigger. |
| 6098 | * |
| 6099 | * @param array $data data. |
| 6100 | * @return mixed |
| 6101 | */ |
| 6102 | public function search_project_huddle_comment_triggers_last_data( $data ) { |
| 6103 | global $wpdb; |
| 6104 | |
| 6105 | $context = []; |
| 6106 | |
| 6107 | if ( -1 !== $data['dynamic'] ) { |
| 6108 | $threads = get_posts( |
| 6109 | [ |
| 6110 | 'post_type' => 'phw_comment_loc', |
| 6111 | 'posts_per_page' => 1, |
| 6112 | 'meta_value' => $data['dynamic'], |
| 6113 | 'meta_key' => 'project_id', |
| 6114 | 'orderby' => 'asc', |
| 6115 | ] |
| 6116 | ); |
| 6117 | } else { |
| 6118 | $threads = []; |
| 6119 | } |
| 6120 | |
| 6121 | if ( ! empty( $threads ) ) { |
| 6122 | $comment_result = $wpdb->get_row( |
| 6123 | $wpdb->prepare( |
| 6124 | 'SELECT ' . $wpdb->prefix . 'comments.comment_ID |
| 6125 | FROM ' . $wpdb->prefix . 'comments |
| 6126 | WHERE ( ( comment_approved = "0" OR comment_approved = "1" ) ) AND comment_type IN ("ph_comment") AND comment_post_ID = %d |
| 6127 | ORDER BY ' . $wpdb->prefix . 'comments.comment_date_gmt DESC |
| 6128 | LIMIT 0,1', |
| 6129 | $threads[0]->ID |
| 6130 | ), |
| 6131 | ARRAY_A |
| 6132 | ); |
| 6133 | |
| 6134 | if ( ! empty( $comment_result ) ) { |
| 6135 | $comment_id = get_comment( $comment_result['comment_ID'], ARRAY_A ); |
| 6136 | $comments['comment_ID'] = isset( $comment_id['comment_ID'] ) ? $comment_id['comment_ID'] : ''; |
| 6137 | $comments['comment_post_ID'] = isset( $comment_id['comment_post_ID'] ) ? $comment_id['comment_post_ID'] : ''; |
| 6138 | |
| 6139 | $comments['comment_author'] = isset( $comment_id['comment_author'] ) ? $comment_id['comment_author'] : ''; |
| 6140 | |
| 6141 | $comments['comment_author_email'] = isset( $comment_id['comment_author_email'] ) ? $comment_id['comment_author_email'] : ''; |
| 6142 | |
| 6143 | $comments['comment_date'] = isset( $comment_id['comment_date'] ) ? $comment_id['comment_date'] : ''; |
| 6144 | |
| 6145 | $comments['comment_content'] = isset( $comment_id['comment_content'] ) ? $comment_id['comment_content'] : ''; |
| 6146 | |
| 6147 | $comments['comment_type'] = isset( $comment_id['comment_type'] ) ? $comment_id['comment_type'] : ''; |
| 6148 | |
| 6149 | $context['pluggable_data'] = $comments; |
| 6150 | $context['response_type'] = 'live'; |
| 6151 | } else { |
| 6152 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"comment_ID":"1","comment_post_ID":"1","comment_author":"test","comment_author_email":"test@test.com","comment_date":"2023-03-27 13:44:26","comment_content":"<p>Leave comment<\/p>","comment_type":"ph_comment"}}', true ); |
| 6153 | } |
| 6154 | } else { |
| 6155 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"comment_ID":"1","comment_post_ID":"1","comment_author":"test","comment_author_email":"test@test.com","comment_date":"2023-03-27 13:44:26","comment_content":"<p>Leave comment<\/p>","comment_type":"ph_comment"}}', true ); |
| 6156 | } |
| 6157 | |
| 6158 | return $context; |
| 6159 | } |
| 6160 | |
| 6161 | /** |
| 6162 | * Get last data for trigger. |
| 6163 | * |
| 6164 | * @param array $data data. |
| 6165 | * @return mixed |
| 6166 | */ |
| 6167 | public function search_project_huddle_resolved_comment_triggers_last_data( $data ) { |
| 6168 | global $wpdb; |
| 6169 | |
| 6170 | $context = []; |
| 6171 | |
| 6172 | $get_comments = $wpdb->get_row( |
| 6173 | 'SELECT ' . $wpdb->prefix . 'comments.comment_ID, ' . $wpdb->prefix . 'comments.comment_content |
| 6174 | FROM ' . $wpdb->prefix . 'comments |
| 6175 | WHERE ( ( comment_approved = "0" OR comment_approved = "1" ) ) AND comment_type IN ("ph_status") AND comment_content = "Resolved" |
| 6176 | ORDER BY ' . $wpdb->prefix . 'comments.comment_date_gmt DESC |
| 6177 | LIMIT 0,1' |
| 6178 | ); |
| 6179 | |
| 6180 | if ( ! empty( $get_comments ) ) { |
| 6181 | $comment_id = get_comment( $get_comments->comment_ID, ARRAY_A ); |
| 6182 | $comment_result = $wpdb->get_row( |
| 6183 | $wpdb->prepare( |
| 6184 | 'SELECT ' . $wpdb->prefix . 'comments.comment_ID |
| 6185 | FROM ' . $wpdb->prefix . 'comments |
| 6186 | WHERE ( ( comment_approved = "0" OR comment_approved = "1" ) ) AND comment_type IN ("ph_comment") AND comment_post_ID = %d |
| 6187 | ORDER BY ' . $wpdb->prefix . 'comments.comment_date_gmt DESC |
| 6188 | LIMIT 0,1', |
| 6189 | isset( $comment_id['comment_post_ID'] ) ? $comment_id['comment_post_ID'] : '' |
| 6190 | ), |
| 6191 | ARRAY_A |
| 6192 | ); |
| 6193 | |
| 6194 | $actual_comment = get_comment( $comment_result['comment_ID'], ARRAY_A ); |
| 6195 | $comments['comment_ID'] = isset( $actual_comment['comment_ID'] ) ? $actual_comment['comment_ID'] : ''; |
| 6196 | $comments['comment_post_ID'] = isset( $actual_comment['comment_post_ID'] ) ? $actual_comment['comment_post_ID'] : ''; |
| 6197 | $comments['comment_author'] = isset( $actual_comment['comment_author'] ) ? $actual_comment['comment_author'] : ''; |
| 6198 | $comments['comment_author_email'] = isset( $actual_comment['comment_author_email'] ) ? $actual_comment['comment_author_email'] : ''; |
| 6199 | $comments['comment_date'] = isset( $actual_comment['comment_date'] ) ? $actual_comment['comment_date'] : ''; |
| 6200 | $comments['comment_content'] = isset( $actual_comment['comment_content'] ) ? $actual_comment['comment_content'] : ''; |
| 6201 | $comments['comment_type'] = isset( $actual_comment['comment_type'] ) ? $actual_comment['comment_type'] : ''; |
| 6202 | $comments['comment_status'] = $get_comments->comment_content; |
| 6203 | $context['pluggable_data'] = $comments; |
| 6204 | $context['response_type'] = 'live'; |
| 6205 | } else { |
| 6206 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"comment_ID":"1","comment_post_ID":"1","comment_author":"test","comment_author_email":"test@test.com","comment_date":"2023-03-27 13:44:26","comment_content":"<p>Leave comment<\/p>","comment_type":"ph_comment","comment_status":"Resolved"}}', true ); |
| 6207 | } |
| 6208 | |
| 6209 | return $context; |
| 6210 | } |
| 6211 | |
| 6212 | /** |
| 6213 | * Get MasterStudy LMS Courses. |
| 6214 | * |
| 6215 | * @param array $data data. |
| 6216 | * |
| 6217 | * @return array |
| 6218 | */ |
| 6219 | public function search_ms_lms_courses( $data ) { |
| 6220 | |
| 6221 | $page = $data['page']; |
| 6222 | $limit = Utilities::get_search_page_limit(); |
| 6223 | $offset = $limit * ( $page - 1 ); |
| 6224 | |
| 6225 | $args = [ |
| 6226 | 'post_type' => 'stm-courses', |
| 6227 | 'posts_per_page' => $limit, |
| 6228 | 'offset' => $offset, |
| 6229 | 'orderby' => 'title', |
| 6230 | 'order' => 'ASC', |
| 6231 | 'post_status' => 'publish', |
| 6232 | ]; |
| 6233 | |
| 6234 | $courses = get_posts( $args ); |
| 6235 | |
| 6236 | $course_count = count( $courses ); |
| 6237 | |
| 6238 | $options = []; |
| 6239 | if ( ! empty( $courses ) ) { |
| 6240 | if ( is_array( $courses ) ) { |
| 6241 | foreach ( $courses as $course ) { |
| 6242 | $options[] = [ |
| 6243 | 'label' => $course->post_title, |
| 6244 | 'value' => $course->ID, |
| 6245 | ]; |
| 6246 | } |
| 6247 | } |
| 6248 | } |
| 6249 | return [ |
| 6250 | 'options' => $options, |
| 6251 | 'hasMore' => $course_count > $limit && $course_count > $offset, |
| 6252 | ]; |
| 6253 | |
| 6254 | } |
| 6255 | |
| 6256 | /** |
| 6257 | * Get MasterStudy LMS Lessons. |
| 6258 | * |
| 6259 | * @param array $data data. |
| 6260 | * |
| 6261 | * @return array |
| 6262 | */ |
| 6263 | public function search_ms_lms_lessons( $data ) { |
| 6264 | |
| 6265 | global $wpdb; |
| 6266 | $page = $data['page']; |
| 6267 | $limit = Utilities::get_search_page_limit(); |
| 6268 | $offset = $limit * ( $page - 1 ); |
| 6269 | |
| 6270 | $course_id = $data['dynamic']; |
| 6271 | |
| 6272 | $lessons = $wpdb->get_results( |
| 6273 | $wpdb->prepare( |
| 6274 | "SELECT ID, post_title |
| 6275 | FROM $wpdb->posts |
| 6276 | WHERE FIND_IN_SET( |
| 6277 | ID, |
| 6278 | (SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'curriculum') |
| 6279 | ) |
| 6280 | AND post_type = 'stm-lessons' |
| 6281 | ORDER BY post_title ASC", |
| 6282 | absint( $course_id ) |
| 6283 | ) |
| 6284 | ); |
| 6285 | |
| 6286 | if ( '-1' === $course_id ) { |
| 6287 | $lessons = $wpdb->get_results( |
| 6288 | $wpdb->prepare( |
| 6289 | "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = %s ORDER BY post_title ASC", |
| 6290 | 'stm-lessons' |
| 6291 | ) |
| 6292 | ); |
| 6293 | } |
| 6294 | |
| 6295 | $lessons_count = count( $lessons ); |
| 6296 | |
| 6297 | $options = []; |
| 6298 | if ( ! empty( $lessons ) ) { |
| 6299 | if ( is_array( $lessons ) ) { |
| 6300 | foreach ( $lessons as $lesson ) { |
| 6301 | $options[] = [ |
| 6302 | 'label' => $lesson->post_title, |
| 6303 | 'value' => $lesson->ID, |
| 6304 | ]; |
| 6305 | } |
| 6306 | } |
| 6307 | } |
| 6308 | return [ |
| 6309 | 'options' => $options, |
| 6310 | 'hasMore' => $lessons_count > $limit && $lessons_count > $offset, |
| 6311 | ]; |
| 6312 | |
| 6313 | } |
| 6314 | |
| 6315 | /** |
| 6316 | * Get MasterStudy LMS Quiz. |
| 6317 | * |
| 6318 | * @param array $data data. |
| 6319 | * |
| 6320 | * @return array |
| 6321 | */ |
| 6322 | public function search_ms_lms_quiz( $data ) { |
| 6323 | |
| 6324 | global $wpdb; |
| 6325 | $page = $data['page']; |
| 6326 | $limit = Utilities::get_search_page_limit(); |
| 6327 | $offset = $limit * ( $page - 1 ); |
| 6328 | |
| 6329 | $course_id = $data['dynamic']; |
| 6330 | |
| 6331 | $quizzes = $wpdb->get_results( |
| 6332 | $wpdb->prepare( |
| 6333 | "SELECT ID, post_title |
| 6334 | FROM $wpdb->posts |
| 6335 | WHERE FIND_IN_SET( |
| 6336 | ID, |
| 6337 | (SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'curriculum') |
| 6338 | ) |
| 6339 | AND post_type = 'stm-quizzes' |
| 6340 | ORDER BY post_title ASC |
| 6341 | ", |
| 6342 | absint( $course_id ) |
| 6343 | ) |
| 6344 | ); |
| 6345 | |
| 6346 | if ( '-1' === $course_id ) { |
| 6347 | $quizzes = $wpdb->get_results( |
| 6348 | $wpdb->prepare( |
| 6349 | "SELECT ID, post_title |
| 6350 | FROM $wpdb->posts |
| 6351 | WHERE post_type = %s |
| 6352 | ORDER BY post_title ASC", |
| 6353 | 'stm-quizzes' |
| 6354 | ) |
| 6355 | ); |
| 6356 | } |
| 6357 | |
| 6358 | $quizzes_count = count( $quizzes ); |
| 6359 | |
| 6360 | $options = []; |
| 6361 | if ( ! empty( $quizzes ) ) { |
| 6362 | if ( is_array( $quizzes ) ) { |
| 6363 | foreach ( $quizzes as $quiz ) { |
| 6364 | $options[] = [ |
| 6365 | 'label' => $quiz->post_title, |
| 6366 | 'value' => $quiz->ID, |
| 6367 | ]; |
| 6368 | } |
| 6369 | } |
| 6370 | } |
| 6371 | return [ |
| 6372 | 'options' => $options, |
| 6373 | 'hasMore' => $quizzes_count > $limit && $quizzes_count > $offset, |
| 6374 | ]; |
| 6375 | |
| 6376 | } |
| 6377 | |
| 6378 | /** |
| 6379 | * Search MasterStudy LMS data. |
| 6380 | * |
| 6381 | * @param array $data data. |
| 6382 | * @return array|void |
| 6383 | */ |
| 6384 | public function search_ms_lms_last_data( $data ) { |
| 6385 | global $wpdb; |
| 6386 | $post_type = $data['post_type']; |
| 6387 | $trigger = $data['search_term']; |
| 6388 | $context = []; |
| 6389 | |
| 6390 | if ( 'stm_lms_course_completed' === $trigger ) { |
| 6391 | $post_id = $data['filter']['course']['value']; |
| 6392 | if ( -1 === $post_id ) { |
| 6393 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.progress_percent=100 AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_type ) ); |
| 6394 | } else { |
| 6395 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.course_id = %s AND postmeta.progress_percent=100 AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 6396 | } |
| 6397 | } elseif ( 'stm_lesson_passed' === $trigger ) { |
| 6398 | $post_id = $data['filter']['lesson']['value']; |
| 6399 | if ( -1 === $post_id ) { |
| 6400 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_lessons as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.lesson_id WHERE posts.post_type=%s order by postmeta.user_lesson_id DESC LIMIT 1", $post_type ) ); |
| 6401 | } else { |
| 6402 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_lessons as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.lesson_id WHERE postmeta.lesson_id=%s AND posts.post_type=%s order by postmeta.user_lesson_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 6403 | } |
| 6404 | } elseif ( 'stm_quiz_passed' === $trigger ) { |
| 6405 | $post_id = $data['filter']['quiz']['value']; |
| 6406 | if ( -1 === $post_id ) { |
| 6407 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_quizzes as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.quiz_id WHERE postmeta.status='passed' AND posts.post_type=%s order by postmeta.user_quiz_id DESC LIMIT 1", $post_type ) ); |
| 6408 | } else { |
| 6409 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_quizzes as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.quiz_id WHERE postmeta.quiz_id=%s AND postmeta.status='passed' AND posts.post_type=%s order by postmeta.user_quiz_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 6410 | } |
| 6411 | } elseif ( 'stm_quiz_failed' === $trigger ) { |
| 6412 | $post_id = $data['filter']['quiz']['value']; |
| 6413 | if ( -1 === $post_id ) { |
| 6414 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_quizzes as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.quiz_id WHERE postmeta.status='failed' AND posts.post_type=%s order by postmeta.user_quiz_id DESC LIMIT 1", $post_type ) ); |
| 6415 | } else { |
| 6416 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_quizzes as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.quiz_id WHERE postmeta.quiz_id=%s AND postmeta.status='failed' AND posts.post_type=%s order by postmeta.user_quiz_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 6417 | } |
| 6418 | } elseif ( 'stm_lms_user_enroll_course' === $trigger ) { |
| 6419 | $post_id = $data['filter']['course']['value']; |
| 6420 | if ( -1 === $post_id ) { |
| 6421 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.status='enrolled' AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_type ) ); |
| 6422 | } else { |
| 6423 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.course_id=%s AND postmeta.status='enrolled' AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 6424 | } |
| 6425 | } |
| 6426 | |
| 6427 | if ( ! empty( $result ) ) { |
| 6428 | |
| 6429 | switch ( $trigger ) { |
| 6430 | case 'stm_lms_course_completed': |
| 6431 | $result_course_id = $result[0]->course_id; |
| 6432 | $result_user_id = $result[0]->user_id; |
| 6433 | $course = get_the_title( $result_course_id ); |
| 6434 | $course_link = get_the_permalink( $result_course_id ); |
| 6435 | $featured_image = get_the_post_thumbnail_url( $result_course_id ); |
| 6436 | |
| 6437 | $data = [ |
| 6438 | 'course_id' => $result_course_id, |
| 6439 | 'course_title' => $course, |
| 6440 | 'course_link' => $course_link, |
| 6441 | 'course_featured_image' => $featured_image, |
| 6442 | 'course_progress' => $result[0]->progress_percent, |
| 6443 | ]; |
| 6444 | $context_data = array_merge( |
| 6445 | WordPress::get_user_context( $result_user_id ), |
| 6446 | $data |
| 6447 | ); |
| 6448 | break; |
| 6449 | case 'stm_lesson_passed': |
| 6450 | $result_lesson_id = $result[0]->lesson_id; |
| 6451 | $result_user_id = $result[0]->user_id; |
| 6452 | $lesson = get_the_title( $result_lesson_id ); |
| 6453 | $lesson_link = get_the_permalink( $result_lesson_id ); |
| 6454 | |
| 6455 | $data = [ |
| 6456 | 'lesson_id' => $result_lesson_id, |
| 6457 | 'lesson_title' => $lesson, |
| 6458 | 'lesson_link' => $lesson_link, |
| 6459 | ]; |
| 6460 | $context_data = array_merge( |
| 6461 | WordPress::get_user_context( $result_user_id ), |
| 6462 | $data |
| 6463 | ); |
| 6464 | break; |
| 6465 | case 'stm_quiz_passed': |
| 6466 | $result_quiz_id = $result[0]->quiz_id; |
| 6467 | $result_user_id = $result[0]->user_id; |
| 6468 | $quiz_title = get_the_title( $result_quiz_id ); |
| 6469 | $quiz_link = get_the_permalink( $result_quiz_id ); |
| 6470 | |
| 6471 | $data = [ |
| 6472 | 'quiz_id' => $result_quiz_id, |
| 6473 | 'quiz_title' => $quiz_title, |
| 6474 | 'quiz_link' => $quiz_link, |
| 6475 | 'quiz_score' => $result[0]->progress, |
| 6476 | 'result' => 'passed', |
| 6477 | ]; |
| 6478 | $context_data = array_merge( |
| 6479 | WordPress::get_user_context( $result_user_id ), |
| 6480 | $data |
| 6481 | ); |
| 6482 | break; |
| 6483 | case 'stm_quiz_failed': |
| 6484 | $result_quiz_id = $result[0]->quiz_id; |
| 6485 | $result_user_id = $result[0]->user_id; |
| 6486 | $quiz_title = get_the_title( $result_quiz_id ); |
| 6487 | $quiz_link = get_the_permalink( $result_quiz_id ); |
| 6488 | |
| 6489 | $data = [ |
| 6490 | 'quiz_id' => $result_quiz_id, |
| 6491 | 'quiz_title' => $quiz_title, |
| 6492 | 'quiz_link' => $quiz_link, |
| 6493 | 'quiz_score' => $result[0]->progress, |
| 6494 | 'result' => 'failed', |
| 6495 | ]; |
| 6496 | $context_data = array_merge( |
| 6497 | WordPress::get_user_context( $result_user_id ), |
| 6498 | $data |
| 6499 | ); |
| 6500 | break; |
| 6501 | case 'stm_lms_user_enroll_course': |
| 6502 | $result_course_id = $result[0]->course_id; |
| 6503 | $result_user_id = $result[0]->user_id; |
| 6504 | |
| 6505 | $course = get_the_title( $result_course_id ); |
| 6506 | $course_link = get_the_permalink( $result_course_id ); |
| 6507 | $featured_image = get_the_post_thumbnail_url( $result_course_id ); |
| 6508 | |
| 6509 | $data = [ |
| 6510 | 'course_id' => $result_course_id, |
| 6511 | 'course_title' => $course, |
| 6512 | 'course_link' => $course_link, |
| 6513 | 'course_featured_image' => $featured_image, |
| 6514 | ]; |
| 6515 | $context_data = array_merge( |
| 6516 | WordPress::get_user_context( $result_user_id ), |
| 6517 | $data |
| 6518 | ); |
| 6519 | break; |
| 6520 | default: |
| 6521 | return; |
| 6522 | } |
| 6523 | $context['pluggable_data'] = $context_data; |
| 6524 | $context['response_type'] = 'live'; |
| 6525 | } |
| 6526 | |
| 6527 | return $context; |
| 6528 | |
| 6529 | } |
| 6530 | |
| 6531 | /** |
| 6532 | * Prepare Fluent Support Mailbox list. |
| 6533 | * |
| 6534 | * @param array $data data. |
| 6535 | * |
| 6536 | * @return array |
| 6537 | */ |
| 6538 | public function search_fs_mailbox_list( $data ) { |
| 6539 | $options = []; |
| 6540 | global $wpdb; |
| 6541 | $mailboxes = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}fs_mail_boxes ORDER BY id DESC", ARRAY_A ); |
| 6542 | if ( ! empty( $mailboxes ) ) { |
| 6543 | foreach ( $mailboxes as $key => $value ) { |
| 6544 | |
| 6545 | $options[] = [ |
| 6546 | 'label' => $value['name'], |
| 6547 | 'value' => $value['id'], |
| 6548 | ]; |
| 6549 | |
| 6550 | } |
| 6551 | } |
| 6552 | |
| 6553 | return [ |
| 6554 | 'options' => $options, |
| 6555 | 'hasMore' => false, |
| 6556 | ]; |
| 6557 | } |
| 6558 | |
| 6559 | /** |
| 6560 | * Get last data for trigger. |
| 6561 | * |
| 6562 | * @param array $data data. |
| 6563 | * @return array |
| 6564 | */ |
| 6565 | public function search_fluent_support_triggers_last_data( $data ) { |
| 6566 | global $wpdb; |
| 6567 | $context = []; |
| 6568 | $context['response_type'] = 'sample'; |
| 6569 | |
| 6570 | $ticket_data = [ |
| 6571 | 'id' => '1', |
| 6572 | 'customer_id' => '2', |
| 6573 | 'agent_id' => '3', |
| 6574 | 'product_id' => '5', |
| 6575 | 'product_source' => 'local', |
| 6576 | 'privacy' => 'private', |
| 6577 | 'priority' => 'normal', |
| 6578 | 'client_priority' => 'medium', |
| 6579 | 'status' => 'active', |
| 6580 | 'title' => 'Sample Ticket Title', |
| 6581 | 'slug' => 'sample-ticket-title', |
| 6582 | 'hash' => 'f8a8cfb946', |
| 6583 | 'content_hash' => 'd65500d62621be8b493c22b1d888052c', |
| 6584 | 'content' => '<p>Sample content.</p>', |
| 6585 | 'last_customer_response' => '2023-04-27 07:30:46', |
| 6586 | 'waiting_since' => '2023-04-27 07:30:46', |
| 6587 | 'response_count' => '2', |
| 6588 | 'total_close_time' => '7042', |
| 6589 | 'resolved at' => '2023-04-27 09:28:08', |
| 6590 | 'closed_by' => '1', |
| 6591 | 'created_at' => '2023-04-27 07:30:46', |
| 6592 | 'updated_at' => '2023-04-27 10:28:08', |
| 6593 | 'mailbox_id' => '1', |
| 6594 | 'mailbox_name' => 'SureTriggers', |
| 6595 | 'mailbox_slug' => 'suretriggers', |
| 6596 | 'mailbox_box_type' => 'web', |
| 6597 | 'mailbox email' => 'john_doe@sample.com', |
| 6598 | 'mailbox_settings_admin_email_address' => 'john_doe@sample.com', |
| 6599 | 'mailbox_created_by' => '1', |
| 6600 | 'mailbox_is_default' => 'yes', |
| 6601 | 'mailbox_created_at' => '2023-04-26 06:29:01', |
| 6602 | 'mailbox_updated_at' => '2023-04-26 06:29:01', |
| 6603 | ]; |
| 6604 | |
| 6605 | $customer_data = [ |
| 6606 | 'id' => '1', |
| 6607 | 'first_name' => 'John', |
| 6608 | 'last_name' => 'Doe', |
| 6609 | 'email' => 'john_doe@sample.com', |
| 6610 | 'person_type' => 'agent', |
| 6611 | 'status' => 'active', |
| 6612 | 'hash' => '3b2b5f0432561cb81b1302b8a16b93a0', |
| 6613 | 'user_id' => '1', |
| 6614 | 'created_at' => '2023-04-27 07:30:46', |
| 6615 | 'updated_at' => '2023-04-27 10:28:08', |
| 6616 | 'full_name' => 'John Doe', |
| 6617 | 'photo' => 'https://www.gravatar.com/avatar/c2b06ae950033b392998ada50767b50e?s=128', |
| 6618 | ]; |
| 6619 | |
| 6620 | $reply_data = [ |
| 6621 | 'ticket_id' => '1', |
| 6622 | 'conversation_type' => 'response', |
| 6623 | 'content' => '<p>Sample content.</p>', |
| 6624 | 'source' => 'web', |
| 6625 | 'content_hash' => '2cc0e35d8fb92a0675d67999b073b3a4', |
| 6626 | 'created_at' => '2023-04-27 07:30:46', |
| 6627 | 'updated_at' => '2023-04-27 10:28:08', |
| 6628 | 'id' => '1', |
| 6629 | 'person_id' => '2', |
| 6630 | 'person_first_name' => 'John', |
| 6631 | 'person_last_name' => 'Doe', |
| 6632 | 'person_email' => 'john_doe@sample.com', |
| 6633 | 'person_person_type' => 'agent', |
| 6634 | 'person_status' => 'active', |
| 6635 | 'person_hash' => '3b2b5f0432561cb81b1302b8a16b93a0', |
| 6636 | 'person_user_id' => '1', |
| 6637 | 'person_created_at' => '2023-04-27 07:30:46', |
| 6638 | 'person_updated_at' => '2023-04-27 10:28:08', |
| 6639 | 'person_full_name' => 'John Doe', |
| 6640 | 'person_photo' => 'https://www.gravatar.com/avatar/c2b06ae950033b392998ada50767b50e?s=128', |
| 6641 | ]; |
| 6642 | |
| 6643 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 6644 | $mailbox = isset( $data['mailbox_id'] ) ? $data['mailbox_id'] : ''; |
| 6645 | |
| 6646 | if ( in_array( $term, [ 'response_added_by_agent', 'response_added_by_customer' ], true ) ) { |
| 6647 | if ( 'response_added_by_agent' == $term ) { |
| 6648 | $agents_type = $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}fs_persons WHERE person_type = 'agent'" ); |
| 6649 | $replies = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}fs_conversations WHERE conversation_type = 'response' ORDER BY id DESC LIMIT 1" ); |
| 6650 | $tickets = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fs_tickets WHERE id = %d ORDER BY id DESC LIMIT 1", $replies[0]->ticket_id ) ); |
| 6651 | if ( ! empty( $tickets ) ) { |
| 6652 | $customers = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fs_persons WHERE id = %d ORDER BY id DESC LIMIT 1", $tickets[0]->customer_id ) ); |
| 6653 | $ticket_data = $tickets[0]; |
| 6654 | $customer_data = $customers[0]; |
| 6655 | $reply_data = $replies[0]; |
| 6656 | } |
| 6657 | } elseif ( 'response_added_by_customer' == $term ) { |
| 6658 | $agents_type = $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}fs_persons WHERE person_type = 'customer'" ); |
| 6659 | $replies = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}fs_conversations WHERE conversation_type = 'response' ORDER BY id DESC LIMIT 1" ); |
| 6660 | $tickets = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fs_tickets WHERE id = %d ORDER BY id DESC LIMIT 1", $replies[0]->ticket_id ) ); |
| 6661 | if ( ! empty( $tickets ) ) { |
| 6662 | $customers = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fs_persons WHERE id = %d ORDER BY id DESC LIMIT 1", $tickets[0]->customer_id ) ); |
| 6663 | $ticket_data = $tickets[0]; |
| 6664 | $customer_data = $customers[0]; |
| 6665 | $reply_data = $replies[0]; |
| 6666 | } |
| 6667 | } |
| 6668 | $context['pluggable_data'] = array_merge( |
| 6669 | [ |
| 6670 | 'reply' => $reply_data, |
| 6671 | 'ticket' => $ticket_data, |
| 6672 | 'customer' => $customer_data, |
| 6673 | ] |
| 6674 | ); |
| 6675 | } else { |
| 6676 | if ( 'ticket_created' == $term ) { |
| 6677 | if ( -1 == $mailbox ) { |
| 6678 | $tickets = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}fs_tickets WHERE status = 'new' ORDER BY id DESC LIMIT 1" ); |
| 6679 | } else { |
| 6680 | $tickets = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fs_tickets WHERE status = 'new' AND mailbox_id = %d ORDER BY id DESC LIMIT 1", $mailbox ) ); |
| 6681 | } |
| 6682 | if ( ! empty( $tickets ) ) { |
| 6683 | $customers = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fs_persons WHERE id = %d", $tickets[0]->customer_id ) ); |
| 6684 | $ticket_data = $tickets[0]; |
| 6685 | $customer_data = $customers[0]; |
| 6686 | } |
| 6687 | } elseif ( 'ticket_closed_by_customer' == $term ) { |
| 6688 | $customers_type = $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}fs_persons WHERE person_type = 'customer'" ); |
| 6689 | $tickets = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fs_tickets WHERE status = 'closed' AND closed_by IN %s ORDER BY id DESC LIMIT 1", $customers_type[0] ) ); |
| 6690 | if ( ! empty( $tickets ) ) { |
| 6691 | $customers = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fs_persons WHERE id = %d ORDER BY id DESC LIMIT 1", $tickets[0]->customer_id ) ); |
| 6692 | $ticket_data = $tickets[0]; |
| 6693 | $customer_data = $customers[0]; |
| 6694 | } |
| 6695 | } elseif ( 'ticket_closed_by_agent' == $term ) { |
| 6696 | $agents_type = $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}fs_persons WHERE person_type = 'agent'" ); |
| 6697 | $tickets = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fs_tickets WHERE status = 'closed' AND closed_by IN %s ORDER BY id DESC LIMIT 1", $agents_type[0] ) ); |
| 6698 | if ( ! empty( $tickets ) ) { |
| 6699 | $customers = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}fs_persons WHERE id = %d ORDER BY id DESC LIMIT 1", $tickets[0]->customer_id ) ); |
| 6700 | $ticket_data = $tickets[0]; |
| 6701 | $customer_data = $customers[0]; |
| 6702 | } |
| 6703 | } |
| 6704 | $context['pluggable_data'] = array_merge( |
| 6705 | [ |
| 6706 | 'ticket' => $ticket_data, |
| 6707 | 'customer' => $customer_data, |
| 6708 | ] |
| 6709 | ); |
| 6710 | if ( 'ticket_created' == $term ) { |
| 6711 | $context['pluggable_data']['mailbox_id'] = $mailbox; |
| 6712 | } |
| 6713 | $context['response_type'] = 'live'; |
| 6714 | } |
| 6715 | |
| 6716 | return $context; |
| 6717 | } |
| 6718 | |
| 6719 | /** |
| 6720 | * Prepare Ultimate Member user_roles. |
| 6721 | * |
| 6722 | * @param array $data data. |
| 6723 | * |
| 6724 | * @return array |
| 6725 | */ |
| 6726 | public function search_um_user_roles( $data ) { |
| 6727 | if ( function_exists( 'get_editable_roles' ) ) { |
| 6728 | $roles = get_editable_roles(); |
| 6729 | } else { |
| 6730 | $roles = wp_roles()->roles; |
| 6731 | $roles = apply_filters( 'editable_roles', $roles ); |
| 6732 | } |
| 6733 | |
| 6734 | $options = []; |
| 6735 | foreach ( $roles as $role => $details ) { |
| 6736 | |
| 6737 | $options[] = [ |
| 6738 | 'label' => $details['name'], |
| 6739 | 'value' => $role, |
| 6740 | ]; |
| 6741 | |
| 6742 | } |
| 6743 | |
| 6744 | return [ |
| 6745 | 'options' => $options, |
| 6746 | 'hasMore' => false, |
| 6747 | ]; |
| 6748 | } |
| 6749 | |
| 6750 | /** |
| 6751 | * Prepare Ultimate Member forms_list. |
| 6752 | * |
| 6753 | * @param array $data data. |
| 6754 | * |
| 6755 | * @return array |
| 6756 | */ |
| 6757 | public function search_um_forms_list( $data ) { |
| 6758 | |
| 6759 | $page = $data['page']; |
| 6760 | $limit = Utilities::get_search_page_limit(); |
| 6761 | $offset = $limit * ( $page - 1 ); |
| 6762 | |
| 6763 | $args = [ |
| 6764 | 'posts_per_page' => $limit, |
| 6765 | 'offset' => $offset, |
| 6766 | 'orderby' => 'title', |
| 6767 | 'order' => 'ASC', |
| 6768 | 'post_type' => 'um_form', |
| 6769 | 'post_status' => 'publish', |
| 6770 | 'fields' => 'ids', |
| 6771 | ]; |
| 6772 | |
| 6773 | $forms_list = get_posts( $args ); |
| 6774 | |
| 6775 | $forms_list_count = count( $forms_list ); |
| 6776 | |
| 6777 | $options = []; |
| 6778 | if ( ! empty( $forms_list ) ) { |
| 6779 | foreach ( $forms_list as $form ) { |
| 6780 | $options[] = [ |
| 6781 | 'label' => get_the_title( $form ), |
| 6782 | 'value' => $form, |
| 6783 | ]; |
| 6784 | } |
| 6785 | } |
| 6786 | |
| 6787 | return [ |
| 6788 | 'options' => $options, |
| 6789 | 'hasMore' => $forms_list_count > $limit && $forms_list_count > $offset, |
| 6790 | ]; |
| 6791 | } |
| 6792 | |
| 6793 | /** |
| 6794 | * Get last data for Ultimate Member Login trigger. |
| 6795 | * |
| 6796 | * @param array $data data. |
| 6797 | * @return mixed |
| 6798 | */ |
| 6799 | public function search_ultimate_member_user_logsin( $data ) { |
| 6800 | $context = []; |
| 6801 | $args = [ |
| 6802 | 'orderby' => 'meta_value', |
| 6803 | 'meta_key' => '_um_last_login', |
| 6804 | 'order' => 'DESC', |
| 6805 | 'number' => 1, |
| 6806 | ]; |
| 6807 | $users = get_users( $args ); |
| 6808 | |
| 6809 | if ( ! empty( $users ) ) { |
| 6810 | $user = $users[0]; |
| 6811 | $pluggable_data = WordPress::get_user_context( $user->ID ); |
| 6812 | $context['pluggable_data'] = $pluggable_data; |
| 6813 | $context['response_type'] = 'live'; |
| 6814 | } else { |
| 6815 | $role = 'subscriber'; |
| 6816 | $context['pluggable_data'] = [ |
| 6817 | 'wp_user_id' => 1, |
| 6818 | 'user_login' => 'test', |
| 6819 | 'display_name' => 'Test User', |
| 6820 | 'user_firstname' => 'Test', |
| 6821 | 'user_lastname' => 'User', |
| 6822 | 'user_email' => 'testuser@gmail.com', |
| 6823 | 'user_role' => [ $role ], |
| 6824 | ]; |
| 6825 | $context['response_type'] = 'sample'; |
| 6826 | } |
| 6827 | return $context; |
| 6828 | } |
| 6829 | |
| 6830 | /** |
| 6831 | * Get last data for Ultimate Member Register trigger. |
| 6832 | * |
| 6833 | * @param array $data data. |
| 6834 | * @return mixed |
| 6835 | */ |
| 6836 | public function search_ultimate_member_user_registers( $data ) { |
| 6837 | $context = []; |
| 6838 | $args = [ |
| 6839 | 'orderby' => 'meta_value', |
| 6840 | 'meta_key' => 'um_user_profile_url_slug_user_login', |
| 6841 | 'order' => 'DESC', |
| 6842 | 'number' => 1, |
| 6843 | ]; |
| 6844 | $users = get_users( $args ); |
| 6845 | |
| 6846 | if ( ! empty( $users ) ) { |
| 6847 | $user = $users[0]; |
| 6848 | $pluggable_data = WordPress::get_user_context( $user->ID ); |
| 6849 | $context['pluggable_data'] = $pluggable_data; |
| 6850 | $context['response_type'] = 'live'; |
| 6851 | } else { |
| 6852 | $role = 'subscriber'; |
| 6853 | $context['pluggable_data'] = [ |
| 6854 | 'wp_user_id' => 1, |
| 6855 | 'user_login' => 'test', |
| 6856 | 'display_name' => 'Test User', |
| 6857 | 'user_firstname' => 'Test', |
| 6858 | 'user_lastname' => 'User', |
| 6859 | 'user_email' => 'testuser@gmail.com', |
| 6860 | 'user_role' => [ $role ], |
| 6861 | ]; |
| 6862 | $context['response_type'] = 'sample'; |
| 6863 | } |
| 6864 | return $context; |
| 6865 | } |
| 6866 | |
| 6867 | /** |
| 6868 | * Get last data for Ultimate Member Register trigger. |
| 6869 | * |
| 6870 | * @param array $data data. |
| 6871 | * @return mixed |
| 6872 | */ |
| 6873 | public function search_ultimate_member_user_inactive( $data ) { |
| 6874 | $context = []; |
| 6875 | $args = [ |
| 6876 | 'orderby' => 'user_id', |
| 6877 | 'meta_key' => 'account_status', |
| 6878 | 'meta_value' => 'inactive', |
| 6879 | 'order' => 'ASC', |
| 6880 | 'number' => 1, |
| 6881 | ]; |
| 6882 | $users = get_users( $args ); |
| 6883 | |
| 6884 | if ( ! empty( $users ) ) { |
| 6885 | $user = $users[0]; |
| 6886 | $pluggable_data = []; |
| 6887 | $pluggable_data[] = WordPress::get_user_context( $user->ID ); |
| 6888 | $pluggable_data['user_account_status'] = 'inactive'; |
| 6889 | $context['pluggable_data'] = $pluggable_data; |
| 6890 | $context['response_type'] = 'live'; |
| 6891 | } else { |
| 6892 | $role = 'subscriber'; |
| 6893 | $context['pluggable_data'] = [ |
| 6894 | 'wp_user_id' => 1, |
| 6895 | 'user_login' => 'test', |
| 6896 | 'display_name' => 'Test User', |
| 6897 | 'user_firstname' => 'Test', |
| 6898 | 'user_lastname' => 'User', |
| 6899 | 'user_email' => 'testuser@gmail.com', |
| 6900 | 'user_role' => [ $role ], |
| 6901 | 'user_account_status' => 'inactive', |
| 6902 | ]; |
| 6903 | $context['response_type'] = 'sample'; |
| 6904 | } |
| 6905 | return $context; |
| 6906 | } |
| 6907 | |
| 6908 | /** |
| 6909 | * Get last data for Ultimate Member Change Role trigger. |
| 6910 | * |
| 6911 | * @param array $data data. |
| 6912 | * @return mixed |
| 6913 | */ |
| 6914 | public function search_ultimate_member_user_role_change( $data ) { |
| 6915 | $context = []; |
| 6916 | |
| 6917 | $role = $data['filter']['role']['value']; |
| 6918 | |
| 6919 | $args = [ |
| 6920 | 'number' => 1, |
| 6921 | 'role' => $role, |
| 6922 | ]; |
| 6923 | $users = get_users( $args ); |
| 6924 | shuffle( $users ); |
| 6925 | if ( ! empty( $users ) ) { |
| 6926 | $user = $users[0]; |
| 6927 | $pluggable_data = WordPress::get_user_context( $user->ID ); |
| 6928 | $context['pluggable_data'] = $pluggable_data; |
| 6929 | $context['response_type'] = 'live'; |
| 6930 | } else { |
| 6931 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 6932 | $context['pluggable_data'] = [ |
| 6933 | 'wp_user_id' => 1, |
| 6934 | 'user_login' => 'test', |
| 6935 | 'display_name' => 'Test User', |
| 6936 | 'user_firstname' => 'Test', |
| 6937 | 'user_lastname' => 'User', |
| 6938 | 'user_email' => 'testuser@gmail.com', |
| 6939 | 'user_role' => [ $role ], |
| 6940 | 'user_account_status' => 'inactive', |
| 6941 | ]; |
| 6942 | $context['response_type'] = 'sample'; |
| 6943 | } |
| 6944 | return $context; |
| 6945 | } |
| 6946 | |
| 6947 | /** |
| 6948 | * Get JetEngine WP Posttypes. |
| 6949 | * |
| 6950 | * @param array $data data. |
| 6951 | * |
| 6952 | * @return array |
| 6953 | */ |
| 6954 | public function search_je_posttype_list( $data ) { |
| 6955 | |
| 6956 | $post_types = get_post_types( [ 'public' => true ], 'object' ); |
| 6957 | $post_types = apply_filters( 'suretriggers_post_types', $post_types ); |
| 6958 | if ( isset( $post_types['attachment'] ) ) { |
| 6959 | unset( $post_types['attachment'] ); |
| 6960 | } |
| 6961 | |
| 6962 | $options = []; |
| 6963 | foreach ( $post_types as $post_type => $details ) { |
| 6964 | $options[] = [ |
| 6965 | 'label' => $details->label, |
| 6966 | 'value' => $post_type, |
| 6967 | ]; |
| 6968 | } |
| 6969 | |
| 6970 | return [ |
| 6971 | 'options' => $options, |
| 6972 | 'hasMore' => false, |
| 6973 | ]; |
| 6974 | } |
| 6975 | |
| 6976 | /** |
| 6977 | * Get JetEngine WP fields. |
| 6978 | * |
| 6979 | * @param array $data data. |
| 6980 | * |
| 6981 | * @return array |
| 6982 | */ |
| 6983 | public function search_je_field_list( $data ) { |
| 6984 | |
| 6985 | $post_type = $data['dynamic']; |
| 6986 | |
| 6987 | $metaboxes = (array) get_option( 'jet_engine_meta_boxes', [] ); |
| 6988 | |
| 6989 | $post_fields = array_filter( |
| 6990 | $metaboxes, |
| 6991 | function( $metabox ) { |
| 6992 | /** |
| 6993 | * |
| 6994 | * Ignore line |
| 6995 | * |
| 6996 | * @phpstan-ignore-next-line |
| 6997 | */ |
| 6998 | return 'post' === $metabox['args']['object_type']; |
| 6999 | } |
| 7000 | ); |
| 7001 | |
| 7002 | $post_fields_count = count( $post_fields ); |
| 7003 | |
| 7004 | $options = []; |
| 7005 | if ( ! empty( $post_fields ) ) { |
| 7006 | if ( is_array( $post_fields ) ) { |
| 7007 | foreach ( $post_fields as $post_field ) { |
| 7008 | if ( in_array( $post_type, $post_field['args']['allowed_post_type'], true ) ) { |
| 7009 | foreach ( $post_field['meta_fields'] as $meta_field ) { |
| 7010 | $options[] = [ |
| 7011 | 'label' => $meta_field['title'], |
| 7012 | 'value' => $meta_field['name'], |
| 7013 | ]; |
| 7014 | } |
| 7015 | } |
| 7016 | } |
| 7017 | } |
| 7018 | } |
| 7019 | return [ |
| 7020 | 'options' => $options, |
| 7021 | 'hasMore' => false, |
| 7022 | ]; |
| 7023 | } |
| 7024 | |
| 7025 | /** |
| 7026 | * Search Last Updated Field Data. |
| 7027 | * |
| 7028 | * @param array $data data. |
| 7029 | * @return array |
| 7030 | */ |
| 7031 | public function search_jet_engine_field_data( $data ) { |
| 7032 | global $wpdb; |
| 7033 | |
| 7034 | $context = []; |
| 7035 | |
| 7036 | $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); |
| 7037 | |
| 7038 | $post_type = $data['filter']['wp_post_type']['value']; |
| 7039 | |
| 7040 | if ( -1 === $field ) { |
| 7041 | $metaboxes = (array) get_option( 'jet_engine_meta_boxes', [] ); |
| 7042 | |
| 7043 | $post_fields = array_filter( |
| 7044 | $metaboxes, |
| 7045 | function( $metabox ) { |
| 7046 | /** |
| 7047 | * |
| 7048 | * Ignore line |
| 7049 | * |
| 7050 | * @phpstan-ignore-next-line |
| 7051 | */ |
| 7052 | return 'post' === $metabox['args']['object_type']; |
| 7053 | } |
| 7054 | ); |
| 7055 | |
| 7056 | $options = []; |
| 7057 | if ( ! empty( $post_fields ) ) { |
| 7058 | if ( is_array( $post_fields ) ) { |
| 7059 | foreach ( $post_fields as $post_field ) { |
| 7060 | if ( in_array( $post_type, $post_field['args']['allowed_post_type'], true ) ) { |
| 7061 | foreach ( $post_field['meta_fields'] as $meta_field ) { |
| 7062 | $options[] = $meta_field['name']; |
| 7063 | } |
| 7064 | } |
| 7065 | } |
| 7066 | } |
| 7067 | } |
| 7068 | $random_key = array_rand( $options ); |
| 7069 | $random_value = $options[ $random_key ]; |
| 7070 | $string = '%' . $random_value . '%'; |
| 7071 | } else { |
| 7072 | $string = '%' . $data['filter']['field_id']['value'] . '%'; |
| 7073 | } |
| 7074 | |
| 7075 | $result = $wpdb->get_results( |
| 7076 | $wpdb->prepare( |
| 7077 | 'SELECT post_id FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key LIKE %s', |
| 7078 | [ $string ] |
| 7079 | ), |
| 7080 | ARRAY_A |
| 7081 | ); |
| 7082 | |
| 7083 | $ids = []; |
| 7084 | |
| 7085 | if ( ! empty( $result ) ) { |
| 7086 | foreach ( $result as $val ) { |
| 7087 | $ids[] = $val['post_id']; |
| 7088 | } |
| 7089 | } |
| 7090 | |
| 7091 | $lastupdated_args = [ |
| 7092 | 'post_type' => $post_type, |
| 7093 | 'orderby' => 'modified', |
| 7094 | 'post__in' => $ids, |
| 7095 | 'posts_per_page' => 1, |
| 7096 | ]; |
| 7097 | $lastupdated_loop = get_posts( $lastupdated_args ); |
| 7098 | |
| 7099 | $response = []; |
| 7100 | if ( ! empty( $result ) ) { |
| 7101 | $context['post'] = $lastupdated_loop[0]; |
| 7102 | |
| 7103 | $meta_value = get_post_meta( $lastupdated_loop[0]->ID, sprintf( '%s', $data['filter']['field_id']['value'] ), true ); |
| 7104 | $meta_key = sprintf( '%s', $data['filter']['field_id']['value'] ); |
| 7105 | |
| 7106 | $context[ $meta_key ] = $meta_value; |
| 7107 | |
| 7108 | $response['pluggable_data'] = $context; |
| 7109 | $response['response_type'] = 'live'; |
| 7110 | } else { |
| 7111 | $response = json_decode( '{"response_type":"sample","pluggable_data":{"post":{"ID":198,"post_author":"1","post_date":"2023-02-08 13:31:13","post_date_gmt":"2023-02-08 13:31:13","post_content":"New Category1 - content","post_title":"jennjennn - Post - jenn","post_excerpt":"","post_status":"publish","comment_status":"open","ping_status":"open","post_password":"","post_name":"jennjennn-post-jenn","to_ping":"","pinged":"","post_modified":"2023-04-10 06:23:40","post_modified_gmt":"2023-04-10 06:23:40","post_content_filtered":"","post_parent":0,"guid":"https:\/\/suretriggerswp.local\/jennjennn-post-jenn\/","menu_order":0,"post_type":"post","post_mime_type":"","comment_count":"0","filter":"raw"},"enter-post-extra-content-title":"dummy"}}', true ); |
| 7112 | } |
| 7113 | |
| 7114 | return $response; |
| 7115 | |
| 7116 | } |
| 7117 | |
| 7118 | /** |
| 7119 | * Get Formidable Forms. |
| 7120 | * |
| 7121 | * @param array $data data. |
| 7122 | * |
| 7123 | * @return array|void |
| 7124 | */ |
| 7125 | public function search_formidable_form_list( $data ) { |
| 7126 | if ( ! class_exists( 'FrmForm' ) ) { |
| 7127 | return; |
| 7128 | } |
| 7129 | |
| 7130 | $page = $data['page']; |
| 7131 | $term = $data['search_term']; |
| 7132 | $limit = Utilities::get_search_page_limit(); |
| 7133 | $offset = $limit * ( $page - 1 ); |
| 7134 | $per_page = 10; |
| 7135 | |
| 7136 | $query = [ |
| 7137 | [ |
| 7138 | 'or' => 1, |
| 7139 | 'name LIKE' => $term, |
| 7140 | 'parent_form_id' => null, |
| 7141 | ], |
| 7142 | ]; |
| 7143 | $query['is_template'] = 0; |
| 7144 | $query['status !'] = 'trash'; |
| 7145 | $forms_list = FrmForm::getAll( $query, '', $offset . ',' . $per_page ); |
| 7146 | $form_count = FrmForm::getAll( $query ); |
| 7147 | $form_count = count( $form_count ); |
| 7148 | $options = []; |
| 7149 | |
| 7150 | if ( ! empty( $forms_list ) ) { |
| 7151 | if ( is_array( $forms_list ) ) { |
| 7152 | foreach ( $forms_list as $form ) { |
| 7153 | $options[] = [ |
| 7154 | 'label' => $form->name, |
| 7155 | 'value' => $form->id, |
| 7156 | ]; |
| 7157 | } |
| 7158 | } |
| 7159 | } |
| 7160 | |
| 7161 | return [ |
| 7162 | 'options' => $options, |
| 7163 | 'hasMore' => $form_count > $limit && $form_count > $offset, |
| 7164 | ]; |
| 7165 | } |
| 7166 | |
| 7167 | /** |
| 7168 | * Get JetFormBuilder Form List. |
| 7169 | * |
| 7170 | * @param array $data data. |
| 7171 | * |
| 7172 | * @return array|void |
| 7173 | */ |
| 7174 | public function search_jetform_list( $data ) { |
| 7175 | if ( ! class_exists( '\Jet_Form_Builder\Classes\Tools' ) ) { |
| 7176 | return; |
| 7177 | } |
| 7178 | |
| 7179 | $forms = \Jet_Form_Builder\Classes\Tools::get_forms_list_for_js(); |
| 7180 | |
| 7181 | $options = []; |
| 7182 | foreach ( $forms as $form ) { |
| 7183 | |
| 7184 | if ( ! empty( $form['value'] ) ) { |
| 7185 | $options[] = [ |
| 7186 | 'label' => esc_html( $form['label'] ), |
| 7187 | 'value' => esc_attr( $form['value'] ), |
| 7188 | ]; |
| 7189 | } |
| 7190 | } |
| 7191 | |
| 7192 | return [ |
| 7193 | 'options' => $options, |
| 7194 | 'hasMore' => false, |
| 7195 | ]; |
| 7196 | } |
| 7197 | |
| 7198 | /** |
| 7199 | * Get Forminator Form List. |
| 7200 | * |
| 7201 | * @param array $data data. |
| 7202 | * |
| 7203 | * @return array|void |
| 7204 | */ |
| 7205 | public function search_forminator_form_list( $data ) { |
| 7206 | if ( ! class_exists( 'Forminator_API' ) ) { |
| 7207 | return; |
| 7208 | } |
| 7209 | |
| 7210 | $forms = Forminator_API::get_forms( null, 1, 10 ); |
| 7211 | |
| 7212 | $options = []; |
| 7213 | foreach ( $forms as $form ) { |
| 7214 | $options[] = [ |
| 7215 | 'label' => isset( $form->settings ) && isset( $form->settings['form_name'] ) ? $form->settings['form_name'] : $form->name, |
| 7216 | 'value' => $form->id, |
| 7217 | ]; |
| 7218 | } |
| 7219 | |
| 7220 | return [ |
| 7221 | 'options' => $options, |
| 7222 | 'hasMore' => false, |
| 7223 | ]; |
| 7224 | } |
| 7225 | |
| 7226 | |
| 7227 | /** |
| 7228 | * Get BbPress topics list. |
| 7229 | * |
| 7230 | * @param array $data data. |
| 7231 | * |
| 7232 | * @return array|void |
| 7233 | */ |
| 7234 | public function search_bbp_topic_list( $data ) { |
| 7235 | $page = $data['page']; |
| 7236 | $forum_id = $data['dynamic']; |
| 7237 | $limit = Utilities::get_search_page_limit(); |
| 7238 | $offset = $limit * ( $page - 1 ); |
| 7239 | $args = [ |
| 7240 | 'post_type' => 'topic', |
| 7241 | 'offset' => $offset, |
| 7242 | 'meta_query' => [ |
| 7243 | [ |
| 7244 | 'key' => '_bbp_forum_id', |
| 7245 | 'value' => $forum_id, |
| 7246 | 'compare' => '==', |
| 7247 | ], |
| 7248 | ], |
| 7249 | ]; |
| 7250 | |
| 7251 | $topics = get_posts( $args ); |
| 7252 | $topics_count = count( $topics ); |
| 7253 | |
| 7254 | $options = []; |
| 7255 | if ( ! empty( $topics ) ) { |
| 7256 | if ( is_array( $topics ) ) { |
| 7257 | foreach ( $topics as $topic ) { |
| 7258 | $options[] = [ |
| 7259 | 'label' => $topic->post_title, |
| 7260 | 'value' => $topic->ID, |
| 7261 | ]; |
| 7262 | } |
| 7263 | } |
| 7264 | } |
| 7265 | return [ |
| 7266 | 'options' => $options, |
| 7267 | 'hasMore' => $topics_count > $limit && $topics_count > $offset, |
| 7268 | ]; |
| 7269 | } |
| 7270 | |
| 7271 | |
| 7272 | /** |
| 7273 | * Search Last Updated Field Data. |
| 7274 | * |
| 7275 | * @param array $data data. |
| 7276 | * @return array |
| 7277 | */ |
| 7278 | public function search_bbp_last_data( $data ) { |
| 7279 | global $wpdb; |
| 7280 | |
| 7281 | $post_type = $data['post_type']; |
| 7282 | $trigger = $data['search_term']; |
| 7283 | $context = []; |
| 7284 | |
| 7285 | if ( 'topic' === $post_type ) { |
| 7286 | $post_id = $data['filter']['forum']['value']; |
| 7287 | if ( -1 === $post_id ) { |
| 7288 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID = postmeta.post_id WHERE posts.post_type = 'topic' AND postmeta.meta_key= '_bbp_forum_id' ORDER BY posts.ID DESC LIMIT 1" ); |
| 7289 | |
| 7290 | } else { |
| 7291 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID=postmeta.post_id WHERE posts.post_type ='topic' AND postmeta.meta_key= '_bbp_forum_id' AND postmeta.meta_value=%s ORDER BY posts.ID DESC LIMIT 1", $post_id ) ); |
| 7292 | |
| 7293 | } |
| 7294 | } elseif ( 'reply' === $post_type ) { |
| 7295 | $post_id = $data['filter']['topic']['value']; |
| 7296 | |
| 7297 | if ( -1 === $post_id ) { |
| 7298 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID = postmeta.post_id WHERE posts.post_type = 'reply' AND postmeta.meta_key= '_bbp_topic_id' ORDER BY posts.ID DESC LIMIT 1" ); |
| 7299 | |
| 7300 | } else { |
| 7301 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID=postmeta.post_id WHERE posts.post_type ='reply' AND postmeta.meta_key= '_bbp_topic_id' AND postmeta.meta_value=%s ORDER BY posts.ID DESC LIMIT 1", $post_id ) ); |
| 7302 | } |
| 7303 | } |
| 7304 | |
| 7305 | |
| 7306 | $response = []; |
| 7307 | if ( ! empty( $result ) ) { |
| 7308 | if ( 'bbpress_topic_created' === $trigger ) { |
| 7309 | $topic_id = $result[0]->post_id; |
| 7310 | $forum_id = $result[0]->meta_value; |
| 7311 | $topic = get_the_title( $topic_id ); |
| 7312 | $topic_link = get_the_permalink( $topic_id ); |
| 7313 | $topic_description = get_the_content( $topic_id ); |
| 7314 | $topic_status = get_post_status( $topic_id ); |
| 7315 | |
| 7316 | $forum = get_the_title( $forum_id ); |
| 7317 | $forum_link = get_the_permalink( $forum_id ); |
| 7318 | $forum_description = get_the_content( $forum_id ); |
| 7319 | $forum_status = get_post_status( $forum_id ); |
| 7320 | |
| 7321 | $forum = [ |
| 7322 | 'forum' => $forum_id, |
| 7323 | 'forum_title' => $forum, |
| 7324 | 'forum_link' => $forum_link, |
| 7325 | 'forum_description' => $forum_description, |
| 7326 | 'forum_status' => $forum_status, |
| 7327 | ]; |
| 7328 | |
| 7329 | $topic = [ |
| 7330 | 'topic_title' => $topic, |
| 7331 | 'topic_link' => $topic_link, |
| 7332 | 'topic_description' => $topic_description, |
| 7333 | 'topic_status' => $topic_status, |
| 7334 | ]; |
| 7335 | |
| 7336 | $user_id = $result[0]->post_author; |
| 7337 | $context = array_merge( |
| 7338 | WordPress::get_user_context( $user_id ), |
| 7339 | $forum, |
| 7340 | $topic |
| 7341 | ); |
| 7342 | |
| 7343 | $response['pluggable_data'] = $context; |
| 7344 | $response['response_type'] = 'live'; |
| 7345 | } else { |
| 7346 | $reply_id = $result[0]->post_id; |
| 7347 | $topic_id = $result[0]->meta_value; |
| 7348 | $forum_id = get_post_meta( $topic_id, '_bbp_forum_id', true ); |
| 7349 | $forum_id = intval( '"' . $forum_id . '"' ); |
| 7350 | $reply = get_the_title( $reply_id ); |
| 7351 | $reply_link = get_the_permalink( $reply_id ); |
| 7352 | $reply_description = get_the_content( $reply_id ); |
| 7353 | $reply_status = get_post_status( $reply_id ); |
| 7354 | |
| 7355 | |
| 7356 | $topic = get_the_title( $topic_id ); |
| 7357 | $topic_link = get_the_permalink( $topic_id ); |
| 7358 | $topic_description = get_the_content( $topic_id ); |
| 7359 | $topic_status = get_post_status( $topic_id ); |
| 7360 | |
| 7361 | $forum = get_the_title( $forum_id ); |
| 7362 | $forum_link = get_the_permalink( $forum_id ); |
| 7363 | $forum_description = get_the_content( null, false, $forum_id ); |
| 7364 | $forum_status = get_post_status( $forum_id ); |
| 7365 | |
| 7366 | $forum = [ |
| 7367 | 'forum' => $forum_id, |
| 7368 | 'forum_title' => $forum, |
| 7369 | 'forum_link' => $forum_link, |
| 7370 | 'forum_description' => $forum_description, |
| 7371 | 'forum_status' => $forum_status, |
| 7372 | ]; |
| 7373 | |
| 7374 | $topic = [ |
| 7375 | 'topic_title' => $topic, |
| 7376 | 'topic_link' => $topic_link, |
| 7377 | 'topic_description' => $topic_description, |
| 7378 | 'topic_status' => $topic_status, |
| 7379 | ]; |
| 7380 | |
| 7381 | $reply = [ |
| 7382 | 'reply_title' => $reply, |
| 7383 | 'reply_link' => $reply_link, |
| 7384 | 'reply_description' => $reply_description, |
| 7385 | 'reply_status' => $reply_status, |
| 7386 | ]; |
| 7387 | $user_id = $result[0]->post_author; |
| 7388 | $context = array_merge( |
| 7389 | WordPress::get_user_context( $user_id ), |
| 7390 | $forum, |
| 7391 | $topic, |
| 7392 | $reply |
| 7393 | ); |
| 7394 | |
| 7395 | $response['pluggable_data'] = $context; |
| 7396 | $response['response_type'] = 'live'; |
| 7397 | } |
| 7398 | } |
| 7399 | |
| 7400 | return $response; |
| 7401 | } |
| 7402 | |
| 7403 | /** |
| 7404 | * Search Last Updated Field Data. |
| 7405 | * |
| 7406 | * @param array $data data. |
| 7407 | * @return array|void |
| 7408 | */ |
| 7409 | public function search_happyform_list( $data ) { |
| 7410 | if ( ! function_exists( 'happyforms_get_form_controller' ) ) { |
| 7411 | return; |
| 7412 | } |
| 7413 | |
| 7414 | $form_controller = happyforms_get_form_controller(); |
| 7415 | |
| 7416 | $forms = $form_controller->do_get(); |
| 7417 | $options = []; |
| 7418 | if ( ! empty( $forms ) ) { |
| 7419 | foreach ( $forms as $form ) { |
| 7420 | $options[] = [ |
| 7421 | 'label' => $form['post_title'], |
| 7422 | 'value' => $form['ID'], |
| 7423 | ]; |
| 7424 | } |
| 7425 | } |
| 7426 | |
| 7427 | return [ |
| 7428 | 'options' => $options, |
| 7429 | 'hasMore' => false, |
| 7430 | ]; |
| 7431 | } |
| 7432 | |
| 7433 | /** |
| 7434 | * Get Memberpress Course List. |
| 7435 | * |
| 7436 | * @param array $data data. |
| 7437 | * |
| 7438 | * @return array|void |
| 7439 | */ |
| 7440 | public function search_mpc_lessons_list( $data ) { |
| 7441 | if ( ! class_exists( '\memberpress\courses\models\Lesson' ) ) { |
| 7442 | return; |
| 7443 | } |
| 7444 | global $wpdb; |
| 7445 | $options = []; |
| 7446 | $course_id = $data['dynamic']; |
| 7447 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mpcs_sections WHERE course_id =%s", $course_id ) ); |
| 7448 | $sections = []; |
| 7449 | foreach ( $result as $rec ) { |
| 7450 | $sections[] = [ |
| 7451 | 'id' => $rec->id, |
| 7452 | 'title' => $rec->title, |
| 7453 | ]; |
| 7454 | } |
| 7455 | if ( is_array( $sections ) && count( $sections ) > 0 ) { |
| 7456 | foreach ( $sections as $section ) { |
| 7457 | $post_types_string = \memberpress\courses\models\Lesson::lesson_cpts(); |
| 7458 | $post_types_string = implode( "','", $post_types_string ); |
| 7459 | |
| 7460 | $query = $wpdb->prepare( |
| 7461 | "SELECT * FROM {$wpdb->posts} AS p |
| 7462 | JOIN {$wpdb->postmeta} AS pm |
| 7463 | ON p.ID = pm.post_id |
| 7464 | AND pm.meta_key = %s |
| 7465 | AND pm.meta_value = %s |
| 7466 | JOIN {$wpdb->postmeta} AS pm_order |
| 7467 | ON p.ID = pm_order.post_id |
| 7468 | AND pm_order.meta_key = %s |
| 7469 | WHERE p.post_type in ( %s ) AND p.post_status <> 'trash' |
| 7470 | ORDER BY pm_order.meta_value * 1", |
| 7471 | models\Lesson::$section_id_str, |
| 7472 | $section['id'], |
| 7473 | models\Lesson::$lesson_order_str, |
| 7474 | stripcslashes( $post_types_string ) |
| 7475 | ); |
| 7476 | |
| 7477 | $db_lessons = $wpdb->get_results( stripcslashes( $query ) ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 7478 | foreach ( $db_lessons as $lesson ) { |
| 7479 | $options[] = [ |
| 7480 | 'label' => $section['title'] . '->' . $lesson->post_title, |
| 7481 | 'value' => $lesson->ID, |
| 7482 | ]; |
| 7483 | } |
| 7484 | } |
| 7485 | } |
| 7486 | return [ |
| 7487 | 'options' => $options, |
| 7488 | 'hasMore' => false, |
| 7489 | ]; |
| 7490 | } |
| 7491 | |
| 7492 | /** |
| 7493 | * Get Memberpress Course List. |
| 7494 | * |
| 7495 | * @param array $data data. |
| 7496 | * |
| 7497 | * @return array|void |
| 7498 | */ |
| 7499 | public function search_gp_rank_type_list( $data ) { |
| 7500 | global $wpdb; |
| 7501 | |
| 7502 | $posts = $wpdb->get_results( |
| 7503 | "SELECT ID, post_name, post_title, post_type |
| 7504 | FROM $wpdb->posts |
| 7505 | WHERE post_type LIKE 'rank-type' AND post_status = 'publish' ORDER BY post_title ASC" |
| 7506 | ); |
| 7507 | |
| 7508 | $posts_count = count( $posts ); |
| 7509 | |
| 7510 | $options = []; |
| 7511 | if ( $posts ) { |
| 7512 | foreach ( $posts as $post ) { |
| 7513 | $options[] = [ |
| 7514 | 'label' => $post->post_title, |
| 7515 | 'value' => $post->post_name, |
| 7516 | ]; |
| 7517 | } |
| 7518 | } |
| 7519 | |
| 7520 | return [ |
| 7521 | 'options' => $options, |
| 7522 | 'hasMore' => false, |
| 7523 | ]; |
| 7524 | } |
| 7525 | |
| 7526 | /** |
| 7527 | * Get MPC last data. |
| 7528 | * |
| 7529 | * @param array $data data. |
| 7530 | * |
| 7531 | * @return array |
| 7532 | */ |
| 7533 | public function search_mpc_last_data( $data ) { |
| 7534 | global $wpdb; |
| 7535 | $trigger = $data['search_term']; |
| 7536 | $course_data = []; |
| 7537 | $lesson_data = []; |
| 7538 | $context = []; |
| 7539 | |
| 7540 | if ( 'mpc_course_completed' === $trigger ) { |
| 7541 | $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course]']['value'] : '-1' ); |
| 7542 | if ( $course_id > 0 ) { |
| 7543 | |
| 7544 | $course = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE ID= %s ORDER BY id DESC LIMIT 1", $course_id ) ); |
| 7545 | } else { |
| 7546 | $course = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}posts where post_type = 'mpcs-course' ORDER BY id DESC LIMIT 1" ); |
| 7547 | } |
| 7548 | |
| 7549 | if ( ! empty( $course ) ) { |
| 7550 | $course_data = [ |
| 7551 | 'course_id' => $course->ID, |
| 7552 | 'course_title' => get_the_title( $course_id ), |
| 7553 | 'course_url' => get_permalink( $course_id ), |
| 7554 | 'course_featured_image_id' => get_post_meta( $course_id, '_thumbnail_id', true ), |
| 7555 | 'course_featured_image_url' => get_the_post_thumbnail_url( $course_id ), |
| 7556 | ]; |
| 7557 | } |
| 7558 | $user_progress = $wpdb->get_row( $wpdb->prepare( "SELECT user_id FROM {$wpdb->prefix}mpcs_user_progress WHERE course_id=%s", $course_id ) ); |
| 7559 | if ( ! empty( $user_progress ) ) { |
| 7560 | $context['response_type'] = 'live'; |
| 7561 | $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_progress->user_id ), $course_data, $lesson_data ); |
| 7562 | } else { |
| 7563 | $sample_data = '{"pluggable_data":{"wp_user_id":1,"user_login":"suretriggers","display_name":"suretriggers","user_firstname":"suretriggers","user_lastname":"suretriggers","user_email":"hello@suretriggers.io","user_role":["administrator","subscriber","tutor_instructor","bbp_keymaster"],"course_id":617,"course_title":"Course One","course_url":"https:\/\/connector.com\/courses\/course-one\/","course_featured_image_id":"","course_featured_image_url":false} |
| 7564 | ,"response_type":"sample"} '; |
| 7565 | $context = json_decode( $sample_data, true ); |
| 7566 | } |
| 7567 | } elseif ( 'mpc_lesson_completed' === $trigger ) { |
| 7568 | $lesson_id = (int) ( isset( $data['filter']['lesson']['value'] ) ? $data['filter']['lesson']['value'] : '-1' ); |
| 7569 | $course_id = (int) $data['filter']['course']['value']; |
| 7570 | if ( $lesson_id > 0 ) { |
| 7571 | |
| 7572 | $lesson = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE ID= %s ORDER BY id DESC LIMIT 1", $lesson_id ) ); |
| 7573 | } else { |
| 7574 | $lesson = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}posts where post_type = 'mpcs-lesson' ORDER BY id DESC LIMIT 1" ); |
| 7575 | } |
| 7576 | |
| 7577 | if ( ! empty( $lesson ) ) { |
| 7578 | $lesson_data = [ |
| 7579 | 'lesson_id' => $lesson->ID, |
| 7580 | 'lesson_title' => get_the_title( $lesson_id ), |
| 7581 | 'lesson_url' => get_permalink( $lesson_id ), |
| 7582 | 'lesson_featured_image_id' => get_post_meta( $lesson_id, '_thumbnail_id', true ), |
| 7583 | 'lesson_featured_image_url' => get_the_post_thumbnail_url( $lesson_id ), |
| 7584 | ]; |
| 7585 | |
| 7586 | $lesson_section_id = get_post_meta( $lesson->ID, '_mpcs_lesson_section_id', true ); |
| 7587 | |
| 7588 | $section = $wpdb->get_row( $wpdb->prepare( "SELECT course_id FROM {$wpdb->prefix}mpcs_sections WHERE ID= %s", $lesson_section_id ) ); |
| 7589 | |
| 7590 | $course_data = [ |
| 7591 | 'course_id' => $course_id, |
| 7592 | 'course_title' => get_the_title( $course_id ), |
| 7593 | 'course_url' => get_permalink( $course_id ), |
| 7594 | 'course_featured_image_id' => get_post_meta( $course_id, '_thumbnail_id', true ), |
| 7595 | 'course_featured_image_url' => get_the_post_thumbnail_url( $section->course_id ), |
| 7596 | ]; |
| 7597 | } |
| 7598 | |
| 7599 | $user_progress = $wpdb->get_row( $wpdb->prepare( "SELECT user_id FROM {$wpdb->prefix}mpcs_user_progress WHERE lesson_id= %s AND course_id=%s", $lesson_id, $course_id ) ); |
| 7600 | if ( ! empty( $user_progress ) ) { |
| 7601 | $context['response_type'] = 'live'; |
| 7602 | $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_progress->user_id ), $course_data, $lesson_data ); |
| 7603 | } else { |
| 7604 | $sample_data = '{"pluggable_data":{"wp_user_id":1,"user_login":"suretriggers","display_name":"suretriggers","user_firstname":"suretriggers","user_lastname":"dev","user_email":"hello@suretriggers.com","user_role":["administrator","subscriber","tutor_instructor","bbp_keymaster"],"lesson_id":620,"lesson_title":"second section","lesson_url":"https:\/\/connector.com\/courses\/course-one\/lessons\/second-section\/","lesson_featured_image_id":"","lesson_featured_image_url":false,"course_id":617,"course_title":"Course One","course_url":"https:\/\/connector.com\/courses\/course-one\/","course_featured_image_id":"","course_featured_image_url":false},"response_type":"sample"}'; |
| 7605 | $context = json_decode( $sample_data, true ); |
| 7606 | } |
| 7607 | } |
| 7608 | |
| 7609 | |
| 7610 | return $context; |
| 7611 | } |
| 7612 | |
| 7613 | /** Get GamiPress Rank List. |
| 7614 | * |
| 7615 | * @param array $data data. |
| 7616 | * |
| 7617 | * @return array|void |
| 7618 | */ |
| 7619 | public function search_gp_rank_list( $data ) { |
| 7620 | global $wpdb; |
| 7621 | |
| 7622 | $page = $data['page']; |
| 7623 | $limit = Utilities::get_search_page_limit(); |
| 7624 | $offset = $limit * ( $page - 1 ); |
| 7625 | |
| 7626 | $args = [ |
| 7627 | 'post_type' => $data['dynamic']['rank_type'], |
| 7628 | 'posts_per_page' => $limit, |
| 7629 | 'offset' => $offset, |
| 7630 | 'orderby' => 'title', |
| 7631 | 'order' => 'ASC', |
| 7632 | 'post_status' => 'publish', |
| 7633 | 's' => $data['search_term'], |
| 7634 | ]; |
| 7635 | |
| 7636 | $rank_type = get_posts( $args ); |
| 7637 | |
| 7638 | $count_args = [ |
| 7639 | 'post_type' => $data['dynamic']['rank_type'], |
| 7640 | 'posts_per_page' => -1, |
| 7641 | 'post_status' => 'publish', |
| 7642 | 's' => $data['search_term'], |
| 7643 | ]; |
| 7644 | |
| 7645 | $rank_posts = get_posts( $count_args ); |
| 7646 | $rank_type_count = count( $rank_posts ); |
| 7647 | |
| 7648 | $options = []; |
| 7649 | if ( $rank_type ) { |
| 7650 | foreach ( $rank_type as $rank ) { |
| 7651 | $options[] = [ |
| 7652 | 'label' => $rank->post_title, |
| 7653 | 'value' => $rank->ID, |
| 7654 | ]; |
| 7655 | } |
| 7656 | } |
| 7657 | |
| 7658 | return [ |
| 7659 | 'options' => $options, |
| 7660 | 'hasMore' => $rank_type_count > $limit && $rank_type_count > $offset, |
| 7661 | ]; |
| 7662 | } |
| 7663 | |
| 7664 | /** |
| 7665 | * Get GamiPress PointType List. |
| 7666 | * |
| 7667 | * @param array $data data. |
| 7668 | * |
| 7669 | * @return array|void |
| 7670 | */ |
| 7671 | public function search_gp_point_type_list( $data ) { |
| 7672 | global $wpdb; |
| 7673 | |
| 7674 | $page = $data['page']; |
| 7675 | $limit = Utilities::get_search_page_limit(); |
| 7676 | $offset = $limit * ( $page - 1 ); |
| 7677 | |
| 7678 | $args = [ |
| 7679 | 'post_type' => 'points-type', |
| 7680 | 'posts_per_page' => $limit, |
| 7681 | 'offset' => $offset, |
| 7682 | 'orderby' => 'title', |
| 7683 | 'order' => 'ASC', |
| 7684 | 'post_status' => 'publish', |
| 7685 | 's' => $data['search_term'], |
| 7686 | ]; |
| 7687 | |
| 7688 | $point_type = get_posts( $args ); |
| 7689 | |
| 7690 | $count_args = [ |
| 7691 | 'post_type' => 'points-type', |
| 7692 | 'posts_per_page' => -1, |
| 7693 | 'post_status' => 'publish', |
| 7694 | 's' => $data['search_term'], |
| 7695 | ]; |
| 7696 | |
| 7697 | $count_point_type = get_posts( $count_args ); |
| 7698 | $point_type_count = count( $count_point_type ); |
| 7699 | |
| 7700 | $options = []; |
| 7701 | if ( $point_type ) { |
| 7702 | foreach ( $point_type as $point ) { |
| 7703 | $options[] = [ |
| 7704 | 'label' => $point->post_title, |
| 7705 | 'value' => $point->ID, |
| 7706 | ]; |
| 7707 | } |
| 7708 | } |
| 7709 | |
| 7710 | return [ |
| 7711 | 'options' => $options, |
| 7712 | 'hasMore' => $point_type_count > $limit && $point_type_count > $offset, |
| 7713 | ]; |
| 7714 | } |
| 7715 | |
| 7716 | /** |
| 7717 | * Get GamiPress AchievementType List. |
| 7718 | * |
| 7719 | * @param array $data data. |
| 7720 | * |
| 7721 | * @return array|void |
| 7722 | */ |
| 7723 | public function search_gp_achivement_type_list( $data ) { |
| 7724 | global $wpdb; |
| 7725 | |
| 7726 | $posts = $wpdb->get_results( |
| 7727 | "SELECT ID, post_name, post_title, post_type |
| 7728 | FROM $wpdb->posts |
| 7729 | WHERE post_type LIKE 'achievement-type' AND post_status = 'publish' ORDER BY post_title ASC" |
| 7730 | ); |
| 7731 | |
| 7732 | $posts_count = count( $posts ); |
| 7733 | |
| 7734 | $options = []; |
| 7735 | if ( $posts ) { |
| 7736 | foreach ( $posts as $post ) { |
| 7737 | $options[] = [ |
| 7738 | 'label' => $post->post_title, |
| 7739 | 'value' => $post->post_name, |
| 7740 | ]; |
| 7741 | } |
| 7742 | } |
| 7743 | |
| 7744 | $options[] = [ |
| 7745 | 'label' => 'Points awards', |
| 7746 | 'value' => 'points-award', |
| 7747 | ]; |
| 7748 | $options[] = [ |
| 7749 | 'label' => 'Step', |
| 7750 | 'value' => 'step', |
| 7751 | ]; |
| 7752 | $options[] = [ |
| 7753 | 'label' => 'Rank requirement', |
| 7754 | 'value' => 'rank-requirement', |
| 7755 | ]; |
| 7756 | |
| 7757 | return [ |
| 7758 | 'options' => $options, |
| 7759 | 'hasMore' => false, |
| 7760 | ]; |
| 7761 | } |
| 7762 | |
| 7763 | /** |
| 7764 | * Get GamiPress Award List. |
| 7765 | * |
| 7766 | * @param array $data data. |
| 7767 | * |
| 7768 | * @return array|void |
| 7769 | */ |
| 7770 | public function search_gp_award_list( $data ) { |
| 7771 | global $wpdb; |
| 7772 | |
| 7773 | $page = $data['page']; |
| 7774 | $limit = Utilities::get_search_page_limit(); |
| 7775 | $offset = $limit * ( $page - 1 ); |
| 7776 | |
| 7777 | $args = [ |
| 7778 | 'post_type' => $data['dynamic']['achivement_type'], |
| 7779 | 'posts_per_page' => $limit, |
| 7780 | 'offset' => $offset, |
| 7781 | 'orderby' => 'title', |
| 7782 | 'order' => 'ASC', |
| 7783 | 'post_status' => 'publish', |
| 7784 | 's' => $data['search_term'], |
| 7785 | ]; |
| 7786 | |
| 7787 | $award_type = get_posts( $args ); |
| 7788 | $count_args = [ |
| 7789 | 'post_type' => $data['dynamic']['achivement_type'], |
| 7790 | 'posts_per_page' => -1, |
| 7791 | 'post_status' => 'publish', |
| 7792 | 's' => $data['search_term'], |
| 7793 | ]; |
| 7794 | |
| 7795 | $count_award_type = get_posts( $count_args ); |
| 7796 | $award_type_count = count( $count_award_type ); |
| 7797 | $options = []; |
| 7798 | if ( $award_type ) { |
| 7799 | foreach ( $award_type as $award ) { |
| 7800 | $options[] = [ |
| 7801 | 'label' => $award->post_title, |
| 7802 | 'value' => $award->ID, |
| 7803 | ]; |
| 7804 | } |
| 7805 | } |
| 7806 | |
| 7807 | return [ |
| 7808 | 'options' => $options, |
| 7809 | 'hasMore' => $award_type_count > $limit && $award_type_count > $offset, |
| 7810 | ]; |
| 7811 | } |
| 7812 | |
| 7813 | /** |
| 7814 | * Get Woocommerce Subscription Product List. |
| 7815 | * |
| 7816 | * @param array $data data. |
| 7817 | * |
| 7818 | * @return array|void |
| 7819 | */ |
| 7820 | public function search_wc_subscription_product_list( $data ) { |
| 7821 | global $wpdb; |
| 7822 | |
| 7823 | $subscriptions = $wpdb->get_results( |
| 7824 | $wpdb->prepare( |
| 7825 | "SELECT posts.ID, posts.post_title FROM $wpdb->posts as posts |
| 7826 | LEFT JOIN $wpdb->term_relationships as rel ON (posts.ID = rel.object_id) |
| 7827 | WHERE rel.term_taxonomy_id IN (SELECT term_id FROM $wpdb->terms WHERE slug IN ('subscription','variable-subscription')) |
| 7828 | AND posts.post_type = %s |
| 7829 | AND posts.post_status = %s |
| 7830 | UNION ALL |
| 7831 | SELECT ID, post_title FROM $wpdb->posts |
| 7832 | WHERE post_type = %s |
| 7833 | AND post_status = %s |
| 7834 | ORDER BY post_title", |
| 7835 | 'product', |
| 7836 | 'publish', |
| 7837 | 'shop_subscription', |
| 7838 | 'publish' |
| 7839 | ) |
| 7840 | ); |
| 7841 | |
| 7842 | $options = []; |
| 7843 | if ( $subscriptions ) { |
| 7844 | foreach ( $subscriptions as $post ) { |
| 7845 | $options[] = [ |
| 7846 | 'label' => $post->post_title, |
| 7847 | 'value' => $post->ID, |
| 7848 | ]; |
| 7849 | } |
| 7850 | } |
| 7851 | |
| 7852 | return [ |
| 7853 | 'options' => $options, |
| 7854 | 'hasMore' => false, |
| 7855 | ]; |
| 7856 | } |
| 7857 | |
| 7858 | /** |
| 7859 | * Get Woocommerce Subscriptions Variation list. |
| 7860 | * |
| 7861 | * @param array $data data. |
| 7862 | * |
| 7863 | * @return array|void |
| 7864 | */ |
| 7865 | public function search_wc_variable_subscription_list( $data ) { |
| 7866 | global $wpdb; |
| 7867 | |
| 7868 | $page = $data['page']; |
| 7869 | $limit = Utilities::get_search_page_limit(); |
| 7870 | $offset = $limit * ( $page - 1 ); |
| 7871 | |
| 7872 | if ( ! function_exists( 'wc_get_products' ) ) { |
| 7873 | return; |
| 7874 | } |
| 7875 | $subscription_products = wc_get_products( |
| 7876 | [ |
| 7877 | 'type' => [ 'variable-subscription' ], |
| 7878 | 'posts_per_page' => $limit, |
| 7879 | 'offset' => $offset, |
| 7880 | 'orderby' => 'date', |
| 7881 | 'order' => 'DESC', |
| 7882 | ] |
| 7883 | ); |
| 7884 | |
| 7885 | $subscription_products_count = count( (array) $subscription_products ); |
| 7886 | |
| 7887 | $options = []; |
| 7888 | if ( $subscription_products ) { |
| 7889 | foreach ( (array) $subscription_products as $product ) { |
| 7890 | $options[] = [ |
| 7891 | 'label' => $product->get_title(), |
| 7892 | 'value' => $product->get_id(), |
| 7893 | ]; |
| 7894 | } |
| 7895 | } |
| 7896 | |
| 7897 | return [ |
| 7898 | 'options' => $options, |
| 7899 | 'hasMore' => $subscription_products_count > $limit && $subscription_products_count > $offset, |
| 7900 | ]; |
| 7901 | } |
| 7902 | |
| 7903 | /** |
| 7904 | * Get Woocommerce Variation list. |
| 7905 | * |
| 7906 | * @param array $data data. |
| 7907 | * |
| 7908 | * @return array|void |
| 7909 | */ |
| 7910 | public function search_wc_variation_list( $data ) { |
| 7911 | global $wpdb; |
| 7912 | |
| 7913 | $page = $data['page']; |
| 7914 | $limit = Utilities::get_search_page_limit(); |
| 7915 | $offset = $limit * ( $page - 1 ); |
| 7916 | |
| 7917 | $args = [ |
| 7918 | 'post_type' => 'product_variation', |
| 7919 | 'post_parent' => $data['dynamic']['variable_subscription'], |
| 7920 | 'posts_per_page' => $limit, |
| 7921 | 'offset' => $offset, |
| 7922 | 'orderby' => 'ID', |
| 7923 | 'order' => 'ASC', |
| 7924 | 'post_status' => 'publish', |
| 7925 | ]; |
| 7926 | |
| 7927 | $variation = get_posts( $args ); |
| 7928 | $variation_count = count( $variation ); |
| 7929 | |
| 7930 | $options = []; |
| 7931 | if ( $variation ) { |
| 7932 | foreach ( $variation as $product ) { |
| 7933 | $options[] = [ |
| 7934 | 'label' => ! empty( $product->post_excerpt ) ? $product->post_excerpt : $product->post_title, |
| 7935 | 'value' => $product->ID, |
| 7936 | ]; |
| 7937 | } |
| 7938 | } |
| 7939 | |
| 7940 | return [ |
| 7941 | 'options' => $options, |
| 7942 | 'hasMore' => $variation_count > $limit && $variation_count > $offset, |
| 7943 | ]; |
| 7944 | } |
| 7945 | |
| 7946 | /** |
| 7947 | * Get Membership List. |
| 7948 | * |
| 7949 | * @param array $data data. |
| 7950 | * |
| 7951 | * @return array |
| 7952 | */ |
| 7953 | public function search_membership_list( $data ) { |
| 7954 | global $wpdb; |
| 7955 | |
| 7956 | $levels = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}pmpro_membership_levels ORDER BY id ASC" ); |
| 7957 | $options = []; |
| 7958 | if ( $levels ) { |
| 7959 | foreach ( $levels as $level ) { |
| 7960 | $options[] = [ |
| 7961 | 'label' => $level->name, |
| 7962 | 'value' => $level->id, |
| 7963 | ]; |
| 7964 | } |
| 7965 | } |
| 7966 | |
| 7967 | return [ |
| 7968 | 'options' => $options, |
| 7969 | 'hasMore' => false, |
| 7970 | ]; |
| 7971 | } |
| 7972 | |
| 7973 | /** |
| 7974 | |
| 7975 | * Get EventsManager last data. |
| 7976 | * |
| 7977 | * @param array $data data. |
| 7978 | * |
| 7979 | * @return array |
| 7980 | */ |
| 7981 | public function search_events_manager_data( $data ) { |
| 7982 | global $wpdb; |
| 7983 | $trigger = $data['search_term']; |
| 7984 | $context = []; |
| 7985 | |
| 7986 | $post_id = (int) ( isset( $data['filter']['post_id']['value'] ) ? $data['filter']['post_id']['value'] : '-1' ); |
| 7987 | if ( 'em_user_register_in_event' === $trigger ) { |
| 7988 | if ( $post_id > 0 ) { |
| 7989 | $event_id_id = get_post_meta( $post_id, '_event_id', true ); |
| 7990 | $all_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status NOT IN (2,3) AND b.event_id = %s AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1", $event_id_id ) ); |
| 7991 | } else { |
| 7992 | $all_bookings = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status NOT IN (2,3) AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1" ); |
| 7993 | |
| 7994 | } |
| 7995 | |
| 7996 | if ( ! empty( $all_bookings ) ) { |
| 7997 | $user_id = $all_bookings->person_id; |
| 7998 | $location = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_locations as b WHERE b.location_id = %s", $all_bookings->location_id ) ); |
| 7999 | $context['pluggable_data'] = array_merge( |
| 8000 | WordPress::get_user_context( $user_id ), |
| 8001 | json_decode( wp_json_encode( $all_bookings ), true ) |
| 8002 | ); |
| 8003 | if ( ! empty( $location ) ) { |
| 8004 | $context['pluggable_data'] = array_merge( $context['pluggable_data'], json_decode( wp_json_encode( $location ), true ) ); |
| 8005 | } |
| 8006 | |
| 8007 | $context['response_type'] = 'live'; |
| 8008 | } |
| 8009 | } elseif ( 'em_user_unregister_from_event' === $trigger ) { |
| 8010 | |
| 8011 | if ( $post_id > 0 ) { |
| 8012 | $event_id_id = get_post_meta( $post_id, '_event_id', true ); |
| 8013 | $all_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status IN (2,3) AND b.event_id = %s AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1", $event_id_id ) ); |
| 8014 | } else { |
| 8015 | $all_bookings = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status IN (2,3) AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1" ); |
| 8016 | |
| 8017 | } |
| 8018 | |
| 8019 | if ( ! empty( $all_bookings ) ) { |
| 8020 | $user_id = $all_bookings->person_id; |
| 8021 | $context['pluggable_data'] = array_merge( |
| 8022 | WordPress::get_user_context( $user_id ), |
| 8023 | json_decode( wp_json_encode( $all_bookings ), true ) |
| 8024 | ); |
| 8025 | $context['response_type'] = 'live'; |
| 8026 | } |
| 8027 | } elseif ( 'em_user_booking_approved' === $trigger ) { |
| 8028 | |
| 8029 | if ( $post_id > 0 ) { |
| 8030 | $event_id_id = get_post_meta( $post_id, '_event_id', true ); |
| 8031 | $all_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status=1 AND b.event_id = %s AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1", $event_id_id ) ); |
| 8032 | } else { |
| 8033 | $all_bookings = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status=1 AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1" ); |
| 8034 | |
| 8035 | } |
| 8036 | |
| 8037 | if ( ! empty( $all_bookings ) ) { |
| 8038 | $user_id = $all_bookings->person_id; |
| 8039 | $location = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_locations as b WHERE b.location_id = %s", $all_bookings->location_id ) ); |
| 8040 | $context['pluggable_data'] = array_merge( |
| 8041 | WordPress::get_user_context( $user_id ), |
| 8042 | json_decode( wp_json_encode( $all_bookings ), true ) |
| 8043 | ); |
| 8044 | if ( ! empty( $location ) ) { |
| 8045 | $context['pluggable_data'] = array_merge( $context['pluggable_data'], json_decode( wp_json_encode( $location ), true ) ); |
| 8046 | } |
| 8047 | |
| 8048 | $context['response_type'] = 'live'; |
| 8049 | |
| 8050 | } |
| 8051 | } |
| 8052 | return $context; |
| 8053 | } |
| 8054 | |
| 8055 | /** |
| 8056 | |
| 8057 | * Get learnpress last data. |
| 8058 | * |
| 8059 | * @param array $data data. |
| 8060 | * |
| 8061 | * @return array |
| 8062 | */ |
| 8063 | public function search_learnpress_lms_last_data( $data ) { |
| 8064 | global $wpdb; |
| 8065 | $trigger = $data['search_term']; |
| 8066 | $course_data = []; |
| 8067 | $lesson_data = []; |
| 8068 | $context = []; |
| 8069 | |
| 8070 | |
| 8071 | if ( 'learnpress_course_completed' === $trigger ) { |
| 8072 | $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course']['value'] : '-1' ); |
| 8073 | if ( $course_id > 0 ) { |
| 8074 | |
| 8075 | $course = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_id= %s && user_id>0 && status= 'finished' ORDER BY item_id DESC LIMIT 1", $course_id ) ); |
| 8076 | } else { |
| 8077 | |
| 8078 | $course = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_type= 'lp_course' && user_id>0 && status= 'finished' ORDER BY item_id DESC LIMIT 1" ); |
| 8079 | } |
| 8080 | |
| 8081 | if ( ! empty( $course ) ) { |
| 8082 | $course_data = array_merge( WordPress::get_user_context( $course->user_id ), LearnPress::get_lpc_course_context( $course->item_id ) ); |
| 8083 | $context['response_type'] = 'live'; |
| 8084 | $context['pluggable_data'] = $course_data; |
| 8085 | } |
| 8086 | } elseif ( 'learnpress_lesson_completed' === $trigger ) { |
| 8087 | $lesson_id = (int) ( isset( $data['filter']['lesson']['value'] ) ? $data['filter']['lesson']['value'] : '-1' ); |
| 8088 | if ( $lesson_id > 0 ) { |
| 8089 | |
| 8090 | $lesson = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_id= %s && user_id>0 && status= 'completed' ORDER BY item_id DESC LIMIT 1", $lesson_id ) ); |
| 8091 | } else { |
| 8092 | |
| 8093 | $lesson = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_type= 'lp_lesson' && user_id>0 && status= 'completed' ORDER BY item_id DESC LIMIT 1" ); |
| 8094 | } |
| 8095 | |
| 8096 | if ( ! empty( $lesson ) ) { |
| 8097 | $lesson_data = array_merge( WordPress::get_user_context( $lesson->user_id ), LearnPress::get_lpc_lesson_context( $lesson->item_id ), LearnPress::get_lpc_course_context( $lesson->ref_id ) ); |
| 8098 | $context['response_type'] = 'live'; |
| 8099 | $context['pluggable_data'] = $lesson_data; |
| 8100 | } |
| 8101 | } elseif ( 'learnpress_user_enrolled_in_course' === $trigger ) { |
| 8102 | $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course']['value'] : '-1' ); |
| 8103 | if ( $course_id > 0 ) { |
| 8104 | |
| 8105 | $course = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_id= %s && status= 'enrolled' ORDER BY item_id DESC LIMIT 1", $course_id ) ); |
| 8106 | } else { |
| 8107 | |
| 8108 | $course = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_type= 'lp_course' && user_id>0 && status= 'enrolled' ORDER BY item_id DESC LIMIT 1" ); |
| 8109 | } |
| 8110 | |
| 8111 | if ( ! empty( $course ) ) { |
| 8112 | $course_data = array_merge( WordPress::get_user_context( $course->user_id ), LearnPress::get_lpc_course_context( $course->item_id ) ); |
| 8113 | $context['response_type'] = 'live'; |
| 8114 | $context['pluggable_data'] = $course_data; |
| 8115 | |
| 8116 | } |
| 8117 | } |
| 8118 | |
| 8119 | return $context; |
| 8120 | } |
| 8121 | |
| 8122 | /** |
| 8123 | * Get Woocommerce Memberships Plan List. |
| 8124 | * |
| 8125 | * @param array $data data. |
| 8126 | * |
| 8127 | * @return array|void |
| 8128 | */ |
| 8129 | public function search_wc_membership_plan_list( $data ) { |
| 8130 | global $wpdb; |
| 8131 | |
| 8132 | $page = $data['page']; |
| 8133 | $limit = Utilities::get_search_page_limit(); |
| 8134 | $offset = $limit * ( $page - 1 ); |
| 8135 | |
| 8136 | $args = [ |
| 8137 | 'post_type' => 'wc_membership_plan', |
| 8138 | 'posts_per_page' => $limit, |
| 8139 | 'offset' => $offset, |
| 8140 | 'orderby' => 'title', |
| 8141 | 'order' => 'ASC', |
| 8142 | 'post_status' => 'publish', |
| 8143 | 'fields' => 'ids', |
| 8144 | ]; |
| 8145 | $loop = new WP_Query( $args ); |
| 8146 | |
| 8147 | $plans = (array) $loop->posts; |
| 8148 | $plans_count = count( $plans ); |
| 8149 | |
| 8150 | $options = []; |
| 8151 | if ( ! empty( $plans ) ) { |
| 8152 | if ( is_array( $plans ) ) { |
| 8153 | foreach ( $plans as $plan_id ) { |
| 8154 | $options[] = [ |
| 8155 | 'label' => get_the_title( $plan_id ), |
| 8156 | 'value' => $plan_id, |
| 8157 | ]; |
| 8158 | } |
| 8159 | } |
| 8160 | } |
| 8161 | |
| 8162 | return [ |
| 8163 | 'options' => $options, |
| 8164 | 'hasMore' => $plans_count > $limit && $plans_count > $offset, |
| 8165 | ]; |
| 8166 | } |
| 8167 | |
| 8168 | /** |
| 8169 | * Get BuddyPress Private group. |
| 8170 | * |
| 8171 | * @param array $data data. |
| 8172 | * |
| 8173 | * @return array|void |
| 8174 | */ |
| 8175 | public function search_bp_private_group_list( $data ) { |
| 8176 | global $wpdb; |
| 8177 | |
| 8178 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups WHERE status = 'private'" ); |
| 8179 | |
| 8180 | $options = []; |
| 8181 | if ( $groups ) { |
| 8182 | foreach ( $groups as $group ) { |
| 8183 | $options[] = [ |
| 8184 | 'label' => $group->name, |
| 8185 | 'value' => $group->id, |
| 8186 | ]; |
| 8187 | } |
| 8188 | } |
| 8189 | |
| 8190 | return [ |
| 8191 | 'options' => $options, |
| 8192 | 'hasMore' => false, |
| 8193 | ]; |
| 8194 | } |
| 8195 | |
| 8196 | /** |
| 8197 | * Get BuddyPress Public group. |
| 8198 | * |
| 8199 | * @param array $data data. |
| 8200 | * |
| 8201 | * @return array|void |
| 8202 | */ |
| 8203 | public function search_bp_public_group_list( $data ) { |
| 8204 | global $wpdb; |
| 8205 | |
| 8206 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups WHERE status = 'public'" ); |
| 8207 | |
| 8208 | $options = []; |
| 8209 | if ( $groups ) { |
| 8210 | foreach ( $groups as $group ) { |
| 8211 | $options[] = [ |
| 8212 | 'label' => $group->name, |
| 8213 | 'value' => $group->id, |
| 8214 | ]; |
| 8215 | } |
| 8216 | } |
| 8217 | |
| 8218 | return [ |
| 8219 | 'options' => $options, |
| 8220 | 'hasMore' => false, |
| 8221 | ]; |
| 8222 | } |
| 8223 | |
| 8224 | /** |
| 8225 | * Get BuddyPress group. |
| 8226 | * |
| 8227 | * @param array $data data. |
| 8228 | * |
| 8229 | * @return array|void |
| 8230 | */ |
| 8231 | public function search_bp_group_list( $data ) { |
| 8232 | global $wpdb; |
| 8233 | |
| 8234 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups" ); |
| 8235 | |
| 8236 | $options = []; |
| 8237 | if ( $groups ) { |
| 8238 | foreach ( $groups as $group ) { |
| 8239 | $options[] = [ |
| 8240 | 'label' => $group->name, |
| 8241 | 'value' => $group->id, |
| 8242 | ]; |
| 8243 | } |
| 8244 | } |
| 8245 | |
| 8246 | return [ |
| 8247 | 'options' => $options, |
| 8248 | 'hasMore' => false, |
| 8249 | ]; |
| 8250 | } |
| 8251 | |
| 8252 | /** |
| 8253 | * Get BuddyPress field. |
| 8254 | * |
| 8255 | * @param array $data data. |
| 8256 | * |
| 8257 | * @return array|void |
| 8258 | */ |
| 8259 | public function search_bp_field_list( $data ) { |
| 8260 | global $wpdb; |
| 8261 | |
| 8262 | $base_group_id = 1; |
| 8263 | if ( function_exists( 'bp_xprofile_base_group_id' ) ) { |
| 8264 | $base_group_id = bp_xprofile_base_group_id(); |
| 8265 | } |
| 8266 | |
| 8267 | $xprofile_fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}bp_xprofile_fields WHERE parent_id = 0 AND group_id = %d ORDER BY field_order ASC", $base_group_id ) ); |
| 8268 | |
| 8269 | $options = []; |
| 8270 | if ( ! empty( $xprofile_fields ) ) { |
| 8271 | foreach ( $xprofile_fields as $xprofile_field ) { |
| 8272 | $options[] = [ |
| 8273 | 'label' => $xprofile_field->name, |
| 8274 | 'value' => $xprofile_field->id, |
| 8275 | ]; |
| 8276 | } |
| 8277 | } |
| 8278 | |
| 8279 | return [ |
| 8280 | 'options' => $options, |
| 8281 | 'hasMore' => false, |
| 8282 | ]; |
| 8283 | } |
| 8284 | |
| 8285 | /** |
| 8286 | * Get BuddyPress member type. |
| 8287 | * |
| 8288 | * @param array $data data. |
| 8289 | * |
| 8290 | * @return array|void |
| 8291 | */ |
| 8292 | public function search_bp_member_type_list( $data ) { |
| 8293 | $options = []; |
| 8294 | if ( function_exists( 'bp_get_member_types' ) ) { |
| 8295 | $types = bp_get_member_types( [] ); |
| 8296 | if ( $types ) { |
| 8297 | foreach ( $types as $key => $type ) { |
| 8298 | $options[] = [ |
| 8299 | 'label' => $type, |
| 8300 | 'value' => $key, |
| 8301 | ]; |
| 8302 | } |
| 8303 | } |
| 8304 | } |
| 8305 | |
| 8306 | return [ |
| 8307 | 'options' => $options, |
| 8308 | 'hasMore' => false, |
| 8309 | ]; |
| 8310 | } |
| 8311 | |
| 8312 | /** |
| 8313 | * Get last data for WP All Import. |
| 8314 | * |
| 8315 | * @param array $data data. |
| 8316 | * @return mixed |
| 8317 | */ |
| 8318 | public function search_wp_all_import_last_data( $data ) { |
| 8319 | global $wpdb; |
| 8320 | $post_type = $data['filter']['post_type']['value']; |
| 8321 | $trigger = $data['search_term']; |
| 8322 | |
| 8323 | if ( 'wp_all_import_post_type_imported' === $trigger ) { |
| 8324 | if ( -1 == $post_type ) { |
| 8325 | $imports = $wpdb->get_row( "SELECT post_id FROM {$wpdb->prefix}pmxi_posts ORDER BY id DESC LIMIT 1", ARRAY_A ); |
| 8326 | $posts[0] = $imports['post_id']; |
| 8327 | } else { |
| 8328 | $imports = $wpdb->get_results( "SELECT post_id FROM {$wpdb->prefix}pmxi_posts", ARRAY_A ); |
| 8329 | $imports = array_column( $imports, 'post_id' ); |
| 8330 | $args = [ |
| 8331 | 'posts_per_page' => 1, |
| 8332 | 'post_type' => $post_type, |
| 8333 | 'post__in' => $imports, |
| 8334 | ]; |
| 8335 | $posts = get_posts( $args ); |
| 8336 | } |
| 8337 | } elseif ( 'wp_all_import_completed' === $trigger ) { |
| 8338 | $imports = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}pmxi_imports WHERE failed = 0 ORDER BY id DESC LIMIT 1", ARRAY_A ); |
| 8339 | } elseif ( 'wp_all_import_failed' === $trigger ) { |
| 8340 | $imports = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}pmxi_imports WHERE failed = 1 ORDER BY id DESC LIMIT 1", ARRAY_A ); |
| 8341 | } |
| 8342 | |
| 8343 | if ( 'wp_all_import_post_type_imported' === $trigger && empty( $imports ) ) { |
| 8344 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"ID": 1,"post_author": "1","post_date": "2023-07-12 06:31:35","post_date_gmt": "2023-07-12 06:31:35","post_content": "","post_title": "Test","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "test","to_ping": "","pinged": "","post_modified": "2023-07-12 06:31:35","post_modified_gmt": "2023-07-12 06:31:35","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example.com\/test\/","menu_order": 0,"post_type": "post","post_mime_type": "","comment_count": "0","filter": "raw"}}', true ); |
| 8345 | return $context; |
| 8346 | } elseif ( empty( $imports ) ) { |
| 8347 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id": "1","parent_import_id": "0","name": "demowpinstawpxyz.WordPress.2023_07_12.xml","friendly_name": "","type": "upload","feed_type": "","path": "\/wpallimport\/uploads\/ee8816eebf7a373454cdd1189c831241\/demowpinstawpxyz.WordPress.2023_07_12.xml","xpath": "\/rss","registered_on": "2023-07-12 05:10:29","root_element": "rss","processing": "0","executing": "0","triggered": "0","queue_chunk_number": "0","first_import": "2023-07-12 05:09:41","count": "1","imported": "0","created": "0","updated": "0","skipped": "1","deleted": "0","changed_missing": "0","canceled": "0","canceled_on": "0000-00-00 00:00:00","failed": "0","failed_on": "0000-00-00 00:00:00","settings_update_on": "0000-00-00 00:00:00","last_activity": "2023-07-12 05:10:24","iteration": "1"}}', true ); |
| 8348 | return $context; |
| 8349 | } |
| 8350 | |
| 8351 | $context['response_type'] = 'live'; |
| 8352 | if ( ! empty( $posts ) ) { |
| 8353 | $context['pluggable_data'] = WordPress::get_post_context( $posts[0] ); |
| 8354 | } else { |
| 8355 | $context['pluggable_data'] = $imports; |
| 8356 | } |
| 8357 | |
| 8358 | return $context; |
| 8359 | } |
| 8360 | |
| 8361 | /** |
| 8362 | * Get Wp Simple Pay Forms. |
| 8363 | * |
| 8364 | * @param array $data data. |
| 8365 | * |
| 8366 | * @return array |
| 8367 | */ |
| 8368 | public function search_wp_simple_pay_forms( $data ) { |
| 8369 | |
| 8370 | $page = $data['page']; |
| 8371 | $limit = Utilities::get_search_page_limit(); |
| 8372 | $offset = $limit * ( $page - 1 ); |
| 8373 | |
| 8374 | $forms = get_posts( |
| 8375 | [ |
| 8376 | 'post_type' => 'simple-pay', |
| 8377 | 'posts_per_page' => $limit, |
| 8378 | 'offset' => $offset, |
| 8379 | 'fields' => 'ids', |
| 8380 | ] |
| 8381 | ); |
| 8382 | |
| 8383 | $forms_count = count( $forms ); |
| 8384 | |
| 8385 | $options = []; |
| 8386 | |
| 8387 | if ( ! empty( $forms ) ) { |
| 8388 | foreach ( $forms as $form_id ) { |
| 8389 | if ( function_exists( 'simpay_get_form' ) ) { |
| 8390 | $form = simpay_get_form( $form_id ); |
| 8391 | $options[] = [ |
| 8392 | 'label' => null !== get_the_title( $form_id ) ? $form->company_name : get_the_title( $form_id ), |
| 8393 | 'value' => $form_id, |
| 8394 | ]; |
| 8395 | } |
| 8396 | } |
| 8397 | } |
| 8398 | |
| 8399 | return [ |
| 8400 | 'options' => $options, |
| 8401 | 'hasMore' => $forms_count > $limit && $forms_count > $offset, |
| 8402 | ]; |
| 8403 | } |
| 8404 | |
| 8405 | /** |
| 8406 | * Get Post list as per post type for metabox. |
| 8407 | * |
| 8408 | * @param array $data data. |
| 8409 | * |
| 8410 | * @return array |
| 8411 | */ |
| 8412 | public function search_mb_posts_list( $data ) { |
| 8413 | |
| 8414 | $page = $data['page']; |
| 8415 | $limit = Utilities::get_search_page_limit(); |
| 8416 | $offset = $limit * ( $page - 1 ); |
| 8417 | |
| 8418 | $posts = get_posts( |
| 8419 | [ |
| 8420 | 'post_type' => $data['dynamic'], |
| 8421 | 'posts_per_page' => $limit, |
| 8422 | 'offset' => $offset, |
| 8423 | 'fields' => 'ids', |
| 8424 | ] |
| 8425 | ); |
| 8426 | |
| 8427 | $all_posts = get_posts( |
| 8428 | [ |
| 8429 | 'post_type' => $data['dynamic'], |
| 8430 | 'posts_per_page' => -1, |
| 8431 | 'fields' => 'ids', |
| 8432 | ] |
| 8433 | ); |
| 8434 | |
| 8435 | $posts_count = count( $all_posts ); |
| 8436 | |
| 8437 | $options = []; |
| 8438 | |
| 8439 | if ( ! empty( $posts ) ) { |
| 8440 | foreach ( $posts as $post ) { |
| 8441 | $options[] = [ |
| 8442 | 'label' => get_the_title( $post ), |
| 8443 | 'value' => $post, |
| 8444 | ]; |
| 8445 | } |
| 8446 | } |
| 8447 | |
| 8448 | return [ |
| 8449 | 'options' => $options, |
| 8450 | 'hasMore' => $posts_count > $limit && $posts_count > $offset, |
| 8451 | ]; |
| 8452 | } |
| 8453 | |
| 8454 | /** |
| 8455 | * Get Metabox Custom box in Post list. |
| 8456 | * |
| 8457 | * @param array $data data. |
| 8458 | * |
| 8459 | * @return array |
| 8460 | */ |
| 8461 | public function search_mb_field_list( $data ) { |
| 8462 | |
| 8463 | if ( ! function_exists( 'rwmb_get_object_fields' ) ) { |
| 8464 | return []; |
| 8465 | } |
| 8466 | |
| 8467 | $options = []; |
| 8468 | |
| 8469 | $metabox_fields = (array) rwmb_get_object_fields( $data['dynamic'] ); |
| 8470 | |
| 8471 | foreach ( $metabox_fields as $metabox_field ) { |
| 8472 | |
| 8473 | if ( ! empty( $metabox_field['id'] ) && ! empty( $metabox_field['name'] ) ) { |
| 8474 | |
| 8475 | $options[] = [ |
| 8476 | 'label' => $metabox_field['name'], |
| 8477 | 'value' => $metabox_field['id'], |
| 8478 | ]; |
| 8479 | |
| 8480 | } |
| 8481 | } |
| 8482 | |
| 8483 | return [ |
| 8484 | 'options' => $options, |
| 8485 | 'hasMore' => false, |
| 8486 | ]; |
| 8487 | } |
| 8488 | |
| 8489 | /** |
| 8490 | * Get Metabox Custom box user list. |
| 8491 | * |
| 8492 | * @param array $data data. |
| 8493 | * |
| 8494 | * @return array |
| 8495 | */ |
| 8496 | public function search_mb_user_field_list( $data ) { |
| 8497 | |
| 8498 | if ( ! function_exists( 'rwmb_get_object_fields' ) ) { |
| 8499 | return []; |
| 8500 | } |
| 8501 | |
| 8502 | $options = []; |
| 8503 | |
| 8504 | $metabox_fields = (array) rwmb_get_object_fields( null, 'user' ); |
| 8505 | |
| 8506 | foreach ( $metabox_fields as $metabox_field ) { |
| 8507 | |
| 8508 | if ( ! empty( $metabox_field['id'] ) && ! empty( $metabox_field['name'] ) ) { |
| 8509 | |
| 8510 | $options[] = [ |
| 8511 | 'label' => $metabox_field['name'], |
| 8512 | 'value' => $metabox_field['id'], |
| 8513 | ]; |
| 8514 | |
| 8515 | } |
| 8516 | } |
| 8517 | |
| 8518 | return [ |
| 8519 | 'options' => $options, |
| 8520 | 'hasMore' => false, |
| 8521 | ]; |
| 8522 | } |
| 8523 | |
| 8524 | /** |
| 8525 | * Search Last Updated Field Data for MetaBox. |
| 8526 | * |
| 8527 | * @param array $data data. |
| 8528 | * @return array |
| 8529 | */ |
| 8530 | public function search_meta_box_field_data( $data ) { |
| 8531 | global $wpdb; |
| 8532 | |
| 8533 | $context = []; |
| 8534 | |
| 8535 | $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); |
| 8536 | |
| 8537 | $post_type = $data['filter']['wp_post_type']['value']; |
| 8538 | $post = $data['filter']['wp_post']['value']; |
| 8539 | |
| 8540 | if ( -1 === $field ) { |
| 8541 | if ( function_exists( 'rwmb_get_object_fields' ) ) { |
| 8542 | $metaboxes = rwmb_get_object_fields( $post_type ); |
| 8543 | |
| 8544 | if ( ! empty( $metaboxes ) ) { |
| 8545 | $random_key = array_rand( $metaboxes ); |
| 8546 | $field = $random_key; |
| 8547 | } else { |
| 8548 | $result = ''; |
| 8549 | } |
| 8550 | } |
| 8551 | } else { |
| 8552 | $field = $data['filter']['field_id']['value']; |
| 8553 | } |
| 8554 | |
| 8555 | if ( function_exists( 'rwmb_meta' ) ) { |
| 8556 | $result = rwmb_meta( $field, '', $post ); |
| 8557 | } |
| 8558 | |
| 8559 | $response = []; |
| 8560 | if ( ! empty( $result ) ) { |
| 8561 | $response['pluggable_data'] = array_merge( [ $field => $result ], WordPress::get_post_context( $post ) ); |
| 8562 | $response['response_type'] = 'live'; |
| 8563 | } else { |
| 8564 | $response = json_decode( '{"response_type":"sample","pluggable_data":{"custom_description": "custom message", "ID": 1, "post_author": "1", "post_date": "2023-05-31 13:26:24", "post_date_gmt": "2023-05-31 13:26:24", "post_content": "", "post_title": "Test", "post_excerpt": "", "post_status": "publish", "comment_status": "open", "ping_status": "open", "post_password": "", "post_name": "test", "to_ping": "", "pinged": "", "post_modified": "2023-08-17 09:15:56", "post_modified_gmt": "2023-08-17 09:15:56", "post_content_filtered": "", "post_parent": 0, "guid": "https:\/\/example.com\/?p=1", "menu_order": 0, "post_type": "post", "post_mime_type": "", "comment_count": "2", "filter": "raw"}}', true ); |
| 8565 | } |
| 8566 | |
| 8567 | return $response; |
| 8568 | } |
| 8569 | |
| 8570 | /** |
| 8571 | * Search Last Updated User Field Data MetaBox. |
| 8572 | * |
| 8573 | * @param array $data data. |
| 8574 | * @return array |
| 8575 | */ |
| 8576 | public function search_user_meta_box_field_data( $data ) { |
| 8577 | global $wpdb; |
| 8578 | |
| 8579 | $context = []; |
| 8580 | |
| 8581 | $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); |
| 8582 | |
| 8583 | if ( -1 === $field ) { |
| 8584 | if ( function_exists( 'rwmb_get_object_fields' ) ) { |
| 8585 | $metabox_fields = (array) rwmb_get_object_fields( null, 'user' ); |
| 8586 | |
| 8587 | if ( ! empty( $metabox_fields ) ) { |
| 8588 | $random_key = array_rand( $metabox_fields ); |
| 8589 | $field = $random_key; |
| 8590 | } else { |
| 8591 | $result = ''; |
| 8592 | } |
| 8593 | } |
| 8594 | } else { |
| 8595 | $field = $data['filter']['field_id']['value']; |
| 8596 | } |
| 8597 | |
| 8598 | $users = get_users( |
| 8599 | [ |
| 8600 | 'fields' => 'ID', |
| 8601 | 'meta_key' => $field, |
| 8602 | ] |
| 8603 | ); |
| 8604 | |
| 8605 | if ( ! empty( $users ) ) { |
| 8606 | $user_random_key = array_rand( $users ); |
| 8607 | $user_id = $user_random_key; |
| 8608 | if ( function_exists( 'rwmb_get_value' ) ) { |
| 8609 | $result = rwmb_get_value( $field, [ 'object_type' => 'user' ], $users[ $user_id ] ); |
| 8610 | } |
| 8611 | |
| 8612 | $response = []; |
| 8613 | if ( ! empty( $result ) ) { |
| 8614 | $context = [ |
| 8615 | 'field_id' => $field, |
| 8616 | $field => $result, |
| 8617 | 'user' => WordPress::get_user_context( $users[ $user_id ] ), |
| 8618 | ]; |
| 8619 | $response['pluggable_data'] = $context; |
| 8620 | $response['response_type'] = 'live'; |
| 8621 | } else { |
| 8622 | $response = json_decode( |
| 8623 | '{ |
| 8624 | "response_type": "sample", |
| 8625 | "pluggable_data": { |
| 8626 | "field_id": "gender", |
| 8627 | "user": { |
| 8628 | "wp_user_id": 114, |
| 8629 | "user_login": "test", |
| 8630 | "display_name": "test", |
| 8631 | "user_firstname": "test", |
| 8632 | "user_lastname": "test", |
| 8633 | "user_email": "test@test.com", |
| 8634 | "user_role": [ "subscriber" ] |
| 8635 | } |
| 8636 | } |
| 8637 | }', |
| 8638 | true |
| 8639 | ); |
| 8640 | } |
| 8641 | } else { |
| 8642 | $response = json_decode( |
| 8643 | '{ |
| 8644 | "response_type": "sample", |
| 8645 | "pluggable_data": { |
| 8646 | "field_id": "gender", |
| 8647 | "user": { |
| 8648 | "wp_user_id": 114, |
| 8649 | "user_login": "test", |
| 8650 | "display_name": "test", |
| 8651 | "user_firstname": "test", |
| 8652 | "user_lastname": "test", |
| 8653 | "user_email": "test@test.com", |
| 8654 | "user_role": [ "subscriber" ] |
| 8655 | } |
| 8656 | } |
| 8657 | }', |
| 8658 | true |
| 8659 | ); |
| 8660 | } |
| 8661 | |
| 8662 | return $response; |
| 8663 | } |
| 8664 | |
| 8665 | /** |
| 8666 | * Search forms of Pie Forms. |
| 8667 | * |
| 8668 | * @param array $data data. |
| 8669 | * @return array |
| 8670 | */ |
| 8671 | public function search_wp_polls_list( $data ) { |
| 8672 | global $wpdb; |
| 8673 | $options = []; |
| 8674 | |
| 8675 | if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'pollsq' ) ) ) { |
| 8676 | |
| 8677 | $results = $wpdb->get_results( 'SELECT pollq_id, pollq_question FROM ' . $wpdb->prefix . 'pollsq WHERE pollq_active = 1' ); |
| 8678 | |
| 8679 | if ( $results ) { |
| 8680 | foreach ( $results as $result ) { |
| 8681 | $options[] = [ |
| 8682 | 'label' => $result->pollq_question, |
| 8683 | 'value' => $result->pollq_id, |
| 8684 | ]; |
| 8685 | } |
| 8686 | } |
| 8687 | } |
| 8688 | |
| 8689 | return [ |
| 8690 | 'options' => $options, |
| 8691 | 'hasMore' => false, |
| 8692 | ]; |
| 8693 | } |
| 8694 | |
| 8695 | /** |
| 8696 | * Search answers of WP-Polls questions. |
| 8697 | * |
| 8698 | * @param array $data data. |
| 8699 | * @return array |
| 8700 | */ |
| 8701 | public function search_wp_polls_answers( $data ) { |
| 8702 | global $wpdb; |
| 8703 | |
| 8704 | $options = []; |
| 8705 | $poll_id = $data['dynamic']; |
| 8706 | |
| 8707 | if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'pollsa' ) ) ) { |
| 8708 | |
| 8709 | if ( '-1' !== $poll_id ) { |
| 8710 | $results = $wpdb->get_results( $wpdb->prepare( 'SELECT polla_aid, polla_answers FROM ' . $wpdb->prefix . 'pollsa WHERE polla_qid = %d', $poll_id ) ); |
| 8711 | } else { |
| 8712 | $results = $wpdb->get_results( 'SELECT polla_aid, polla_answers FROM ' . $wpdb->prefix . 'pollsa' ); |
| 8713 | } |
| 8714 | |
| 8715 | if ( $results ) { |
| 8716 | foreach ( $results as $result ) { |
| 8717 | $options[] = [ |
| 8718 | 'label' => $result->polla_answers, |
| 8719 | 'value' => $result->polla_aid, |
| 8720 | ]; |
| 8721 | } |
| 8722 | } |
| 8723 | } |
| 8724 | |
| 8725 | return [ |
| 8726 | 'options' => $options, |
| 8727 | 'hasMore' => false, |
| 8728 | ]; |
| 8729 | } |
| 8730 | |
| 8731 | /** |
| 8732 | * Get last data for trigger. |
| 8733 | * |
| 8734 | * @param array $data data. |
| 8735 | * @return array |
| 8736 | */ |
| 8737 | public function search_wp_polls_triggers_last_data( $data ) { |
| 8738 | global $wpdb; |
| 8739 | |
| 8740 | $context = []; |
| 8741 | $context['response_type'] = 'sample'; |
| 8742 | |
| 8743 | $poll = [ |
| 8744 | 'poll_id' => 1, |
| 8745 | 'question' => 'Which skills are you interested to learn?', |
| 8746 | 'answers' => 'Web Development, Graphic Designing, Content Writing, Digital Marketing', |
| 8747 | 'start_date' => '2023-08-29 17:19:13', |
| 8748 | 'end_date' => 'Not set', |
| 8749 | 'selected_answers' => 'Content Writing, Web Development', |
| 8750 | 'selected_answer_id' => 2, |
| 8751 | ]; |
| 8752 | |
| 8753 | $poll_data = $wpdb->get_row( "SELECT pollip_qid AS poll_id, pollip_aid AS answer_id FROM {$wpdb->prefix}pollsip ORDER BY pollip_id DESC LIMIT 1" ); |
| 8754 | |
| 8755 | if ( ! empty( $poll_data ) ) { |
| 8756 | $poll = WpPolls::get_poll_context( (string) $poll_data->answer_id, (int) $poll_data->poll_id ); |
| 8757 | $poll['selected_answer_id'] = (int) $poll_data->answer_id; |
| 8758 | |
| 8759 | $context['response_type'] = 'live'; |
| 8760 | } |
| 8761 | |
| 8762 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 8763 | |
| 8764 | if ( 'poll_submitted' === $term ) { |
| 8765 | unset( $poll['selected_answer_id'] ); |
| 8766 | } |
| 8767 | |
| 8768 | $context['pluggable_data'] = $poll; |
| 8769 | |
| 8770 | return $context; |
| 8771 | } |
| 8772 | |
| 8773 | /** |
| 8774 | * Get ACF Custom fields list. |
| 8775 | * |
| 8776 | * @param array $data data. |
| 8777 | * |
| 8778 | * @return array |
| 8779 | */ |
| 8780 | public function search_acf_post_field_list( $data ) { |
| 8781 | |
| 8782 | $post_id = $data['dynamic']; |
| 8783 | |
| 8784 | $args = [ |
| 8785 | 'post_id' => $post_id, |
| 8786 | ]; |
| 8787 | if ( ! is_numeric( $post_id ) ) { |
| 8788 | $args = [ |
| 8789 | 'post_type' => $post_id, |
| 8790 | ]; |
| 8791 | } |
| 8792 | $options = []; |
| 8793 | if ( function_exists( 'acf_get_field_groups' ) ) { |
| 8794 | $field_groups_collection = acf_get_field_groups( $args ); |
| 8795 | foreach ( $field_groups_collection as $field_group ) { |
| 8796 | if ( function_exists( 'acf_get_fields' ) ) { |
| 8797 | $field_groups[] = acf_get_fields( $field_group['key'] ); |
| 8798 | } |
| 8799 | } |
| 8800 | |
| 8801 | if ( ! empty( $field_groups ) && is_array( $field_groups ) ) { |
| 8802 | foreach ( $field_groups as $field_groups ) { |
| 8803 | foreach ( $field_groups as $field_group ) { |
| 8804 | $options[] = [ |
| 8805 | 'value' => $field_group['name'], |
| 8806 | 'label' => $field_group['label'], |
| 8807 | ]; |
| 8808 | } |
| 8809 | } |
| 8810 | } |
| 8811 | } |
| 8812 | |
| 8813 | return [ |
| 8814 | 'options' => $options, |
| 8815 | 'hasMore' => false, |
| 8816 | ]; |
| 8817 | } |
| 8818 | |
| 8819 | /** |
| 8820 | * Get ACF Custom fields list. |
| 8821 | * |
| 8822 | * @param array $data data. |
| 8823 | * |
| 8824 | * @return array |
| 8825 | */ |
| 8826 | public function search_acf_user_field_list( $data ) { |
| 8827 | |
| 8828 | if ( ! function_exists( 'acf_get_fields' ) ) { |
| 8829 | return []; |
| 8830 | } |
| 8831 | if ( ! function_exists( 'acf_get_field_groups' ) ) { |
| 8832 | return []; |
| 8833 | } |
| 8834 | $groups_user_form = []; |
| 8835 | $options = []; |
| 8836 | if ( function_exists( 'acf_get_field_groups' ) ) { |
| 8837 | $field_groups = acf_get_field_groups(); |
| 8838 | foreach ( $field_groups as $group ) { |
| 8839 | if ( ! empty( $group['location'] ) ) { |
| 8840 | foreach ( $group['location'] as $locations ) { |
| 8841 | foreach ( $locations as $location ) { |
| 8842 | if ( 'user_form' === $location['param'] || 'user_role' === $location['param'] || 'current_user' === $location['param'] || 'current_user_role' === $location['param'] ) { |
| 8843 | $groups_user_form[] = $group; |
| 8844 | } |
| 8845 | } |
| 8846 | } |
| 8847 | } |
| 8848 | } |
| 8849 | |
| 8850 | if ( empty( $groups_user_form ) ) { |
| 8851 | return []; |
| 8852 | } |
| 8853 | |
| 8854 | $key_values = array_map( |
| 8855 | function ( $item ) { |
| 8856 | return $item['key']; |
| 8857 | }, |
| 8858 | $groups_user_form |
| 8859 | ); |
| 8860 | $unique_keys = array_unique( $key_values ); |
| 8861 | $unique_array = array_intersect_key( $groups_user_form, $unique_keys ); |
| 8862 | |
| 8863 | foreach ( $unique_array as $group ) { |
| 8864 | if ( function_exists( 'acf_get_fields' ) ) { |
| 8865 | $group_fields = acf_get_fields( $group['key'] ); |
| 8866 | } |
| 8867 | if ( ! empty( $group_fields ) ) { |
| 8868 | foreach ( $group_fields as $field ) { |
| 8869 | $options[] = [ |
| 8870 | 'value' => $field['name'], |
| 8871 | 'label' => $field['label'], |
| 8872 | ]; |
| 8873 | |
| 8874 | } |
| 8875 | } |
| 8876 | } |
| 8877 | } |
| 8878 | |
| 8879 | return [ |
| 8880 | 'options' => $options, |
| 8881 | 'hasMore' => false, |
| 8882 | ]; |
| 8883 | } |
| 8884 | |
| 8885 | /** |
| 8886 | * Get ACF Custom fields list. |
| 8887 | * |
| 8888 | * @param array $data data. |
| 8889 | * |
| 8890 | * @return array |
| 8891 | */ |
| 8892 | public function search_acf_options_field_list( $data ) { |
| 8893 | |
| 8894 | if ( ! function_exists( 'acf_get_fields' ) ) { |
| 8895 | return []; |
| 8896 | } |
| 8897 | if ( ! function_exists( 'acf_get_field_groups' ) ) { |
| 8898 | return []; |
| 8899 | } |
| 8900 | $groups_options_form = []; |
| 8901 | $options = []; |
| 8902 | if ( function_exists( 'acf_get_field_groups' ) ) { |
| 8903 | $field_groups = acf_get_field_groups(); |
| 8904 | foreach ( $field_groups as $group ) { |
| 8905 | if ( ! empty( $group['location'] ) ) { |
| 8906 | foreach ( $group['location'] as $locations ) { |
| 8907 | foreach ( $locations as $location ) { |
| 8908 | if ( 'options_page' === $location['param'] ) { |
| 8909 | $groups_options_form[] = $group; |
| 8910 | } |
| 8911 | } |
| 8912 | } |
| 8913 | } |
| 8914 | } |
| 8915 | if ( empty( $groups_options_form ) ) { |
| 8916 | return []; |
| 8917 | } |
| 8918 | $key_values = array_map( |
| 8919 | function ( $item ) { |
| 8920 | return $item['key']; |
| 8921 | }, |
| 8922 | $groups_options_form |
| 8923 | ); |
| 8924 | $unique_keys = array_unique( $key_values ); |
| 8925 | $unique_array = array_intersect_key( $groups_options_form, $unique_keys ); |
| 8926 | foreach ( $unique_array as $group ) { |
| 8927 | if ( function_exists( 'acf_get_fields' ) ) { |
| 8928 | $group_fields = acf_get_fields( $group['key'] ); |
| 8929 | } |
| 8930 | if ( ! empty( $group_fields ) ) { |
| 8931 | foreach ( $group_fields as $field ) { |
| 8932 | $options[] = [ |
| 8933 | 'value' => $field['name'], |
| 8934 | 'label' => $field['label'], |
| 8935 | ]; |
| 8936 | |
| 8937 | } |
| 8938 | } |
| 8939 | } |
| 8940 | } |
| 8941 | |
| 8942 | return [ |
| 8943 | 'options' => $options, |
| 8944 | 'hasMore' => false, |
| 8945 | ]; |
| 8946 | } |
| 8947 | |
| 8948 | /** |
| 8949 | * Search Last Updated Field Data for ACF. |
| 8950 | * |
| 8951 | * @param array $data data. |
| 8952 | * @return array |
| 8953 | */ |
| 8954 | public function search_acf_post_field_data( $data ) { |
| 8955 | $context = []; |
| 8956 | |
| 8957 | $field = ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); |
| 8958 | |
| 8959 | $post_type = $data['filter']['wp_post_type']['value']; |
| 8960 | $post = $data['filter']['wp_post']['value']; |
| 8961 | |
| 8962 | if ( -1 === $field ) { |
| 8963 | $args = [ |
| 8964 | 'post_id' => $post, |
| 8965 | ]; |
| 8966 | if ( function_exists( 'acf_get_field_groups' ) ) { |
| 8967 | $field_groups_collection = acf_get_field_groups( $args ); |
| 8968 | } |
| 8969 | if ( ! empty( $field_groups_collection ) ) { |
| 8970 | foreach ( $field_groups_collection as $field_group ) { |
| 8971 | if ( function_exists( 'acf_get_fields' ) ) { |
| 8972 | $field_groups[] = acf_get_fields( $field_group['key'] ); |
| 8973 | } |
| 8974 | } |
| 8975 | } |
| 8976 | $fields = []; |
| 8977 | if ( ! empty( $field_groups ) && is_array( $field_groups ) ) { |
| 8978 | foreach ( $field_groups as $field_groups ) { |
| 8979 | $fields[] = $field_groups; |
| 8980 | } |
| 8981 | } |
| 8982 | if ( ! empty( $fields ) ) { |
| 8983 | $random_key = array_rand( $fields ); |
| 8984 | $field = $random_key; |
| 8985 | } else { |
| 8986 | $result = ''; |
| 8987 | } |
| 8988 | } else { |
| 8989 | $field = $data['filter']['field_id']['value']; |
| 8990 | } |
| 8991 | if ( function_exists( ( 'get_field' ) ) ) { |
| 8992 | $result = get_field( $field, $post ); |
| 8993 | } |
| 8994 | |
| 8995 | $response = []; |
| 8996 | if ( ! empty( $result ) ) { |
| 8997 | $response['pluggable_data'] = array_merge( [ $field => $result ], [ 'field_id' => $field ], [ 'post' => WordPress::get_post_context( $post ) ] ); |
| 8998 | $response['response_type'] = 'live'; |
| 8999 | } else { |
| 9000 | $response = json_decode( '{"response_type":"sample","pluggable_data":{"custom_description": "custom message", "ID": 1, "post_author": "1", "post_date": "2023-05-31 13:26:24", "post_date_gmt": "2023-05-31 13:26:24", "post_content": "", "post_title": "Test", "post_excerpt": "", "post_status": "publish", "comment_status": "open", "ping_status": "open", "post_password": "", "post_name": "test", "to_ping": "", "pinged": "", "post_modified": "2023-08-17 09:15:56", "post_modified_gmt": "2023-08-17 09:15:56", "post_content_filtered": "", "post_parent": 0, "guid": "https:\/\/example.com\/?p=1", "menu_order": 0, "post_type": "post", "post_mime_type": "", "comment_count": "2", "filter": "raw"}}', true ); |
| 9001 | } |
| 9002 | |
| 9003 | return $response; |
| 9004 | } |
| 9005 | |
| 9006 | /** |
| 9007 | * Search Last Updated User Field Data ACF. |
| 9008 | * |
| 9009 | * @param array $data data. |
| 9010 | * @return array |
| 9011 | */ |
| 9012 | public function search_acf_user_field_data( $data ) { |
| 9013 | global $wpdb; |
| 9014 | |
| 9015 | $context = []; |
| 9016 | |
| 9017 | $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); |
| 9018 | |
| 9019 | if ( -1 === $field ) { |
| 9020 | $groups_user_form = []; |
| 9021 | if ( function_exists( 'acf_get_field_groups' ) ) { |
| 9022 | $field_groups = acf_get_field_groups(); |
| 9023 | } |
| 9024 | if ( ! empty( $field_groups ) ) { |
| 9025 | foreach ( $field_groups as $group ) { |
| 9026 | if ( ! empty( $group['location'] ) ) { |
| 9027 | foreach ( $group['location'] as $locations ) { |
| 9028 | foreach ( $locations as $location ) { |
| 9029 | if ( 'user_form' === $location['param'] || 'user_role' === $location['param'] || 'current_user' === $location['param'] || 'current_user_role' === $location['param'] ) { |
| 9030 | $groups_user_form[] = $group; |
| 9031 | } |
| 9032 | } |
| 9033 | } |
| 9034 | } |
| 9035 | } |
| 9036 | $field_groups = $groups_user_form; |
| 9037 | } |
| 9038 | if ( empty( $field_groups ) ) { |
| 9039 | $result = ''; |
| 9040 | } |
| 9041 | $fields = []; |
| 9042 | if ( ! empty( $field_groups ) ) { |
| 9043 | foreach ( $field_groups as $group ) { |
| 9044 | if ( function_exists( 'acf_get_fields' ) ) { |
| 9045 | $group_fields = acf_get_fields( $group['key'] ); |
| 9046 | } |
| 9047 | if ( ! empty( $group_fields ) ) { |
| 9048 | foreach ( $group_fields as $field ) { |
| 9049 | $fields[] = $group_fields; |
| 9050 | } |
| 9051 | } |
| 9052 | } |
| 9053 | } |
| 9054 | if ( ! empty( $fields ) ) { |
| 9055 | $random_key = array_rand( $fields ); |
| 9056 | $field = $random_key; |
| 9057 | } else { |
| 9058 | $result = ''; |
| 9059 | } |
| 9060 | } else { |
| 9061 | $field = $data['filter']['field_id']['value']; |
| 9062 | } |
| 9063 | $users = get_users( |
| 9064 | [ |
| 9065 | 'fields' => 'ID', |
| 9066 | 'meta_key' => $field, |
| 9067 | ] |
| 9068 | ); |
| 9069 | |
| 9070 | if ( ! empty( $users ) ) { |
| 9071 | $user_random_key = array_rand( $users ); |
| 9072 | $user_id = $user_random_key; |
| 9073 | if ( function_exists( 'get_field' ) ) { |
| 9074 | $result = get_field( $field, 'user_' . $users[ $user_id ] ); |
| 9075 | } |
| 9076 | $response = []; |
| 9077 | if ( ! empty( $result ) ) { |
| 9078 | $context = [ |
| 9079 | 'field_id' => $field, |
| 9080 | $field => $result, |
| 9081 | 'user' => WordPress::get_user_context( $users[ $user_id ] ), |
| 9082 | ]; |
| 9083 | $response['pluggable_data'] = $context; |
| 9084 | $response['response_type'] = 'live'; |
| 9085 | } else { |
| 9086 | $response = json_decode( |
| 9087 | '{ |
| 9088 | "response_type": "sample", |
| 9089 | "pluggable_data": { |
| 9090 | "field_id": "gender", |
| 9091 | "user": { |
| 9092 | "wp_user_id": 114, |
| 9093 | "user_login": "test", |
| 9094 | "display_name": "test", |
| 9095 | "user_firstname": "test", |
| 9096 | "user_lastname": "test", |
| 9097 | "user_email": "test@test.com", |
| 9098 | "user_role": [ "subscriber" ] |
| 9099 | } |
| 9100 | } |
| 9101 | }', |
| 9102 | true |
| 9103 | ); |
| 9104 | } |
| 9105 | } else { |
| 9106 | $response = json_decode( |
| 9107 | '{ |
| 9108 | "response_type": "sample", |
| 9109 | "pluggable_data": { |
| 9110 | "field_id": "gender", |
| 9111 | "user": { |
| 9112 | "wp_user_id": 114, |
| 9113 | "user_login": "test", |
| 9114 | "display_name": "test", |
| 9115 | "user_firstname": "test", |
| 9116 | "user_lastname": "test", |
| 9117 | "user_email": "test@test.com", |
| 9118 | "user_role": [ "subscriber" ] |
| 9119 | } |
| 9120 | } |
| 9121 | }', |
| 9122 | true |
| 9123 | ); |
| 9124 | } |
| 9125 | |
| 9126 | return $response; |
| 9127 | } |
| 9128 | |
| 9129 | /** |
| 9130 | * Search Last Updated Options Field Data ACF. |
| 9131 | * |
| 9132 | * @param array $data data. |
| 9133 | * @return array |
| 9134 | */ |
| 9135 | public function search_acf_options_field_data( $data ) { |
| 9136 | global $wpdb; |
| 9137 | $context = []; |
| 9138 | $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); |
| 9139 | |
| 9140 | if ( -1 === $field ) { |
| 9141 | $groups_options_form = []; |
| 9142 | if ( function_exists( 'acf_get_field_groups' ) ) { |
| 9143 | $field_groups = acf_get_field_groups(); |
| 9144 | } |
| 9145 | if ( ! empty( $field_groups ) ) { |
| 9146 | foreach ( $field_groups as $group ) { |
| 9147 | if ( ! empty( $group['location'] ) ) { |
| 9148 | foreach ( $group['location'] as $locations ) { |
| 9149 | foreach ( $locations as $location ) { |
| 9150 | if ( 'options_page' === $location['param'] ) { |
| 9151 | $groups_options_form[] = $group; |
| 9152 | } |
| 9153 | } |
| 9154 | } |
| 9155 | } |
| 9156 | } |
| 9157 | } |
| 9158 | if ( empty( $groups_options_form ) ) { |
| 9159 | $result = ''; |
| 9160 | } |
| 9161 | $key_values = array_map( |
| 9162 | function ( $item ) { |
| 9163 | return $item['key']; |
| 9164 | }, |
| 9165 | $groups_options_form |
| 9166 | ); |
| 9167 | $unique_keys = array_unique( $key_values ); |
| 9168 | $unique_array = array_intersect_key( $groups_options_form, $unique_keys ); |
| 9169 | $fields = []; |
| 9170 | if ( ! empty( $unique_array ) ) { |
| 9171 | foreach ( $unique_array as $group ) { |
| 9172 | if ( function_exists( 'acf_get_fields' ) ) { |
| 9173 | $group_fields = acf_get_fields( $group['key'] ); |
| 9174 | } |
| 9175 | if ( ! empty( $group_fields ) ) { |
| 9176 | foreach ( $group_fields as $field ) { |
| 9177 | $fields[] = $group_fields; |
| 9178 | } |
| 9179 | } |
| 9180 | } |
| 9181 | } |
| 9182 | if ( ! empty( $fields ) ) { |
| 9183 | $random_key = array_rand( $fields ); |
| 9184 | $field = $random_key; |
| 9185 | } else { |
| 9186 | $result = ''; |
| 9187 | } |
| 9188 | } else { |
| 9189 | $field = $data['filter']['field_id']['value']; |
| 9190 | } |
| 9191 | if ( function_exists( 'get_field' ) ) { |
| 9192 | $option_value = get_field( $field, 'option' ); |
| 9193 | } |
| 9194 | if ( ! empty( $option_value ) ) { |
| 9195 | if ( function_exists( 'acf_get_field' ) ) { |
| 9196 | $options_fields = acf_get_field( $field ); |
| 9197 | if ( function_exists( 'acf_maybe_get' ) ) { |
| 9198 | $options_page = acf_maybe_get( $options_fields, 'parent' ); |
| 9199 | } |
| 9200 | } |
| 9201 | $context = [ |
| 9202 | 'field_id' => $field, |
| 9203 | $field => $option_value, |
| 9204 | ]; |
| 9205 | $response['pluggable_data'] = $context; |
| 9206 | $response['response_type'] = 'live'; |
| 9207 | } else { |
| 9208 | $response = json_decode( |
| 9209 | '{ |
| 9210 | "response_type": "sample", |
| 9211 | "pluggable_data": { |
| 9212 | "field_id": "optionpage", |
| 9213 | "optionpage": "newoption" |
| 9214 | } |
| 9215 | }', |
| 9216 | true |
| 9217 | ); |
| 9218 | } |
| 9219 | return $response; |
| 9220 | } |
| 9221 | |
| 9222 | /** |
| 9223 | * Get WP Fusion Tags list. |
| 9224 | * |
| 9225 | * @param array $data data. |
| 9226 | * |
| 9227 | * @return array |
| 9228 | */ |
| 9229 | public function search_wp_fusion_tag_list( $data ) { |
| 9230 | |
| 9231 | if ( ! function_exists( 'wp_fusion' ) ) { |
| 9232 | return []; |
| 9233 | } |
| 9234 | |
| 9235 | $options = []; |
| 9236 | $tags = wp_fusion()->settings->get( 'available_tags' ); |
| 9237 | |
| 9238 | if ( $tags ) { |
| 9239 | foreach ( $tags as $t_id => $tag ) { |
| 9240 | if ( is_array( $tag ) && isset( $tag['label'] ) ) { |
| 9241 | $options[] = [ |
| 9242 | 'value' => $t_id, |
| 9243 | 'label' => $tag['label'], |
| 9244 | ]; |
| 9245 | } else { |
| 9246 | $options[] = [ |
| 9247 | 'value' => $t_id, |
| 9248 | 'label' => $tag, |
| 9249 | ]; |
| 9250 | } |
| 9251 | } |
| 9252 | } |
| 9253 | |
| 9254 | return [ |
| 9255 | 'options' => $options, |
| 9256 | 'hasMore' => false, |
| 9257 | ]; |
| 9258 | } |
| 9259 | |
| 9260 | /** |
| 9261 | * Get list of events for Modern Events Calendar. |
| 9262 | * |
| 9263 | * @param array $data data. |
| 9264 | * @return array |
| 9265 | */ |
| 9266 | public function search_mec_events_list( $data ) { |
| 9267 | $page = $data['page']; |
| 9268 | $limit = Utilities::get_search_page_limit(); |
| 9269 | $offset = $limit * ( $page - 1 ); |
| 9270 | |
| 9271 | $args = [ |
| 9272 | 'post_type' => 'mec-events', |
| 9273 | 'post_status' => [ 'publish', 'private' ], |
| 9274 | ]; |
| 9275 | $loop = new WP_Query( $args ); |
| 9276 | $events_count = count( $loop->posts ); |
| 9277 | |
| 9278 | $args = [ |
| 9279 | 'post_type' => 'mec-events', |
| 9280 | 'posts_per_page' => $limit, |
| 9281 | 'offset' => $offset, |
| 9282 | 'orderby' => 'title', |
| 9283 | 'order' => 'ASC', |
| 9284 | 'post_status' => [ 'publish', 'private' ], |
| 9285 | ]; |
| 9286 | |
| 9287 | $loop = new WP_Query( $args ); |
| 9288 | $events = $loop->posts; |
| 9289 | |
| 9290 | $options = []; |
| 9291 | if ( ! empty( $events ) ) { |
| 9292 | foreach ( $events as $event ) { |
| 9293 | if ( isset( $event->ID ) ) { |
| 9294 | $options[] = [ |
| 9295 | 'label' => get_the_title( $event ), |
| 9296 | 'value' => $event->ID, |
| 9297 | ]; |
| 9298 | } |
| 9299 | } |
| 9300 | } |
| 9301 | |
| 9302 | return [ |
| 9303 | 'options' => $options, |
| 9304 | 'hasMore' => $events_count > $limit && $events_count > $offset, |
| 9305 | ]; |
| 9306 | } |
| 9307 | |
| 9308 | /** |
| 9309 | * Search tickets of MEC events. |
| 9310 | * |
| 9311 | * @param array $data data. |
| 9312 | * @return array |
| 9313 | */ |
| 9314 | public function search_mec_event_tickets( $data ) { |
| 9315 | $options = []; |
| 9316 | $event_id = $data['dynamic']; |
| 9317 | |
| 9318 | $event_tickets = get_post_meta( $event_id, 'mec_tickets', true ); |
| 9319 | |
| 9320 | if ( ! empty( $event_tickets ) && is_array( $event_tickets ) ) { |
| 9321 | foreach ( $event_tickets as $ticket_id => $event_ticket ) { |
| 9322 | if ( isset( $event_ticket['name'] ) ) { |
| 9323 | $options[] = [ |
| 9324 | 'label' => $event_ticket['name'], |
| 9325 | 'value' => $ticket_id, |
| 9326 | ]; |
| 9327 | } |
| 9328 | } |
| 9329 | } |
| 9330 | |
| 9331 | return [ |
| 9332 | 'options' => $options, |
| 9333 | 'hasMore' => false, |
| 9334 | ]; |
| 9335 | } |
| 9336 | |
| 9337 | /** |
| 9338 | * Get last data for trigger. |
| 9339 | * |
| 9340 | * @param array $data data. |
| 9341 | * @return array |
| 9342 | */ |
| 9343 | public function search_mec_triggers_last_data( $data ) { |
| 9344 | global $wpdb; |
| 9345 | |
| 9346 | $context = []; |
| 9347 | $context['response_type'] = 'sample'; |
| 9348 | |
| 9349 | $event = [ |
| 9350 | 'event_id' => 1, |
| 9351 | 'title' => 'Sample Event', |
| 9352 | 'description' => 'Description of the sample event.', |
| 9353 | 'categories' => 'New, Sample', |
| 9354 | 'start_date' => 'September 13, 2023', |
| 9355 | 'start_time' => '8:00 AM', |
| 9356 | 'end_date' => 'September 13, 2023', |
| 9357 | 'end_time' => '11:00 AM', |
| 9358 | 'location' => 'City Hall', |
| 9359 | 'organizer' => 'John Doe', |
| 9360 | 'cost' => '5000', |
| 9361 | 'featured_image_id' => 1, |
| 9362 | 'featured_image_url' => 'https://suretriggers.com/wp-content/uploads/2022/12/Screenshot_20221127_021332.png', |
| 9363 | 'tickets' => [ |
| 9364 | [ |
| 9365 | 'id' => 1, |
| 9366 | 'name' => 'Silver', |
| 9367 | 'description' => 'Standard seat with reasonable price.', |
| 9368 | 'price' => '300', |
| 9369 | 'price_label' => 'USD', |
| 9370 | 'limit' => '20', |
| 9371 | ], |
| 9372 | [ |
| 9373 | 'id' => 2, |
| 9374 | 'name' => 'Premium', |
| 9375 | 'description' => 'VIP seat with high price.', |
| 9376 | 'price' => '500', |
| 9377 | 'price_label' => 'USD', |
| 9378 | 'limit' => '10', |
| 9379 | ], |
| 9380 | ], |
| 9381 | 'attendees' => [ |
| 9382 | [ |
| 9383 | 'id' => 1, |
| 9384 | 'email' => 'johndoe@test.com', |
| 9385 | 'name' => 'John Doe', |
| 9386 | ], |
| 9387 | [ |
| 9388 | 'id' => 2, |
| 9389 | 'email' => 'adamsmith@test.com', |
| 9390 | 'name' => 'Adam Smith', |
| 9391 | ], |
| 9392 | ], |
| 9393 | 'booking' => [ |
| 9394 | 'title' => 'johndoe@test.com - John Doe', |
| 9395 | 'transaction_id' => 'RSH59404', |
| 9396 | 'amount_payable' => '800', |
| 9397 | 'price' => '800', |
| 9398 | 'time' => '2023-09-07 06:40:32', |
| 9399 | 'payment_gateway' => 'Manual Pay', |
| 9400 | 'confirmation_status' => 'Pending', |
| 9401 | 'verification_status' => 'Verified', |
| 9402 | 'attendees_count' => 2, |
| 9403 | ], |
| 9404 | ]; |
| 9405 | |
| 9406 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 9407 | |
| 9408 | $where = ''; |
| 9409 | |
| 9410 | if ( 'cancelled' === $term ) { |
| 9411 | $where = 'WHERE verified = -1'; |
| 9412 | } elseif ( 'confirmed' === $term ) { |
| 9413 | $where = 'WHERE confirmed = 1'; |
| 9414 | } elseif ( 'pending' === $term ) { |
| 9415 | $where = 'WHERE confirmed = 0'; |
| 9416 | } |
| 9417 | |
| 9418 | $event_id = (int) ( isset( $data['filter']['event_id']['value'] ) ? $data['filter']['event_id']['value'] : '-1' ); |
| 9419 | |
| 9420 | if ( -1 !== $event_id ) { |
| 9421 | if ( ! empty( $where ) ) { |
| 9422 | $where .= ' AND event_id = ' . $event_id; |
| 9423 | } else { |
| 9424 | $where = 'WHERE event_id = ' . $event_id; |
| 9425 | } |
| 9426 | } |
| 9427 | |
| 9428 | $event_data = $wpdb->get_row( "SELECT booking_id FROM {$wpdb->prefix}mec_bookings $where ORDER BY id DESC LIMIT 1" ); // @phpcs:ignore |
| 9429 | |
| 9430 | if ( ! empty( $event_data ) ) { |
| 9431 | $event = ModernEventsCalendar::get_event_context( (int) $event_data->booking_id ); |
| 9432 | $context['response_type'] = 'live'; |
| 9433 | } |
| 9434 | |
| 9435 | $context['pluggable_data'] = $event; |
| 9436 | |
| 9437 | return $context; |
| 9438 | } |
| 9439 | |
| 9440 | /** |
| 9441 | * Get form list Contact Form 7. |
| 9442 | * |
| 9443 | * @param array $data data. |
| 9444 | * |
| 9445 | * @return array |
| 9446 | */ |
| 9447 | public function search_contact_form7_list( $data ) { |
| 9448 | |
| 9449 | $page = $data['page']; |
| 9450 | $limit = Utilities::get_search_page_limit(); |
| 9451 | $offset = $limit * ( $page - 1 ); |
| 9452 | |
| 9453 | $posts = get_posts( |
| 9454 | [ |
| 9455 | 'post_type' => 'wpcf7_contact_form', |
| 9456 | 'posts_per_page' => $limit, |
| 9457 | 'offset' => $offset, |
| 9458 | ] |
| 9459 | ); |
| 9460 | |
| 9461 | $all_posts = get_posts( |
| 9462 | [ |
| 9463 | 'post_type' => 'wpcf7_contact_form', |
| 9464 | 'posts_per_page' => -1, |
| 9465 | ] |
| 9466 | ); |
| 9467 | |
| 9468 | $posts_count = count( $all_posts ); |
| 9469 | |
| 9470 | $options = []; |
| 9471 | |
| 9472 | if ( ! empty( $posts ) ) { |
| 9473 | foreach ( $posts as $post ) { |
| 9474 | $options[] = [ |
| 9475 | 'label' => get_the_title( $post->ID ), |
| 9476 | 'value' => $post->ID, |
| 9477 | ]; |
| 9478 | } |
| 9479 | } |
| 9480 | |
| 9481 | return [ |
| 9482 | 'options' => $options, |
| 9483 | 'hasMore' => $posts_count > $limit && $posts_count > $offset, |
| 9484 | ]; |
| 9485 | } |
| 9486 | |
| 9487 | /** |
| 9488 | * Get Thrive Leads form list |
| 9489 | * |
| 9490 | * @param array $data data. |
| 9491 | * |
| 9492 | * @return array |
| 9493 | */ |
| 9494 | public function search_thrive_leads_forms_list( $data ) { |
| 9495 | $options = []; |
| 9496 | |
| 9497 | $lg_ids = get_posts( |
| 9498 | [ |
| 9499 | 'post_type' => '_tcb_form_settings', |
| 9500 | 'fields' => 'id=>parent', |
| 9501 | 'posts_per_page' => -1, |
| 9502 | 'post_status' => 'any', |
| 9503 | ] |
| 9504 | ); |
| 9505 | |
| 9506 | if ( function_exists( 'tve_leads_get_form_variations' ) ) { |
| 9507 | foreach ( $lg_ids as $lg_id => $lg_parent ) { |
| 9508 | $variations = tve_leads_get_form_variations( $lg_parent ); |
| 9509 | foreach ( $variations as $variation ) { |
| 9510 | $options[] = [ |
| 9511 | 'label' => $variation['post_title'], |
| 9512 | 'value' => $lg_parent, |
| 9513 | ]; |
| 9514 | } |
| 9515 | } |
| 9516 | } |
| 9517 | |
| 9518 | return [ |
| 9519 | 'options' => $options, |
| 9520 | 'hasMore' => false, |
| 9521 | ]; |
| 9522 | } |
| 9523 | |
| 9524 | /** |
| 9525 | * Get list for Woocommerce Subscriptions |
| 9526 | * |
| 9527 | * @param array $data data. |
| 9528 | * |
| 9529 | * @return array |
| 9530 | */ |
| 9531 | public function search_wc_subscription_variation_products( $data ) { |
| 9532 | $options = []; |
| 9533 | |
| 9534 | global $wpdb; |
| 9535 | |
| 9536 | if ( ! function_exists( 'wc_get_product' ) ) { |
| 9537 | return []; |
| 9538 | } |
| 9539 | $subscriptions = $wpdb->get_results( |
| 9540 | $wpdb->prepare( |
| 9541 | "SELECT posts.ID, posts.post_title FROM $wpdb->posts as posts |
| 9542 | LEFT JOIN $wpdb->term_relationships as rel ON (posts.ID = rel.object_id) |
| 9543 | WHERE rel.term_taxonomy_id IN (SELECT term_id FROM $wpdb->terms WHERE slug IN ('subscription','variable-subscription')) |
| 9544 | AND posts.post_type = %s |
| 9545 | AND posts.post_status = %s |
| 9546 | UNION ALL |
| 9547 | SELECT ID, post_title FROM $wpdb->posts |
| 9548 | WHERE post_type = %s |
| 9549 | AND post_status = %s |
| 9550 | ORDER BY post_title", |
| 9551 | 'product', |
| 9552 | 'publish', |
| 9553 | 'shop_subscription', |
| 9554 | 'publish' |
| 9555 | ) |
| 9556 | ); |
| 9557 | |
| 9558 | if ( $subscriptions ) { |
| 9559 | foreach ( $subscriptions as $product ) { |
| 9560 | $options[] = [ |
| 9561 | 'label' => $product->post_title . ' (#' . $product->ID . ')', |
| 9562 | 'value' => (int) $product->ID, |
| 9563 | ]; |
| 9564 | $product_s = wc_get_product( $product->ID ); |
| 9565 | /** |
| 9566 | * |
| 9567 | * Ignore line |
| 9568 | * |
| 9569 | * @phpstan-ignore-next-line |
| 9570 | */ |
| 9571 | if ( 'variable-subscription' == $product_s->product_type ) { |
| 9572 | $args = [ |
| 9573 | 'post_type' => 'product_variation', |
| 9574 | 'post_parent' => $product->ID, |
| 9575 | 'posts_per_page' => -1, |
| 9576 | 'orderby' => 'ID', |
| 9577 | 'order' => 'ASC', |
| 9578 | 'post_status' => 'publish', |
| 9579 | ]; |
| 9580 | |
| 9581 | $variations = get_posts( $args ); |
| 9582 | |
| 9583 | foreach ( $variations as $var ) { |
| 9584 | $options[] = [ |
| 9585 | 'label' => $var->post_title . ' (#' . $var->ID . ')', |
| 9586 | 'value' => $var->ID, |
| 9587 | ]; |
| 9588 | } |
| 9589 | } |
| 9590 | } |
| 9591 | } |
| 9592 | |
| 9593 | return [ |
| 9594 | 'options' => $options, |
| 9595 | 'hasMore' => false, |
| 9596 | ]; |
| 9597 | } |
| 9598 | |
| 9599 | /** |
| 9600 | * Get WS Forms form list |
| 9601 | * |
| 9602 | * @param array $data data. |
| 9603 | * |
| 9604 | * @return array |
| 9605 | */ |
| 9606 | public function search_ws_forms_list( $data ) { |
| 9607 | $options = []; |
| 9608 | global $wpdb; |
| 9609 | |
| 9610 | $forms = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wsf_form", 'ARRAY_A' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 9611 | |
| 9612 | foreach ( $forms as $form ) { |
| 9613 | $options[] = [ |
| 9614 | 'label' => $form['label'], |
| 9615 | 'value' => $form['id'], |
| 9616 | ]; |
| 9617 | } |
| 9618 | |
| 9619 | return [ |
| 9620 | 'options' => $options, |
| 9621 | 'hasMore' => false, |
| 9622 | ]; |
| 9623 | } |
| 9624 | |
| 9625 | /** |
| 9626 | * Get Learndash Achievement list |
| 9627 | * |
| 9628 | * @param array $data data. |
| 9629 | * |
| 9630 | * @return array |
| 9631 | */ |
| 9632 | public function search_ld_achievements_list( $data ) { |
| 9633 | $page = $data['page']; |
| 9634 | $limit = Utilities::get_search_page_limit(); |
| 9635 | $offset = $limit * ( $page - 1 ); |
| 9636 | |
| 9637 | $posts = get_posts( |
| 9638 | [ |
| 9639 | 'post_type' => 'ld-achievement', |
| 9640 | 'posts_per_page' => $limit, |
| 9641 | 'offset' => $offset, |
| 9642 | 'post_status' => [ 'publish' ], |
| 9643 | ] |
| 9644 | ); |
| 9645 | |
| 9646 | $posts_count = wp_count_posts( 'ld-achievement' )->publish; |
| 9647 | |
| 9648 | $options = []; |
| 9649 | |
| 9650 | if ( ! empty( $posts ) ) { |
| 9651 | foreach ( $posts as $post ) { |
| 9652 | $options[] = [ |
| 9653 | 'label' => get_the_title( $post->ID ), |
| 9654 | 'value' => $post->ID, |
| 9655 | ]; |
| 9656 | } |
| 9657 | } |
| 9658 | |
| 9659 | return [ |
| 9660 | 'options' => $options, |
| 9661 | 'hasMore' => $posts_count > $limit && $posts_count > $offset, |
| 9662 | ]; |
| 9663 | } |
| 9664 | |
| 9665 | /** |
| 9666 | * Get Advanced Ads list |
| 9667 | * |
| 9668 | * @param array $data data. |
| 9669 | * |
| 9670 | * @return array |
| 9671 | */ |
| 9672 | public function search_ads_list( $data ) { |
| 9673 | $page = $data['page']; |
| 9674 | $limit = Utilities::get_search_page_limit(); |
| 9675 | $offset = $limit * ( $page - 1 ); |
| 9676 | |
| 9677 | $posts = get_posts( |
| 9678 | [ |
| 9679 | 'post_type' => 'advanced_ads', |
| 9680 | 'posts_per_page' => $limit, |
| 9681 | 'offset' => $offset, |
| 9682 | 'post_status' => [ 'publish', 'draft' ], |
| 9683 | ] |
| 9684 | ); |
| 9685 | |
| 9686 | $posts_count = wp_count_posts( 'advanced_ads' )->publish; |
| 9687 | |
| 9688 | $options = []; |
| 9689 | |
| 9690 | if ( ! empty( $posts ) ) { |
| 9691 | foreach ( $posts as $post ) { |
| 9692 | $options[] = [ |
| 9693 | 'label' => get_the_title( $post->ID ), |
| 9694 | 'value' => $post->ID, |
| 9695 | ]; |
| 9696 | } |
| 9697 | } |
| 9698 | |
| 9699 | return [ |
| 9700 | 'options' => $options, |
| 9701 | 'hasMore' => $posts_count > $limit && $posts_count > $offset, |
| 9702 | ]; |
| 9703 | } |
| 9704 | |
| 9705 | /** |
| 9706 | * Advanced Ads pluggable data. |
| 9707 | * |
| 9708 | * @param array $data data. |
| 9709 | * @return array |
| 9710 | */ |
| 9711 | public function search_ad_last_data( $data ) { |
| 9712 | $context = []; |
| 9713 | $args = [ |
| 9714 | 'post_type' => 'advanced_ads', |
| 9715 | 'posts_per_page' => 1, |
| 9716 | 'orderby' => 'modified', |
| 9717 | 'order' => 'DESC', |
| 9718 | ]; |
| 9719 | |
| 9720 | if ( isset( $data['filter']['ad_status']['value'] ) ) { |
| 9721 | $post_status = $data['filter']['ad_status']['value']; |
| 9722 | $args['post_status'] = $post_status; |
| 9723 | } |
| 9724 | |
| 9725 | if ( isset( $data['filter']['ad_new_status']['value'] ) ) { |
| 9726 | $post_status = $data['filter']['ad_new_status']['value']; |
| 9727 | $args['post_status'] = $post_status; |
| 9728 | } |
| 9729 | |
| 9730 | if ( isset( $data['filter']['ad_id']['value'] ) ) { |
| 9731 | $post_id = $data['filter']['ad_id']['value']; |
| 9732 | if ( -1 != $post_id ) { |
| 9733 | if ( $post_id > 0 ) { |
| 9734 | $args['p'] = $post_id; |
| 9735 | } |
| 9736 | } |
| 9737 | } |
| 9738 | |
| 9739 | $posts = get_posts( $args ); |
| 9740 | if ( ! empty( $posts ) ) { |
| 9741 | $context['pluggable_data'] = $posts[0]; |
| 9742 | $context['pluggable_data'] = WordPress::get_post_context( $posts[0]->ID ); |
| 9743 | if ( isset( $data['filter']['ad_new_status']['value'] ) ) { |
| 9744 | $context['pluggable_data']['ad_new_status'] = $posts[0]->post_status; |
| 9745 | } |
| 9746 | if ( isset( $data['filter']['ad_old_status']['value'] ) ) { |
| 9747 | $context['pluggable_data']['ad_old_status'] = $data['filter']['ad_old_status']['value']; |
| 9748 | } |
| 9749 | $context['pluggable_data']['ad_id'] = $posts[0]->ID; |
| 9750 | if ( isset( $data['filter']['ad_status']['value'] ) ) { |
| 9751 | $context['pluggable_data']['ad_status'] = $posts[0]->post_status; |
| 9752 | } |
| 9753 | $context['response_type'] = 'live'; |
| 9754 | } else { |
| 9755 | $context['pluggable_data'] = [ |
| 9756 | 'ID' => 1, |
| 9757 | 'post' => 1, |
| 9758 | 'post_author' => 1, |
| 9759 | 'post_date' => '2022-11-18 12:18:14', |
| 9760 | 'post_date_gmt' => '2022-11-18 12:18:14', |
| 9761 | 'post_content' => 'Ad Post Content', |
| 9762 | 'post_title' => 'Ad Post', |
| 9763 | 'post_excerpt' => '', |
| 9764 | 'post_status' => 'draft', |
| 9765 | 'comment_status' => 'open', |
| 9766 | 'ping_status' => 'open', |
| 9767 | 'post_password' => '', |
| 9768 | 'post_name' => 'ad-post', |
| 9769 | 'to_ping' => '', |
| 9770 | 'pinged' => '', |
| 9771 | 'post_modified' => '2022-11-18 12:18:14', |
| 9772 | 'post_modified_gmt' => '2022-11-18 12:18:14', |
| 9773 | 'post_content_filtered' => '', |
| 9774 | 'post_parent' => 0, |
| 9775 | 'guid' => 'https://example.com/ad-post/', |
| 9776 | 'menu_order' => 0, |
| 9777 | 'post_type' => 'advanced_ads', |
| 9778 | 'post_mime_type' => '', |
| 9779 | 'comment_count' => 0, |
| 9780 | 'filter' => 'raw', |
| 9781 | ]; |
| 9782 | if ( isset( $data['filter']['ad_new_status']['value'] ) ) { |
| 9783 | $context['pluggable_data']['ad_new_status'] = $data['filter']['ad_new_status']['value']; |
| 9784 | } |
| 9785 | if ( isset( $data['filter']['ad_old_status']['value'] ) ) { |
| 9786 | $context['pluggable_data']['ad_old_status'] = $data['filter']['ad_old_status']['value']; |
| 9787 | } |
| 9788 | $context['pluggable_data']['ad_id'] = 1; |
| 9789 | if ( isset( $data['filter']['ad_status']['value'] ) ) { |
| 9790 | $context['pluggable_data']['ad_status'] = $data['filter']['ad_status']['value']; |
| 9791 | } |
| 9792 | $context['response_type'] = 'sample'; |
| 9793 | } |
| 9794 | |
| 9795 | return $context; |
| 9796 | } |
| 9797 | |
| 9798 | /** |
| 9799 | * Get Newsletter lists |
| 9800 | * |
| 9801 | * @param array $data data. |
| 9802 | * |
| 9803 | * @return array |
| 9804 | */ |
| 9805 | public function search_newsletter_lists( $data ) { |
| 9806 | |
| 9807 | $options = []; |
| 9808 | if ( class_exists( '\Newsletter' ) ) { |
| 9809 | |
| 9810 | $lists = \Newsletter::instance()->get_lists(); |
| 9811 | |
| 9812 | if ( ! empty( $lists ) ) { |
| 9813 | foreach ( $lists as $list ) { |
| 9814 | $options[] = [ |
| 9815 | 'label' => $list->name, |
| 9816 | 'value' => 'list_' . $list->id, |
| 9817 | ]; |
| 9818 | } |
| 9819 | } |
| 9820 | } |
| 9821 | |
| 9822 | return [ |
| 9823 | 'options' => $options, |
| 9824 | 'hasMore' => false, |
| 9825 | ]; |
| 9826 | } |
| 9827 | |
| 9828 | /** |
| 9829 | * Newsletter pluggable data. |
| 9830 | * |
| 9831 | * @param array $data data. |
| 9832 | * @return array |
| 9833 | */ |
| 9834 | public function search_newsletter_last_data( $data ) { |
| 9835 | $context = []; |
| 9836 | global $wpdb; |
| 9837 | |
| 9838 | $list = $data['filter']['list_id']['value']; |
| 9839 | |
| 9840 | if ( -1 == $list ) { |
| 9841 | $log = $wpdb->get_results( 'SELECT * from ' . $wpdb->prefix . "newsletter where status='C' ORDER BY id DESC LIMIT 1" ); |
| 9842 | } else { |
| 9843 | $num = $list; |
| 9844 | $location = 1; |
| 9845 | $sql = 'SELECT * FROM ' . $wpdb->prefix . "newsletter WHERE $num = %d AND status = 'C' ORDER BY id DESC LIMIT 1"; |
| 9846 | $log = $wpdb->get_results( $wpdb->prepare( $sql, $location ), ARRAY_A );// @phpcs:ignore |
| 9847 | } |
| 9848 | |
| 9849 | if ( ! empty( $log ) ) { |
| 9850 | $lists_arr = get_option( 'newsletter_lists' ); |
| 9851 | if ( -1 == $list ) { |
| 9852 | foreach ( $log[0] as $key => $val ) { |
| 9853 | if ( defined( 'NEWSLETTER_LIST_MAX' ) ) { |
| 9854 | for ( $i = 1; $i <= NEWSLETTER_LIST_MAX; $i++ ) { |
| 9855 | $list_key = "list_$i"; |
| 9856 | |
| 9857 | if ( $key == $list_key ) { |
| 9858 | if ( 1 == $val ) { |
| 9859 | $context['pluggable_data']['list_id'] = $key; |
| 9860 | if ( is_array( $lists_arr ) ) { |
| 9861 | if ( isset( $lists_arr[ $key ] ) ) { |
| 9862 | $list_name = $lists_arr[ $key ]; |
| 9863 | $context['pluggable_data']['list_name'] = $list_name; |
| 9864 | } |
| 9865 | } |
| 9866 | continue; |
| 9867 | } |
| 9868 | } |
| 9869 | } |
| 9870 | } |
| 9871 | if ( 'email' == $key ) { |
| 9872 | $context['pluggable_data']['email'] = $val; |
| 9873 | } |
| 9874 | } |
| 9875 | } else { |
| 9876 | $context['pluggable_data']['list_id'] = $list; |
| 9877 | $context['pluggable_data']['email'] = $log[0]['email']; |
| 9878 | if ( is_array( $lists_arr ) ) { |
| 9879 | if ( isset( $lists_arr[ $list ] ) ) { |
| 9880 | $list_name = $lists_arr[ $list ]; |
| 9881 | $context['pluggable_data']['list_name'] = $list_name; |
| 9882 | } |
| 9883 | } |
| 9884 | } |
| 9885 | $context['response_type'] = 'live'; |
| 9886 | } else { |
| 9887 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"list_id": "list_1","email": "johnd@mailinator.com","list_name": "Contact List"}}', true ); |
| 9888 | } |
| 9889 | |
| 9890 | return $context; |
| 9891 | } |
| 9892 | |
| 9893 | /** |
| 9894 | * Get wpForo Forum list |
| 9895 | * |
| 9896 | * @param array $data data. |
| 9897 | * |
| 9898 | * @return array |
| 9899 | */ |
| 9900 | public function search_wp_forum_list( $data ) { |
| 9901 | |
| 9902 | if ( ! function_exists( 'WPF' ) ) { |
| 9903 | return []; |
| 9904 | } |
| 9905 | |
| 9906 | $forums = WPF()->forum->get_forums( [ 'type' => 'forum' ] ); |
| 9907 | |
| 9908 | $options = []; |
| 9909 | |
| 9910 | if ( ! empty( $forums ) ) { |
| 9911 | foreach ( $forums as $forum ) { |
| 9912 | $options[] = [ |
| 9913 | 'label' => $forum['title'], |
| 9914 | 'value' => $forum['forumid'], |
| 9915 | ]; |
| 9916 | } |
| 9917 | } |
| 9918 | |
| 9919 | return [ |
| 9920 | 'options' => $options, |
| 9921 | 'hasMore' => false, |
| 9922 | ]; |
| 9923 | } |
| 9924 | |
| 9925 | /** |
| 9926 | * Get wpForo Topic list |
| 9927 | * |
| 9928 | * @param array $data data. |
| 9929 | * |
| 9930 | * @return array |
| 9931 | */ |
| 9932 | public function search_wp_topic_list( $data ) { |
| 9933 | |
| 9934 | if ( ! function_exists( 'WPF' ) ) { |
| 9935 | return []; |
| 9936 | } |
| 9937 | |
| 9938 | $forum_id = $data['dynamic']; |
| 9939 | |
| 9940 | $topics = WPF()->topic->get_topics( [ 'forumid' => $forum_id ] ); |
| 9941 | |
| 9942 | $options = []; |
| 9943 | |
| 9944 | if ( ! empty( $topics ) ) { |
| 9945 | foreach ( $topics as $topic ) { |
| 9946 | $options[] = [ |
| 9947 | 'label' => $topic['title'], |
| 9948 | 'value' => $topic['topicid'], |
| 9949 | ]; |
| 9950 | } |
| 9951 | } |
| 9952 | |
| 9953 | return [ |
| 9954 | 'options' => $options, |
| 9955 | 'hasMore' => false, |
| 9956 | ]; |
| 9957 | } |
| 9958 | |
| 9959 | /** |
| 9960 | * Get wpForo Groups list |
| 9961 | * |
| 9962 | * @param array $data data. |
| 9963 | * |
| 9964 | * @return array |
| 9965 | */ |
| 9966 | public function search_wp_user_groups_list( $data ) { |
| 9967 | |
| 9968 | if ( ! function_exists( 'WPF' ) ) { |
| 9969 | return []; |
| 9970 | } |
| 9971 | |
| 9972 | $usergroups = WPF()->usergroup->get_usergroups(); |
| 9973 | |
| 9974 | $options = []; |
| 9975 | |
| 9976 | if ( ! empty( $usergroups ) ) { |
| 9977 | foreach ( $usergroups as $group ) { |
| 9978 | $options[] = [ |
| 9979 | 'label' => $group['name'], |
| 9980 | 'value' => intval( $group['groupid'] ), |
| 9981 | ]; |
| 9982 | } |
| 9983 | } |
| 9984 | |
| 9985 | return [ |
| 9986 | 'options' => $options, |
| 9987 | 'hasMore' => false, |
| 9988 | ]; |
| 9989 | } |
| 9990 | |
| 9991 | /** |
| 9992 | * Get wpForo Reputation list |
| 9993 | * |
| 9994 | * @param array $data data. |
| 9995 | * |
| 9996 | * @return array |
| 9997 | */ |
| 9998 | public function search_wp_foro_reputation_list( $data ) { |
| 9999 | |
| 10000 | if ( ! function_exists( 'WPF' ) ) { |
| 10001 | return []; |
| 10002 | } |
| 10003 | |
| 10004 | $levels = WPF()->member->levels(); |
| 10005 | $options = []; |
| 10006 | |
| 10007 | if ( ! empty( $levels ) ) { |
| 10008 | foreach ( $levels as $level ) { |
| 10009 | $options[] = [ |
| 10010 | 'label' => esc_attr__( 'Level', 'suretriggers' ) . ' ' . $level . ' - ' . WPF()->member->rating( $level, 'title' ), |
| 10011 | 'value' => strval( $level ), |
| 10012 | ]; |
| 10013 | } |
| 10014 | } |
| 10015 | |
| 10016 | return [ |
| 10017 | 'options' => $options, |
| 10018 | 'hasMore' => false, |
| 10019 | ]; |
| 10020 | } |
| 10021 | |
| 10022 | /** |
| 10023 | * WPForo new topic pluggable data. |
| 10024 | * |
| 10025 | * @param array $data data. |
| 10026 | * @return array |
| 10027 | */ |
| 10028 | public function search_pluggables_wpforo_topic_last_data( $data ) { |
| 10029 | $context = []; |
| 10030 | global $wpdb; |
| 10031 | |
| 10032 | $forum_id = $data['filter']['forum_id']['value']; |
| 10033 | |
| 10034 | if ( -1 == $forum_id ) { |
| 10035 | $results = $wpdb->get_results( 'SELECT * from ' . $wpdb->prefix . 'wpforo_topics WHERE closed = 0 ORDER BY topicid DESC LIMIT 1', ARRAY_A ); |
| 10036 | } else { |
| 10037 | $forum = $forum_id; |
| 10038 | $sql = 'SELECT * FROM ' . $wpdb->prefix . 'wpforo_topics WHERE forumid = %d AND closed = 0 ORDER BY topicid DESC LIMIT 1'; |
| 10039 | $results = $wpdb->get_results( $wpdb->prepare( $sql, $forum ), ARRAY_A );// @phpcs:ignore |
| 10040 | } |
| 10041 | |
| 10042 | if ( ! empty( $results ) ) { |
| 10043 | $context['pluggable_data']['forum_id'] = $results[0]['forumid']; |
| 10044 | $context['pluggable_data']['topic_id'] = $results[0]['topicid']; |
| 10045 | |
| 10046 | if ( function_exists( 'WPF' ) ) { |
| 10047 | $context['pluggable_data']['forum'] = WPF()->forum->get_forum( $results[0]['forumid'] ); |
| 10048 | $context['pluggable_data']['topic'] = WPF()->topic->get_topic( $results[0]['topicid'] ); |
| 10049 | } |
| 10050 | $context['pluggable_data']['user'] = WordPress::get_user_context( $results[0]['userid'] ); |
| 10051 | $context['response_type'] = 'live'; |
| 10052 | } else { |
| 10053 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"forum_id": "2","topic_id": "1","forum": {"forumid": "2","title": "Main Forum","slug": "main-forum","description": "This is a simple parent forum","parentid": "1","icon": "fas fa-comments","cover": 0,"cover_height": "150","last_topicid": "1","last_postid": "2","last_userid": "4","last_post_date": "2023-09-19 11:40:19","topics": "1","posts": "2","permissions": "a:5:{i:1;s:4:\"full\";i:2;s:9:\"moderator\";i:3;s:8:\"standard\";i:4;s:9:\"read_only\";i:5;s:8:\"standard\";}","meta_key": "","meta_desc": "","status": "1","is_cat": "0","layout": "4","order": "0","color": "#888888","url": "https:\/\/example.com\/community\/main-forum\/","cover_url": ""},"topic": {"topicid": "1","forumid": "2","first_postid": "1","userid": "4","title": "New Forum topic title","slug": "new-forum-topic-title","created": "2023-09-19 11:39:01","modified": "2023-09-19 11:40:19","last_post": "2","posts": "2","votes": "0","answers": "0","views": "1","meta_key": "","meta_desc": "","type": "0","solved": "0","closed": "0","has_attach": "0","private": "0","status": "0","name": "","email": "","prefix": "","tags": "","url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/","full_url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/","short_url": "https:\/\/example.com\/community\/topicid\/1\/"},"user": {"wp_user_id": 4,"user_login": "john@d.com","display_name": "john@d.com","user_firstname": "john","user_lastname": "d","user_email": "john@d.com","user_role": ["customer"]}}}', true );// @phpcs:ignore |
| 10054 | } |
| 10055 | |
| 10056 | return $context; |
| 10057 | } |
| 10058 | |
| 10059 | /** |
| 10060 | * WpForo Topic Reply pluggable data. |
| 10061 | * |
| 10062 | * @param array $data data. |
| 10063 | * @return array |
| 10064 | */ |
| 10065 | public function search_pluggables_wpforo_topic_reply_last_data( $data ) { |
| 10066 | $context = []; |
| 10067 | global $wpdb; |
| 10068 | |
| 10069 | $forum_id = $data['filter']['forum_id']['value']; |
| 10070 | $topic_id = $data['filter']['topic_id']['value']; |
| 10071 | |
| 10072 | if ( -1 == $forum_id && -1 != $topic_id ) { |
| 10073 | $sql = 'SELECT * from ' . $wpdb->prefix . 'wpforo_posts WHERE topicid = %d ORDER BY postid DESC LIMIT 1'; |
| 10074 | $results = $wpdb->get_results( $wpdb->prepare( $sql, $topic_id ), ARRAY_A );// @phpcs:ignore |
| 10075 | } elseif ( -1 != $forum_id && -1 == $topic_id ) { |
| 10076 | $sql = 'SELECT * from ' . $wpdb->prefix . 'wpforo_posts WHERE forumid = %d ORDER BY postid DESC LIMIT 1'; |
| 10077 | $results = $wpdb->get_results( $wpdb->prepare( $sql, $forum_id ), ARRAY_A );// @phpcs:ignore |
| 10078 | } elseif ( -1 == $forum_id && -1 == $topic_id ) { |
| 10079 | $sql = 'SELECT * from ' . $wpdb->prefix . 'wpforo_posts ORDER BY postid DESC LIMIT 1'; |
| 10080 | $results = $wpdb->get_results( $wpdb->prepare( $sql ), ARRAY_A );// @phpcs:ignore |
| 10081 | } else { |
| 10082 | $sql = 'SELECT * FROM ' . $wpdb->prefix . 'wpforo_posts WHERE forumid = %d AND topicid = %d ORDER BY postid DESC LIMIT 1'; |
| 10083 | $results = $wpdb->get_results( $wpdb->prepare( $sql, $forum_id, $topic_id ), ARRAY_A );// @phpcs:ignore |
| 10084 | } |
| 10085 | |
| 10086 | if ( ! empty( $results ) ) { |
| 10087 | $context['pluggable_data']['forum_id'] = $results[0]['forumid']; |
| 10088 | $context['pluggable_data']['topic_id'] = $results[0]['topicid']; |
| 10089 | if ( function_exists( 'WPF' ) ) { |
| 10090 | $context['pluggable_data']['forum'] = WPF()->forum->get_forum( $results[0]['forumid'] ); |
| 10091 | $context['pluggable_data']['topic'] = WPF()->topic->get_topic( $results[0]['topicid'] ); |
| 10092 | $context['pluggable_data']['reply'] = WPF()->post->get_post( $results[0]['postid'] ); |
| 10093 | } |
| 10094 | $context['pluggable_data']['user'] = WordPress::get_user_context( $results[0]['userid'] ); |
| 10095 | $context['response_type'] = 'live'; |
| 10096 | } else { |
| 10097 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"forum_id": "2","topic_id": "1","forum": {"forumid": "2","title": "Main Forum","slug": "main-forum","description": "This is a simple parent forum","parentid": "1","icon": "fas fa-comments","cover": 0,"cover_height": "150","last_topicid": "1","last_postid": "2","last_userid": "4","last_post_date": "2023-09-19 11:40:19","topics": "1","posts": "2","permissions": "a:5:{i:1;s:4:\"full\";i:2;s:9:\"moderator\";i:3;s:8:\"standard\";i:4;s:9:\"read_only\";i:5;s:8:\"standard\";}","meta_key": "","meta_desc": "","status": "1","is_cat": "0","layout": "4","order": "0","color": "#888888","url": "https:\/\/example.com\/community\/main-forum\/","cover_url": ""},"topic": {"topicid": "1","forumid": "2","first_postid": "1","userid": "4","title": "New Forum topic title","slug": "new-forum-topic-title","created": "2023-09-19 11:39:01","modified": "2023-09-19 11:40:19","last_post": "2","posts": "2","votes": "0","answers": "0","views": "1","meta_key": "","meta_desc": "","type": "0","solved": "0","closed": "0","has_attach": "0","private": "0","status": "0","name": "","email": "","prefix": "","tags": "","url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/","full_url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/","short_url": "https:\/\/example.com\/community\/topicid\/1\/"},"reply_url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/#post-2","reply": {"postid": "2","parentid": "0","forumid": "2","topicid": "1","userid": 4,"title": "RE: New Forum topic title","body": "<p>new reply<\/p>","created": "2023-09-19 11:40:19","modified": "2023-09-19 11:40:19","likes": "0","votes": "0","is_answer": "0","is_first_post": "0","status": "0","name": "","email": "","private": "0","root": "-1","url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/#post-2","full_url": "https:\/\/example.com\/community\/main-forum\/new-forum-topic-title\/#post-2","short_url": "https:\/\/example.com\/community\/postid\/2\/"},"user": {"wp_user_id": 4,"user_login": "john@d.com","display_name": "john@d.com","user_firstname": "john","user_lastname": "d","user_email": "john@d.com","user_role": ["customer"]}}}', true );// @phpcs:ignore |
| 10098 | } |
| 10099 | |
| 10100 | return $context; |
| 10101 | } |
| 10102 | |
| 10103 | /** |
| 10104 | * Get RafflePress Giveaways list |
| 10105 | * |
| 10106 | * @param array $data data. |
| 10107 | * |
| 10108 | * @return array |
| 10109 | */ |
| 10110 | public function search_rp_giveaways_list( $data ) { |
| 10111 | |
| 10112 | global $wpdb; |
| 10113 | $options = []; |
| 10114 | |
| 10115 | $giveaways = $wpdb->get_results( "SELECT id,name FROM {$wpdb->prefix}rafflepress_giveaways WHERE deleted_at is null ORDER BY name ASC", ARRAY_A ); |
| 10116 | foreach ( $giveaways as $giveaway ) { |
| 10117 | $options[] = [ |
| 10118 | 'label' => $giveaway['name'], |
| 10119 | 'value' => $giveaway['id'], |
| 10120 | ]; |
| 10121 | } |
| 10122 | |
| 10123 | return [ |
| 10124 | 'options' => $options, |
| 10125 | 'hasMore' => false, |
| 10126 | ]; |
| 10127 | } |
| 10128 | |
| 10129 | /** |
| 10130 | * Get RafflePress Giveaway Actions list |
| 10131 | * |
| 10132 | * @param array $data data. |
| 10133 | * |
| 10134 | * @return array |
| 10135 | */ |
| 10136 | public function search_rp_giveaway_actions_list( $data ) { |
| 10137 | |
| 10138 | global $wpdb; |
| 10139 | $options = []; |
| 10140 | |
| 10141 | $giveaway = $wpdb->get_row( $wpdb->prepare( "SELECT settings FROM {$wpdb->prefix}rafflepress_giveaways WHERE id=%d", $data['dynamic'] ), ARRAY_A ); |
| 10142 | |
| 10143 | if ( is_array( $giveaway ) && isset( $giveaway['settings'] ) ) { |
| 10144 | $settings = json_decode( $giveaway['settings'], true ); |
| 10145 | |
| 10146 | if ( is_array( $settings ) && isset( $settings['entry_options'] ) ) { |
| 10147 | foreach ( $settings['entry_options'] as $action ) { |
| 10148 | $options[] = [ |
| 10149 | 'label' => $action['name'], |
| 10150 | 'value' => $action['id'], |
| 10151 | ]; |
| 10152 | } |
| 10153 | } |
| 10154 | } |
| 10155 | |
| 10156 | return [ |
| 10157 | 'options' => $options, |
| 10158 | 'hasMore' => false, |
| 10159 | ]; |
| 10160 | } |
| 10161 | |
| 10162 | /** |
| 10163 | * Get last data for trigger. |
| 10164 | * |
| 10165 | * @param array $data data. |
| 10166 | * @return array |
| 10167 | */ |
| 10168 | public function search_raffle_press_triggers_last_data( $data ) { |
| 10169 | |
| 10170 | global $wpdb; |
| 10171 | |
| 10172 | $context = []; |
| 10173 | $context['response_type'] = 'sample'; |
| 10174 | |
| 10175 | $pluggable_data = [ |
| 10176 | 'giveaway_id' => 1, |
| 10177 | 'giveaway_title' => 'Sample Giveaway (ID#1)', |
| 10178 | 'giveaway_start_date' => 'September 20, 2023', |
| 10179 | 'giveaway_end_date' => 'October 6, 2023', |
| 10180 | 'giveaway_entries' => 9, |
| 10181 | 'giveaway_user_count' => 3, |
| 10182 | 'giveaway_status' => 'Active', |
| 10183 | 'contestant_name' => 'John Doe', |
| 10184 | 'contestant_email' => 'john_doe@gmail.com', |
| 10185 | 'contestant_email_verified' => 'Yes', |
| 10186 | 'action_id' => '0jnex', |
| 10187 | 'action_name' => 'Visit us on Instagram', |
| 10188 | ]; |
| 10189 | |
| 10190 | $giveaway_id = isset( $data['filter']['giveaway_id'] ) ? $data['filter']['giveaway_id']['value'] : null; |
| 10191 | $action_id = isset( $data['filter']['action_id'] ) ? $data['filter']['action_id']['value'] : null; |
| 10192 | |
| 10193 | $query = "SELECT contestant_id, giveaway_id, action_id, meta FROM {$wpdb->prefix}rafflepress_entries"; |
| 10194 | |
| 10195 | if ( $giveaway_id && -1 != $giveaway_id ) { |
| 10196 | $query .= ' WHERE giveaway_id = ' . $giveaway_id; |
| 10197 | |
| 10198 | if ( $action_id ) { |
| 10199 | $query .= " AND action_id = '" . $action_id . "'"; |
| 10200 | } |
| 10201 | } |
| 10202 | |
| 10203 | $query .= ' ORDER BY created_at DESC LIMIT 1'; |
| 10204 | |
| 10205 | $giveaway_data = $wpdb->get_row( $query, ARRAY_A ); // @phpcs:ignore |
| 10206 | |
| 10207 | if ( ! empty( $giveaway_data ) ) { |
| 10208 | $pluggable_data = array_merge( |
| 10209 | RafflePress::get_giveaway_context( $giveaway_data['giveaway_id'] ), |
| 10210 | RafflePress::get_contestant_context( $giveaway_data['contestant_id'] ) |
| 10211 | ); |
| 10212 | |
| 10213 | $pluggable_data['performed_action_id'] = isset( $giveaway_data['action_id'] ) ? $giveaway_data['action_id'] : 0; |
| 10214 | |
| 10215 | $giveaway_meta = isset( $giveaway_data['meta'] ) ? json_decode( $giveaway_data['meta'], true ) : []; |
| 10216 | $pluggable_data['performed_action_name'] = is_array( $giveaway_meta ) && isset( $giveaway_meta['action'] ) ? $giveaway_meta['action'] : ''; |
| 10217 | |
| 10218 | $context['response_type'] = 'live'; |
| 10219 | } |
| 10220 | |
| 10221 | $context['pluggable_data'] = $pluggable_data; |
| 10222 | |
| 10223 | return $context; |
| 10224 | } |
| 10225 | |
| 10226 | /** |
| 10227 | * Get last data for trigger |
| 10228 | * |
| 10229 | * @param array $data data. |
| 10230 | * @return array |
| 10231 | */ |
| 10232 | public function search_woo_commerce_shipstation_triggers_last_data( $data ) { |
| 10233 | $context = []; |
| 10234 | $context['response_type'] = 'sample'; |
| 10235 | $context['pluggable_data'] = []; |
| 10236 | |
| 10237 | $order_sample_data = json_decode( '{"product_id": 47,"id": 49,"parent_id": 0,"status": "completed","currency": "USD","version": "8.1.1","prices_include_tax": false,"date_created": {"date": "2023-09-23 10:28:00.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-09-23 10:29:55.000000","timezone_type": 1,"timezone": "+00:00"},"discount_total": "0","discount_tax": "0", "shipping_total": "0","shipping_tax": "0","cart_tax": "0","total": "1.00","total_tax": "0","customer_id": 1,"order_key": "wc_order_64IaGkeQKRXdm","billing": {"first_name": "john","last_name": "d","company": "","address_1": "123 Main Street","address_2": "","city": "London","state": "Greater London","postcode": "SW1A 1AA","country": "GB","email": "johnd@d.com","phone": "9878988766"},"shipping": {"first_name": "","last_name": "","company": "","address_1": "","address_2": "","city": "","state": "","postcode": "","country": "","phone": ""},"payment_method": "cod","payment_method_title": "Cash on delivery","transaction_id": "","customer_ip_address": "182.184.87.226","customer_user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/116.0.0.0 Safari\/537.36","created_via": "checkout","customer_note": "", "date_completed": { "date": "2023-09-23 10:29:55.000000", "timezone_type": 1, "timezone": "+00:00" }, "date_paid": { "date": "2023-09-23 10:29:55.000000", "timezone_type": 1, "timezone": "+00:00" }, "cart_hash": "ac073abcdc9a52025211d0fad52cfa46", "order_stock_reduced": true, "download_permissions_granted": true, "new_order_email_sent": true, "recorded_sales": true, "recorded_coupon_usage_counts": true, "number": "49", "meta_data": [{ "id": 1206, "key":"is_vat_exempt", "value": "no"},{"id": 1207,"key": "weglot_language","value": "en"},{"id": 1208,"key": "_shipstation_exported","value": "yes"},{"id": 1209,"key": "_shipstation_shipped_item_count","value": "1"}],"line_items": {"id": "25","order_id": "49","name": "New Product","product_id": "47","variation_id": "0","quantity": "1","tax_class": "","subtotal": "1","subtotal_tax": "0","total": "1","total_tax": "0","taxes": "","meta_data": []},"tax_lines": [],"shipping_lines": [],"fee_lines": [],"coupon_lines": [],"coupons": [],"products": [{"id": 25,"order_id": 49,"name": "New Product","product_id": 47,"variation_id": 0,"quantity": 1,"tax_class": "","subtotal": "1","subtotal_tax": "0","total": "1","total_tax": "0","taxes": {"total": [],"subtotal": []},"meta_data": []}],"quantity": "1","wp_user_id": 1,"user_login": "johnd","display_name": "johnd","user_firstname": "john","user_lastname": "d","user_email": "johnd@d.com","user_role": ["administrator"],"shipping_tracking_number": "","shipping_carrier": "","ship_date": "",}', true ); //phpcs:ignore |
| 10238 | |
| 10239 | $product_id = (int) ( isset( $data['filter']['product_id']['value'] ) ? $data['filter']['product_id']['value'] : -1 ); |
| 10240 | $condition = $data['filter']['condition_compare']['value']; |
| 10241 | $price = $data['filter']['price']['value']; |
| 10242 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 10243 | |
| 10244 | if ( 'order_shipped' === $term ) { |
| 10245 | $orders = wc_get_orders( |
| 10246 | [ |
| 10247 | 'numberposts' => 1, |
| 10248 | 'orderby' => 'date', |
| 10249 | 'order' => 'DESC', |
| 10250 | 'status' => 'completed', |
| 10251 | 'meta_query' => [ |
| 10252 | [ |
| 10253 | 'key' => '_shipstation_shipped_item_count', |
| 10254 | 'compare' => 'EXISTS', |
| 10255 | ], |
| 10256 | ], |
| 10257 | ] |
| 10258 | ); |
| 10259 | if ( count( $orders ) > 0 ) { |
| 10260 | $order_id = $orders[0]->get_id(); |
| 10261 | $order = wc_get_order( $order_id ); |
| 10262 | $user_id = $order->get_customer_id(); |
| 10263 | $product_ids = []; |
| 10264 | if ( $order ) { |
| 10265 | $items = $order->get_items(); |
| 10266 | foreach ( $items as $item ) { |
| 10267 | if ( method_exists( $item, 'get_product_id' ) ) { |
| 10268 | $product_ids[] = $item->get_product_id(); |
| 10269 | } |
| 10270 | } |
| 10271 | |
| 10272 | foreach ( $product_ids as $product_id ) { |
| 10273 | $context['product_id'] = $product_id; |
| 10274 | } |
| 10275 | } |
| 10276 | $context = array_merge( |
| 10277 | WooCommerce::get_order_context( $order_id ), |
| 10278 | WordPress::get_user_context( $user_id ) |
| 10279 | ); |
| 10280 | $context['shipping_tracking_number'] = $order->get_meta( '_tracking_number', true ); |
| 10281 | $context['shipping_carrier'] = $order->get_meta( '_tracking_provider', true ); |
| 10282 | /** |
| 10283 | * |
| 10284 | * Ignore line |
| 10285 | * |
| 10286 | * @phpstan-ignore-next-line |
| 10287 | */ |
| 10288 | $timestamp = strtotime( $order->get_meta( '_date_shipped', true ) ); |
| 10289 | /** |
| 10290 | * |
| 10291 | * Ignore line |
| 10292 | * |
| 10293 | * @phpstan-ignore-next-line |
| 10294 | */ |
| 10295 | $date = date_i18n( get_option( 'date_format' ), $timestamp ); |
| 10296 | $context['ship_date'] = $date; |
| 10297 | $context['response_type'] = 'live'; |
| 10298 | } |
| 10299 | |
| 10300 | $context['pluggable_data'] = $context; |
| 10301 | } elseif ( 'specific_product_order_shipped' === $term ) { |
| 10302 | if ( -1 != $product_id ) { |
| 10303 | $product_ids = [ $product_id ]; |
| 10304 | $orders = wc_get_orders( |
| 10305 | [ |
| 10306 | 'numberposts' => 1, |
| 10307 | 'orderby' => 'date', |
| 10308 | 'order' => 'DESC', |
| 10309 | 'status' => 'completed', |
| 10310 | 'meta_query' => [ |
| 10311 | [ |
| 10312 | 'key' => '_shipstation_shipped_item_count', |
| 10313 | 'compare' => 'EXISTS', |
| 10314 | ], |
| 10315 | [ |
| 10316 | 'key' => '_product_id', |
| 10317 | 'value' => $product_ids, |
| 10318 | 'compare' => 'IN', |
| 10319 | ], |
| 10320 | ], |
| 10321 | ] |
| 10322 | ); |
| 10323 | } else { |
| 10324 | $orders = wc_get_orders( |
| 10325 | [ |
| 10326 | 'numberposts' => 1, |
| 10327 | 'orderby' => 'date', |
| 10328 | 'order' => 'DESC', |
| 10329 | 'status' => 'completed', |
| 10330 | 'meta_query' => [ |
| 10331 | [ |
| 10332 | 'key' => '_shipstation_shipped_item_count', |
| 10333 | 'compare' => 'EXISTS', |
| 10334 | ], |
| 10335 | ], |
| 10336 | ] |
| 10337 | ); |
| 10338 | } |
| 10339 | if ( count( $orders ) > 0 ) { |
| 10340 | $order_id = $orders[0]->get_id(); |
| 10341 | $order = wc_get_order( $order_id ); |
| 10342 | $user_id = $order->get_customer_id(); |
| 10343 | $productids = []; |
| 10344 | $items = $order->get_items(); |
| 10345 | foreach ( $items as $item ) { |
| 10346 | if ( method_exists( $item, 'get_product_id' ) ) { |
| 10347 | $productids[] = $item->get_product_id(); |
| 10348 | } |
| 10349 | } |
| 10350 | $context = array_merge( |
| 10351 | WooCommerce::get_order_context( $order_id ), |
| 10352 | WordPress::get_user_context( $user_id ) |
| 10353 | ); |
| 10354 | |
| 10355 | foreach ( $productids as $product_id ) { |
| 10356 | $context['product_id'] = $product_id; |
| 10357 | } |
| 10358 | |
| 10359 | $context['shipping_tracking_number'] = $order->get_meta( '_tracking_number', true ); |
| 10360 | $context['shipping_carrier'] = $order->get_meta( '_tracking_provider', true ); |
| 10361 | /** |
| 10362 | * |
| 10363 | * Ignore line |
| 10364 | * |
| 10365 | * @phpstan-ignore-next-line |
| 10366 | */ |
| 10367 | $timestamp = strtotime( $order->get_meta( '_date_shipped', true ) ); |
| 10368 | /** |
| 10369 | * |
| 10370 | * Ignore line |
| 10371 | * |
| 10372 | * @phpstan-ignore-next-line |
| 10373 | */ |
| 10374 | $date = date_i18n( get_option( 'date_format' ), $timestamp ); |
| 10375 | $context['ship_date'] = $date; |
| 10376 | $context['response_type'] = 'live'; |
| 10377 | } |
| 10378 | |
| 10379 | $context['pluggable_data'] = $context; |
| 10380 | } elseif ( 'specific_amount_order_shipped' === $term ) { |
| 10381 | $orders = wc_get_orders( |
| 10382 | [ |
| 10383 | 'numberposts' => 1, |
| 10384 | 'orderby' => 'date', |
| 10385 | 'order' => 'DESC', |
| 10386 | 'status' => 'completed', |
| 10387 | 'meta_query' => [ |
| 10388 | [ |
| 10389 | 'key' => '_shipstation_shipped_item_count', |
| 10390 | 'compare' => 'EXISTS', |
| 10391 | ], |
| 10392 | [ |
| 10393 | 'key' => '_order_total', |
| 10394 | 'value' => $price, |
| 10395 | 'compare' => $condition, |
| 10396 | ], |
| 10397 | ], |
| 10398 | ] |
| 10399 | ); |
| 10400 | if ( count( $orders ) > 0 ) { |
| 10401 | $order_id = $orders[0]->get_id(); |
| 10402 | $order = wc_get_order( $order_id ); |
| 10403 | $user_id = $order->get_customer_id(); |
| 10404 | $product_ids = []; |
| 10405 | $items = $order->get_items(); |
| 10406 | foreach ( $items as $item ) { |
| 10407 | if ( method_exists( $item, 'get_product_id' ) ) { |
| 10408 | $product_ids[] = $item->get_product_id(); |
| 10409 | } |
| 10410 | } |
| 10411 | $context = array_merge( |
| 10412 | WooCommerce::get_order_context( $order_id ), |
| 10413 | WordPress::get_user_context( $user_id ) |
| 10414 | ); |
| 10415 | |
| 10416 | foreach ( $product_ids as $product_id ) { |
| 10417 | $context['product_id'] = $product_id; |
| 10418 | } |
| 10419 | |
| 10420 | $context['shipping_tracking_number'] = $order->get_meta( '_tracking_number', true ); |
| 10421 | $context['shipping_carrier'] = $order->get_meta( '_tracking_provider', true ); |
| 10422 | /** |
| 10423 | * |
| 10424 | * Ignore line |
| 10425 | * |
| 10426 | * @phpstan-ignore-next-line |
| 10427 | */ |
| 10428 | $timestamp = strtotime( $order->get_meta( '_date_shipped', true ) ); |
| 10429 | /** |
| 10430 | * |
| 10431 | * Ignore line |
| 10432 | * |
| 10433 | * @phpstan-ignore-next-line |
| 10434 | */ |
| 10435 | $date = date_i18n( get_option( 'date_format' ), $timestamp ); |
| 10436 | $context['ship_date'] = $date; |
| 10437 | $context['response_type'] = 'live'; |
| 10438 | } |
| 10439 | |
| 10440 | $context['pluggable_data'] = $context; |
| 10441 | } |
| 10442 | |
| 10443 | return $context; |
| 10444 | } |
| 10445 | |
| 10446 | /** |
| 10447 | * Get GroundHogg Tag list |
| 10448 | * |
| 10449 | * @param array $data data. |
| 10450 | * |
| 10451 | * @return array |
| 10452 | */ |
| 10453 | public function search_groundhogg_tag_list( $data ) { |
| 10454 | if ( ! class_exists( '\Groundhogg\DB\Tags' ) ) { |
| 10455 | return []; |
| 10456 | } |
| 10457 | |
| 10458 | $tags = new \Groundhogg\DB\Tags(); |
| 10459 | $options = []; |
| 10460 | |
| 10461 | if ( ! empty( $tags->get_tags() ) ) { |
| 10462 | foreach ( $tags->get_tags() as $tag ) { |
| 10463 | $options[] = [ |
| 10464 | 'label' => $tag->tag_name, |
| 10465 | 'value' => $tag->tag_id, |
| 10466 | ]; |
| 10467 | } |
| 10468 | } |
| 10469 | |
| 10470 | return [ |
| 10471 | 'options' => $options, |
| 10472 | 'hasMore' => false, |
| 10473 | ]; |
| 10474 | } |
| 10475 | |
| 10476 | /** |
| 10477 | * Get WP courseware courses list |
| 10478 | * |
| 10479 | * @param array $data data. |
| 10480 | * |
| 10481 | * @return array |
| 10482 | */ |
| 10483 | public function search_wpcw_courses( $data ) { |
| 10484 | $options = []; |
| 10485 | |
| 10486 | $page = $data['page']; |
| 10487 | $limit = Utilities::get_search_page_limit(); |
| 10488 | $offset = $limit * ( $page - 1 ); |
| 10489 | |
| 10490 | $args = [ |
| 10491 | 'post_type' => 'wpcw_course', |
| 10492 | 'posts_per_page' => $limit, |
| 10493 | 'offset' => $offset, |
| 10494 | 'orderby' => 'title', |
| 10495 | 'order' => 'ASC', |
| 10496 | 'post_status' => 'publish', |
| 10497 | ]; |
| 10498 | |
| 10499 | $courses = get_posts( $args ); |
| 10500 | |
| 10501 | $course_count = wp_count_posts( 'wpcw_course' )->publish; |
| 10502 | |
| 10503 | if ( ! empty( $courses ) ) { |
| 10504 | if ( is_array( $courses ) ) { |
| 10505 | foreach ( $courses as $course ) { |
| 10506 | $options[] = [ |
| 10507 | 'label' => $course->post_title, |
| 10508 | 'value' => $course->ID, |
| 10509 | ]; |
| 10510 | } |
| 10511 | } |
| 10512 | } |
| 10513 | return [ |
| 10514 | 'options' => $options, |
| 10515 | 'hasMore' => $course_count > $limit && $course_count > $offset, |
| 10516 | ]; |
| 10517 | } |
| 10518 | |
| 10519 | /** |
| 10520 | * Get WP courseware courses list |
| 10521 | * |
| 10522 | * @param array $data data. |
| 10523 | * |
| 10524 | * @return array |
| 10525 | */ |
| 10526 | public function search_wpcw_modules( $data ) { |
| 10527 | $options = []; |
| 10528 | |
| 10529 | if ( function_exists( 'wpcw_get_modules' ) ) { |
| 10530 | $modules = wpcw_get_modules(); |
| 10531 | } |
| 10532 | |
| 10533 | if ( ! empty( $modules ) ) { |
| 10534 | if ( is_array( $modules ) ) { |
| 10535 | foreach ( $modules as $module ) { |
| 10536 | $options[] = [ |
| 10537 | 'label' => $module->module_title, |
| 10538 | 'value' => $module->module_id, |
| 10539 | ]; |
| 10540 | } |
| 10541 | } |
| 10542 | } |
| 10543 | return [ |
| 10544 | 'options' => $options, |
| 10545 | 'hasMore' => false, |
| 10546 | ]; |
| 10547 | } |
| 10548 | |
| 10549 | /** |
| 10550 | * Get WP courseware unit list |
| 10551 | * |
| 10552 | * @param array $data data. |
| 10553 | * |
| 10554 | * @return array |
| 10555 | */ |
| 10556 | public function search_wpcw_units( $data ) { |
| 10557 | $options = []; |
| 10558 | |
| 10559 | $page = $data['page']; |
| 10560 | $limit = Utilities::get_search_page_limit(); |
| 10561 | $offset = $limit * ( $page - 1 ); |
| 10562 | |
| 10563 | $args = [ |
| 10564 | 'post_type' => 'course_unit', |
| 10565 | 'posts_per_page' => $limit, |
| 10566 | 'offset' => $offset, |
| 10567 | 'orderby' => 'title', |
| 10568 | 'order' => 'ASC', |
| 10569 | 'post_status' => 'publish', |
| 10570 | ]; |
| 10571 | |
| 10572 | $units = get_posts( $args ); |
| 10573 | |
| 10574 | $unit_count = wp_count_posts( 'course_unit' )->publish; |
| 10575 | |
| 10576 | if ( ! empty( $units ) ) { |
| 10577 | if ( is_array( $units ) ) { |
| 10578 | foreach ( $units as $unit ) { |
| 10579 | $options[] = [ |
| 10580 | 'label' => $unit->post_title, |
| 10581 | 'value' => $unit->ID, |
| 10582 | ]; |
| 10583 | } |
| 10584 | } |
| 10585 | } |
| 10586 | return [ |
| 10587 | 'options' => $options, |
| 10588 | 'hasMore' => $unit_count > $limit && $unit_count > $offset, |
| 10589 | ]; |
| 10590 | } |
| 10591 | |
| 10592 | /** |
| 10593 | * Search WP Courseware data. |
| 10594 | * |
| 10595 | * @param array $data data. |
| 10596 | * @return array|void |
| 10597 | */ |
| 10598 | public function search_wpcw_last_data( $data ) { |
| 10599 | global $wpdb; |
| 10600 | $post_type = $data['post_type']; |
| 10601 | $trigger = $data['search_term']; |
| 10602 | $context = []; |
| 10603 | |
| 10604 | if ( 'wpcw_course_completed' === $trigger ) { |
| 10605 | $post_id = $data['filter']['course_post_id']['value']; |
| 10606 | if ( -1 === $post_id ) { |
| 10607 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.course_progress=100 order by postmeta.user_id DESC LIMIT 1" ); |
| 10608 | } else { |
| 10609 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.course_id = %s AND postmeta.course_progress=100 order by postmeta.user_id DESC LIMIT 1", $post_id ) ); |
| 10610 | } |
| 10611 | } elseif ( 'wpcw_module_completed' === $trigger ) { |
| 10612 | $post_id = $data['filter']['module_id']['value']; |
| 10613 | if ( -1 === $post_id ) { |
| 10614 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}wpcw_modules as posts ON posts.parent_course_id=postmeta.course_id WHERE postmeta.course_progress>=0 order by postmeta.course_enrolment_date DESC LIMIT 1" ); |
| 10615 | } else { |
| 10616 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}wpcw_modules as posts ON posts.parent_course_id=postmeta.course_id WHERE postmeta.course_progress>=0 AND posts.module_id=%s order by postmeta.course_enrolment_date DESC LIMIT 1", $post_id ) ); |
| 10617 | } |
| 10618 | } elseif ( 'wpcw_unit_completed' === $trigger ) { |
| 10619 | $post_id = $data['filter']['unit_id']['value']; |
| 10620 | if ( -1 === $post_id ) { |
| 10621 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpcw_user_progress WHERE unit_completed_status='complete' order by unit_id DESC LIMIT 1" ); |
| 10622 | } else { |
| 10623 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpcw_user_progress WHERE unit_id=%d AND unit_completed_status='complete' order by unit_id DESC LIMIT 1", $post_id ) ); |
| 10624 | } |
| 10625 | } elseif ( 'wpcw_enroll_course' === $trigger ) { |
| 10626 | $post_id = $data['filter']['course_post_id']['value']; |
| 10627 | if ( -1 === $post_id ) { |
| 10628 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}wpcw_courses as posts ON posts.course_id=postmeta.course_id order by course_enrolment_date DESC LIMIT 1" ); |
| 10629 | } else { |
| 10630 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpcw_user_courses as postmeta JOIN {$wpdb->prefix}wpcw_courses as posts ON posts.course_id=postmeta.course_id WHERE posts.course_post_id=%d order by course_enrolment_date DESC LIMIT 1", $post_id ) ); |
| 10631 | } |
| 10632 | } |
| 10633 | |
| 10634 | if ( ! empty( $result ) ) { |
| 10635 | |
| 10636 | switch ( $trigger ) { |
| 10637 | case 'wpcw_course_completed': |
| 10638 | $result_course_id = $result[0]->course_id; |
| 10639 | $result_user_id = $result[0]->user_id; |
| 10640 | if ( function_exists( 'wpcw_get_course' ) ) { |
| 10641 | $course = wpcw_get_course( $result_course_id ); |
| 10642 | if ( is_object( $course ) ) { |
| 10643 | $course = get_object_vars( $course ); |
| 10644 | } |
| 10645 | $context = array_merge( WordPress::get_user_context( $result_user_id ), $course ); |
| 10646 | } |
| 10647 | break; |
| 10648 | case 'wpcw_module_completed': |
| 10649 | $result_module_id = $result[0]->module_id; |
| 10650 | $result_user_id = $result[0]->user_id; |
| 10651 | if ( function_exists( 'wpcw_get_module' ) ) { |
| 10652 | $module = wpcw_get_module( $result_module_id ); |
| 10653 | if ( is_object( $module ) ) { |
| 10654 | $module = get_object_vars( $module ); |
| 10655 | } |
| 10656 | $context = array_merge( WordPress::get_user_context( $result_user_id ), $module ); |
| 10657 | } |
| 10658 | break; |
| 10659 | case 'wpcw_unit_completed': |
| 10660 | $result_unit_id = $result[0]->unit_id; |
| 10661 | $result_user_id = $result[0]->user_id; |
| 10662 | if ( function_exists( 'wpcw_get_unit' ) ) { |
| 10663 | $unit = wpcw_get_unit( $result_unit_id ); |
| 10664 | if ( is_object( $unit ) ) { |
| 10665 | $unit = get_object_vars( $unit ); |
| 10666 | $unit['name'] = get_the_title( $result_unit_id ); |
| 10667 | } |
| 10668 | $context = array_merge( WordPress::get_user_context( $result_user_id ), $unit ); |
| 10669 | } |
| 10670 | break; |
| 10671 | case 'wpcw_enroll_course': |
| 10672 | $result_course_id = $result[0]->course_id; |
| 10673 | $result_user_id = $result[0]->user_id; |
| 10674 | if ( function_exists( 'WPCW_courses_getCourseDetails' ) ) { |
| 10675 | $course_detail = WPCW_courses_getCourseDetails( $result_course_id ); |
| 10676 | if ( is_object( $course_detail ) ) { |
| 10677 | $course_detail = get_object_vars( $course_detail ); |
| 10678 | } |
| 10679 | $context = array_merge( WordPress::get_user_context( $result_user_id ), $course_detail ); |
| 10680 | } |
| 10681 | break; |
| 10682 | default: |
| 10683 | return; |
| 10684 | } |
| 10685 | $context['pluggable_data'] = $context; |
| 10686 | $context['response_type'] = 'live'; |
| 10687 | } |
| 10688 | |
| 10689 | return $context; |
| 10690 | |
| 10691 | } |
| 10692 | |
| 10693 | /** |
| 10694 | * Get WooCommerce Order Note list. |
| 10695 | * |
| 10696 | * @param array $data data. |
| 10697 | * |
| 10698 | * @return array |
| 10699 | */ |
| 10700 | public function search_note_type_list( $data ) { |
| 10701 | |
| 10702 | $options = []; |
| 10703 | |
| 10704 | $options[] = [ |
| 10705 | 'label' => 'Customer', |
| 10706 | 'value' => 'customer', |
| 10707 | ]; |
| 10708 | $options[] = [ |
| 10709 | 'label' => 'Private', |
| 10710 | 'value' => 'internal', |
| 10711 | ]; |
| 10712 | |
| 10713 | return [ |
| 10714 | 'options' => $options, |
| 10715 | 'hasMore' => false, |
| 10716 | ]; |
| 10717 | } |
| 10718 | |
| 10719 | /** |
| 10720 | * Get last data for trigger |
| 10721 | * |
| 10722 | * @param array $data data. |
| 10723 | * @return array |
| 10724 | */ |
| 10725 | public function search_woo_commerce_customers_triggers_last_data( $data ) { |
| 10726 | $context = []; |
| 10727 | $context['response_type'] = 'sample'; |
| 10728 | $context['pluggable_data'] = []; |
| 10729 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 10730 | global $wpdb; |
| 10731 | if ( 'customer_created' === $term ) { |
| 10732 | $customer_query = get_users( |
| 10733 | [ |
| 10734 | 'fields' => 'ID', |
| 10735 | 'role' => 'customer', |
| 10736 | 'orderby' => 'ID', |
| 10737 | 'order' => 'DESC', |
| 10738 | 'number' => 1, |
| 10739 | ] |
| 10740 | ); |
| 10741 | $results = $customer_query; |
| 10742 | if ( ! empty( $results ) ) { |
| 10743 | $customer = new WC_Customer( $results[0] ); |
| 10744 | $last_order = $customer->get_last_order(); |
| 10745 | $customer_data = [ |
| 10746 | 'id' => $customer->get_id(), |
| 10747 | 'email' => $customer->get_email(), |
| 10748 | 'first_name' => $customer->get_first_name(), |
| 10749 | 'last_name' => $customer->get_last_name(), |
| 10750 | 'username' => $customer->get_username(), |
| 10751 | 'last_order_id' => is_object( $last_order ) ? $last_order->get_id() : null, |
| 10752 | 'orders_count' => $customer->get_order_count(), |
| 10753 | 'total_spent' => wc_format_decimal( $customer->get_total_spent(), 2 ), |
| 10754 | 'avatar_url' => $customer->get_avatar_url(), |
| 10755 | 'billing_address' => [ |
| 10756 | 'first_name' => $customer->get_billing_first_name(), |
| 10757 | 'last_name' => $customer->get_billing_last_name(), |
| 10758 | 'company' => $customer->get_billing_company(), |
| 10759 | 'address_1' => $customer->get_billing_address_1(), |
| 10760 | 'address_2' => $customer->get_billing_address_2(), |
| 10761 | 'city' => $customer->get_billing_city(), |
| 10762 | 'state' => $customer->get_billing_state(), |
| 10763 | 'postcode' => $customer->get_billing_postcode(), |
| 10764 | 'country' => $customer->get_billing_country(), |
| 10765 | 'email' => $customer->get_billing_email(), |
| 10766 | 'phone' => $customer->get_billing_phone(), |
| 10767 | ], |
| 10768 | 'shipping_address' => [ |
| 10769 | 'first_name' => $customer->get_shipping_first_name(), |
| 10770 | 'last_name' => $customer->get_shipping_last_name(), |
| 10771 | 'company' => $customer->get_shipping_company(), |
| 10772 | 'address_1' => $customer->get_shipping_address_1(), |
| 10773 | 'address_2' => $customer->get_shipping_address_2(), |
| 10774 | 'city' => $customer->get_shipping_city(), |
| 10775 | 'state' => $customer->get_shipping_state(), |
| 10776 | 'postcode' => $customer->get_shipping_postcode(), |
| 10777 | 'country' => $customer->get_shipping_country(), |
| 10778 | ], |
| 10779 | ]; |
| 10780 | if ( is_object( $last_order ) && method_exists( $last_order, 'get_date_created' ) ) { |
| 10781 | $created_date = $last_order->get_date_created(); |
| 10782 | if ( is_object( $created_date ) && method_exists( $created_date, 'getTimestamp' ) ) { |
| 10783 | $last_order_date = $created_date->getTimestamp(); |
| 10784 | $customer_data['created_at'] = $last_order_date; |
| 10785 | $customer_data['last_order_date'] = $last_order_date; |
| 10786 | } |
| 10787 | } |
| 10788 | $order_sample_data = $customer_data; |
| 10789 | $context['response_type'] = 'live'; |
| 10790 | $context['pluggable_data'] = $order_sample_data; |
| 10791 | } else { |
| 10792 | $order_sample_data = json_decode( '{"id": 158,"email": "johnd@d.com","first_name": "john","last_name": "d","username": "johnd","last_order_id": 6604,"orders_count": 3,"total_spent": "45.00","avatar_url": "https:\/\/secure.gravatar.com\/avatar\/0f9c8dc78cff3ea4d447b2297c8f6803?s=96&d=mm&r=g","billing_address": {"first_name": "john","last_name": "d","company": "","address_1": "","address_2": "","city": "London","state": "TN","postcode": "PV1 QW2","country": "UK","email": "johnd@d.com","phone": "9878988766"},"shipping_address": {"first_name": "","last_name": "","company": "","address_1": "","address_2": "","city": "","state": "","postcode": "","country": ""},"created_at": 1697631243,"last_order_date": 1697631243}', true ); |
| 10793 | $context['pluggable_data'] = $order_sample_data; |
| 10794 | } |
| 10795 | } elseif ( 'total_spend_reach' === $term ) { |
| 10796 | $total_spend_selected = isset( $data['filter']['total_spend']['value'] ) ? $data['filter']['total_spend']['value'] : ''; |
| 10797 | $customers = $wpdb->get_col( |
| 10798 | "SELECT DISTINCT meta_value FROM $wpdb->postmeta |
| 10799 | WHERE meta_key = '_customer_user' AND meta_value > 0" |
| 10800 | ); |
| 10801 | $target_customer = null; |
| 10802 | foreach ( $customers as $customer ) { |
| 10803 | $total_spend = (int) wc_get_customer_total_spent( $customer ); |
| 10804 | if ( $total_spend == $total_spend_selected ) { |
| 10805 | $target_customer = $customer; |
| 10806 | break; // Exit the loop once a matching customer is found. |
| 10807 | } |
| 10808 | } |
| 10809 | if ( $target_customer ) { |
| 10810 | $new_customer = new WC_Customer( $target_customer ); |
| 10811 | $new_customer_data = [ |
| 10812 | 'id' => $new_customer->get_id(), |
| 10813 | 'email' => $new_customer->get_email(), |
| 10814 | 'first_name' => $new_customer->get_first_name(), |
| 10815 | 'last_name' => $new_customer->get_last_name(), |
| 10816 | 'username' => $new_customer->get_username(), |
| 10817 | 'order_count' => $new_customer->get_order_count(), |
| 10818 | 'total_spend' => wc_format_decimal( $new_customer->get_total_spent(), 2 ), |
| 10819 | ]; |
| 10820 | $context['response_type'] = 'live'; |
| 10821 | $context['pluggable_data'] = $new_customer_data; |
| 10822 | } else { |
| 10823 | $sample_customer_data = [ |
| 10824 | 'id' => '101', |
| 10825 | 'created_at' => '1680675247', |
| 10826 | 'email' => 'john@d.com', |
| 10827 | 'first_name' => 'John', |
| 10828 | 'last_name' => 'D', |
| 10829 | 'username' => 'johnd', |
| 10830 | 'order_count' => '3', |
| 10831 | 'total_spend' => '22.00', |
| 10832 | ]; |
| 10833 | $context['pluggable_data'] = $sample_customer_data; |
| 10834 | } |
| 10835 | } elseif ( 'order_count_reach' === $term ) { |
| 10836 | $total_order_selected = isset( $data['filter']['order_count']['value'] ) ? $data['filter']['order_count']['value'] : ''; |
| 10837 | $customers = $wpdb->get_col( |
| 10838 | "SELECT DISTINCT meta_value FROM $wpdb->postmeta |
| 10839 | WHERE meta_key = '_customer_user' AND meta_value > 0" |
| 10840 | ); |
| 10841 | $target_customer = null; |
| 10842 | foreach ( $customers as $customer ) { |
| 10843 | $args = [ |
| 10844 | 'customer_id' => $customer, |
| 10845 | 'limit' => -1, |
| 10846 | 'status' => [ 'wc-completed' ], |
| 10847 | ]; |
| 10848 | $orders = wc_get_orders( $args ); |
| 10849 | if ( ! empty( $orders ) ) { |
| 10850 | $total_order = (int) wc_get_customer_order_count( $customer ); |
| 10851 | if ( $total_order == $total_order_selected ) { |
| 10852 | $target_customer = $customer; |
| 10853 | break; // Exit the loop once a matching customer is found. |
| 10854 | } |
| 10855 | } |
| 10856 | } |
| 10857 | if ( $target_customer ) { |
| 10858 | $new_customer = new WC_Customer( $target_customer ); |
| 10859 | $new_customer_data = [ |
| 10860 | 'id' => $new_customer->get_id(), |
| 10861 | 'email' => $new_customer->get_email(), |
| 10862 | 'first_name' => $new_customer->get_first_name(), |
| 10863 | 'last_name' => $new_customer->get_last_name(), |
| 10864 | 'username' => $new_customer->get_username(), |
| 10865 | 'order_count' => $new_customer->get_order_count(), |
| 10866 | ]; |
| 10867 | $context['response_type'] = 'live'; |
| 10868 | $context['pluggable_data'] = $new_customer_data; |
| 10869 | } else { |
| 10870 | $sample_customer_data = [ |
| 10871 | 'id' => '101', |
| 10872 | 'created_at' => '1680675247', |
| 10873 | 'email' => 'john@d.com', |
| 10874 | 'first_name' => 'John', |
| 10875 | 'last_name' => 'D', |
| 10876 | 'username' => 'johnd', |
| 10877 | 'orders_count' => '3', |
| 10878 | ]; |
| 10879 | $context['pluggable_data'] = $sample_customer_data; |
| 10880 | } |
| 10881 | } |
| 10882 | |
| 10883 | return $context; |
| 10884 | } |
| 10885 | |
| 10886 | /** |
| 10887 | * Get Affiliate list |
| 10888 | * |
| 10889 | * @param array $data data. |
| 10890 | * |
| 10891 | * @return array |
| 10892 | */ |
| 10893 | public function search_affiliate_list( $data ) { |
| 10894 | $options = []; |
| 10895 | |
| 10896 | $args = [ |
| 10897 | 'meta_query' => [ |
| 10898 | [ |
| 10899 | 'key' => 'wafp_is_affiliate', |
| 10900 | 'value' => '1', |
| 10901 | 'compare' => '=', |
| 10902 | ], |
| 10903 | ], |
| 10904 | ]; |
| 10905 | |
| 10906 | $affiliates = get_users( $args ); |
| 10907 | |
| 10908 | foreach ( $affiliates as $user ) { |
| 10909 | $options[] = [ |
| 10910 | 'label' => $user->display_name, |
| 10911 | 'value' => $user->ID, |
| 10912 | ]; |
| 10913 | } |
| 10914 | return [ |
| 10915 | 'options' => $options, |
| 10916 | 'hasMore' => false, |
| 10917 | ]; |
| 10918 | } |
| 10919 | |
| 10920 | /** |
| 10921 | * Get Affiliate Source list |
| 10922 | * |
| 10923 | * @param array $data data. |
| 10924 | * |
| 10925 | * @return array |
| 10926 | */ |
| 10927 | public function search_affiliate_transaction_source_list( $data ) { |
| 10928 | $options = []; |
| 10929 | |
| 10930 | $sources = [ |
| 10931 | 'General', |
| 10932 | 'MemberPress', |
| 10933 | 'WooCommerce', |
| 10934 | 'Easy Digital Downloads', |
| 10935 | 'WPForms', |
| 10936 | 'Formidable', |
| 10937 | 'PayPal', |
| 10938 | ]; |
| 10939 | foreach ( $sources as $source ) { |
| 10940 | $options[] = [ |
| 10941 | 'label' => $source, |
| 10942 | 'value' => str_replace( ' ', '_', strtolower( $source ) ), |
| 10943 | ]; |
| 10944 | } |
| 10945 | |
| 10946 | return [ |
| 10947 | 'options' => $options, |
| 10948 | 'hasMore' => false, |
| 10949 | ]; |
| 10950 | } |
| 10951 | |
| 10952 | /** |
| 10953 | * Search Easy Affiliate data. |
| 10954 | * |
| 10955 | * @param array $data data. |
| 10956 | * @return array|void |
| 10957 | */ |
| 10958 | public function search_easy_affiliate_last_data( $data ) { |
| 10959 | |
| 10960 | global $wpdb; |
| 10961 | $trigger = $data['search_term']; |
| 10962 | $context = []; |
| 10963 | |
| 10964 | if ( 'sale_recorded' === $trigger ) { |
| 10965 | $affiliate_id = $data['filter']['affiliate_id']['value']; |
| 10966 | if ( -1 === $affiliate_id ) { |
| 10967 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wafp_transactions as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.status='complete' order by postmeta.id DESC LIMIT 1" ); |
| 10968 | } else { |
| 10969 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wafp_transactions as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.status='complete' AND affiliate_id=%d order by postmeta.id DESC LIMIT 1", $affiliate_id ) ); |
| 10970 | } |
| 10971 | } elseif ( 'sale_added' === $trigger ) { |
| 10972 | $orderby = 'signup_date'; |
| 10973 | $order = 'DESC'; |
| 10974 | $paged = 1; |
| 10975 | $search = ''; |
| 10976 | $perpage = 1; |
| 10977 | /** |
| 10978 | * |
| 10979 | * Ignore line |
| 10980 | * |
| 10981 | * @phpstan-ignore-next-line |
| 10982 | */ |
| 10983 | $result = \EasyAffiliate\Models\User::affiliate_list_table( $orderby, $order, $paged, $search, $perpage ); |
| 10984 | if ( empty( $result['results'] ) ) { |
| 10985 | $result = []; |
| 10986 | } |
| 10987 | } elseif ( 'payout_made' === $trigger ) { |
| 10988 | $affiliate_id = $data['filter']['affiliate_id']['value']; |
| 10989 | if ( -1 === $affiliate_id ) { |
| 10990 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wafp_payments as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.amount>0 order by postmeta.id DESC LIMIT 1" ); |
| 10991 | } else { |
| 10992 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wafp_payments as postmeta JOIN {$wpdb->prefix}wafp_events as posts ON posts.evt_id=postmeta.id WHERE postmeta.amount>0 AND affiliate_id=%d order by postmeta.id DESC LIMIT 1", $affiliate_id ) ); |
| 10993 | } |
| 10994 | } |
| 10995 | |
| 10996 | if ( ! empty( $result ) ) { |
| 10997 | switch ( $trigger ) { |
| 10998 | case 'sale_recorded': |
| 10999 | $result_affiliate_id = $result[0]->affiliate_id; |
| 11000 | /** |
| 11001 | * |
| 11002 | * Ignore line |
| 11003 | * |
| 11004 | * @phpstan-ignore-next-line |
| 11005 | */ |
| 11006 | $affiliate = \EasyAffiliate\Lib\ModelFactory::fetch( $result[0]->evt_id_type, $result[0]->evt_id ); |
| 11007 | $affiliate = get_object_vars( $affiliate->rec ); |
| 11008 | $context = array_merge( WordPress::get_user_context( $result_affiliate_id ), $affiliate ); |
| 11009 | break; |
| 11010 | case 'sale_added': |
| 11011 | /** |
| 11012 | * |
| 11013 | * Ignore line |
| 11014 | * |
| 11015 | * @phpstan-ignore-next-line |
| 11016 | */ |
| 11017 | $data = new \EasyAffiliate\Models\User( $result['results'][0]->ID ); |
| 11018 | /** |
| 11019 | * |
| 11020 | * Ignore line |
| 11021 | * |
| 11022 | * @phpstan-ignore-next-line |
| 11023 | */ |
| 11024 | $context = get_object_vars( $data->rec ); |
| 11025 | break; |
| 11026 | case 'payout_made': |
| 11027 | $result_affiliate_id = $result[0]->affiliate_id; |
| 11028 | /** |
| 11029 | * |
| 11030 | * Ignore line |
| 11031 | * |
| 11032 | * @phpstan-ignore-next-line |
| 11033 | */ |
| 11034 | $affiliate = \EasyAffiliate\Lib\ModelFactory::fetch( $result[0]->evt_id_type, $result[0]->evt_id ); |
| 11035 | $affiliate = get_object_vars( $affiliate->rec ); |
| 11036 | $context = array_merge( WordPress::get_user_context( $result_affiliate_id ), $affiliate ); |
| 11037 | break; |
| 11038 | default: |
| 11039 | return; |
| 11040 | } |
| 11041 | $context['pluggable_data'] = $context; |
| 11042 | $context['response_type'] = 'live'; |
| 11043 | } elseif ( empty( $result ) ) { |
| 11044 | switch ( $trigger ) { |
| 11045 | case 'sale_added': |
| 11046 | $context = json_decode( |
| 11047 | '{"ID": 1,"first_name": "John","last_name": "D","user_login": "johnd","user_nicename": "johnd","user_email": "johnd@d.com","user_url": "","user_registered": "2023-10-13 13:39:16","user_activation_key": "","user_status": "0","display_name": "johnd","paypal_email": "johnd@d.com","address_one": "1street","address_two": "", |
| 11048 | "city": "london","state": "","zip": "","country": "UK","tax_id_us": "","tax_id_int": "","is_affiliate": "1","is_blocked": "","blocked_message": "","referrer": "0","notes": "","unsubscribed": ""}', |
| 11049 | true |
| 11050 | ); |
| 11051 | break; |
| 11052 | case 'sale_recorded': |
| 11053 | $context = json_decode( '{"wp_user_id": 73,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["subscriber"],"id": "5","affiliate_id": "73","click_id": "0","item_id": "","item_name": "test","coupon": "","sale_amount": "10.00","refund_amount": "20.00","subscr_id": "","subscr_paynum": "0","ip_addr": "","cust_email": "","cust_name": "","trans_num": "test5","type": "commission","source": "general","order_id": "0","status": "complete","rebill": "0","created_at": "2023-10-11 09:18:41"}', true ); |
| 11054 | break; |
| 11055 | case 'payout_made': |
| 11056 | $context = json_decode( '{"wp_user_id": 73,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["subscriber"],"id": "5","affiliate_id": "73","click_id": "0","item_id": "","item_name": "test","coupon": "","sale_amount": "10.00","refund_amount": "20.00","subscr_id": "","subscr_paynum": "0","ip_addr": "","cust_email": "","cust_name": "","trans_num": "test5","type": "commission","source": "general","order_id": "0","status": "complete","rebill": "0","created_at": "2023-10-11 09:18:41"}', true ); |
| 11057 | break; |
| 11058 | default: |
| 11059 | return; |
| 11060 | } |
| 11061 | $context['pluggable_data'] = $context; |
| 11062 | $context['response_type'] = 'sample'; |
| 11063 | } |
| 11064 | |
| 11065 | return $context; |
| 11066 | |
| 11067 | } |
| 11068 | |
| 11069 | /** |
| 11070 | * Get WooCommerce Subscriptions Coupon list |
| 11071 | * |
| 11072 | * @param array $data data. |
| 11073 | * |
| 11074 | * @return array |
| 11075 | */ |
| 11076 | public function search_woo_subscription_coupon_list( $data ) { |
| 11077 | $options = []; |
| 11078 | |
| 11079 | $coupon_codes = []; |
| 11080 | |
| 11081 | $query = new \WP_Query( |
| 11082 | [ |
| 11083 | 'post_type' => 'shop_coupon', |
| 11084 | 'posts_per_page' => -1, |
| 11085 | 'no_found_rows' => true, |
| 11086 | 'meta_query' => [ |
| 11087 | [ |
| 11088 | 'key' => '_is_aw_coupon', |
| 11089 | 'compare' => 'NOT EXISTS', |
| 11090 | ], |
| 11091 | ], |
| 11092 | ] |
| 11093 | ); |
| 11094 | |
| 11095 | foreach ( $query->posts as $coupon ) { |
| 11096 | /** |
| 11097 | * |
| 11098 | * Ignore line |
| 11099 | * |
| 11100 | * @phpstan-ignore-next-line |
| 11101 | */ |
| 11102 | $code = wc_format_coupon_code( $coupon->post_title ); |
| 11103 | $coupon_codes[ $code ] = $code; |
| 11104 | } |
| 11105 | |
| 11106 | foreach ( $coupon_codes as $code ) { |
| 11107 | |
| 11108 | $coupon = new \WC_Coupon( $code ); |
| 11109 | |
| 11110 | if ( ! in_array( $coupon->get_discount_type(), [ 'recurring_fee', 'recurring_percent' ], true ) ) { |
| 11111 | unset( $coupon_codes[ $code ] ); |
| 11112 | } |
| 11113 | } |
| 11114 | |
| 11115 | if ( ! empty( $coupon_codes ) ) { |
| 11116 | if ( is_array( $coupon_codes ) ) { |
| 11117 | foreach ( $coupon_codes as $coupon_code ) { |
| 11118 | $options[] = [ |
| 11119 | 'label' => $coupon_code, |
| 11120 | 'value' => $coupon_code, |
| 11121 | ]; |
| 11122 | } |
| 11123 | } |
| 11124 | } |
| 11125 | return [ |
| 11126 | 'options' => $options, |
| 11127 | 'hasMore' => false, |
| 11128 | ]; |
| 11129 | } |
| 11130 | |
| 11131 | /** |
| 11132 | * Get BuddyBoss field. |
| 11133 | * |
| 11134 | * @param array $data data. |
| 11135 | * |
| 11136 | * @return array|void |
| 11137 | */ |
| 11138 | public function search_bb_field_list( $data ) { |
| 11139 | global $wpdb; |
| 11140 | $options = []; |
| 11141 | |
| 11142 | $xprofile_fields = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_xprofile_fields WHERE parent_id = 0 ORDER BY field_order ASC" ); |
| 11143 | if ( ! empty( $xprofile_fields ) ) { |
| 11144 | foreach ( $xprofile_fields as $xprofile_field ) { |
| 11145 | $options[] = [ |
| 11146 | 'label' => $xprofile_field->name, |
| 11147 | 'value' => $xprofile_field->id, |
| 11148 | ]; |
| 11149 | } |
| 11150 | } |
| 11151 | |
| 11152 | return [ |
| 11153 | 'options' => $options, |
| 11154 | 'hasMore' => false, |
| 11155 | ]; |
| 11156 | } |
| 11157 | |
| 11158 | /** |
| 11159 | * Get Woocommerce Bookings Product List. |
| 11160 | * |
| 11161 | * @param array $data data. |
| 11162 | * |
| 11163 | * @return array|void |
| 11164 | */ |
| 11165 | public function search_wb_bookable_product_list( $data ) { |
| 11166 | $options = []; |
| 11167 | |
| 11168 | if ( ! class_exists( 'WC_Bookings_Admin' ) ) { |
| 11169 | return; |
| 11170 | } |
| 11171 | |
| 11172 | $products = WC_Bookings_Admin::get_booking_products(); |
| 11173 | if ( ! empty( $products ) ) { |
| 11174 | if ( is_array( $products ) ) { |
| 11175 | foreach ( $products as $product ) { |
| 11176 | $options[] = [ |
| 11177 | 'label' => $product->get_name(), |
| 11178 | 'value' => $product->get_id(), |
| 11179 | ]; |
| 11180 | $resources = $product->get_resources(); |
| 11181 | if ( ! empty( $resources ) ) { |
| 11182 | foreach ( $resources as $resource ) { |
| 11183 | $options[] = [ |
| 11184 | 'label' => $resource->get_name(), |
| 11185 | 'value' => $resource->get_id(), |
| 11186 | ]; |
| 11187 | } |
| 11188 | } |
| 11189 | } |
| 11190 | } |
| 11191 | } |
| 11192 | |
| 11193 | return [ |
| 11194 | 'options' => $options, |
| 11195 | 'hasMore' => false, |
| 11196 | ]; |
| 11197 | } |
| 11198 | |
| 11199 | /** |
| 11200 | * Get last data for WooCommerce Booking trigger |
| 11201 | * |
| 11202 | * @param array $data data. |
| 11203 | * @return array |
| 11204 | */ |
| 11205 | public function search_woo_commerce_booking_last_data( $data ) { |
| 11206 | $context = []; |
| 11207 | $context['response_type'] = 'sample'; |
| 11208 | $context['pluggable_data'] = []; |
| 11209 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 11210 | global $wpdb; |
| 11211 | if ( 'booking_created' === $term ) { |
| 11212 | $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type='wc_booking' AND post_status='confirmed' order by ID DESC LIMIT 1" ); |
| 11213 | |
| 11214 | if ( ! empty( $results ) ) { |
| 11215 | if ( class_exists( 'WC_Booking' ) ) { |
| 11216 | $booking = new WC_Booking( $results[0]->ID ); |
| 11217 | $person_counts = $booking->get_person_counts(); |
| 11218 | $bookable_product_id = $booking->get_product_id(); |
| 11219 | if ( method_exists( $booking, 'get_data' ) ) { |
| 11220 | $booking = $booking->get_data(); |
| 11221 | $booking['start'] = gmdate( 'Y-m-d H:i:s', $booking['start'] ); |
| 11222 | $booking['end'] = gmdate( 'Y-m-d H:i:s', $booking['end'] ); |
| 11223 | if ( ! empty( $person_counts ) ) { |
| 11224 | $total_count = 0; |
| 11225 | foreach ( $person_counts as $key => $value ) { |
| 11226 | $total_count += $value; |
| 11227 | } |
| 11228 | $booking['total_person_counts'] = $total_count; |
| 11229 | } |
| 11230 | $booking['bookable_product'] = $bookable_product_id; |
| 11231 | $booking['bookable_product'] = $booking->get_product_id(); |
| 11232 | $context['response_type'] = 'live'; |
| 11233 | $context['pluggable_data'] = array_merge( $booking, WordPress::get_user_context( $booking['customer_id'] ) ); |
| 11234 | } |
| 11235 | } |
| 11236 | } else { |
| 11237 | $booking_sample_data = json_decode( '{"id": 6546,"all_day": false,"cost": "45.02","customer_id": 1,"date_created": 1696915500,"date_modified": 1696915863,"end": "2023-10-14 12:00:00","google_calendar_event_id": "0","order_id": 0,"order_item_id": 0,"parent_id": 0,"person_counts": {"6525": 1,"6526": 1},"product_id": 6527,"resource_id": 0,"start": "2023-10-14 10:00:00","status": "confirmed","local_timezone": "","meta_data": [{"id": 12163,"key": "_booking_all_day","value": "0"},{"id": 12164,"key": "_booking_cost","value": "45.02"},{"id": 12165,"key": "_booking_customer_id","value": "1"},{"id": 12166,"key": "_booking_order_item_id","value": "0"},{"id": 12167,"key": "_booking_parent_id","value": "0"},{"id": 12168,"key": "_booking_persons","value": {"6525": 1,"6526": 1}},{"id": 12169,"key": "_booking_product_id","value": "6527"},{"id": 12170,"key": "_booking_resource_id","value": "0"},{"id": 12171,"key": "_booking_start","value": "20231014100000"},{"id": 12172,"key": "_booking_end","value": "20231014120000"},{"id": 12173,"key": "_wc_bookings_gcalendar_event_id","value": "0"},{"id": 12175,"key": "_edit_lock","value": "1696915725:1"},{"id": 12176,"key": "_edit_last","value": "1"}],"total_person_counts": 2,"bookable_product": 6527,"wp_user_id": 1,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["customer"]}', true ); |
| 11238 | $context['pluggable_data'] = $booking_sample_data; |
| 11239 | } |
| 11240 | } elseif ( 'booking_status_changed' === $term ) { |
| 11241 | $to_status = isset( $data['filter']['to_status']['value'] ) ? $data['filter']['to_status']['value'] : -1; |
| 11242 | |
| 11243 | if ( -1 == $to_status ) { |
| 11244 | $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type='wc_booking' order by ID DESC LIMIT 1" ); |
| 11245 | } else { |
| 11246 | $results = $wpdb->get_results( |
| 11247 | $wpdb->prepare( |
| 11248 | " |
| 11249 | SELECT * |
| 11250 | FROM {$wpdb->prefix}posts |
| 11251 | WHERE `post_status` = %s |
| 11252 | AND `post_type` LIKE %s |
| 11253 | ", |
| 11254 | $to_status, |
| 11255 | 'wc_booking' |
| 11256 | ) |
| 11257 | ); |
| 11258 | } |
| 11259 | |
| 11260 | if ( ! empty( $results ) ) { |
| 11261 | if ( class_exists( 'WC_Booking' ) ) { |
| 11262 | $booking = new WC_Booking( $results[0]->ID ); |
| 11263 | $person_counts = $booking->get_person_counts(); |
| 11264 | $bookable_product_id = $booking->get_product_id(); |
| 11265 | if ( method_exists( $booking, 'get_data' ) ) { |
| 11266 | $booking = $booking->get_data(); |
| 11267 | $booking['start'] = gmdate( 'Y-m-d H:i:s', $booking['start'] ); |
| 11268 | $booking['end'] = gmdate( 'Y-m-d H:i:s', $booking['end'] ); |
| 11269 | if ( ! empty( $person_counts ) ) { |
| 11270 | $total_count = 0; |
| 11271 | foreach ( $person_counts as $key => $value ) { |
| 11272 | $total_count += $value; |
| 11273 | } |
| 11274 | $booking['total_person_counts'] = $total_count; |
| 11275 | } |
| 11276 | $booking['bookable_product'] = $bookable_product_id; |
| 11277 | $booking['from_status'] = $data['filter']['from_status']['value']; |
| 11278 | $booking['to_status'] = $booking['status']; |
| 11279 | $context['response_type'] = 'live'; |
| 11280 | $context['pluggable_data'] = array_merge( $booking, WordPress::get_user_context( $booking['customer_id'] ) ); |
| 11281 | } |
| 11282 | } |
| 11283 | } else { |
| 11284 | $booking_sample_data = json_decode( '{"id": 6546,"all_day": false,"cost": "45.02","customer_id": 1,"date_created": 1696915500,"date_modified": 1696915863,"end": "2023-10-14 12:00:00","google_calendar_event_id": "0","order_id": 0,"order_item_id": 0,"parent_id": 0,"person_counts": {"6525": 1,"6526": 1},"product_id": 6527,"resource_id": 0,"start": "2023-10-14 10:00:00","status": "confirmed","to_status": "confirmed","from_status": "cancelled","local_timezone": "","meta_data": [{"id": 12163,"key": "_booking_all_day","value": "0"},{"id": 12164,"key": "_booking_cost","value": "45.02"},{"id": 12165,"key": "_booking_customer_id","value": "1"},{"id": 12166,"key": "_booking_order_item_id","value": "0"},{"id": 12167,"key": "_booking_parent_id","value": "0"},{"id": 12168,"key": "_booking_persons","value": {"6525": 1,"6526": 1}},{"id": 12169,"key": "_booking_product_id","value": "6527"},{"id": 12170,"key": "_booking_resource_id","value": "0"},{"id": 12171,"key": "_booking_start","value": "20231014100000"},{"id": 12172,"key": "_booking_end","value": "20231014120000"},{"id": 12173,"key": "_wc_bookings_gcalendar_event_id","value": "0"},{"id": 12175,"key": "_edit_lock","value": "1696915725:1"},{"id": 12176,"key": "_edit_last","value": "1"}],"total_person_counts": 2,"bookable_product": 6527,"wp_user_id": 1,"user_login": "johnd@yopmail.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "johnd@yopmail.com","user_role": ["customer"]}', true ); |
| 11285 | $context['pluggable_data'] = $booking_sample_data; |
| 11286 | } |
| 11287 | } |
| 11288 | return $context; |
| 11289 | } |
| 11290 | |
| 11291 | /** |
| 11292 | * Get WooCommerce Booking status list. |
| 11293 | * |
| 11294 | * @param array $data data. |
| 11295 | * |
| 11296 | * @return array |
| 11297 | */ |
| 11298 | public function search_woo_booking_status_list( $data ) { |
| 11299 | |
| 11300 | $options = [ |
| 11301 | [ |
| 11302 | 'label' => 'Pending Confirmation', |
| 11303 | 'value' => 'pending-confirmation', |
| 11304 | ], |
| 11305 | [ |
| 11306 | 'label' => 'Unpaid', |
| 11307 | 'value' => 'unpaid', |
| 11308 | ], |
| 11309 | [ |
| 11310 | 'label' => 'Confirmed', |
| 11311 | 'value' => 'confirmed', |
| 11312 | ], |
| 11313 | [ |
| 11314 | 'label' => 'Paid', |
| 11315 | 'value' => 'paid', |
| 11316 | ], |
| 11317 | [ |
| 11318 | 'label' => 'Complete', |
| 11319 | 'value' => 'complete', |
| 11320 | ], |
| 11321 | [ |
| 11322 | 'label' => 'In Cart', |
| 11323 | 'value' => 'in-cart', |
| 11324 | ], |
| 11325 | [ |
| 11326 | 'label' => 'Cancelled', |
| 11327 | 'value' => 'cancelled', |
| 11328 | ], |
| 11329 | ]; |
| 11330 | |
| 11331 | return [ |
| 11332 | 'options' => $options, |
| 11333 | 'hasMore' => false, |
| 11334 | ]; |
| 11335 | } |
| 11336 | |
| 11337 | /** |
| 11338 | * Get Woocommerce Memberships Status List. |
| 11339 | * |
| 11340 | * @param array $data data. |
| 11341 | * |
| 11342 | * @return array|void |
| 11343 | */ |
| 11344 | public function search_wc_membership_status_list( $data ) { |
| 11345 | $options = []; |
| 11346 | if ( ! function_exists( 'wc_memberships_get_user_membership_statuses' ) ) { |
| 11347 | return; |
| 11348 | } |
| 11349 | |
| 11350 | $statuses = wc_memberships_get_user_membership_statuses(); |
| 11351 | if ( ! empty( $statuses ) ) { |
| 11352 | if ( is_array( $statuses ) ) { |
| 11353 | foreach ( $statuses as $status => $value ) { |
| 11354 | $status = 0 === strpos( $status, 'wcm-' ) ? substr( $status, 4 ) : $status; |
| 11355 | $options[] = [ |
| 11356 | 'label' => $value['label'], |
| 11357 | 'value' => $status, |
| 11358 | ]; |
| 11359 | } |
| 11360 | } |
| 11361 | } |
| 11362 | |
| 11363 | return [ |
| 11364 | 'options' => $options, |
| 11365 | 'hasMore' => false, |
| 11366 | ]; |
| 11367 | } |
| 11368 | |
| 11369 | /** |
| 11370 | * Search Woocommerce Subscription data. |
| 11371 | * |
| 11372 | * @param array $data data. |
| 11373 | * @return array|void |
| 11374 | */ |
| 11375 | public function search_user_subscription_last_data( $data ) { |
| 11376 | |
| 11377 | $context = []; |
| 11378 | |
| 11379 | if ( ! function_exists( 'wcs_get_subscription' ) ) { |
| 11380 | return; |
| 11381 | } |
| 11382 | if ( ! function_exists( 'wcs_get_subscriptions_for_product' ) ) { |
| 11383 | return; |
| 11384 | } |
| 11385 | if ( ! function_exists( 'wcs_order_contains_renewal' ) ) { |
| 11386 | return; |
| 11387 | } |
| 11388 | if ( ! function_exists( 'wcs_get_subscriptions_for_order' ) ) { |
| 11389 | return; |
| 11390 | } |
| 11391 | |
| 11392 | if ( 'trial_end' == $data['search_term'] ) { |
| 11393 | $subscription_id = $data['filter']['subscription']['value']; |
| 11394 | $query_args = [ |
| 11395 | 'post_type' => 'shop_subscription', |
| 11396 | 'orderby' => 'ID', |
| 11397 | 'order' => 'DESC', |
| 11398 | 'post_status' => 'wc-active', |
| 11399 | 'posts_per_page' => 1, |
| 11400 | 'meta_query' => [ |
| 11401 | [ |
| 11402 | 'key' => '_schedule_trial_end', |
| 11403 | 'value' => gmdate( 'Y-m-d H:i:s' ), |
| 11404 | 'compare' => '<=', |
| 11405 | ], |
| 11406 | ], |
| 11407 | 'post__in' => [ $subscription_id ], |
| 11408 | ]; |
| 11409 | $query_result = new WP_Query( $query_args ); |
| 11410 | $subscription_orders = $query_result->get_posts(); |
| 11411 | |
| 11412 | if ( ! empty( $subscription_orders ) ) { |
| 11413 | /** |
| 11414 | * |
| 11415 | * Ignore line |
| 11416 | * |
| 11417 | * @phpstan-ignore-next-line |
| 11418 | */ |
| 11419 | $subscription = wcs_get_subscription( $subscription_orders[0]->ID ); |
| 11420 | $user_id = $subscription->get_user_id(); |
| 11421 | |
| 11422 | $items = $subscription->get_items(); |
| 11423 | $product_ids = []; |
| 11424 | foreach ( $items as $item ) { |
| 11425 | $product_ids[] = $item->get_product_id(); |
| 11426 | } |
| 11427 | |
| 11428 | $subscription_status = $subscription->get_status(); |
| 11429 | $subscription_start_date = $subscription->get_date_created(); |
| 11430 | |
| 11431 | $context['subscription_data'] = [ |
| 11432 | 'status' => $subscription_status, |
| 11433 | 'start_date' => $subscription_start_date, |
| 11434 | 'trial_end_date' => $subscription->get_date( 'schedule_trial_end' ), |
| 11435 | 'next_payment_date' => $subscription->get_date( 'next_payment' ), |
| 11436 | 'end_date' => $subscription->get_date( 'schedule_end' ), |
| 11437 | ]; |
| 11438 | $context['user'] = WordPress::get_user_context( $user_id ); |
| 11439 | |
| 11440 | foreach ( $product_ids as $val ) { |
| 11441 | $context['subscription'] = $val; |
| 11442 | $context['subscription_name'] = get_the_title( $val ); |
| 11443 | } |
| 11444 | $context['pluggable_data'] = $context; |
| 11445 | $context['response_type'] = 'live'; |
| 11446 | } else { |
| 11447 | $context = json_decode( '{"subscription_data": {"status": "active","start_date": {"date": "2023-05-18 12:36:53.000000","timezone_type": 1,"timezone": "+00:00"},"trial_end_date": "2023-10-20 03:31:04","next_payment_date": 0,"end_date": "2024-05-28 12:36:53"},"user": {"wp_user_id": 1,"user_login": "john@d.com","display_name": "john d","user_firstname": "john","user_lastname": "d","user_email": "john@d.com","user_role": ["customer","subscriber"]},"subscription": 5861,"subscription_name": "Demo Subscription"}', true ); |
| 11448 | $context['pluggable_data'] = $context; |
| 11449 | $context['response_type'] = 'sample'; |
| 11450 | } |
| 11451 | } elseif ( 'renewal_payment_failed' == $data['search_term'] ) { |
| 11452 | $subscription_item = $data['filter']['subscription_item']['value']; |
| 11453 | $subscription_ids = wcs_get_subscriptions_for_product( $subscription_item ); |
| 11454 | $ids = []; |
| 11455 | $related = []; |
| 11456 | foreach ( $subscription_ids as $subscription ) { |
| 11457 | $ids[] = $subscription; |
| 11458 | /** |
| 11459 | * |
| 11460 | * Ignore line |
| 11461 | * |
| 11462 | * @phpstan-ignore-next-line |
| 11463 | */ |
| 11464 | $subscriptions = new WC_Subscription( $subscription ); |
| 11465 | /** |
| 11466 | * |
| 11467 | * Ignore line |
| 11468 | * |
| 11469 | * @phpstan-ignore-next-line |
| 11470 | */ |
| 11471 | $related[] = $subscriptions->get_related_orders(); |
| 11472 | } |
| 11473 | |
| 11474 | $failed_payment_orders = []; |
| 11475 | foreach ( $related as $value ) { |
| 11476 | foreach ( $value as $val ) { |
| 11477 | if ( wcs_order_contains_renewal( $val ) ) { |
| 11478 | $order = wc_get_order( $val ); |
| 11479 | if ( $order ) { |
| 11480 | /** |
| 11481 | * |
| 11482 | * Ignore line |
| 11483 | * |
| 11484 | * @phpstan-ignore-next-line |
| 11485 | */ |
| 11486 | $payment_status = $order->get_status(); |
| 11487 | if ( 'failed' === $payment_status || 'wc-on-hold' === $payment_status ) { |
| 11488 | $failed_payment_orders[] = $val; |
| 11489 | } |
| 11490 | } |
| 11491 | } |
| 11492 | } |
| 11493 | } |
| 11494 | |
| 11495 | if ( ! empty( $failed_payment_orders ) ) { |
| 11496 | $failed = array_rand( $failed_payment_orders ); |
| 11497 | $related_subscriptions = wcs_get_subscriptions_for_order( $failed_payment_orders[ $failed ] ); |
| 11498 | if ( ! empty( $related_subscriptions ) ) { |
| 11499 | $sub_id = get_post_meta( $failed_payment_orders[ $failed ], '_subscription_renewal', true ); |
| 11500 | $subscription = wcs_get_subscription( $sub_id ); |
| 11501 | |
| 11502 | $items = $subscription->get_items(); |
| 11503 | $product_ids = []; |
| 11504 | foreach ( $items as $item ) { |
| 11505 | $product_ids[] = $item->get_product_id(); |
| 11506 | } |
| 11507 | |
| 11508 | $context['user'] = WordPress::get_user_context( $subscription->get_user_id() ); |
| 11509 | foreach ( [ 'renewal' ] as $order_type ) { |
| 11510 | foreach ( $subscription->get_related_orders( 'ids', $order_type ) as $order_id ) { |
| 11511 | $context['subscription_related_order'][] = $order_id; |
| 11512 | } |
| 11513 | } |
| 11514 | foreach ( $product_ids as $val ) { |
| 11515 | $context['subscription_item'] = $val; |
| 11516 | $context['subscription_name'] = get_the_title( $val ); |
| 11517 | } |
| 11518 | $context['data'] = $subscription->get_data(); |
| 11519 | $context['pluggable_data'] = $context; |
| 11520 | $context['response_type'] = 'live'; |
| 11521 | } else { |
| 11522 | $context['pluggable_data'] = json_decode( '{"user": {"wp_user_id": 36,"user_login": "john@d.com","display_name": "test","user_firstname": "Test","user_lastname": "test","user_email": "john@d.com","user_role": ["wpamelia-customer","customer"]},"subscription_related_order": [6643],"subscription_item": 5962,"subscription_name": "Demo2 Subscription","data": {"id": 6642,"parent_id": 6641,"status": "on-hold","currency": "USD","version": "7.6.1","prices_include_tax": false,"date_created": {"date": "2023-10-20 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-20 08:45:02.000000","timezone_type": 1,"timezone": "+00:00"},"discount_total": "0","discount_tax": "0","shipping_total": "0","shipping_tax": "0","cart_tax": "0","total": "1.00","total_tax": "0","customer_id": 36,"order_key": "wc_order_6Pdirh5WDDiVA","billing": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "test","state": "TN","postcode": "600144","country": "IN","email": "john@d.com","phone": "98675757"},"shipping": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "Chennai","state": "TN","postcode": "600100","country": "IN","phone": ""},"payment_method": "","payment_method_title": "","transaction_id": "","customer_ip_address": "127.0.0.1","customer_user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/118.0.0.0 Safari\/537.36","created_via": "checkout","customer_note": "","date_completed": null,"date_paid": null,"cart_hash": "","order_stock_reduced": false,"download_permissions_granted": true,"new_order_email_sent": false,"recorded_sales": false,"recorded_coupon_usage_counts": false,"billing_period": "day","billing_interval": "1","suspension_count": 1,"requires_manual_renewal": true,"cancelled_email_sent": "","trial_period": "day","schedule_trial_end": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_next_payment": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_end": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_start": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"switch_data": [],"number": "6642","meta_data": [{"id": 13719,"key": "is_vat_exempt","value": "no"}],"line_items": {"142": []},"tax_lines": [],"shipping_lines": [],"fee_lines": [],"coupon_lines": []}}', true ); |
| 11523 | $context['response_type'] = 'sample'; |
| 11524 | } |
| 11525 | } else { |
| 11526 | $context['pluggable_data'] = json_decode( '{"user": {"wp_user_id": 36,"user_login": "john@d.com","display_name": "test","user_firstname": "Test","user_lastname": "test","user_email": "john@d.com","user_role": ["wpamelia-customer","customer"]},"subscription_related_order": [6643],"subscription_item": 5962,"subscription_name": "Demo2 Subscription","data": {"id": 6642,"parent_id": 6641,"status": "on-hold","currency": "USD","version": "7.6.1","prices_include_tax": false,"date_created": {"date": "2023-10-20 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-20 08:45:02.000000","timezone_type": 1,"timezone": "+00:00"},"discount_total": "0","discount_tax": "0","shipping_total": "0","shipping_tax": "0","cart_tax": "0","total": "1.00","total_tax": "0","customer_id": 36,"order_key": "wc_order_6Pdirh5WDDiVA","billing": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "test","state": "TN","postcode": "600144","country": "IN","email": "john@d.com","phone": "98675757"},"shipping": {"first_name": "bella","last_name": "test","company": "","address_1": "test","address_2": "","city": "Chennai","state": "TN","postcode": "600100","country": "IN","phone": ""},"payment_method": "","payment_method_title": "","transaction_id": "","customer_ip_address": "127.0.0.1","customer_user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/118.0.0.0 Safari\/537.36","created_via": "checkout","customer_note": "","date_completed": null,"date_paid": null,"cart_hash": "","order_stock_reduced": false,"download_permissions_granted": true,"new_order_email_sent": false,"recorded_sales": false,"recorded_coupon_usage_counts": false,"billing_period": "day","billing_interval": "1","suspension_count": 1,"requires_manual_renewal": true,"cancelled_email_sent": "","trial_period": "day","schedule_trial_end": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_next_payment": {"date": "2023-10-21 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_end": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"schedule_start": {"date": "2023-10-22 08:44:25.000000","timezone_type": 1,"timezone": "+00:00"},"switch_data": [],"number": "6642","meta_data": [{"id": 13719,"key": "is_vat_exempt","value": "no"}],"line_items": {"142": []},"tax_lines": [],"shipping_lines": [],"fee_lines": [],"coupon_lines": []}}', true ); |
| 11527 | $context['response_type'] = 'sample'; |
| 11528 | } |
| 11529 | } |
| 11530 | return $context; |
| 11531 | } |
| 11532 | |
| 11533 | /** |
| 11534 | * Get Masteriyo LMS Courses. |
| 11535 | * |
| 11536 | * @param array $data data. |
| 11537 | * |
| 11538 | * @return array |
| 11539 | */ |
| 11540 | public function search_masteriyo_lms_courses( $data ) { |
| 11541 | |
| 11542 | $page = $data['page']; |
| 11543 | $limit = Utilities::get_search_page_limit(); |
| 11544 | $offset = $limit * ( $page - 1 ); |
| 11545 | |
| 11546 | $args = [ |
| 11547 | 'post_type' => 'mto-course', |
| 11548 | 'posts_per_page' => $limit, |
| 11549 | 'offset' => $offset, |
| 11550 | 'orderby' => 'title', |
| 11551 | 'order' => 'ASC', |
| 11552 | 'post_status' => 'publish', |
| 11553 | ]; |
| 11554 | |
| 11555 | $courses = get_posts( $args ); |
| 11556 | |
| 11557 | $course_count = wp_count_posts( 'mto-course' )->publish; |
| 11558 | |
| 11559 | $options = []; |
| 11560 | if ( ! empty( $courses ) ) { |
| 11561 | if ( is_array( $courses ) ) { |
| 11562 | foreach ( $courses as $course ) { |
| 11563 | $options[] = [ |
| 11564 | 'label' => $course->post_title, |
| 11565 | 'value' => $course->ID, |
| 11566 | ]; |
| 11567 | } |
| 11568 | } |
| 11569 | } |
| 11570 | return [ |
| 11571 | 'options' => $options, |
| 11572 | 'hasMore' => $course_count > $limit && $course_count > $offset, |
| 11573 | ]; |
| 11574 | } |
| 11575 | |
| 11576 | /** |
| 11577 | * Get Masteriyo LMS Lessons. |
| 11578 | * |
| 11579 | * @param array $data data. |
| 11580 | * |
| 11581 | * @return array |
| 11582 | */ |
| 11583 | public function search_masteriyo_lms_lessons( $data ) { |
| 11584 | |
| 11585 | $course_id = $data['dynamic']; |
| 11586 | $page = $data['page']; |
| 11587 | $limit = Utilities::get_search_page_limit(); |
| 11588 | $offset = $limit * ( $page - 1 ); |
| 11589 | $options = []; |
| 11590 | $args = [ |
| 11591 | 'post_type' => 'mto-lesson', |
| 11592 | 'posts_per_page' => $limit, |
| 11593 | 'offset' => $offset, |
| 11594 | 'orderby' => 'title', |
| 11595 | 'order' => 'ASC', |
| 11596 | 'post_status' => 'publish', |
| 11597 | 'meta_query' => [ |
| 11598 | [ |
| 11599 | 'key' => '_course_id', |
| 11600 | 'value' => $course_id, |
| 11601 | 'compare' => '=', |
| 11602 | ], |
| 11603 | ], |
| 11604 | ]; |
| 11605 | |
| 11606 | $lessons = get_posts( $args ); |
| 11607 | $lesson_count = wp_count_posts( 'mto-lesson' )->publish; |
| 11608 | if ( ! empty( $lessons ) ) { |
| 11609 | if ( is_array( $lessons ) ) { |
| 11610 | foreach ( $lessons as $lesson ) { |
| 11611 | $options[] = [ |
| 11612 | 'label' => $lesson->post_title, |
| 11613 | 'value' => $lesson->ID, |
| 11614 | ]; |
| 11615 | } |
| 11616 | } |
| 11617 | } |
| 11618 | return [ |
| 11619 | 'options' => $options, |
| 11620 | 'hasMore' => $lesson_count > $limit && $lesson_count > $offset, |
| 11621 | ]; |
| 11622 | } |
| 11623 | |
| 11624 | /** |
| 11625 | * Get Masteriyo LMS Quiz. |
| 11626 | * |
| 11627 | * @param array $data data. |
| 11628 | * |
| 11629 | * @return array |
| 11630 | */ |
| 11631 | public function search_masteriyo_lms_quizs( $data ) { |
| 11632 | |
| 11633 | $course_id = $data['dynamic']; |
| 11634 | $page = $data['page']; |
| 11635 | $limit = Utilities::get_search_page_limit(); |
| 11636 | $offset = $limit * ( $page - 1 ); |
| 11637 | $options = []; |
| 11638 | $args = [ |
| 11639 | 'post_type' => 'mto-quiz', |
| 11640 | 'posts_per_page' => $limit, |
| 11641 | 'offset' => $offset, |
| 11642 | 'orderby' => 'title', |
| 11643 | 'order' => 'ASC', |
| 11644 | 'post_status' => 'publish', |
| 11645 | 'meta_query' => [ |
| 11646 | [ |
| 11647 | 'key' => '_course_id', |
| 11648 | 'value' => $course_id, |
| 11649 | 'compare' => '=', |
| 11650 | ], |
| 11651 | ], |
| 11652 | ]; |
| 11653 | |
| 11654 | $quizs = get_posts( $args ); |
| 11655 | $quiz_count = wp_count_posts( 'mto-quiz' )->publish; |
| 11656 | if ( ! empty( $quizs ) ) { |
| 11657 | if ( is_array( $quizs ) ) { |
| 11658 | foreach ( $quizs as $quiz ) { |
| 11659 | $options[] = [ |
| 11660 | 'label' => $quiz->post_title, |
| 11661 | 'value' => $quiz->ID, |
| 11662 | ]; |
| 11663 | } |
| 11664 | } |
| 11665 | } |
| 11666 | return [ |
| 11667 | 'options' => $options, |
| 11668 | 'hasMore' => $quiz_count > $limit && $quiz_count > $offset, |
| 11669 | ]; |
| 11670 | } |
| 11671 | |
| 11672 | /** |
| 11673 | * Search Masteriyo LMS data. |
| 11674 | * |
| 11675 | * @param array $data data. |
| 11676 | * @return array|void|mixed |
| 11677 | */ |
| 11678 | public function search_masteriyo_lms_last_data( $data ) { |
| 11679 | global $wpdb; |
| 11680 | $post_type = $data['post_type']; |
| 11681 | $trigger = $data['search_term']; |
| 11682 | $context = []; |
| 11683 | |
| 11684 | $post_id = -1; |
| 11685 | if ( 'course_completed' === $trigger ) { |
| 11686 | $post_id = $data['filter']['course_id']['value']; |
| 11687 | } elseif ( 'lesson_completed' === $trigger ) { |
| 11688 | $post_id = $data['filter']['lesson_id']['value']; |
| 11689 | } elseif ( 'quiz_completed' === $trigger || 'quiz_failed' === $trigger ) { |
| 11690 | $post_id = $data['filter']['quiz_id']['value']; |
| 11691 | } |
| 11692 | |
| 11693 | if ( 'course_completed' === $trigger || 'lesson_completed' === $trigger ) { |
| 11694 | if ( -1 === $post_id ) { |
| 11695 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.activity_status='completed' AND posts.post_type=%s order by postmeta.id DESC LIMIT 1", $post_type ) ); |
| 11696 | } else { |
| 11697 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.item_id = %s AND postmeta.activity_status='completed' AND posts.post_type=%s order by postmeta.id DESC LIMIT 1", $post_id, $post_type ) ); |
| 11698 | } |
| 11699 | } |
| 11700 | |
| 11701 | if ( 'quiz_completed' === $trigger || 'quiz_failed' === $trigger ) { |
| 11702 | if ( -1 === $post_id ) { |
| 11703 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.activity_status='completed' AND postmeta.activity_type='quiz' AND posts.post_type=%s order by postmeta.user_item_id DESC LIMIT 1", $post_type ) ); |
| 11704 | } else { |
| 11705 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_user_activities as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.item_id WHERE postmeta.item_id=%s AND postmeta.activity_type='quiz' OR postmeta.activity_status='completed' AND posts.post_type=%s order by postmeta.id DESC LIMIT 1", $post_id, $post_type ) ); |
| 11706 | } |
| 11707 | if ( ! empty( $result ) ) { |
| 11708 | $resultt = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_quiz_attempts WHERE quiz_id=%d AND user_id=%d order by id DESC LIMIT 1", $result[0]->item_id, $result[0]->user_id ) ); |
| 11709 | |
| 11710 | if ( function_exists( 'masteriyo_get_quiz' ) ) { |
| 11711 | $quiz = masteriyo_get_quiz( $resultt[0]->quiz_id ); |
| 11712 | if ( is_object( $quiz ) && method_exists( $quiz, 'get_pass_mark' ) ) { |
| 11713 | if ( 'quiz_completed' === $trigger && $resultt[0]->earned_marks < $quiz->get_pass_mark() ) { |
| 11714 | $result = []; |
| 11715 | } elseif ( 'quiz_failed' === $trigger && $resultt[0]->earned_marks > $quiz->get_pass_mark() ) { |
| 11716 | $result = []; |
| 11717 | } |
| 11718 | } |
| 11719 | } |
| 11720 | } |
| 11721 | } |
| 11722 | |
| 11723 | if ( ! empty( $result ) ) { |
| 11724 | $result_item_id = $result[0]->item_id; |
| 11725 | $result_user_id = $result[0]->user_id; |
| 11726 | $quiz_attempt = ''; |
| 11727 | if ( 'quiz_completed' === $trigger || 'quiz_failed' === $trigger ) { |
| 11728 | $resultt = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}masteriyo_quiz_attempts WHERE quiz_id=%d AND user_id=%d order by id DESC LIMIT 1", $result[0]->item_id, $result[0]->user_id ) ); |
| 11729 | $quiz_attempt = $resultt[0]->id; |
| 11730 | } |
| 11731 | switch ( $trigger ) { |
| 11732 | case 'course_completed': |
| 11733 | if ( function_exists( 'masteriyo_get_course' ) ) { |
| 11734 | $course = masteriyo_get_course( $result_item_id ); |
| 11735 | $context_data = array_merge( |
| 11736 | WordPress::get_user_context( $result_user_id ), |
| 11737 | $course->get_data() |
| 11738 | ); |
| 11739 | $context_data['course_id'] = $result_item_id; |
| 11740 | } |
| 11741 | break; |
| 11742 | case 'lesson_completed': |
| 11743 | if ( function_exists( 'masteriyo_get_lesson' ) ) { |
| 11744 | $lesson = masteriyo_get_lesson( $result_item_id ); |
| 11745 | $context_data = array_merge( |
| 11746 | WordPress::get_user_context( $result_user_id ), |
| 11747 | $lesson->get_data() |
| 11748 | ); |
| 11749 | $context_data['lesson_id'] = $result_item_id; |
| 11750 | } |
| 11751 | break; |
| 11752 | case 'quiz_completed': |
| 11753 | case 'quiz_failed': |
| 11754 | if ( function_exists( 'masteriyo_get_quiz' ) ) { |
| 11755 | $quiz = masteriyo_get_quiz( $result_item_id ); |
| 11756 | $context_data = WordPress::get_user_context( $result_user_id ); |
| 11757 | if ( function_exists( 'masteriyo_get_quiz_attempt' ) ) { |
| 11758 | $attempt = masteriyo_get_quiz_attempt( $quiz_attempt ); |
| 11759 | $context_data['quiz_id'] = $result_item_id; |
| 11760 | $context_data['course_id'] = $quiz->get_course_id(); |
| 11761 | $context_data['quiz'] = $quiz->get_data(); |
| 11762 | $context_data['attempt'] = $attempt->get_data(); |
| 11763 | } |
| 11764 | } |
| 11765 | break; |
| 11766 | default: |
| 11767 | return; |
| 11768 | } |
| 11769 | if ( ! empty( $context_data ) ) { |
| 11770 | $context['pluggable_data'] = $context_data; |
| 11771 | $context['response_type'] = 'live'; |
| 11772 | } |
| 11773 | } elseif ( empty( $result ) ) { |
| 11774 | switch ( $trigger ) { |
| 11775 | case 'course_completed': |
| 11776 | $sample_data = '{"pluggable_data":{"wp_user_id": 1,"user_login": "admin","display_name": "admin","user_firstname": "test","user_lastname": "test","user_email": "john@d.com","user_role": ["customer"],"id": 6636,"name": "Modes Master Class","slug": "modes-master-class-2","date_created": {"date": "2023-10-20 06:09:15.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-21 15:22:29.000000","timezone_type": 1,"timezone": "+00:00"},"status": "publish","menu_order": 0,"featured": false,"catalog_visibility": "visible","description": "Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words.","short_description": "","post_password": "","author_id": 1,"parent_id": 0,"reviews_allowed": true,"date_on_sale_from": null,"date_on_sale_to": null,"price": "0","regular_price": "0","sale_price": "","price_type": "free","category_ids": [106,107],"tag_ids": [],"difficulty_id": 0,"featured_image": 6616,"rating_counts": [],"average_rating": "0","review_count": 0,"enrollment_limit": 0,"duration": 360,"access_mode": "open","billing_cycle": "","show_curriculum": true,"purchase_note": "","highlights": "<li>Suscipit tortor eget felis.<\/li><li>Curabitur arcu erat idimper.<\/li><li>Lorem ipsum dolor sit amet.<\/li>","is_ai_created": false,"is_creating": false,"meta_data": []},"response_type":"sample"} '; |
| 11777 | break; |
| 11778 | case 'lesson_completed': |
| 11779 | $sample_data = '{"pluggable_data":{"wp_user_id": 1,"user_login": "admin","display_name": "admin","user_firstname": "test","user_lastname": "test","user_email": "john@d.com","user_role": ["customer"],"id": 6636,"name": "Lesson 1","slug": "lesson-1","date_created": {"date": "2023-10-20 06:09:15.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-21 15:22:29.000000","timezone_type": 1,"timezone": "+00:00"},"status": "publish","menu_order": 0,"featured": false,"catalog_visibility": "visible","description": "new lesson","short_description": "","post_password": "","author_id": 1,"parent_id": 0,"course_id": 6594,"reviews_allowed": true,"featured_image": 6616,"rating_counts": [],"average_rating": "0","review_count": 0,"meta_data": [],"lesson_id": "6596"},"response_type":"sample"} '; |
| 11780 | break; |
| 11781 | case 'quiz_completed': |
| 11782 | case 'quiz_failed': |
| 11783 | $sample_data = '{"pluggable_data":{"wp_user_id": 18,"user_login": "john@yopmail.com","display_name": "johns john","user_firstname": "johns","user_lastname": "john","user_email": "john@d.com","user_role": ["customer"],"quiz_id": "6654","course_id": 6634,"quiz": {"id": 6654,"name": "New Quiz","slug": "new-quiz","date_created": {"date": "2023-10-23 16:36:14.000000","timezone_type": 1,"timezone": "+00:00"},"date_modified": {"date": "2023-10-23 17:10:42.000000","timezone_type": 1,"timezone": "+00:00"},"parent_id": 6630,"course_id": 6634,"author_id": 0,"menu_order": 4,"status": "publish","description": "","short_description": "","pass_mark": 2,"full_mark": 100,"duration": 0,"attempts_allowed": 0,"questions_display_per_page": 0,"meta_data": []},"attempt": {"id": 17,"course_id": 6634,"quiz_id": 6654,"user_id": "18","total_questions": 2,"total_answered_questions": 2,"total_marks": "100.00","total_attempts": 1,"total_correct_answers": 1,"total_incorrect_answers": 1,"earned_marks": "1.00","answers": {"6655": {"answered": "False","correct": false},"6656": {"answered": "False","correct": true}},"attempt_status": "attempt_ended","attempt_started_at": {"date": "2023-10-24 09:34:16.000000","timezone_type": 1,"timezone": "+00:00"},"attempt_ended_at": {"date": "2023-10-24 09:34:29.000000","timezone_type": 1,"timezone": "+00:00"},"meta_data": []}},"response_type":"sample"}'; |
| 11784 | break; |
| 11785 | default: |
| 11786 | return; |
| 11787 | } |
| 11788 | $context = json_decode( $sample_data, true ); |
| 11789 | } |
| 11790 | |
| 11791 | return $context; |
| 11792 | } |
| 11793 | |
| 11794 | /** |
| 11795 | * Search learndash user added in group. |
| 11796 | * |
| 11797 | * @param array $data data. |
| 11798 | * @return array|void |
| 11799 | */ |
| 11800 | public function search_pluggables_user_added_in_group( $data ) { |
| 11801 | $context = []; |
| 11802 | |
| 11803 | if ( ! function_exists( 'learndash_get_groups_user_ids' ) ) { |
| 11804 | return; |
| 11805 | } |
| 11806 | |
| 11807 | $group_id = $data['filter']['sfwd_group_id']['value']; |
| 11808 | |
| 11809 | if ( -1 === $group_id ) { |
| 11810 | $args = [ |
| 11811 | 'numberposts' => 1, |
| 11812 | 'fields' => 'ids', |
| 11813 | 'orderby' => 'rand', |
| 11814 | 'post_type' => 'groups', |
| 11815 | ]; |
| 11816 | $posts = get_posts( $args ); |
| 11817 | $random_key = array_rand( $posts ); |
| 11818 | $random_value = $posts[ $random_key ]; |
| 11819 | $group_users = learndash_get_groups_user_ids( $random_value ); |
| 11820 | $group_id = $random_value; |
| 11821 | } else { |
| 11822 | $group_users = learndash_get_groups_user_ids( $group_id ); |
| 11823 | } |
| 11824 | |
| 11825 | $users = get_users( |
| 11826 | [ |
| 11827 | 'meta_key' => 'learndash_group_' . $group_id . '_enrolled_at', |
| 11828 | 'orderby' => 'meta_value', |
| 11829 | 'order' => 'DESC', |
| 11830 | 'number' => 1, |
| 11831 | 'include' => $group_users, |
| 11832 | ] |
| 11833 | ); |
| 11834 | |
| 11835 | if ( ! empty( $users ) ) { |
| 11836 | $context = WordPress::get_user_context( $users[0]->ID ); |
| 11837 | $context['sfwd_group_id'] = $group_id; |
| 11838 | $context['group_title'] = get_the_title( $group_id ); |
| 11839 | $context['group_url'] = get_permalink( $group_id ); |
| 11840 | $context['group_featured_image_id'] = get_post_meta( $group_id, '_thumbnail_id', true ); |
| 11841 | $context['group_featured_image_url'] = get_the_post_thumbnail_url( $group_id ); |
| 11842 | $context['response_type'] = 'live'; |
| 11843 | } else { |
| 11844 | $context = WordPress::get_sample_user_context(); |
| 11845 | $context['group_title'] = 'Test Group'; |
| 11846 | $context['sfwd_group_id'] = 112; |
| 11847 | $context['group_url'] = 'https://abc.com/test-group'; |
| 11848 | $context['group_featured_image_id'] = 113; |
| 11849 | $context['group_featured_image_url'] = 'https://pqr.com/test-group-img'; |
| 11850 | $context['response_type'] = 'sample'; |
| 11851 | } |
| 11852 | |
| 11853 | $context['pluggable_data'] = $context; |
| 11854 | return $context; |
| 11855 | } |
| 11856 | |
| 11857 | /** |
| 11858 | * Search learndash user enrolled in course. |
| 11859 | * |
| 11860 | * @param array $data data. |
| 11861 | * @return array|void |
| 11862 | */ |
| 11863 | public function search_pluggables_user_enrolled_course( $data ) { |
| 11864 | global $wpdb; |
| 11865 | $context = []; |
| 11866 | |
| 11867 | if ( ! function_exists( 'ld_course_access_expires_on' ) ) { |
| 11868 | return; |
| 11869 | } |
| 11870 | |
| 11871 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 11872 | |
| 11873 | if ( -1 === $course_id ) { |
| 11874 | $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='access' AND activity.activity_status= %d order by activity_id DESC LIMIT 1", 0 ) ); |
| 11875 | } else { |
| 11876 | $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='access' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d order by activity_id DESC LIMIT 1", 0, $course_id, $course_id ) ); |
| 11877 | } |
| 11878 | |
| 11879 | if ( ! empty( $courses ) ) { |
| 11880 | $context = WordPress::get_user_context( $courses[0]->user_id ); |
| 11881 | $context['course_id'] = $courses[0]->course_id; |
| 11882 | $context['course_title'] = get_the_title( $courses[0]->course_id ); |
| 11883 | $context['course_url'] = get_permalink( $courses[0]->course_id ); |
| 11884 | $context['course_featured_image_id'] = get_post_meta( $courses[0]->course_id, '_thumbnail_id', true ); |
| 11885 | $context['course_featured_image_url'] = get_the_post_thumbnail_url( $courses[0]->course_id ); |
| 11886 | $context['course_access_expiry_date'] = wp_date( get_option( 'date_format' ), ld_course_access_expires_on( $courses[0]->course_id, $courses[0]->user_id ) ); |
| 11887 | $context['response_type'] = 'live'; |
| 11888 | } else { |
| 11889 | $context = WordPress::get_sample_user_context(); |
| 11890 | $context['course_name'] = 'Test Course'; |
| 11891 | $context['sfwd_course_id'] = 112; |
| 11892 | $context['course_url'] = 'https://abc.com/test-course'; |
| 11893 | $context['course_featured_image_id'] = 113; |
| 11894 | $context['course_featured_image_url'] = 'https://pqr.com/test-course-img'; |
| 11895 | $context['course_access_expiry_date'] = '2023-10-20'; |
| 11896 | $context['response_type'] = 'sample'; |
| 11897 | } |
| 11898 | |
| 11899 | $context['pluggable_data'] = $context; |
| 11900 | return $context; |
| 11901 | } |
| 11902 | |
| 11903 | /** |
| 11904 | * Search post by post type. |
| 11905 | * |
| 11906 | * @param array $data Search Params. |
| 11907 | * |
| 11908 | * @since 1.0.0 |
| 11909 | * |
| 11910 | * @return array |
| 11911 | */ |
| 11912 | public function search_edd_prices( $data ) { |
| 11913 | $options = []; |
| 11914 | $downlaod_id = $data['dynamic']['download_id']; |
| 11915 | |
| 11916 | $variable_prices = get_post_meta( $downlaod_id, 'edd_variable_prices', true ); |
| 11917 | if ( ! empty( $variable_prices ) && is_array( $variable_prices ) ) { |
| 11918 | foreach ( $variable_prices as $price_id => $price ) { |
| 11919 | if ( isset( $price['name'] ) ) { |
| 11920 | $options[] = [ |
| 11921 | 'label' => $price['name'] . '(' . $price['amount'] . ')', |
| 11922 | 'value' => $price['index'], |
| 11923 | ]; |
| 11924 | } |
| 11925 | } |
| 11926 | } |
| 11927 | |
| 11928 | return [ |
| 11929 | 'options' => $options, |
| 11930 | 'hasMore' => false, |
| 11931 | ]; |
| 11932 | |
| 11933 | } |
| 11934 | |
| 11935 | /** |
| 11936 | * GetPowerful Docs list. |
| 11937 | * |
| 11938 | * @param array $data data. |
| 11939 | * |
| 11940 | * @return array |
| 11941 | */ |
| 11942 | public function search_pfd_docs_list( $data ) { |
| 11943 | |
| 11944 | $course_id = $data['dynamic']; |
| 11945 | $page = $data['page']; |
| 11946 | $limit = Utilities::get_search_page_limit(); |
| 11947 | $offset = $limit * ( $page - 1 ); |
| 11948 | $options = []; |
| 11949 | $args = [ |
| 11950 | 'post_type' => 'docs', |
| 11951 | 'posts_per_page' => $limit, |
| 11952 | 'offset' => $offset, |
| 11953 | 'orderby' => 'title', |
| 11954 | 'order' => 'ASC', |
| 11955 | 'post_status' => 'publish', |
| 11956 | ]; |
| 11957 | |
| 11958 | $docs = get_posts( $args ); |
| 11959 | $docs_count = wp_count_posts( 'docs' )->publish; |
| 11960 | if ( ! empty( $docs ) ) { |
| 11961 | if ( is_array( $docs ) ) { |
| 11962 | foreach ( $docs as $doc ) { |
| 11963 | $options[] = [ |
| 11964 | 'label' => $doc->post_title, |
| 11965 | 'value' => $doc->ID, |
| 11966 | ]; |
| 11967 | } |
| 11968 | } |
| 11969 | } |
| 11970 | return [ |
| 11971 | 'options' => $options, |
| 11972 | 'hasMore' => $docs_count > $limit && $docs_count > $offset, |
| 11973 | ]; |
| 11974 | } |
| 11975 | |
| 11976 | /** |
| 11977 | * Search Powerful Docs last data. |
| 11978 | * |
| 11979 | * @param array $data data. |
| 11980 | * @return array|void|mixed |
| 11981 | */ |
| 11982 | public function search_pfd_feedback_last_data( $data ) { |
| 11983 | global $wpdb; |
| 11984 | $post_type = $data['post_type']; |
| 11985 | $trigger = $data['search_term']; |
| 11986 | $context = []; |
| 11987 | |
| 11988 | $post_id = $data['filter']['doc_id']['value']; |
| 11989 | |
| 11990 | if ( -1 === $post_id ) { |
| 11991 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}pfd_feedbacks order by id DESC LIMIT 1" ); |
| 11992 | } else { |
| 11993 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}pfd_feedbacks WHERE doc_id=%s order by id DESC LIMIT 1", $post_id ) ); |
| 11994 | } |
| 11995 | |
| 11996 | if ( ! empty( $result ) ) { |
| 11997 | $context_data = [ |
| 11998 | 'feedback' => $result[0]->feedback, |
| 11999 | 'comment' => $result[0]->comment, |
| 12000 | 'doc_id' => $result[0]->doc_id, |
| 12001 | 'time' => $result[0]->time, |
| 12002 | ]; |
| 12003 | $context_data['doc_name'] = get_the_title( $result[0]->doc_id ); |
| 12004 | $context_data['doc_link'] = get_the_permalink( $result[0]->doc_id ); |
| 12005 | $author_id = get_post_field( 'post_author', $result[0]->doc_id ); |
| 12006 | $email = get_the_author_meta( 'user_email', intval( '"' . $author_id . '"' ) ); |
| 12007 | $context_data['doc_author_email'] = $email; |
| 12008 | $context['pluggable_data'] = $context_data; |
| 12009 | $context['response_type'] = 'live'; |
| 12010 | } elseif ( empty( $result ) ) { |
| 12011 | $sample_data = '{"pluggable_data":{"feedback": "yes","comment": "helped me out!!","doc_id": "6689","time": "2023-11-09 11:56:48","doc_name": "First doc","doc_link": "https://example.com","doc_author_email": "john@example.com"},"response_type":"sample"}'; |
| 12012 | $context = json_decode( $sample_data, true ); |
| 12013 | } |
| 12014 | return $context; |
| 12015 | } |
| 12016 | |
| 12017 | /** |
| 12018 | * WooCommerce Coupon Discount type list. |
| 12019 | * |
| 12020 | * @param array $data data. |
| 12021 | * |
| 12022 | * @return array |
| 12023 | */ |
| 12024 | public function search_woo_coupon_discount_type_list( $data ) { |
| 12025 | $options = []; |
| 12026 | |
| 12027 | $discount_types = wc_get_coupon_types(); |
| 12028 | |
| 12029 | if ( ! empty( $discount_types ) ) { |
| 12030 | if ( is_array( $discount_types ) ) { |
| 12031 | foreach ( $discount_types as $key => $value ) { |
| 12032 | $options[] = [ |
| 12033 | 'label' => $value, |
| 12034 | 'value' => $key, |
| 12035 | ]; |
| 12036 | } |
| 12037 | } |
| 12038 | } |
| 12039 | |
| 12040 | return [ |
| 12041 | 'options' => $options, |
| 12042 | 'hasMore' => false, |
| 12043 | ]; |
| 12044 | } |
| 12045 | |
| 12046 | /** |
| 12047 | * WooCommerce Product list along with variation list. |
| 12048 | * |
| 12049 | * @param array $data data. |
| 12050 | * |
| 12051 | * @return array|void |
| 12052 | */ |
| 12053 | public function search_woo_product_variation_list( $data ) { |
| 12054 | $options = []; |
| 12055 | |
| 12056 | $page = $data['page']; |
| 12057 | $limit = Utilities::get_search_page_limit(); |
| 12058 | $offset = $limit * ( $page - 1 ); |
| 12059 | |
| 12060 | if ( ! function_exists( 'wc_get_products' ) ) { |
| 12061 | return; |
| 12062 | } |
| 12063 | $products = wc_get_products( |
| 12064 | [ |
| 12065 | 'posts_per_page' => $limit, |
| 12066 | 'offset' => $offset, |
| 12067 | 'orderby' => 'date', |
| 12068 | 'order' => 'DESC', |
| 12069 | ] |
| 12070 | ); |
| 12071 | |
| 12072 | |
| 12073 | $prod_count = wp_count_posts( 'product' )->publish; |
| 12074 | |
| 12075 | if ( ! empty( $products ) ) { |
| 12076 | if ( is_array( $products ) ) { |
| 12077 | foreach ( $products as $product ) { |
| 12078 | $options[] = [ |
| 12079 | 'label' => $product->get_name(), |
| 12080 | 'value' => $product->get_id(), |
| 12081 | ]; |
| 12082 | if ( $product->is_type( 'variable' ) ) { |
| 12083 | $variations = Utilities::get_product_variations( $product->get_id() ); |
| 12084 | foreach ( $variations['result'] as $variation ) { |
| 12085 | $options[] = [ |
| 12086 | 'label' => $variation->post_title, |
| 12087 | 'value' => $variation->ID, |
| 12088 | ]; |
| 12089 | } |
| 12090 | } |
| 12091 | } |
| 12092 | } |
| 12093 | } |
| 12094 | return [ |
| 12095 | 'options' => $options, |
| 12096 | 'hasMore' => $prod_count > $limit && $prod_count > $offset, |
| 12097 | ]; |
| 12098 | } |
| 12099 | |
| 12100 | /** |
| 12101 | * WooCommerce Product list along with variation list. |
| 12102 | * |
| 12103 | * @param array $data data. |
| 12104 | * |
| 12105 | * @return array |
| 12106 | */ |
| 12107 | public function search_woo_coupon_list( $data ) { |
| 12108 | $options = []; |
| 12109 | |
| 12110 | $page = $data['page']; |
| 12111 | $limit = Utilities::get_search_page_limit(); |
| 12112 | $offset = $limit * ( $page - 1 ); |
| 12113 | |
| 12114 | $coupons = get_posts( |
| 12115 | [ |
| 12116 | 'posts_per_page' => - 1, |
| 12117 | 'orderby' => 'name', |
| 12118 | 'order' => 'asc', |
| 12119 | 'post_type' => 'shop_coupon', |
| 12120 | 'post_status' => 'publish', |
| 12121 | ] |
| 12122 | ); |
| 12123 | $coupon_count = wp_count_posts( 'shop_coupon' )->publish; |
| 12124 | |
| 12125 | if ( ! empty( $coupons ) ) { |
| 12126 | if ( is_array( $coupons ) ) { |
| 12127 | foreach ( $coupons as $coupon ) { |
| 12128 | $code = wc_format_coupon_code( $coupon->post_title ); |
| 12129 | $options[] = [ |
| 12130 | 'label' => $code, |
| 12131 | 'value' => $code, |
| 12132 | ]; |
| 12133 | } |
| 12134 | } |
| 12135 | } |
| 12136 | |
| 12137 | return [ |
| 12138 | 'options' => $options, |
| 12139 | 'hasMore' => $coupon_count > $limit && $coupon_count > $offset, |
| 12140 | ]; |
| 12141 | } |
| 12142 | |
| 12143 | /** |
| 12144 | * Prepare LatePoint Bookings List. |
| 12145 | * |
| 12146 | * @param array $data Search Params. |
| 12147 | * @return array |
| 12148 | */ |
| 12149 | public function search_lp_bookings_list( $data ) { |
| 12150 | |
| 12151 | if ( ! class_exists( 'OsBookingHelper' ) ) { |
| 12152 | return []; |
| 12153 | } |
| 12154 | |
| 12155 | $bookings = OsBookingHelper::get_bookings_for_select(); |
| 12156 | $options = []; |
| 12157 | |
| 12158 | if ( ! empty( $bookings ) ) { |
| 12159 | foreach ( $bookings as $key => $booking ) { |
| 12160 | $options[] = [ |
| 12161 | 'label' => $booking['label'], |
| 12162 | 'value' => $booking['value'], |
| 12163 | ]; |
| 12164 | } |
| 12165 | } |
| 12166 | |
| 12167 | return [ |
| 12168 | 'options' => $options, |
| 12169 | 'hasMore' => false, |
| 12170 | ]; |
| 12171 | } |
| 12172 | |
| 12173 | /** |
| 12174 | * Prepare LatePoint Services List. |
| 12175 | * |
| 12176 | * @param array $data Search Params. |
| 12177 | * @return array |
| 12178 | */ |
| 12179 | public function search_lp_services_list( $data ) { |
| 12180 | |
| 12181 | if ( ! class_exists( 'OsServiceHelper' ) ) { |
| 12182 | return []; |
| 12183 | } |
| 12184 | |
| 12185 | $services = OsServiceHelper::get_services_list(); |
| 12186 | $options = []; |
| 12187 | |
| 12188 | if ( ! empty( $services ) ) { |
| 12189 | foreach ( $services as $key => $service ) { |
| 12190 | $options[] = [ |
| 12191 | 'label' => $service['label'], |
| 12192 | 'value' => $service['value'], |
| 12193 | ]; |
| 12194 | } |
| 12195 | } |
| 12196 | |
| 12197 | return [ |
| 12198 | 'options' => $options, |
| 12199 | 'hasMore' => false, |
| 12200 | ]; |
| 12201 | } |
| 12202 | |
| 12203 | /** |
| 12204 | * Prepare LatePoint Agents List. |
| 12205 | * |
| 12206 | * @param array $data Search Params. |
| 12207 | * @return array |
| 12208 | */ |
| 12209 | public function search_lp_agents_list( $data ) { |
| 12210 | |
| 12211 | if ( ! class_exists( 'OsAgentHelper' ) ) { |
| 12212 | return []; |
| 12213 | } |
| 12214 | |
| 12215 | $agent_ids_for_service = OsAgentHelper::get_agent_ids_for_service_and_location( $data['dynamic'] ); |
| 12216 | $agents = OsAgentHelper::get_agents_list(); |
| 12217 | $options = []; |
| 12218 | |
| 12219 | if ( ! empty( $agents ) ) { |
| 12220 | foreach ( $agents as $key => $agent ) { |
| 12221 | if ( in_array( $agent['value'], $agent_ids_for_service ) ) { |
| 12222 | $options[] = [ |
| 12223 | 'label' => $agent['label'], |
| 12224 | 'value' => $agent['value'], |
| 12225 | ]; |
| 12226 | } |
| 12227 | } |
| 12228 | } |
| 12229 | |
| 12230 | return [ |
| 12231 | 'options' => $options, |
| 12232 | 'hasMore' => false, |
| 12233 | ]; |
| 12234 | } |
| 12235 | |
| 12236 | /** |
| 12237 | * Prepare LatePoint Statuses List. |
| 12238 | * |
| 12239 | * @param array $data Search Params. |
| 12240 | * @return array |
| 12241 | */ |
| 12242 | public function search_lp_statuses_list( $data ) { |
| 12243 | |
| 12244 | if ( ! class_exists( 'OsBookingHelper' ) ) { |
| 12245 | return []; |
| 12246 | } |
| 12247 | |
| 12248 | $statuses = OsBookingHelper::get_statuses_list(); |
| 12249 | $options = []; |
| 12250 | |
| 12251 | if ( ! empty( $statuses ) ) { |
| 12252 | foreach ( $statuses as $key => $label ) { |
| 12253 | $options[] = [ |
| 12254 | 'label' => $label, |
| 12255 | 'value' => $key, |
| 12256 | ]; |
| 12257 | } |
| 12258 | } |
| 12259 | |
| 12260 | return [ |
| 12261 | 'options' => $options, |
| 12262 | 'hasMore' => false, |
| 12263 | ]; |
| 12264 | } |
| 12265 | |
| 12266 | /** |
| 12267 | * Prepare LatePoint Customers List. |
| 12268 | * |
| 12269 | * @param array $data Search Params. |
| 12270 | * @return array |
| 12271 | */ |
| 12272 | public function search_lp_customers_list( $data ) { |
| 12273 | |
| 12274 | if ( ! class_exists( 'OsCustomerHelper' ) ) { |
| 12275 | return []; |
| 12276 | } |
| 12277 | |
| 12278 | $customers = OsCustomerHelper::get_customers_for_select(); |
| 12279 | $options = []; |
| 12280 | |
| 12281 | if ( ! empty( $customers ) ) { |
| 12282 | foreach ( $customers as $key => $customer ) { |
| 12283 | $options[] = [ |
| 12284 | 'label' => $customer['label'], |
| 12285 | 'value' => $customer['value'], |
| 12286 | ]; |
| 12287 | } |
| 12288 | } |
| 12289 | |
| 12290 | return [ |
| 12291 | 'options' => $options, |
| 12292 | 'hasMore' => false, |
| 12293 | ]; |
| 12294 | } |
| 12295 | |
| 12296 | /** |
| 12297 | * Prepare SureForms Forms List. |
| 12298 | * |
| 12299 | * @param array $data Search Params. |
| 12300 | * @return array |
| 12301 | */ |
| 12302 | public function search_sureforms_form_list( $data ) { |
| 12303 | |
| 12304 | $options = []; |
| 12305 | |
| 12306 | $page = $data['page']; |
| 12307 | $limit = Utilities::get_search_page_limit(); |
| 12308 | $offset = $limit * ( $page - 1 ); |
| 12309 | |
| 12310 | $forms = get_posts( |
| 12311 | [ |
| 12312 | 'posts_per_page' => - 1, |
| 12313 | 'orderby' => 'name', |
| 12314 | 'order' => 'asc', |
| 12315 | 'post_type' => 'sureforms_form', |
| 12316 | 'post_status' => 'publish', |
| 12317 | ] |
| 12318 | ); |
| 12319 | $form_count = wp_count_posts( 'sureforms_form' )->publish; |
| 12320 | |
| 12321 | if ( ! empty( $forms ) ) { |
| 12322 | if ( is_array( $forms ) ) { |
| 12323 | foreach ( $forms as $form ) { |
| 12324 | $title = html_entity_decode( get_the_title( $form->ID ), ENT_QUOTES, 'UTF-8' ); |
| 12325 | $options[] = [ |
| 12326 | 'label' => $title, |
| 12327 | 'value' => $form->ID, |
| 12328 | ]; |
| 12329 | } |
| 12330 | } |
| 12331 | } |
| 12332 | |
| 12333 | return [ |
| 12334 | 'options' => $options, |
| 12335 | 'hasMore' => $form_count > $limit && $form_count > $offset, |
| 12336 | ]; |
| 12337 | } |
| 12338 | |
| 12339 | /** |
| 12340 | * Prepare Academy Course List. |
| 12341 | * |
| 12342 | * @param array $data Search Params. |
| 12343 | * @return array |
| 12344 | */ |
| 12345 | public function search_ac_lms_courses( $data ) { |
| 12346 | |
| 12347 | $options = []; |
| 12348 | |
| 12349 | $page = $data['page']; |
| 12350 | $limit = Utilities::get_search_page_limit(); |
| 12351 | $offset = $limit * ( $page - 1 ); |
| 12352 | |
| 12353 | $courses = get_posts( |
| 12354 | [ |
| 12355 | 'posts_per_page' => - 1, |
| 12356 | 'orderby' => 'name', |
| 12357 | 'order' => 'asc', |
| 12358 | 'post_type' => 'academy_courses', |
| 12359 | 'post_status' => 'publish', |
| 12360 | ] |
| 12361 | ); |
| 12362 | $course_count = wp_count_posts( 'academy_courses' )->publish; |
| 12363 | |
| 12364 | if ( ! empty( $courses ) ) { |
| 12365 | if ( is_array( $courses ) ) { |
| 12366 | foreach ( $courses as $course ) { |
| 12367 | $options[] = [ |
| 12368 | 'label' => get_the_title( $course->ID ), |
| 12369 | 'value' => $course->ID, |
| 12370 | ]; |
| 12371 | } |
| 12372 | } |
| 12373 | } |
| 12374 | |
| 12375 | return [ |
| 12376 | 'options' => $options, |
| 12377 | 'hasMore' => $course_count > $limit && $course_count > $offset, |
| 12378 | ]; |
| 12379 | } |
| 12380 | |
| 12381 | /** |
| 12382 | * Prepare Academy Lesson List. |
| 12383 | * |
| 12384 | * @param array $data Search Params. |
| 12385 | * @return array |
| 12386 | */ |
| 12387 | public function search_ac_lms_lessons( $data ) { |
| 12388 | |
| 12389 | $options = []; |
| 12390 | |
| 12391 | if ( ! class_exists( '\Academy\Helper' ) ) { |
| 12392 | return []; |
| 12393 | } |
| 12394 | |
| 12395 | $curriculums = \Academy\Helper::get_course_curriculum( $data['dynamic'] ); |
| 12396 | |
| 12397 | if ( ! empty( $curriculums ) ) { |
| 12398 | foreach ( $curriculums as $topic ) { |
| 12399 | if ( isset( $topic['topics'] ) && is_array( $topic['topics'] ) ) { |
| 12400 | foreach ( $topic['topics'] as $lesson ) { |
| 12401 | if ( isset( $lesson['type'] ) && 'lesson' === $lesson['type'] ) { |
| 12402 | $options[] = [ |
| 12403 | 'label' => $lesson['name'], |
| 12404 | 'value' => $lesson['id'], |
| 12405 | ]; |
| 12406 | } |
| 12407 | } |
| 12408 | } |
| 12409 | } |
| 12410 | } |
| 12411 | |
| 12412 | return [ |
| 12413 | 'options' => $options, |
| 12414 | 'hasMore' => false, |
| 12415 | ]; |
| 12416 | } |
| 12417 | |
| 12418 | /** |
| 12419 | * Prepare Academy Quiz List. |
| 12420 | * |
| 12421 | * @param array $data Search Params. |
| 12422 | * @return array |
| 12423 | */ |
| 12424 | public function search_ac_lms_quiz( $data ) { |
| 12425 | |
| 12426 | $options = []; |
| 12427 | |
| 12428 | $page = $data['page']; |
| 12429 | $limit = Utilities::get_search_page_limit(); |
| 12430 | $offset = $limit * ( $page - 1 ); |
| 12431 | |
| 12432 | $quizs = get_posts( |
| 12433 | [ |
| 12434 | 'posts_per_page' => - 1, |
| 12435 | 'orderby' => 'name', |
| 12436 | 'order' => 'asc', |
| 12437 | 'post_type' => 'academy_quiz', |
| 12438 | 'post_status' => 'publish', |
| 12439 | ] |
| 12440 | ); |
| 12441 | $quiz_count = wp_count_posts( 'academy_quiz' )->publish; |
| 12442 | |
| 12443 | if ( ! empty( $quizs ) ) { |
| 12444 | if ( is_array( $quizs ) ) { |
| 12445 | foreach ( $quizs as $quiz ) { |
| 12446 | $options[] = [ |
| 12447 | 'label' => get_the_title( $quiz->ID ), |
| 12448 | 'value' => $quiz->ID, |
| 12449 | ]; |
| 12450 | } |
| 12451 | } |
| 12452 | } |
| 12453 | |
| 12454 | return [ |
| 12455 | 'options' => $options, |
| 12456 | 'hasMore' => $quiz_count > $limit && $quiz_count > $offset, |
| 12457 | ]; |
| 12458 | } |
| 12459 | |
| 12460 | /** |
| 12461 | * Search Academy LMS data. |
| 12462 | * |
| 12463 | * @param array $data data. |
| 12464 | * @return array|void |
| 12465 | */ |
| 12466 | public function search_ac_lms_last_data( $data ) { |
| 12467 | global $wpdb; |
| 12468 | $post_type = $data['post_type']; |
| 12469 | $trigger = $data['search_term']; |
| 12470 | $context = []; |
| 12471 | |
| 12472 | if ( ! class_exists( '\Academy\Helper' ) ) { |
| 12473 | return []; |
| 12474 | } |
| 12475 | |
| 12476 | $course_id = -1; |
| 12477 | $lesson_id = -1; |
| 12478 | $quiz_id = -1; |
| 12479 | if ( 'ac_lms_course_completed' === $trigger ) { |
| 12480 | $course_id = $data['filter']['course']['value']; |
| 12481 | } elseif ( 'ac_lms_lesson_completed' === $trigger ) { |
| 12482 | $course_id = $data['filter']['course']['value']; |
| 12483 | $lesson_id = $data['filter']['lesson']['value']; |
| 12484 | } elseif ( 'ac_lms_quiz_completed' === $trigger || 'ac_lms_quiz_failed' === $trigger ) { |
| 12485 | $quiz_id = $data['filter']['quiz']['value']; |
| 12486 | } elseif ( 'ac_lms_enrolled_course' === $trigger ) { |
| 12487 | $course_id = $data['filter']['course']['value']; |
| 12488 | } |
| 12489 | |
| 12490 | $users = get_users( |
| 12491 | [ |
| 12492 | 'fields' => 'ID', |
| 12493 | 'meta_key' => 'is_academy_student', |
| 12494 | ] |
| 12495 | ); |
| 12496 | if ( ! empty( $users ) ) { |
| 12497 | $user_random_key = array_rand( $users ); |
| 12498 | $user_id = $users[ $user_random_key ]; |
| 12499 | } |
| 12500 | |
| 12501 | if ( 'ac_lms_course_completed' === $trigger ) { |
| 12502 | if ( -1 === $course_id ) { |
| 12503 | $result = $wpdb->get_results( |
| 12504 | $wpdb->prepare( |
| 12505 | "SELECT * FROM {$wpdb->prefix}comments |
| 12506 | as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.comment_post_ID WHERE postmeta.comment_type='course_completed' AND posts.post_type=%s order by postmeta.comment_ID DESC LIMIT 1", |
| 12507 | $post_type |
| 12508 | ) |
| 12509 | ); |
| 12510 | } else { |
| 12511 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}comments as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.comment_post_ID WHERE postmeta.comment_post_ID = %s AND postmeta.comment_type='course_completed' AND posts.post_type=%s order by postmeta.comment_ID DESC LIMIT 1", $course_id, $post_type ) ); |
| 12512 | } |
| 12513 | } elseif ( 'ac_lms_lesson_completed' === $trigger ) { |
| 12514 | if ( -1 === $course_id ) { |
| 12515 | $courses = get_posts( |
| 12516 | [ |
| 12517 | 'posts_per_page' => - 1, |
| 12518 | 'post_type' => 'academy_courses', |
| 12519 | 'post_status' => 'publish', |
| 12520 | 'fields' => 'ids', |
| 12521 | ] |
| 12522 | ); |
| 12523 | $course_id = array_rand( $courses ); |
| 12524 | $option_name = 'academy_course_' . $course_id . '_completed_topics'; |
| 12525 | } else { |
| 12526 | $option_name = 'academy_course_' . $course_id . '_completed_topics'; |
| 12527 | } |
| 12528 | if ( ! empty( $users ) ) { |
| 12529 | $meta = get_user_meta( $user_id, $option_name, true ); |
| 12530 | if ( is_string( $meta ) ) { |
| 12531 | $saved_topics_lists = (array) json_decode( $meta, true ); |
| 12532 | if ( -1 === $lesson_id ) { |
| 12533 | $result = $saved_topics_lists['lesson']; |
| 12534 | } else { |
| 12535 | if ( is_array( $saved_topics_lists['lesson'] ) ) { |
| 12536 | if ( array_key_exists( $lesson_id, $saved_topics_lists['lesson'] ) ) { |
| 12537 | $result = $saved_topics_lists['lesson']; |
| 12538 | } |
| 12539 | } |
| 12540 | } |
| 12541 | } |
| 12542 | } |
| 12543 | } elseif ( 'ac_lms_quiz_completed' === $trigger ) { |
| 12544 | if ( -1 === $quiz_id ) { |
| 12545 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}academy_quiz_attempts WHERE attempt_status='passed' order by attempt_id DESC LIMIT 1" ); |
| 12546 | } else { |
| 12547 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}academy_quiz_attempts WHERE quiz_id=%s AND attempt_status='passed' order by attempt_id DESC LIMIT 1", $quiz_id ) ); |
| 12548 | } |
| 12549 | } elseif ( 'ac_lms_quiz_failed' === $trigger ) { |
| 12550 | if ( -1 === $quiz_id ) { |
| 12551 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}academy_quiz_attempts WHERE attempt_status='failed' order by attempt_id DESC LIMIT 1" ); |
| 12552 | } else { |
| 12553 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}academy_quiz_attempts WHERE quiz_id=%s AND attempt_status='failed' order by attempt_id DESC LIMIT 1", $quiz_id ) ); |
| 12554 | } |
| 12555 | } elseif ( 'ac_lms_enrolled_course' === $trigger ) { |
| 12556 | if ( -1 === $course_id ) { |
| 12557 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type = %s order by ID DESC LIMIT 1", 'academy_enrolled' ) ); |
| 12558 | } else { |
| 12559 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_parent = %d order by ID DESC LIMIT 1", 'academy_enrolled', $course_id ) ); |
| 12560 | } |
| 12561 | } |
| 12562 | |
| 12563 | if ( ! empty( $result ) ) { |
| 12564 | switch ( $trigger ) { |
| 12565 | case 'ac_lms_course_completed': |
| 12566 | $data = WordPress::get_post_context( $result[0]->comment_post_ID ); |
| 12567 | $context_data = WordPress::get_user_context( $result[0]->user_id ); |
| 12568 | $context_data['course_data'] = $data; |
| 12569 | $context_data['course'] = $result[0]->comment_post_ID; |
| 12570 | break; |
| 12571 | case 'ac_lms_enrolled_course': |
| 12572 | $data = WordPress::get_post_context( $result[0]->post_parent ); |
| 12573 | $context_data = WordPress::get_user_context( $result[0]->post_author ); |
| 12574 | $context_data['course_data'] = $data; |
| 12575 | $context_data['enrollment_data'] = $result[0]; |
| 12576 | $context_data['course'] = $result[0]->post_parent; |
| 12577 | break; |
| 12578 | case 'ac_lms_lesson_completed': |
| 12579 | if ( -1 === $lesson_id ) { |
| 12580 | $key = array_rand( $result ); |
| 12581 | $lesson_data = \Academy\Helper::get_lesson( $key ); |
| 12582 | } else { |
| 12583 | $lesson_data = \Academy\Helper::get_lesson( $lesson_id ); |
| 12584 | } |
| 12585 | if ( is_object( $lesson_data ) ) { |
| 12586 | $lesson_data = get_object_vars( $lesson_data ); |
| 12587 | } |
| 12588 | if ( ! empty( $users ) ) { |
| 12589 | $context_data = array_merge( $lesson_data, WordPress::get_user_context( $user_id ) ); |
| 12590 | } |
| 12591 | $context_data['course_data'] = WordPress::get_post_context( $course_id ); |
| 12592 | $context_data['lesson'] = $lesson_id; |
| 12593 | $context_data['course'] = $course_id; |
| 12594 | break; |
| 12595 | case 'ac_lms_quiz_completed': |
| 12596 | case 'ac_lms_quiz_failed': |
| 12597 | $context_data = WordPress::get_user_context( $result[0]->user_id ); |
| 12598 | $context_data['quiz_data'] = WordPress::get_post_context( $result[0]->quiz_id ); |
| 12599 | $context_data['quiz_attempt_details'] = $result; |
| 12600 | $context_data['quiz'] = $result[0]->quiz_id; |
| 12601 | break; |
| 12602 | default: |
| 12603 | return; |
| 12604 | } |
| 12605 | $context['pluggable_data'] = $context_data; |
| 12606 | $context['response_type'] = 'live'; |
| 12607 | } elseif ( empty( $result ) ) { |
| 12608 | switch ( $trigger ) { |
| 12609 | case 'ac_lms_course_completed': |
| 12610 | $sample_data = '{"pluggable_data":{"wp_user_id": 73, "user_login": "abc@yopmail.com","display_name": "data data1", "user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"course_data": {"ID": 6949,"post_author": "1","post_date": "2023-11-29 05:37:50","post_date_gmt": "2023-11-29 05:37:50","post_content": "<!-- wp:paragraph -->\n<p>this is a business course.<\/p>\n<!-- \/wp:paragraph -->","post_title": "Business Course","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "business-course","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:27","post_modified_gmt": "2023-11-29 09:50:27","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/suretriggers-wpnew.local\/course\/business-course\/","menu_order": 0,"post_type": "academy_courses","post_mime_type": "","comment_count": "0","filter": "raw"},"course": 1},"response_type":"sample"}'; |
| 12611 | break; |
| 12612 | case 'ac_lms_lesson_completed': |
| 12613 | $sample_data = '{"pluggable_data":{"ID": "1","lesson_author": "1","lesson_date": "2023-11-29 07:01:03","lesson_date_gmt": "2023-11-29 07:01:03","lesson_title": "Lesson 1","lesson_name": "","lesson_content": "","lesson_excerpt": "","lesson_status": "publish","comment_status": "close","comment_count": "0","lesson_password": "","lesson_modified": "2023-11-29 07:01:03","lesson_modified_gmt": "2023-11-29 07:01:03","wp_user_id": 73,"user_login": "abc@yopmail.com","display_name": "data data1","user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"course_data": {"ID": 6949,"post_author": "1","post_date": "2023-11-29 05:37:50","post_date_gmt": "2023-11-29 05:37:50","post_content": "<!-- wp:paragraph -->\n<p>this is a business course.<\/p>\n<!-- \/wp:paragraph -->","post_title": "Business Course","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "business-course","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:27","post_modified_gmt": "2023-11-29 09:50:27","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/suretriggers-wpnew.local\/course\/business-course\/","menu_order": 0,"post_type": "academy_courses","post_mime_type": "","comment_count": "0","filter": "raw"},"lesson": 1,"course":1},"response_type":"sample"}'; |
| 12614 | break; |
| 12615 | case 'ac_lms_quiz_completed': |
| 12616 | $sample_data = '{"pluggable_data":{"wp_user_id": 73,"user_login": "abc@yopmail.com","display_name": "data data1","user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"quiz_data": {"ID": 6960,"post_author": "1","post_date": "2023-11-29 09:49:42","post_date_gmt": "2023-11-29 09:49:42","post_content": "","post_title": "First Quiz","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "closed","post_password": "","post_name": "first-quiz","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:11","post_modified_gmt": "2023-11-29 09:50:11","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/suretriggers-wpnew.local\/?post_type=academy_quiz&p=6960","menu_order": 0,"post_type": "academy_quiz","post_mime_type": "","comment_count": "0","filter": "raw"}, "quiz_attempt_details": [{"attempt_id": "2","course_id": "6949","quiz_id": "6960","user_id": "126","total_questions": "1","total_answered_questions": "1","total_marks": "20.00","earned_marks": "20.00","attempt_info": "{\"total_correct_answers\":1}","attempt_status": "passed","attempt_ip": "127.0.0.1","attempt_started_at": "2023-11-30 06:20:10","attempt_ended_at": "2023-11-30 06:20:10","is_manually_reviewed": null,"manually_reviewed_at": null}],"quiz":1},"response_type":"sample"}'; |
| 12617 | break; |
| 12618 | case 'ac_lms_quiz_failed': |
| 12619 | $sample_data = '{"pluggable_data":{"wp_user_id": 73,"user_login": "abc@yopmail.com","display_name": "data data1","user_firstname": "data","user_lastname": "data1","user_email": "abc@yopmail.com","user_role": [],"quiz_data": {"ID": 6960,"post_author": "1","post_date": "2023-11-29 09:49:42","post_date_gmt": "2023-11-29 09:49:42","post_content": "","post_title": "First Quiz","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "closed","post_password": "","post_name": "first-quiz","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:11","post_modified_gmt": "2023-11-29 09:50:11","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/suretriggers-wpnew.local\/?post_type=academy_quiz&p=6960","menu_order": 0,"post_type": "academy_quiz","post_mime_type": "","comment_count": "0","filter": "raw"}, "quiz_attempt_details": [{"attempt_id": "2","course_id": "6949","quiz_id": "6960","user_id": "126","total_questions": "1","total_answered_questions": "1","total_marks": "20.00","earned_marks": "0.00","attempt_info": "{\"total_correct_answers\":0}","attempt_status": "failed","attempt_ip": "127.0.0.1","attempt_started_at": "2023-11-30 06:20:10","attempt_ended_at": "2023-11-30 06:20:10","is_manually_reviewed": null,"manually_reviewed_at": null}],"quiz":1},"response_type":"sample"}'; |
| 12620 | break; |
| 12621 | case 'ac_lms_enrolled_course': |
| 12622 | $sample_data = '{"pluggable_data":{"course_data": {"ID": 6949,"post_author": "1","post_date": "2023-11-29 05:37:50","post_date_gmt": "2023-11-29 05:37:50","post_content": "<!-- wp:paragraph -->\n<p>this is a business course.<\/p>\n<!-- \/wp:paragraph -->","post_title": "Business Course","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "business-course","to_ping": "","pinged": "","post_modified": "2023-11-29 09:50:27","post_modified_gmt": "2023-11-29 09:50:27","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/suretriggers-wpnew.local\/course\/business-course\/","menu_order": 0,"post_type": "academy_courses","post_mime_type": "","comment_count": "0","filter": "raw"},"enrollment_data": {"ID": "6971","post_author": "126","post_date": "2023-11-30 05:52:54","post_date_gmt": "2023-11-30 05:52:54","post_content": "","post_title": "Course Enrolled November 30, 2023 @ 5:52 am","post_excerpt": "","post_status": "completed","comment_status": "closed","ping_status": "closed","post_password": "","post_name": "course-enrolled-november-30-2023-552-am","to_ping": "","pinged": "","post_modified": "2023-11-30 05:52:54","post_modified_gmt": "2023-11-30 05:52:54","post_content_filtered": "","post_parent": "6949","guid": "https:\/\/suretriggers-wpnew.local\/?p=6971","menu_order": "0","post_type": "academy_enrolled","post_mime_type": "","comment_count": "0"},"course":1, "wp_user_id": 2,"user_login": "test","display_name": "test test","user_firstname": "test","user_lastname": "test", "user_email": "test@yopmail.com","user_role": ["academy_student"]},"response_type":"sample"}'; |
| 12623 | break; |
| 12624 | default: |
| 12625 | return; |
| 12626 | } |
| 12627 | $context = (array) json_decode( $sample_data, true ); |
| 12628 | } |
| 12629 | return $context; |
| 12630 | } |
| 12631 | |
| 12632 | /** |
| 12633 | * Search myCred Point Type List. |
| 12634 | * |
| 12635 | * @param array $data Search Params. |
| 12636 | * @return array |
| 12637 | */ |
| 12638 | public function search_mycred_point_type_list( $data ) { |
| 12639 | |
| 12640 | $options = []; |
| 12641 | |
| 12642 | if ( ! function_exists( 'mycred_get_types' ) ) { |
| 12643 | return []; |
| 12644 | } |
| 12645 | |
| 12646 | $posts = mycred_get_types(); |
| 12647 | |
| 12648 | if ( ! empty( $posts ) ) { |
| 12649 | if ( is_array( $posts ) ) { |
| 12650 | foreach ( $posts as $key => $post ) { |
| 12651 | $options[] = [ |
| 12652 | 'label' => $post, |
| 12653 | 'value' => $key, |
| 12654 | ]; |
| 12655 | } |
| 12656 | } |
| 12657 | } |
| 12658 | |
| 12659 | return [ |
| 12660 | 'options' => $options, |
| 12661 | 'hasMore' => false, |
| 12662 | ]; |
| 12663 | } |
| 12664 | } |
| 12665 | |
| 12666 | GlobalSearchController::get_instance(); |
| 12667 |