1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
BaseSource.php
См. документацию.
1<?php
2
4
11
12abstract class BaseSource implements Source
13{
14 protected const USER_ID_FIELD_NAME = 'OTHER_USER_ID';
15
19 protected static array $cache = [];
20 protected ?int $sourceId;
21 protected int $targetId;
22 protected Stage $stage;
23 protected Filter $filter;
24 protected bool $isFirstInit;
25
26 public function __construct(int $targetId, ?int $sourceId, Stage $stage)
27 {
28 $this->targetId = $targetId;
29 $this->sourceId = $sourceId;
30 $this->stage = $stage;
31 $this->filter = FilterFactory::getInstance()->get($this, $targetId);
32 }
33
34 public function getStage(): Stage
35 {
36 return $this->stage;
37 }
38
39 public function getSourceId(): ?int
40 {
41 return $this->sourceId;
42 }
43
44 public static function getInstance(SourceType $type, int $targetId, ?int $sourceId, Stage $stage): Source
45 {
46 return match ($type)
47 {
48 SourceType::Collab => new Collab($targetId, $sourceId ?? 0, $stage),
49 SourceType::Collabs => new Collabs($targetId, null, $stage),
50 };
51 }
52
53 public static function createFromQueueItem(QueueItem $queueItem): Source
54 {
56 $source = static::getInstance($queueItem->sourceType, $queueItem->userId, $queueItem->sourceId, $stage);
57
58 return $source->setIsFirstInit($queueItem->isFirstInit);
59 }
60
61 public function setIsFirstInit(bool $flag): static
62 {
63 $this->isFirstInit = $flag;
64
65 return $this;
66 }
67
68 public function getItems(string $pointer, int $limit): InitialiazerResult
69 {
70 $result = $this->getUsers($pointer, $limit);
71
72 return $this->stage->getItems($result);
73 }
74
75 final protected function getUsers(string $pointer, int $limit): InitialiazerResult
76 {
77 $cacheKey = $this->getCacheKey($pointer, $limit);
78 if (isset(self::$cache[$cacheKey]))
79 {
80 $result = clone self::$cache[$cacheKey];
81
82 return $result->setSelectedItemsCount(0);
83 }
84
85 self::$cache[$cacheKey] = $this->getUsersInternal($pointer, $limit);
86
87 return clone self::$cache[$cacheKey];
88 }
89
90 final protected function getUsersInternal(string $pointer, int $limit): InitialiazerResult
91 {
92 $query = $this->getBaseQuery($pointer, $limit);
93 if ($this->isResultAffectedByStage())
94 {
96 if ($query === null)
97 {
98 return $this->getResultByRaw([], $limit);
99 }
100 }
101
102 return $this->getResultByRaw($query->fetchAll(), $limit);
103 }
104
105 abstract protected function getBaseQuery(string $pointer, int $limit): Query;
106
107 final protected function modifyQueryByStage(Query $query): ?Query
108 {
109 return $this->filter->apply($query, self::USER_ID_FIELD_NAME);
110 }
111
112 abstract protected function getResultByRaw(array $raw, int $limit): InitialiazerResult;
113
114 abstract protected function isResultAffectedByStage(): bool;
115
116 private function getCacheKey(string $pointer, int $limit): string
117 {
118 $sourceType = static::getType()->value;
119 $stageType = $this->isResultAffectedByStage() ? $this->stage::getType()->value : 'none';
120 $sourceId = $this->sourceId ?? 0;
121
122 return "{$sourceType}_{$stageType}_{$sourceId}_{$this->targetId}_{$pointer}_{$limit}";
123 }
124}
$type
Определения options.php:106
static getInstance(SourceType $type, int $targetId, ?int $sourceId, Stage $stage)
Определения BaseSource.php:44
getItems(string $pointer, int $limit)
Определения BaseSource.php:68
__construct(int $targetId, ?int $sourceId, Stage $stage)
Определения BaseSource.php:26
getBaseQuery(string $pointer, int $limit)
getUsers(string $pointer, int $limit)
Определения BaseSource.php:75
static createFromQueueItem(QueueItem $queueItem)
Определения BaseSource.php:53
getUsersInternal(string $pointer, int $limit)
Определения BaseSource.php:90
getResultByRaw(array $raw, int $limit)
modifyQueryByStage(Query $query)
Определения BaseSource.php:107
static createFromQueueItem(QueueItem $queueItem)
Определения BaseStage.php:31
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
Определения chain.php:3