| @@ -161,9 +161,9 @@ | ||
| 161 | 161 | * @param int $lim query limit count. |
| 162 | 162 | * @param array $filters optional list of column filters. |
| 163 | 163 | * @param int $min_id optional minimum notification ID. |
| 164 | 164 | */ |
| 165 | - public function loadNotifications(int $start = 0, int $lim = null, array $filters = [], int $min_id = 0) | |
| 165 | + public function loadNotifications(int $start = 0, int $lim = 0, array $filters = [], int $min_id = 0) | |
| 166 | 166 | { |
| 167 | 167 | $dbo = JFactory::getDbo(); |
| 168 | 168 | |
| 169 | 169 | $q = $dbo->getQuery(true) |
| @@ -391,15 +391,22 @@ | ||
| 391 | 391 | 'new_notifications' => 0, |
| 392 | 392 | ]; |
| 393 | 393 | |
| 394 | 394 | foreach ($notifications as $notification) { |
| 395 | - // wrap the notification array/object into a registry | |
| 396 | - $notif_registry = new VBONotificationElements($notification); | |
| 395 | + // wrap the notification array/object into a proper type-registry | |
| 396 | + $notif_registry = VBONotificationElements::getInstance($notification); | |
| 397 | 397 | |
| 398 | 398 | if ($this->storeNotification($notif_registry)) { |
| 399 | 399 | // record was stored successfully |
| 400 | 400 | $result['new_notifications']++; |
| 401 | 401 | |
| 402 | + /** | |
| 403 | + * Trigger a postflight action for this type of notification. | |
| 404 | + * | |
| 405 | + * @since 1.18.3 (J) - 1.8.3 (WP) | |
| 406 | + */ | |
| 407 | + $notif_registry->postflight(); | |
| 408 | + | |
| 402 | 409 | // parse the next one |
| 403 | 410 | continue; |
| 404 | 411 | } |
| 405 | 412 | |
| @@ -457,8 +464,9 @@ | ||
| 457 | 464 | $record->group = $notification->getGroup(); |
| 458 | 465 | $record->type = $notification->getType(); |
| 459 | 466 | $record->title = $notification->getTitle(); |
| 460 | 467 | $record->summary = $notification->getSummary(); |
| 468 | + $record->avatar = $notification->getAvatar(); | |
| 461 | 469 | $record->cta_data = $notification->getCallToActionData(); |
| 462 | 470 | $record->idorder = $notification->getReservationID(); |
| 463 | 471 | $record->idorderota = $notification->getOTAReservationID(); |
| 464 | 472 | $record->channel = $notification->getChannel(); |
| @@ -496,8 +504,9 @@ | ||
| 496 | 504 | 'sender' => 'guests', |
| 497 | 505 | 'type' => 'guest_message', |
| 498 | 506 | 'title' => JText::sprintf('VBO_MESSAGE_FROM', $message->sender_name ?? 'guest'), |
| 499 | 507 | 'summary' => $message->content ?? '', |
| 508 | + 'avatar' => $message->avatar ?? null, | |
| 500 | 509 | 'idorder' => $thread->idorder ?? null, |
| 501 | 510 | 'idorderota' => $thread->idorderota ?? null, |
| 502 | 511 | 'channel' => $thread->channel ?? null, |
| 503 | 512 | ]; |
| @@ -538,8 +547,9 @@ | ||
| 538 | 547 | $config->set('nc_last_download', $today_dt); |
| 539 | 548 | |
| 540 | 549 | // check if automatic notifications should be generated. |
| 541 | 550 | if (!empty($last_download)) { |
| 551 | + // past month notification | |
| 542 | 552 | $last_info = getdate(strtotime($last_download)); |
| 543 | 553 | $prev_m_info = getdate(strtotime('-1 month')); |
| 544 | 554 | if ($last_info['mon'] == $prev_m_info['mon'] && $last_info['year'] == $prev_m_info['year']) { |
| 545 | 555 | // we are on a new month, generate a finance notification for the past month |
| @@ -544,8 +554,37 @@ | ||
| 544 | 554 | if ($last_info['mon'] == $prev_m_info['mon'] && $last_info['year'] == $prev_m_info['year']) { |
| 545 | 555 | // we are on a new month, generate a finance notification for the past month |
| 546 | 556 | $this->generatePastMonthNotification($last_info); |
| 547 | 557 | } |
| 558 | + | |
| 559 | + /** | |
| 560 | + * Check if there are some pending AI training drafts to review. | |
| 561 | + * | |
| 562 | + * @since 1.18.6 (J) - 1.8.6 (WP) | |
| 563 | + */ | |
| 564 | + try { | |
| 565 | + if (!class_exists('VCMAiModelTraining')) { | |
| 566 | + // do not proceed | |
| 567 | + throw new Exception('E4jConnect Channel Manager unavailable or unsupported.', 500); | |
| 568 | + } | |
| 569 | + // load the draft training sets | |
| 570 | + $response = (new VCMAiModelTraining)->getItems([ | |
| 571 | + // needs review | |
| 572 | + 'status' => 2, | |
| 573 | + ], [ | |
| 574 | + 'ordering' => 'created', | |
| 575 | + 'direction' => 'asc', | |
| 576 | + 'offset' => 0, | |
| 577 | + 'limit' => 1, | |
| 578 | + ]); | |
| 579 | + | |
| 580 | + if ($response->pagination->total ?? 0) { | |
| 581 | + // there are some pending drafts to review, generate a notification | |
| 582 | + $this->generatePendingAiDraftsNotification((int) $response->pagination->total); | |
| 583 | + } | |
| 584 | + } catch (Exception $e) { | |
| 585 | + // do nothing | |
| 586 | + } | |
| 548 | 587 | } |
| 549 | 588 | |
| 550 | 589 | // check if the Channel Manager can download new notifications |
| 551 | 590 | |
| @@ -624,8 +663,38 @@ | ||
| 624 | 663 | 'widget_options' => [ |
| 625 | 664 | 'fromdate' => date('Y-m-01', $month[0]), |
| 626 | 665 | 'todate' => date('Y-m-t', $month[0]), |
| 627 | 666 | 'type' => 'month', |
| 667 | + ], | |
| 668 | + ]; | |
| 669 | + | |
| 670 | + try { | |
| 671 | + // store the notification(s) | |
| 672 | + $this->store([$notification]); | |
| 673 | + } catch (Throwable $e) { | |
| 674 | + // silently catch the error | |
| 675 | + } | |
| 676 | + } | |
| 677 | + | |
| 678 | + /** | |
| 679 | + * Generates a notification for the pending AI training drafts to review. | |
| 680 | + * | |
| 681 | + * @param int $count The number of pending AI drafts to review. | |
| 682 | + * | |
| 683 | + * @return void | |
| 684 | + */ | |
| 685 | + private function generatePendingAiDraftsNotification(int $count) | |
| 686 | + { | |
| 687 | + // build past month finance notification payload | |
| 688 | + $notification = [ | |
| 689 | + 'sender' => 'ai', | |
| 690 | + 'type' => 'training.drafts', | |
| 691 | + 'title' => JText::translate('VBO_W_AITRAININGDRAFTS_TITLE'), | |
| 692 | + 'summary' => JText::plural('VBO_AITRAININGDRAFTS_SUMMARY_COUNT', $count), | |
| 693 | + 'widget' => 'ai_training_drafts', | |
| 694 | + 'widget_options' => [ | |
| 695 | + 'trigger' => 'nc', | |
| 696 | + 'dt' => date('Y-m-d'), | |
| 628 | 697 | ], |
| 629 | 698 | ]; |
| 630 | 699 | |
| 631 | 700 | try { |