1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
QueueProvider.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
16use Throwable;
17
19{
20 private JobRepositoryInterface $repository;
21 private JobCacheInterface $cache;
22
23 private const AVAILABLE_FILTERS = ['ID', 'USER_ID', 'COLLAB_ID', 'TYPE'];
24
25 public function __construct()
26 {
27 $this->repository = ServiceLocator::getInstance()->get('socialnetwork.onboarding.job.repository');
28 $this->cache = JobCacheProxy::getInstance();
29 }
30
31 public function getAll(DateTime $from = new DateTime(), int $limit = 500): JobCollection
32 {
33 try
34 {
35 $jobCollection = $this->repository->getAll($from, $limit);
36 }
37 catch (Throwable $t)
38 {
39 $jobCollection = new JobCollection();
40 $this->logUnknownThrowable($t);
41 }
42
43 return $jobCollection;
44 }
45
46 public function getByCollabId(int $collabId, DateTime $from = new DateTime()): JobCollection
47 {
48 if ($collabId <= 0)
49 {
50 return new JobCollection();
51 }
52
53 try
54 {
55 $jobCollection = $this->repository->getByCollabId($collabId, $from);
56 }
57 catch (Throwable $t)
58 {
59 $jobCollection = new JobCollection();
60 $this->logUnknownThrowable($t);
61 }
62
63 return $jobCollection;
64 }
65
66 public function getNotImmediatedByUserId(int $userId, DateTime $from = new DateTime()): JobCollection
67 {
68 if ($userId <= 0)
69 {
70 return new JobCollection();
71 }
72
73 $jobs = $this->cache->getByUserId($userId);
74
75 if (null === $jobs)
76 {
77 $jobs = $this->getByUserId($userId, $from)->getNotImmediatelyExecuted();
78
79 $this->cache->save([$userId => $jobs]);
80 }
81
82 return $jobs;
83 }
84
85 private function getByUserId(int $userId, DateTime $from = new DateTime()): JobCollection
86 {
87 if ($userId <= 0)
88 {
89 return new JobCollection();
90 }
91
92 try
93 {
94 $jobCollection = $this->repository->getByUserId($userId, $from);
95 }
96 catch (Throwable $t)
97 {
98 $jobCollection = new JobCollection();
99 $this->logUnknownThrowable($t);
100 }
101
102 return $jobCollection;
103 }
104
105 public function getByFilter(array $filter, DateTime $from = new DateTime()): JobCollection
106 {
107 $filter = $this->prepareFilter($filter);
108
109 if (empty($filter))
110 {
111 return new JobCollection();
112 }
113
114 try
115 {
116 $jobCollection = $this->repository->getByFilter($filter, $from);
117 }
118 catch (Throwable $t)
119 {
120 $jobCollection = new JobCollection();
121 $this->logUnknownThrowable($t);
122 }
123
124 return $jobCollection;
125 }
126
127 private function prepareFilter(array $filter): array
128 {
129 $availableFilter = [];
130
131 $idsValidator = new ArrayOfPositiveNumbersValidator();
132 $typeValidator = new ArrayOfJobTypesValidator();
133
134 foreach (self::AVAILABLE_FILTERS as $key)
135 {
136 if (empty($filter[$key]))
137 {
138 continue;
139 }
140
141 $isIdsFilter = str_contains($key, 'ID');
142 if ($isIdsFilter && !$idsValidator->validate($filter[$key])->isSuccess())
143 {
144 return [];
145 }
146
147 $isTypeFilter = $key === 'TYPE';
148 if ($isTypeFilter && !$typeValidator->validate($filter[$key])->isSuccess())
149 {
150 return [];
151 }
152
153 $availableFilter[$key] = $filter[$key];
154 }
155
156 return $availableFilter;
157 }
158
159 private function logUnknownThrowable(Throwable $t): void
160 {
161 Application::getInstance()->getExceptionHandler()->writeToLog($t);
162 }
163}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getNotImmediatedByUserId(int $userId, DateTime $from=new DateTime())
Определения QueueProvider.php:66
getByCollabId(int $collabId, DateTime $from=new DateTime())
Определения QueueProvider.php:46
getAll(DateTime $from=new DateTime(), int $limit=500)
Определения QueueProvider.php:31
getByFilter(array $filter, DateTime $from=new DateTime())
Определения QueueProvider.php:105
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$filter
Определения iblock_catalog_list.php:54
if(empty($signedUserToken)) $key
Определения quickway.php:257