1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
controller.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Catalog\Controller;
5
6use Bitrix\Catalog\Access\AccessController;
7use Bitrix\Catalog\Access\ActionDictionary;
8use Bitrix\Catalog\Model\Event;
9use Bitrix\Catalog\RestView\CatalogViewManager;
10use Bitrix\Main\Engine\Action;
11use Bitrix\Main\Engine\Response\Converter;
12use Bitrix\Main\Error;
13use Bitrix\Main\ORM\Data\DataManager;
14use Bitrix\Main\ORM\Entity;
15use Bitrix\Rest\Event\EventBind;
16use Bitrix\Rest\Event\EventBindInterface;
17use Bitrix\Rest\Integration\Controller\Base;
18
19class Controller extends Base
20{
21 const IBLOCK_READ = 'iblock_admin_display';
22 const IBLOCK_ELEMENT_READ = 'element_read';
23 const IBLOCK_ELEMENT_EDIT = 'element_edit';
24 const IBLOCK_ELEMENT_DELETE = 'element_delete';
25 const IBLOCK_SECTION_READ = 'section_read';
26 const IBLOCK_SECTION_EDIT = 'section_edit';
27 const IBLOCK_SECTION_DELETE = 'section_delete';
28 const IBLOCK_ELEMENT_EDIT_PRICE = 'element_edit_price';
29 const IBLOCK_SECTION_SECTION_BIND = 'section_section_bind';
30 const IBLOCK_ELEMENT_SECTION_BIND = 'section_element_bind';
31 const IBLOCK_EDIT = 'iblock_edit';
32
33 const CATALOG_STORE = ActionDictionary::ACTION_STORE_VIEW;
34 const CATALOG_READ = ActionDictionary::ACTION_CATALOG_READ;
35 const CATALOG_GROUP = ActionDictionary::ACTION_PRICE_GROUP_EDIT;
36 const CATALOG_VAT = ActionDictionary::ACTION_VAT_EDIT;
37
38 public const ERROR_ACCESS_DENIED = 'Access denied';
40
44 protected function init()
45 {
46 parent::init();
47
48 $this->accessController = AccessController::getCurrent();
49 }
50
51 protected function createViewManager(Action $action)
52 {
53 return new CatalogViewManager($action);
54 }
55
56 protected static function getApplication()
57 {
59 global $APPLICATION;
60
61 return $APPLICATION;
62 }
63
70 protected static function getGlobalUser(): ?\CUser
71 {
73 global $USER;
74
75 if (isset($USER) && $USER instanceof \CUser)
76 {
77 return $USER;
78 }
79
80 return null;
81 }
82
83 protected static function getNavData($start, $orm = false)
84 {
85 if($start >= 0)
86 {
87 return ($orm ?
88 ['limit' => \IRestService::LIST_LIMIT, 'offset' => intval($start)]
89 :['nPageSize' => \IRestService::LIST_LIMIT, 'iNumPage' => intval($start / \IRestService::LIST_LIMIT) + 1]
90 );
91 }
92 else
93 {
94 return ($orm ?
95 ['limit' => \IRestService::LIST_LIMIT]
96 :['nTopCount' => \IRestService::LIST_LIMIT]
97 );
98 }
99 }
100
107 protected function getViewFields(): ?array
108 {
109 $view =
110 $this
111 ->getViewManager()
112 ->getView($this)
113 ;
114
115 if (!$view)
116 {
117 return null;
118 }
119
120 return $view->prepareFieldInfos($view->getFields());
121 }
122
129 public function getEntity(): Entity
130 {
131 return $this->getEntityTable()::getEntity();
132 }
133
134 private function getServiceName(): string
135 {
136 return (new \ReflectionClass($this))->getShortName();
137 }
138
139 protected function getServiceItemName(): string
140 {
141 $converter = new Converter(Converter::TO_UPPER | Converter::TO_SNAKE_DIGIT);
142
143 return $converter->process($this->getServiceName());
144 }
145
146 protected function getServiceListName(): string
147 {
148 return $this->getServiceItemName() . 'S';
149 }
150
151 protected function getServiceEntityName(): string
152 {
153 $converter = new Converter(Converter::TO_CAMEL | Converter::LC_FIRST);
154
155 return $converter->process($this->getServiceItemName());
156 }
157
158 protected function getErrorCodeEntityNotExists(): string
159 {
160 return '';
161 }
162
163 protected function getErrorEntityNotExists(): Error
164 {
165 return new Error(
166 $this->getServiceEntityName() . ' does not exist.',
168 );
169 }
170
171 protected function addErrorEntityNotExists(): void
172 {
173 $this->addError($this->getErrorEntityNotExists());
174 }
175
176 protected function getErrorCodeModifyAccessDenied(): string
177 {
179 }
180
181 protected function getErrorModifyAccessDenied(): Error
182 {
183 return new Error('Access Denied', $this->getErrorCodeModifyAccessDenied());
184 }
185
186 protected function getErrorCodeReadAccessDenied(): string
187 {
189 }
190
191 protected function getErrorReadAccessDenied(): Error
192 {
193 return new Error('Access Denied', $this->getErrorCodeReadAccessDenied());
194 }
195
196 // rest-event region
200 public static function getCallbackRestEvent(): array
201 {
202 return [EventBind::class, 'processItemEvent'];
203 }
204
208 public static function getHandlers(): array
209 {
210 return (new EventBind(static::class))->getHandlers(static::getBindings());
211 }
212
219 protected static function getBindings(): array
220 {
221 $entity = (new static())->getEntity();
222 $class = $entity->getNamespace() . $entity->getName();
223
224 return [
225 Event::makeEventName($class,DataManager::EVENT_ON_AFTER_ADD) => $entity->getModule().'.'.$entity->getName().'.on.add',
226 Event::makeEventName($class,DataManager::EVENT_ON_AFTER_UPDATE) => $entity->getModule().'.'.$entity->getName().'.on.update',
227 Event::makeEventName($class,DataManager::EVENT_ON_DELETE) => $entity->getModule().'.'.$entity->getName().'.on.delete',
228 ];
229 }
230 // endregion
231}
global $APPLICATION
Определения include.php:80
static getCallbackRestEvent()
Определения controller.php:200
const IBLOCK_ELEMENT_DELETE
Определения controller.php:24
static getApplication()
Определения controller.php:56
const IBLOCK_SECTION_DELETE
Определения controller.php:27
const IBLOCK_SECTION_SECTION_BIND
Определения controller.php:29
const IBLOCK_ELEMENT_SECTION_BIND
Определения controller.php:30
const IBLOCK_ELEMENT_EDIT_PRICE
Определения controller.php:28
AccessController $accessController
Определения controller.php:39
static getNavData($start, $orm=false)
Определения controller.php:83
static getGlobalUser()
Определения controller.php:70
createViewManager(Action $action)
Определения controller.php:51
const MODIFY_PERMISSION_ACCESS_DENIED
Определения errorcode.php:9
const READ_PERMISSION_ACCESS_DENIED
Определения errorcode.php:8
Определения error.php:15
const LIST_LIMIT
Определения rest.php:897
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$start
Определения get_search.php:9
$entity
global $USER
Определения csv_new_run.php:40
Определения ufield.php:9
$action
Определения file_dialog.php:21