Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
commonsendercomponent.php
1<?php
9
21use CBitrixComponent;
22
23Loc::loadMessages(__FILE__);
24
29abstract class CommonSenderComponent extends CBitrixComponent
30{
32 protected $errors;
36 protected $userId;
37
42
43 protected function checkRequiredParams()
44 {
45 try
46 {
47 if (!Loader::includeModule('sender'))
48 {
49 $this->errors->setError(new Error(Loc::getMessage('SENDER_MODULE_NOT_INSTALLED')));
50
51 return false;
52 }
53 }
54 catch (LoaderException $e)
55 {
56 return false;
57 }
58
59 return true;
60 }
61
67 protected function initParams()
68 {
69 $this->arParams['PATH_TO_LIST'] = $this->arParams['PATH_TO_LIST'] ?? '';
70 $this->arParams['PATH_TO_USER_PROFILE'] = $this->arParams['PATH_TO_USER_PROFILE'] ?? '';
71 $this->arParams['NAME_TEMPLATE'] = empty($this->arParams['NAME_TEMPLATE']) ?
72 \CSite::GetNameFormat(false) :
73 str_replace(array("#NOBR#","#/NOBR#"), array("",""), $this->arParams["NAME_TEMPLATE"]);
74
75 $this->arParams['RENDER_FILTER_INTO_VIEW'] = $this->arParams['RENDER_FILTER_INTO_VIEW'] ?? '';
76 $this->arParams['RENDER_FILTER_INTO_VIEW_SORT'] = $this->arParams['RENDER_FILTER_INTO_VIEW_SORT'] ?? 10;
77
78 if(isset($this->arParams['GRID_ID']))
79 {
80 $this->arParams['FILTER_ID'] = $this->arParams['FILTER_ID'] ?? $this->arParams['GRID_ID'] . '_FILTER';
81 }
82
83 $this->arParams['SET_TITLE'] = !isset($this->arParams['SET_TITLE']) || $this->arParams['SET_TITLE'] == 'Y';
84
85 $this->canEdit();
86 }
87
88 protected function canEdit()
89 {
90 if(is_null(static::getEditAction()))
91 {
92 return;
93 }
94
95 try
96 {
97 $this->arParams['CAN_EDIT'] = $this->arParams['CAN_EDIT']
98 ??
99 $this->getAccessController()->check(static::getEditAction());
100 }
101 catch (UnknownActionException $e)
102 {
103 $this->errors->setError(new Error(Loc::getMessage('SENDER_WRONG_PERMISSION')));
104 exit;
105 }
106 }
107
108 protected function printErrors()
109 {
110 foreach ($this->errors as $error)
111 {
112 $message = $error->getMessage() ?? '';
113 ShowError($message);
114 }
115 }
116
117 protected function checkComponentExecution()
118 {
119 if (!$this->checkRequiredParams())
120 {
121 $this->printErrors();
122 return false;
123 }
124
125 if (!static::prepareResult())
126 {
127 $this->printErrors();
128 return false;
129 }
130
131 return true;
132 }
133
135 {
136 if (!$this->accessController)
137 {
138 $this->accessController = new AccessController($this->userId);
139 }
141 }
142
143 public function executeComponent()
144 {
145 $this->errors = new ErrorCollection();
146 $this->userId = Security\User::current()->getId();
147 Security\Access::registerEvent(EventDictionary::EVENT_ON_AFTER_CHECK);
148
149 try
150 {
151 $canAccess = $this->getAccessController()->check(static::getViewAction());
152
153 if((!isset($this->arParams['CAN_VIEW']) || !$this->arParams['CAN_VIEW']) && !$canAccess)
154 {
155 throw new WrongPermissionException();
156 }
157 }
158 catch (AccessException $e)
159 {
160 $this->errors->setError(new Error(Loc::getMessage('SENDER_WRONG_PERMISSION')));
161 $this->printErrors();
162 exit;
163 }
164 static::initParams();
165
166 if (!$this->checkRequiredParams())
167 {
168 $this->printErrors();
169 exit;
170 }
171 }
172
178 protected function prepareResultAndTemplate($template = "")
179 {
180 if (!static::prepareResult())
181 {
182 $this->printErrors();
183 exit();
184 }
185
186 if (!$this->errors->isEmpty())
187 {
188 $this->printErrors();
189 }
190
191 if(!is_null($template))
192 {
193 $this->includeComponentTemplate($template);
194 return;
195 }
196 }
197
198 abstract protected function prepareResult();
199 abstract public function getEditAction();
200 abstract public function getViewAction();
201}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29