1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
fireduserprovider.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Integration\UI\EntitySelector;
4
5use Bitrix\Main\Application;
6use Bitrix\Main\DB\SqlExpression;
7use Bitrix\Main\Entity\Query;
8use Bitrix\Main\EO_User;
9use Bitrix\Main\EO_User_Collection;
10use Bitrix\Main\Localization\Loc;
11use Bitrix\UI\EntitySelector\Dialog;
12use Bitrix\UI\EntitySelector\Item;
13use Bitrix\UI\EntitySelector\Tab;
14
16{
17 protected const ENTITY_ID = 'fired-user';
18
19 protected function prepareOptions(array $options = []): void
20 {
21 parent::prepareOptions($options);
22 $this->options['activeUsers'] = false;
23
24 if (isset($options['fieldName']) && is_string($options['fieldName']))
25 {
26 $this->options['fieldName'] = $options['fieldName'];
27 }
28
29 if (isset($options['referenceClass']) && is_string($options['referenceClass']))
30 {
31 $this->options['referenceClass'] = $options['referenceClass'];
32 }
33
34 if (isset($options['referenceAdditionalFilter']) && is_array($options['referenceAdditionalFilter']))
35 {
36 $this->options['referenceAdditionalFilter'] = $options['referenceAdditionalFilter'];
37 }
38
39 if (isset($options['referenceFieldName']) && is_string($options['referenceFieldName']))
40 {
41 $this->options['referenceFieldName'] = $options['referenceFieldName'];
42 }
43 else
44 {
45 $this->options['referenceFieldName'] = 'ASSIGNED_BY_ID';
46 }
47
48 $this->options['module'] = (
49 (isset($options['module']) && is_string($options['module']))
50 ? $options['module']
51 : null
52 );
53
54 $this->options['entityTypeId'] = (
55 !empty($options['entityTypeId'])
56 ? (int)$options['entityTypeId']
57 : null
58 );
59 }
60
61 protected static function getQuery(array $options = []): Query
62 {
63 $query = parent::getQuery($options);
64
66
67 if (
68 !empty($options['referenceClass'])
69 && class_exists($options['referenceClass'])
70 && !empty($options['fieldName'])
71 )
72 {
73 /*
74 * If a referenceClass is not null,
75 * then we reduce the list of fired users only have reference in the referenceClass entity
76 */
77 $sqlHelper = Application::getConnection()->getSqlHelper();
78 $fieldName = $sqlHelper->quote($options['fieldName']);
79 $tableName = mb_strtolower($query->getEntity()->getCode());
80
81 $preparedWhere = [];
82 $referenceAdditionalFilter = $options['referenceAdditionalFilter'] ?? [];
83 $referenceClassTableName = $options['referenceClass']::getTableName();
84 foreach ($referenceAdditionalFilter as $filterFieldName => $filterFieldValue)
85 {
86 $preparedWhere[] = $sqlHelper->prepareAssignment(
87 $referenceClassTableName,
88 $filterFieldName,
89 $filterFieldValue,
90 );
91 }
92
93 $where = array_merge(["{$fieldName} = {$tableName}.ID"], $preparedWhere);
94
95 $query->whereExists(new SqlExpression(
96 "SELECT 1 FROM "
97 . $options['referenceClass']::getTableName()
98 . " WHERE " . implode(' AND ', $where)
99 ));
100
101 $derivedTableQuery = $options['referenceClass']::query()
102 ->addSelect($options['referenceFieldName'])
103 ->addGroup($options['referenceFieldName'])
104 ;
105 $entity = \Bitrix\Main\ORM\Entity::getInstanceByQuery($derivedTableQuery);
106
107 $query->registerRuntimeField(
108 'ASSIGNED_BY_ID',
110 'ASSIGNED_BY_ID',
111 $entity,
112 \Bitrix\Main\ORM\Query\Join::on('this.ID', 'ref.' . $options['referenceFieldName'])
113 ))->configureJoinType(\Bitrix\Main\ORM\Query\Join::TYPE_INNER)
114 );
115 }
116
117 return $query;
118 }
119
120 protected static function sendOnFiredUserProviderQueryEvent(array $options): void
121 {
122 $event = new \Bitrix\Main\Event('ui', 'onFiredUserProviderQuery', [
123 'module' => $options['module'],
124 'entityTypeId' => $options['entityTypeId'],
125 ]);
126
127 $event->send();
128 }
129
131 {
132 return $this->getUserCollection([
133 'order' => [
134 'LAST_ACTIVITY_DATE' => 'desc',
135 ],
136 'limit' => self::MAX_USERS_IN_RECENT_TAB,
137 ]);
138 }
139
140 public function handleBeforeItemSave(Item $item): void
141 {
142 // Not add fired users in the recent tab
143 $item->setSaveable(false);
144 }
145
146 public function fillDialog(Dialog $dialog): void
147 {
148 parent::fillDialog($dialog);
149
150 // if the referenced entity has fired users, then add the tab
151 if (count($dialog->getItemCollection()->getEntityItems('fired-user')))
152 {
153 $icon =
154 'data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2223%22%20height%3D%2223%22%20' .
155 'fill%3D%22none%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%3E%3Cpath%20d%3D%22M11' .
156 '.934%202.213a.719.719%200%2001.719%200l3.103%201.79c.222.13.36.367.36.623V8.21a.719.71' .
157 '9%200%2001-.36.623l-3.103%201.791a.72.72%200%2001-.719%200L8.831%208.832a.719.719%200%' .
158 '2001-.36-.623V4.627c0-.257.138-.495.36-.623l3.103-1.791zM7.038%2010.605a.719.719%200%2' .
159 '001.719%200l3.103%201.792a.72.72%200%2001.359.622v3.583a.72.72%200%2001-.36.622l-3.102' .
160 '%201.792a.719.719%200%2001-.72%200l-3.102-1.791a.72.72%200%2001-.36-.623v-3.583c0-.257' .
161 '.138-.494.36-.622l3.103-1.792zM20.829%2013.02a.719.719%200%2000-.36-.623l-3.102-1.792a' .
162 '.719.719%200%2000-.72%200l-3.102%201.792a.72.72%200%2000-.36.622v3.583a.72.72%200%2000' .
163 '.36.622l3.103%201.792a.719.719%200%2000.719%200l3.102-1.791a.719.719%200%2000.36-.623v' .
164 '-3.583z%22%20fill%3D%22%23ABB1B8%22/%3E%3C/svg%3E';
165
166 $firedTab = new Tab([
167 'id' => 'fired-user',
168 'title' => Loc::getMessage('SOCNET_ENTITY_SELECTOR_FIREDUSER_TAB_TITLE'),
169 'stub' => true,
170 'icon' => [
171 'default' => $icon,
172 'selected' => str_replace('ABB1B8', 'fff', $icon),
173 ],
174 ]);
175
176 $footerOptions = [
177 'content' => Loc::getMessage('SOCNET_ENTITY_SELECTOR_FIREDUSER_FOOTER_INFO'),
178 ];
179 $firedTab->setFooter('BX.SocialNetwork.EntitySelector.TextFooter', $footerOptions);
180 $dialog->addTab($firedTab);
181 }
182 }
183
184 public static function makeItem(EO_User $user, array $options = []): Item
185 {
186 $item = parent::makeItem($user, $options);
187
188 // Not add fired users in the recent tab
189 $item->setAvailableInRecentTab(false);
190 return $item;
191 }
192
193}
Определения dialog.php:11
Определения orm.php:16144
static makeItem(EO_User $user, array $options=[])
Определения fireduserprovider.php:184
setSaveable(bool $flag=true)
Определения item.php:552
</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
$entity
Определения chain.php:3
$user
Определения mysql_to_pgsql.php:33
$event
Определения prolog_after.php:141
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936