/**
  * @param string       $type
  * @param Subscription $subscription
  *
  * @internal param \ArrayObject $tokens
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 protected function sendNotification($type, Subscription $subscription)
 {
     $tokens = $this->buildTokens($subscription);
     $notificationCollection = Notification::findBy('type', $type);
     if (null !== $notificationCollection) {
         while ($notificationCollection->next()) {
             $notification = $notificationCollection->current();
             if ($notification->avisotaFilterByMailingList) {
                 $mailingListId = $subscription->getMailingList() ? $subscription->getMailingList()->getId() : null;
                 $selectedMailingLists = deserialize($notification->avisotaFilteredMailingLists, true);
                 if (!in_array($mailingListId, $selectedMailingLists)) {
                     continue;
                 }
             }
             /** @var Notification $notification */
             $notification->send($tokens->getArrayCopy());
         }
     }
 }
Beispiel #2
0
 /**
  * Send the notification
  */
 public function sendNotification()
 {
     if (!\Input::get('master') || !\Leads\NotificationCenterIntegration::available(true)) {
         \Controller::redirect('contao/main.php?act=error');
     }
     // No need to check for null as NotificationCenterIntegration::available(true) already does
     $notificationsCollection = \NotificationCenter\Model\Notification::findBy('type', 'core_form');
     $notifications = [];
     // Generate the notifications
     foreach ($notificationsCollection as $notification) {
         $notifications[$notification->id] = $notification->title;
     }
     // Process the form
     if ('tl_leads_notification' === \Input::post('FORM_SUBMIT')) {
         /**
          * @var \FormModel                             $form
          * @var \NotificationCenter\Model\Notification $notification
          */
         if (!isset($notifications[\Input::post('notification')]) || !is_array(\Input::post('IDS')) || ($form = \FormModel::findByPk(\Input::get('master'))) === null || null === ($notification = \NotificationCenter\Model\Notification::findByPk(\Input::post('notification')))) {
             \Controller::reload();
         }
         if (\Input::get('id')) {
             $ids = [(int) \Input::get('id')];
         } else {
             $session = \Session::getInstance()->getData();
             $ids = array_map('intval', $session['CURRENT']['IDS']);
         }
         foreach ($ids as $id) {
             if (\Leads\NotificationCenterIntegration::send($id, $form, $notification)) {
                 \Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_lead']['notification_confirm'], $id));
             }
         }
         \Controller::redirect($this->getReferer());
     }
     return \Leads\NotificationCenterIntegration::generateForm($notifications, [\Input::get('id')]);
 }
 */
$GLOBALS['TL_DCA'][$table]['palettes']['__selector__'][] = 'stockmanagement_active';
$GLOBALS['TL_DCA'][$table]['palettes']['__selector__'][] = 'stockmanagement_notification';
$GLOBALS['TL_DCA'][$table]['palettes']['standard'] .= ';{stockmanagement_legend},stockmanagement_active';
/**
 * SubPalettes
 */
$GLOBALS['TL_DCA'][$table]['subpalettes']['stockmanagement_active'] = 'stockmanagement_disableProduct,stockmanagement_notification';
$GLOBALS['TL_DCA'][$table]['subpalettes']['stockmanagement_notification'] = 'stockmanagement_notifications';
/**
 * Fields
 */
$GLOBALS['TL_DCA'][$table]['fields']['stockmanagement_active'] = ['label' => &$GLOBALS['TL_LANG'][$table]['stockmanagement_active'], 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'w50', 'submitOnChange' => true], 'sql' => "char(1) NOT NULL default ''"];
$GLOBALS['TL_DCA'][$table]['fields']['stockmanagement_notification'] = ['label' => &$GLOBALS['TL_LANG'][$table]['stockmanagement_notification'], 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'w50', 'submitOnChange' => true], 'sql' => "char(1) NOT NULL default ''"];
$GLOBALS['TL_DCA'][$table]['fields']['stockmanagement_notifications'] = ['label' => &$GLOBALS['TL_LANG'][$table]['stockmanagement_notifications'], 'inputType' => 'multiColumnWizard', 'eval' => ['tl_class' => 'clr', 'columnFields' => ['threshold' => ['inputType' => 'text', 'label' => &$GLOBALS['TL_LANG'][$table]['stockmanagement_notifications_threshold'], 'eval' => ['rgxp' => 'digit', 'mandatory' => true, 'style' => 'width:60px;text-align:right']], 'nc_id' => ['inputType' => 'select', 'label' => &$GLOBALS['TL_LANG'][$table]['stockmanagement_notifications_nc_id'], 'eval' => ['mandatory' => true], 'options_callback' => function () {
    /** @var Notification|\Model\Collection $notifications */
    /** @noinspection PhpUndefinedMethodInspection */
    $notifications = Notification::findBy('type', 'iso_stockmanagement_change');
    if (null === $notifications) {
        return [];
    }
    return $notifications->fetchEach('title');
}]], 'buttons' => ['up' => false, 'down' => false]], 'save_callback' => [function ($value) {
    $value = deserialize($value);
    $thresholds = array_reduce($value, function ($carry, $item) {
        return array_merge($carry, [$item['threshold']]);
    }, []);
    array_multisort($thresholds, SORT_NUMERIC, $value);
    return serialize($value);
}], 'sql' => "text NULL"];
$GLOBALS['TL_DCA'][$table]['fields']['stockmanagement_disableProduct'] = ['label' => &$GLOBALS['TL_LANG'][$table]['stockmanagement_disableProduct'], 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'w50'], 'sql' => "char(1) NOT NULL default ''"];
 /**
  * Get notification ids.
  *
  * @return array
  */
 public function getNotificationIds()
 {
     $collection = Notification::findBy(array('type LIKE ?'), 'workflow_%');
     return OptionsBuilder::fromCollection($collection, 'id', 'title')->groupBy('type')->getOptions();
 }