Пример #1
0
 public static function checkFieldsChain(\Bitrix\Main\Entity\Result $result, $primary = null, array $fields)
 {
     $id = $primary;
     $errorList = array();
     $errorCurrentNumber = 0;
     foreach ($fields as $item) {
         $errorCurrentNumber++;
         $chainFields = array('MAILING_ID' => $id ? $id : 1, 'ID' => $item['ID'], 'REITERATE' => 'Y', 'IS_TRIGGER' => 'Y', 'EMAIL_FROM' => $item['EMAIL_FROM'], 'SUBJECT' => $item['SUBJECT'], 'MESSAGE' => $item['MESSAGE'], 'TIME_SHIFT' => intval($item['TIME_SHIFT']));
         $chainId = 0;
         if (!empty($item['ID'])) {
             $chainId = $item['ID'];
         }
         if ($chainId > 0) {
             $chain = \Bitrix\Sender\MailingChainTable::getRowById(array('ID' => $chainId));
             if ($chain && $chain['STATUS'] != \Bitrix\Sender\MailingChainTable::STATUS_WAIT) {
                 $chainFields['STATUS'] = $chain['STATUS'];
             }
         }
         if (empty($chainFields['STATUS'])) {
             $chainFields['STATUS'] = \Bitrix\Sender\MailingChainTable::STATUS_WAIT;
         }
         $chainFields['ID'] = $chainId;
         $resultItem = new \Bitrix\Main\Entity\Result();
         \Bitrix\Sender\MailingChainTable::checkFields($resultItem, null, $chainFields);
         if ($resultItem->isSuccess()) {
         } else {
             $errorList[$errorCurrentNumber] = $resultItem->getErrors();
         }
     }
     $delimiter = '';
     foreach ($errorList as $number => $errors) {
         /* @var \Bitrix\Main\Entity\FieldError[] $errors*/
         foreach ($errors as $error) {
             $result->addError(new Entity\FieldError($error->getField(), $delimiter . Loc::getMessage('SENDER_ENTITY_MAILING_CHAIN_ITEM_NUMBER') . $number . ': ' . $error->getMessage(), $error->getCode()));
             $delimiter = '';
         }
         $delimiter = "\n";
     }
     return $result;
 }