Beispiel #1
0
 public function onFormMailSend()
 {
     $arElementsID = $this->obRequest->input('checked');
     if (empty($arElementsID) || !is_array($arElementsID)) {
         return $this->listRefresh();
     }
     foreach ($arElementsID as $iElementID) {
         if (!($obElement = Mailing::find($iElementID))) {
             continue;
         }
         //получаем список адресов из категории подписчиков, назначенной рассылке
         $obCategory = Category::find($obElement->category_id);
         if (empty($obCategory)) {
             return;
         }
         $arSendTo = [];
         foreach ($obCategory->subscribers as $obSubscriber) {
             $arSendTo[] = $obSubscriber->email;
             if (empty($obElement->template_code)) {
                 Flash::warning(Lang::get('lovata.subscriptions::lang.message.no_template'));
                 return;
             }
             $sTemplate = $obElement->template_code;
         }
         //если нет подпичиков, то нет смысла рассылки
         //            if(empty($arSendTo)){
         //                return;
         //            }
         //смотрим на источник данных из рассылки и формируем данные
         switch ($obElement->data_source) {
             case 'handprint':
                 $arData = ['title' => $obElement->title, 'preview' => $obElement->preview, 'link' => $obElement->link];
                 break;
             case 'article':
                 if (empty($obElement->article_id) || !PluginManager::instance()->hasPlugin('Lovata.Articles')) {
                     return;
                 }
                 $arData = $this->getArticle($obElement->article_id);
                 break;
             default:
                 return;
         }
         //формируем очередь рассылки данных подписчикам
         foreach ($arSendTo as $sEmail) {
             $this->mailSend($sEmail, $sTemplate, $arData);
         }
     }
     Flash::success(Lang::get('lovata.subscriptions::lang.message.mailsend_success'));
     return $this->listRefresh();
 }