1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
GroupProvider.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Provider;
6
7use Bitrix\Main\ArgumentException;
8use Bitrix\Main\ObjectPropertyException;
9use Bitrix\Main\SystemException;
10use Bitrix\Socialnetwork\Internals\Registry\Event\GroupLoadedEvent;
11use Bitrix\Socialnetwork\Item\Workgroup\Type;
12use Bitrix\Socialnetwork\WorkgroupTable;
13use Bitrix\Socialnetwork\Helper\InstanceTrait;
14
16{
17 use InstanceTrait;
18
19 protected static array $checkedGroups = [];
20 protected static array $groupTypes = [];
21
22 public function isExistingGroup(string $inputName, int $groupId = 0): bool
23 {
24 $name = trim($inputName);
25
26 if (empty($name))
27 {
28 return false;
29 }
30
31 if (isset(static::$checkedGroups[$name]))
32 {
33 return static::$checkedGroups[$name];
34 }
35
36 $query = WorkgroupTable::query()
37 ->setSelect(['ID'])
38 ->where('NAME', $name);
39
40 if ($groupId > 0)
41 {
42 $query->whereNot('ID', $groupId);
43 }
44
45 $groups = $query->exec()->fetchAll();
46
47 static::$checkedGroups[$name] = !empty($groups);
48
49 return static::$checkedGroups[$name];
50 }
51
57 public function getGroupType(int $groupId): ?Type
58 {
59 if (isset(static::$groupTypes[$groupId]))
60 {
61 return static::$groupTypes[$groupId];
62 }
63
64 $this->loadGroupTypes($groupId);
65
66 return static::$groupTypes[$groupId] ?? null;
67 }
68
74 public function loadGroupTypes(int ...$groupIds): void
75 {
76 $uncachedGroups = [];
77 foreach ($groupIds as $groupId)
78 {
79 if (!isset(static::$groupTypes[$groupId]))
80 {
81 $uncachedGroups[] = $groupId;
82 }
83 }
84
85 if (empty($uncachedGroups))
86 {
87 return;
88 }
89
90 $groups = WorkgroupTable::query()
91 ->setSelect(['ID', 'TYPE', 'SCRUM_MASTER_ID', 'PROJECT'])
92 ->setFilter(['ID' => $uncachedGroups])
93 ->fetchAll()
94 ;
95
96 foreach ($groups as $group)
97 {
98 static::$groupTypes[$group['ID']] = $this->getTypeByFields($group);
99 }
100 }
101
103 {
104 $group = $event->getGroup();
105 $type = $group->getType();
106
107 if ($type !== null)
108 {
109 static::$groupTypes[$group->getId()] = $type;
110 }
111 }
112
113 private function getTypeByFields(array $fields): ?Type
114 {
115 if (isset($fields['TYPE']))
116 {
117 return Type::tryFrom($fields['TYPE']);
118 }
119
120 if (isset($fields['SCRUM_MASTER_ID']))
121 {
122 return Type::Scrum;
123 }
124
125 if (($fields['PROJECT'] ?? 'N') === 'Y')
126 {
127 return Type::Project;
128 }
129
130 return Type::getDefault();
131 }
132}
$type
Определения options.php:106
isExistingGroup(string $inputName, int $groupId=0)
Определения GroupProvider.php:22
onObjectLoaded(GroupLoadedEvent $event)
Определения GroupProvider.php:102
loadGroupTypes(int ... $groupIds)
Определения GroupProvider.php:74
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
$inputName
Определения options.php:197
$groups
Определения options.php:30
$name
Определения menu_edit.php:35
Определения collection.php:2
$event
Определения prolog_after.php:141
$fields
Определения yandex_run.php:501