diff --git a/local/classes/Services/Bitrix/AddElement.php b/local/classes/Services/Bitrix/AddElement.php deleted file mode 100644 index 542a4d8..0000000 --- a/local/classes/Services/Bitrix/AddElement.php +++ /dev/null @@ -1,150 +0,0 @@ -model = $model; - $this->translit = $translit; - } - - /** - * Создать элемент инфоблока. - * - * @return boolean - * @throws IblockModelException Внутренняя ошибка. - * @throws IblockModelDuplicateException Уже есть такие данные в базе. - */ - public function create() : bool - { - if ($this->model === null) { - throw new IblockModelException('Model of infoblock not initialized.'); - } - - if ($this->searchDupe()) { - throw new IblockModelDuplicateException('Already have this user - phone & email saved in base.'); - } - - $defaultData = [ - 'MODIFIED_BY' => $GLOBALS['USER']->GetID(), - 'DATE_ACTIVE_FROM' => date('d.m.Y'), - 'IBLOCK_SECTION_ID' => false, - 'NAME' => $this->name, - 'ACTIVE' => 'Y', - 'CODE' => $this->translit->transform($this->name) . ' - ' . date('d.m.Y'), - 'SORT' => 500 - ]; - - $data = array_merge($this->arParams, $defaultData); - - try { - $item = $this->model->create($data); - $item->refresh(); - - return true; - } catch (ExceptionFromBitrix $e) { - return false; - } - } - - /** - * Задать параметры нового элемента. - * - * @param array $arParams Параметры. - * - * @return $this - */ - public function setParams(array $arParams): self - { - $this->arParams = $arParams; - - return $this; - } - - /** - * Задать название нового элемента. - * - * @param string $name Название. - * - * @return $this - */ - public function setName(string $name): self - { - $this->name = $name; - - return $this; - } - - /** - * Задать модель инфоблока. - * - * @param ElementModel $model Модель инфоблока. - * - * @return $this - */ - public function setModel(ElementModel $model): self - { - $this->model = $model; - - return $this; - } - - /** - * Искать дубликаты по телефону и email. - * - * @return boolean - */ - private function searchDupe() : bool - { - $arFilter = [ - 'ACTIVE' => 'Y', - 'PROPERTY_PHONE' => $this->arParams['PROPERTY_VALUES']['PHONE'], - 'PROPERTY_EMAIL' => $this->arParams['PROPERTY_VALUES']['EMAIL'], - ]; - - $items = $this->model->query() - ->filter($arFilter) - ->sort(['SORT' => 'ASC']) - ->getList(); - - return $items->isNotEmpty(); - } -} diff --git a/local/classes/Services/Bitrix/Exceptions/IblockModelDuplicateException.php b/local/classes/Services/Bitrix/Exceptions/IblockModelDuplicateException.php deleted file mode 100644 index 63a4668..0000000 --- a/local/classes/Services/Bitrix/Exceptions/IblockModelDuplicateException.php +++ /dev/null @@ -1,16 +0,0 @@ -