1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
manager.php
См. документацию.
1<?php
2
3namespace Bitrix\Vote\Uf;
4
15
16final class Manager
17{
20
21 protected $params;
22
23 protected $additionalConnectorList = null;
26
27 protected static $instance = array();
28
29 private $int = 0;
30
35 public function __construct(array $params)
36 {
37 $this->params = $params;
38 $this->params['ENTITY_VALUE_ID'] = $this->params['ENTITY_VALUE_ID'] ?? null;
39 $this->params['VALUE_ID'] = $this->params['VALUE_ID'] ?? null;
40 $this->errorCollection = new ErrorCollection();
41 }
42
88 public static function getInstance(array $params)
89 {
90 $id = md5(serialize($params));
91 if (!array_key_exists($id, self::$instance))
92 {
93 self::$instance[$id] = new static($params);
94 }
95 return self::$instance[$id];
96 }
97
103 public function loadFromAttachId($id)
104 {
105 if(!isset($this->loadedAttachedObjects[$id]))
106 {
107 $this->loadedAttachedObjects[$id] = \Bitrix\Vote\Attachment\Manager::loadFromAttachId($id);
108 }
109 return $this->loadedAttachedObjects[$id];
110 }
111
117 public function loadFromVoteId($id)
118 {
120 if(!isset($this->loadedAttachedObjects[$id1]))
121 {
122 [$entityType, $moduleId] = $this->getConnectorDataByEntityType($this->params["ENTITY_ID"]);
124 "ENTITY_ID" => ($this->params["ENTITY_VALUE_ID"] ?: $this->params["VALUE_ID"]), // http://hg.office.bitrix.ru/repos/modules/rev/b614a075ce64
125 "ENTITY_TYPE" => $entityType,
126 "MODULE_ID" => $moduleId), $id);
127 $this->loadedAttachedObjects[$id1] = $attach;
128 }
129 return $this->loadedAttachedObjects[$id1];
130 }
131
135 public function loadEmptyObject()
136 {
137 [$entityType, $moduleId] = $this->getConnectorDataByEntityType($this->params["ENTITY_ID"]);
138 return \Bitrix\Vote\Attachment\Manager::loadEmptyAttach(array(
139 "ENTITY_ID" => ($this->params["ENTITY_VALUE_ID"] ?: $this->params["VALUE_ID"]), // http://hg.office.bitrix.ru/repos/modules/rev/b614a075ce64,
140 "ENTITY_TYPE" => $entityType,
141 "MODULE_ID" => $moduleId), array(
142 "CHANNEL_ID" => $this->params["SETTINGS"]["CHANNEL_ID"]
143 ));
144 }
145
149 public function loadFromEntity()
150 {
151 [$entityType, $moduleId] = $this->getConnectorDataByEntityType($this->params["ENTITY_ID"]);
152 $res = array(
153 "ENTITY_ID" => ($this->params["ENTITY_VALUE_ID"] ?: $this->params["VALUE_ID"]), // http://hg.office.bitrix.ru/repos/modules/rev/b614a075ce64
154 "=ENTITY_TYPE" => $entityType,
155 "=MODULE_ID" => $moduleId);
156 return \Bitrix\Vote\Attachment\Manager::loadFromEntity($res);
157 }
158
165 public function belongsToEntity(Attach $attachedObject, $entityType, $entityId)
166 {
167 [$connectorClass, $moduleId] = $this->getConnectorDataByEntityType($entityType);
168
169 return
170 $attachedObject->getEntityId() == $entityId &&
171 $attachedObject->getModuleId() == $moduleId &&
172 $attachedObject->getEntityType() == $connectorClass;
173 }
174
179 public function getConnectorDataByEntityType($entityType)
180 {
181 $defaultConnectors = $this->getDefaultConnectors();
182 $entityType = mb_strtolower($entityType);
183
184 if(isset($defaultConnectors[$entityType]))
185 return $defaultConnectors[$entityType];
186 if (($connector = $this->getAdditionalConnector($entityType)) !== null)
187 return $connector;
188 return array(DefaultConnector::className(), 'vote');
189 }
190
196 public function getConnectors()
197 {
198 return array_merge($this->getDefaultConnectors(), $this->getAdditionalConnectors());
199 }
200
201 private function getDefaultConnectors(): array
202 {
203 return [
204 'blog_post' => [BlogPostConnector::className(), 'blog'],
205 'forum_message' => [ForumMessageConnector::className(), 'forum'],
206 'im_message' => [ImMessageConnector::className(), 'im'],
207 ];
208 }
209
210
211 private function getAdditionalConnectors()
212 {
213 if($this->additionalConnectorList === null)
214 {
215 $this->buildAdditionalConnectorList();
216 }
217
219 }
220
221 private function getAdditionalConnector($entityType)
222 {
223 $additionalConnectorList = $this->getAdditionalConnectors();
224
225 return isset($additionalConnectorList[$entityType])? $additionalConnectorList[$entityType] : null;
226 }
227
228 private function buildAdditionalConnectorList()
229 {
230 $this->additionalConnectorList = array();
231
232 $event = new Event("vote", "onBuildAdditionalConnectorList");
233 $event->send();
234
235 foreach($event->getResults() as $evenResult)
236 {
237 if($evenResult->getType() != EventResult::SUCCESS)
238 {
239 continue;
240 }
241
242 $result = $evenResult->getParameters();
243 if(!is_array($result))
244 {
245 throw new SystemException('Wrong event result by building AdditionalConnectorList. Must be array.');
246 }
247
248 foreach($result as $connector)
249 {
250 if(empty($connector['ENTITY_TYPE']))
251 {
252 throw new SystemException('Wrong event result by building AdditionalConnectorList. Could not find ENTITY_TYPE.');
253 }
254
255 if(empty($connector['MODULE_ID']))
256 {
257 throw new SystemException('Wrong event result by building AdditionalConnectorList. Could not find MODULE_ID.');
258 }
259
260 if(empty($connector['CLASS']))
261 {
262 throw new SystemException('Wrong event result by building AdditionalConnectorList. Could not find CLASS.');
263 }
264
265 if(is_string($connector['CLASS']) && class_exists($connector['CLASS']) && is_a($connector['CLASS'], Connector::class, true))
266 {
267 $this->additionalConnectorList[mb_strtolower($connector['ENTITY_TYPE'])] = array(
268 $connector['CLASS'],
269 $connector['MODULE_ID']
270 );
271 }
272 else
273 {
274 throw new SystemException('Wrong event result by building AdditionalConnectorList. Could not find class by CLASS.');
275 }
276 }
277 }
278 }
279
287 public function showEdit(&$params, &$result, $component = null)
288 {
289 global $APPLICATION;
290 $APPLICATION->IncludeComponent(
291 "bitrix:voting.uf",
292 ".default",
293 array(
294 'EDIT' => 'Y',
295 'PARAMS' => $params,
296 'RESULT' => $result,
297 ),
298 $component,
299 array("HIDE_ICONS" => "Y")
300 );
301 }
302
310 public function showView(&$params, &$result, $component = null)
311 {
312 global $APPLICATION;
313 $APPLICATION->IncludeComponent(
314 "bitrix:voting.uf",
315 ".default",
316 array(
317 "PARAMS" => $params,
318 "RESULT" => $result
319 ),
320 $component,
321 array("HIDE_ICONS" => "Y")
322 );
323 }
324
329 public function getErrors()
330 {
331 return $this->errorCollection->toArray();
332 }
333}
global $APPLICATION
Определения include.php:80
Определения event.php:5
Определения attach.php:180
getEntityId()
Определения attach.php:587
getModuleId()
Определения attach.php:571
getEntityType()
Определения attach.php:579
Определения blogpostconnector.php:10
static className()
Определения connector.php:52
static loadFromVoteId(array $attach, $id)
Определения manager.php:31
static loadFromAttachId($id)
Определения manager.php:20
loadEmptyObject()
Определения manager.php:135
showView(&$params, &$result, $component=null)
Определения manager.php:310
$loadedAttachedObjects
Определения manager.php:25
getErrors()
Определения manager.php:329
$additionalConnectorList
Определения manager.php:23
__construct(array $params)
Определения manager.php:35
$errorCollection
Определения manager.php:19
loadFromAttachId($id)
Определения manager.php:103
belongsToEntity(Attach $attachedObject, $entityType, $entityId)
Определения manager.php:165
getConnectors()
Определения manager.php:196
loadFromVoteId($id)
Определения manager.php:117
loadFromEntity()
Определения manager.php:149
static $instance
Определения manager.php:27
static getInstance(array $params)
Определения manager.php:88
showEdit(&$params, &$result, $component=null)
Определения manager.php:287
getConnectorDataByEntityType($entityType)
Определения manager.php:179
$params
Определения manager.php:21
const NEW_VOTE_PREFIX
Определения voteusertype.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$moduleId
Определения manager.php:3
$entityId
Определения payment.php:4
$event
Определения prolog_after.php:141