Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
controller.php
1<?php
2
3
5
17
18class Controller extends Base
19{
20 const IBLOCK_READ = 'iblock_admin_display';
21 const IBLOCK_ELEMENT_READ = 'element_read';
22 const IBLOCK_ELEMENT_EDIT = 'element_edit';
23 const IBLOCK_ELEMENT_DELETE = 'element_delete';
24 const IBLOCK_SECTION_READ = 'section_read';
25 const IBLOCK_SECTION_EDIT = 'section_edit';
26 const IBLOCK_SECTION_DELETE = 'section_delete';
27 const IBLOCK_ELEMENT_EDIT_PRICE = 'element_edit_price';
28 const IBLOCK_SECTION_SECTION_BIND = 'section_section_bind';
29 const IBLOCK_ELEMENT_SECTION_BIND = 'section_element_bind';
30 const IBLOCK_EDIT = 'iblock_edit';
31
32 const CATALOG_STORE = ActionDictionary::ACTION_STORE_VIEW;
33 const CATALOG_READ = ActionDictionary::ACTION_CATALOG_READ;
34 const CATALOG_GROUP = ActionDictionary::ACTION_PRICE_GROUP_EDIT;
35 const CATALOG_VAT = ActionDictionary::ACTION_VAT_EDIT;
36
37 public const ERROR_ACCESS_DENIED = 'Access denied';
39
43 protected function init()
44 {
45 parent::init();
46
47 $this->accessController = AccessController::getCurrent();
48 }
49
50 protected function createViewManager(Action $action)
51 {
52 return new CatalogViewManager($action);
53 }
54
55 protected static function getApplication()
56 {
58 global $APPLICATION;
59
60 return $APPLICATION;
61 }
62
63 protected static function getGlobalUser()
64 {
66 global $USER;
67
68 return $USER;
69 }
70
71 protected static function getNavData($start, $orm = false)
72 {
73 if($start >= 0)
74 {
75 return ($orm ?
76 ['limit' => \IRestService::LIST_LIMIT, 'offset' => intval($start)]
77 :['nPageSize' => \IRestService::LIST_LIMIT, 'iNumPage' => intval($start / \IRestService::LIST_LIMIT) + 1]
78 );
79 }
80 else
81 {
82 return ($orm ?
83 ['limit' => \IRestService::LIST_LIMIT]
84 :['nTopCount' => \IRestService::LIST_LIMIT]
85 );
86 }
87 }
88
95 protected function getViewFields(): ?array
96 {
97 $view =
98 $this
99 ->getViewManager()
100 ->getView($this)
101 ;
102
103 if (!$view)
104 {
105 return null;
106 }
107
108 return $view->prepareFieldInfos($view->getFields());
109 }
110
117 public function getEntity(): Entity
118 {
119 return $this->getEntityTable()::getEntity();
120 }
121
122 private function getServiceName(): string
123 {
124 return (new \ReflectionClass($this))->getShortName();
125 }
126
127 protected function getServiceItemName(): string
128 {
129 $converter = new Converter(Converter::TO_UPPER | Converter::TO_SNAKE_DIGIT);
130
131 return $converter->process($this->getServiceName());
132 }
133
134 protected function getServiceListName(): string
135 {
136 return $this->getServiceItemName() . 'S';
137 }
138
139 // rest-event region
143 public static function getCallbackRestEvent(): array
144 {
145 return [EventBind::class, 'processItemEvent'];
146 }
147
151 public static function getHandlers(): array
152 {
153 return (new EventBind(static::class))->getHandlers(static::getBindings());
154 }
155
162 protected static function getBindings(): array
163 {
164 $entity = (new static())->getEntity();
165 $class = $entity->getNamespace() . $entity->getName();
166
167 return [
168 Event::makeEventName($class,DataManager::EVENT_ON_AFTER_ADD) => $entity->getModule().'.'.$entity->getName().'.on.add',
169 Event::makeEventName($class,DataManager::EVENT_ON_AFTER_UPDATE) => $entity->getModule().'.'.$entity->getName().'.on.update',
170 Event::makeEventName($class,DataManager::EVENT_ON_DELETE) => $entity->getModule().'.'.$entity->getName().'.on.delete',
171 ];
172 }
173 // endregion
174}
static getNavData($start, $orm=false)