Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
fireduserprovider.php
1<?php
2
4
7use Bitrix\Main\Entity\Query;
8use Bitrix\Main\EO_User;
9use Bitrix\Main\EO_User_Collection;
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 $this->options['module'] = (
35 (isset($options['module']) && is_string($options['module']))
36 ? $options['module']
37 : null
38 );
39
40 $this->options['entityTypeId'] = (
41 !empty($options['entityTypeId'])
42 ? (int)$options['entityTypeId']
43 : null
44 );
45 }
46
47 protected static function getQuery(array $options = []): Query
48 {
49 $query = parent::getQuery($options);
50
52
53 if (
54 !empty($options['referenceClass'])
55 && class_exists($options['referenceClass'])
56 && !empty($options['fieldName'])
57 )
58 {
59 /*
60 * If a referenceClass is not null,
61 * then we reduce the list of fired users only have reference in the referenceClass entity
62 */
63 $fieldName = Application::getConnection()->getSqlHelper()->forSql($options['fieldName']);
64 $tableName = mb_strtolower($query->getEntity()->getCode());
65
66 $query->whereExists(new SqlExpression(
67 "SELECT 1 FROM "
68 . $options['referenceClass']::getTableName()
69 . " WHERE {$fieldName} = {$tableName}.ID"
70 ));
71
72 $derivedTableQuery = $options['referenceClass']::query()
73 ->addSelect('ASSIGNED_BY_ID')
74 ->addGroup('ASSIGNED_BY_ID')
75 ;
76 $entity = \Bitrix\Main\ORM\Entity::getInstanceByQuery($derivedTableQuery);
77
78 $query->registerRuntimeField(
79 'ASSIGNED_BY_ID',
80 (new \Bitrix\Main\ORM\Fields\Relations\Reference(
81 'ASSIGNED_BY_ID',
82 $entity,
83 \Bitrix\Main\ORM\Query\Join::on('this.ID', 'ref.ASSIGNED_BY_ID')
84 ))->configureJoinType(\Bitrix\Main\ORM\Query\Join::TYPE_INNER)
85 );
86 }
87
88 return $query;
89 }
90
91 protected static function sendOnFiredUserProviderQueryEvent(array $options): void
92 {
93 $event = new \Bitrix\Main\Event('ui', 'onFiredUserProviderQuery', [
94 'module' => $options['module'],
95 'entityTypeId' => $options['entityTypeId'],
96 ]);
97
98 $event->send();
99 }
100
101 protected function getPreloadedUsersCollection(): EO_User_Collection
102 {
103 return $this->getUserCollection([
104 'order' => [
105 'LAST_ACTIVITY_DATE' => 'desc',
106 ],
107 'limit' => self::MAX_USERS_IN_RECENT_TAB,
108 ]);
109 }
110
111 public function handleBeforeItemSave(Item $item): void
112 {
113 // Not add fired users in the recent tab
114 $item->setSaveable(false);
115 }
116
117 public function fillDialog(Dialog $dialog): void
118 {
119 parent::fillDialog($dialog);
120
121 // if the referenced entity has fired users, then add the tab
122 if (count($dialog->getItemCollection()->getEntityItems('fired-user')))
123 {
124 $icon =
125 'data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2223%22%20height%3D%2223%22%20' .
126 'fill%3D%22none%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%3E%3Cpath%20d%3D%22M11' .
127 '.934%202.213a.719.719%200%2001.719%200l3.103%201.79c.222.13.36.367.36.623V8.21a.719.71' .
128 '9%200%2001-.36.623l-3.103%201.791a.72.72%200%2001-.719%200L8.831%208.832a.719.719%200%' .
129 '2001-.36-.623V4.627c0-.257.138-.495.36-.623l3.103-1.791zM7.038%2010.605a.719.719%200%2' .
130 '001.719%200l3.103%201.792a.72.72%200%2001.359.622v3.583a.72.72%200%2001-.36.622l-3.102' .
131 '%201.792a.719.719%200%2001-.72%200l-3.102-1.791a.72.72%200%2001-.36-.623v-3.583c0-.257' .
132 '.138-.494.36-.622l3.103-1.792zM20.829%2013.02a.719.719%200%2000-.36-.623l-3.102-1.792a' .
133 '.719.719%200%2000-.72%200l-3.102%201.792a.72.72%200%2000-.36.622v3.583a.72.72%200%2000' .
134 '.36.622l3.103%201.792a.719.719%200%2000.719%200l3.102-1.791a.719.719%200%2000.36-.623v' .
135 '-3.583z%22%20fill%3D%22%23ABB1B8%22/%3E%3C/svg%3E';
136
137 $firedTab = new Tab([
138 'id' => 'fired-user',
139 'title' => Loc::getMessage('SOCNET_ENTITY_SELECTOR_FIREDUSER_TAB_TITLE'),
140 'stub' => true,
141 'icon' => [
142 'default' => $icon,
143 'selected' => str_replace('ABB1B8', 'fff', $icon),
144 //'default' => '/bitrix/js/socialnetwork/entity-selector/images/project-tab-icon.svg',
145 //'selected' => '/bitrix/js/socialnetwork/entity-selector/images/project-tab-icon-selected.svg'
146 ]
147 ]);
148
149 $footerOptions = [
150 'content' => Loc::getMessage('SOCNET_ENTITY_SELECTOR_FIREDUSER_FOOTER_INFO'),
151 ];
152 $firedTab->setFooter('BX.SocialNetwork.EntitySelector.TextFooter', $footerOptions);
153 $dialog->addTab($firedTab);
154 }
155 }
156
157 public static function makeItem(EO_User $user, array $options = []): Item
158 {
159 $item = parent::makeItem($user, $options);
160
161 // Not add fired users in the recent tab
162 $item->setAvailableInRecentTab(false);
163 return $item;
164 }
165
166}
static getConnection($name="")
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
setSaveable(bool $flag=true)
Definition item.php:552