%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 3.144.28.177 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/sale/lib/controller/ |
Upload File : |
<?php namespace Bitrix\Sale\Controller; use Bitrix\Main\Engine\Response\DataType\Page; use Bitrix\Main\Error; use Bitrix\Main\Localization\Loc; use Bitrix\Sale\Result; class PropertyGroups extends Controller { //region Actions public function getFieldsAction() { $entity = new \Bitrix\Sale\Rest\Entity\PropertyGroups(); return ['PROPERTY_GROUP'=>$entity->prepareFieldInfos( $entity->getFields() )]; } public function addAction(array $fields) { global $APPLICATION; $r = new Result(); $propertyGroupId = 0; $orderPropsGroup = new \CSaleOrderPropsGroup(); if((int)$fields['PERSON_TYPE_ID']<=0) $r->addError(new Error(Loc::getMessage('CONTROLLER_ERROR_PERSON_TYPE_ID_FIELD_EMPTY'), 'PERSON_TYPE_ID_FIELD_EMPTY')); if(trim($fields['NAME'])=='') $r->addError(new Error(Loc::getMessage('CONTROLLER_ERROR_PERSON_TYPE_ID_FIELD_EMPTY'), 'NAME_FIELD_EMPTY')); if($r->isSuccess()) { $propertyGroupId = $orderPropsGroup->Add($fields); if ((int)$propertyGroupId <= 0) { if ($ex = $APPLICATION->GetException()) $r->addError(new Error($ex->GetString(), $ex->GetID())); else $r->addError(new Error(Loc::getMessage('CONTROLLER_ERROR_ADD_PROPS_GROUP'), 'ERROR_ADD_PROPS_GROUP')); } } if(!$r->isSuccess()) { $this->addErrors($r->getErrors()); return null; } else return ['PROPERTY_GROUP'=>$this->get($propertyGroupId)]; } public function updateAction($id, array $fields) { global $APPLICATION; $orderPropsGroup = new \CSaleOrderPropsGroup(); $r = $this->exists($id); if($r->isSuccess()) { if(isset($fields['PERSON_TYPE_ID'])) unset($fields['PERSON_TYPE_ID']); if(!$orderPropsGroup->Update($id, $fields)) { if ($ex = $APPLICATION->GetException()) $r->addError(new Error($ex->GetString(), $ex->GetId())); else $r->addError(new Error(Loc::getMessage('CONTROLLER_ERROR_UPDATE_PROPS_GROUP', ['#ID#'=>$id]), 'ERROR_UPDATE_PROPS_GROUP')); } } if($r->isSuccess()) { return ['PROPERTY_GROUP'=>$this->get($id)]; } else { $this->addErrors($r->getErrors()); return null; } } public function deleteAction($id) { global $APPLICATION; $orderPropsGroup = new \CSaleOrderPropsGroup(); $r = $this->exists($id); if($r->isSuccess()) { if (!$orderPropsGroup->Delete($id)) { if ($ex = $APPLICATION->GetException()) $r->addError(new Error($ex->GetString(), $ex->GetId())); else $r->addError(new Error(Loc::getMessage('CONTROLLER_ERROR_DELETE_PROPS_GROUP', ['#ID#'=>$id]),'ERROR_DELETE_PROPS_GROUP')); } } if($r->isSuccess()) { return true; } else { $this->addErrors($r->getErrors()); return null; } } public function getAction($id) { $r = $this->exists($id); if($r->isSuccess()) { return ['PROPERTY_GROUP'=>$this->get($id)]; } else { $this->addErrors($r->getErrors()); return null; } } public function listAction($select=[], $filter, $order=[], $start=0) { $result = []; $orderPropsGroup = new \CSaleOrderPropsGroup(); $select = empty($select)? ['*']:$select; $order = empty($order)? ['ID'=>'ASC']:$order; $r = $orderPropsGroup->GetList($order, $filter, false, self::getNavData($start), $select); while ($l = $r->fetch()) $result[] = $l; return new Page('PROPERTY_GROUPS', $result, function() use ($filter) { $orderPropsGroup = new \CSaleOrderPropsGroup(); $list = []; $r = $orderPropsGroup->GetList([], $filter); while ($l = $r->fetch()) $list[] = $l; return count($list); }); } //end region protected function get($propertyGroupId) { $orderPropsGroup = new \CSaleOrderPropsGroup(); return $orderPropsGroup->GetById($propertyGroupId); } protected function exists($id) { $r = new Result(); if($this->get($id)['ID']<=0) $r->addError(new Error(Loc::getMessage('CONTROLLER_ERROR_PROPS_GROUP_NOT_EXISTS', ['#ID#'=>$id]), 'PROPS_GROUP_NOT_EXISTS')); return $r; } }