Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
entitymanager.php
1<?php
2
4
5use Bitrix\Socialnetwork\EO_UserToGroup;
6use Bitrix\Socialnetwork\EO_Workgroup;
7use Bitrix\Socialnetwork\EO_WorkgroupFavorites;
8use Bitrix\Socialnetwork\EO_WorkgroupPin;
9use Bitrix\Socialnetwork\EO_WorkgroupView;
10
12{
13 private string $queryInitAlias = '';
14
15 public function __construct(array $params = [])
16 {
17 $this->queryInitAlias = (string)($params['queryInitAlias'] ?? 'SOCIALNETWORK_WORKGROUP');
18 }
19
20 public function wakeUpWorkgroupEntityObject(array $groupFields = []): ?EO_Workgroup
21 {
22 $whiteList = [
23 'ID',
24 'ACTIVE',
25 'NAME',
26 'DESCRIPTION',
27 'KEYWORDS',
28 'CLOSED',
29 'VISIBLE',
30 'OPENED',
31 'DATE_CREATE',
32 'DATE_UPDATE',
33 'DATE_ACTIVITY',
34 'IMAGE_ID',
35 'AVATAR_TYPE',
36 'OWNER_ID',
37 'INITIATE_PERMS',
38 'NUMBER_OF_MEMBERS',
39 'NUMBER_OF_MODERATORS',
40 'PROJECT',
41 'PROJECT_DATE_START',
42 'PROJECT_DATE_FINISH',
43 'SEARCH_INDEX',
44 'LANDING',
45 'SCRUM_OWNER_ID',
46 'SCRUM_MASTER_ID',
47 'SCRUM_SPRINT_DURATION',
48 'SCRUM_TASK_RESPONSIBLE',
49 ];
50 $entityFields = $this->getEntityFields($groupFields, $whiteList);
51
52 return (!empty($entityFields['ID']) ? EO_Workgroup::wakeUp($entityFields) : null);
53 }
54
55 public function wakeUpContextRelationEntityObject(array $groupFields = []): ?EO_UserToGroup
56 {
57 $whiteList = [
58 'ID',
59 'USER_ID',
60 'GROUP_ID',
61 'ROLE',
62 'INITIATED_BY_TYPE',
63 'INITIATED_BY_USER_ID',
64 'DATE_UPDATE',
65 'AUTO_MEMBER',
66 ];
67 $entityFields = $this->getEntityFields($groupFields, $whiteList, $this->queryInitAlias . '_CONTEXT_RELATION_');
68
69 return (!empty($entityFields['ID']) ? EO_UserToGroup::wakeUp($entityFields) : null);
70 }
71
72 public function wakeUpCurrentRelationEntityObject(array $groupFields = []): ?EO_UserToGroup
73 {
74 $whiteList = [
75 'ID',
76 'USER_ID',
77 'GROUP_ID',
78 'ROLE',
79 'INITIATED_BY_TYPE',
80 'INITIATED_BY_USER_ID',
81 'AUTO_MEMBER',
82 ];
83 $entityFields = $this->getEntityFields($groupFields, $whiteList, $this->queryInitAlias . '_CURRENT_RELATION_');
84
85 return (!empty($entityFields['ID']) ? EO_UserToGroup::wakeUp($entityFields) : null);
86 }
87
88 public function wakeUpFavoritesEntityObject(array $groupFields = []): ?EO_WorkgroupFavorites
89 {
90 $whiteList = [
91 'USER_ID',
92 'GROUP_ID',
93 'DATE_ADD',
94 ];
95 $entityFields = $this->getEntityFields($groupFields, $whiteList, $this->queryInitAlias . '_FAVORITES_');
96
97 return (
98 !empty($entityFields['USER_ID'])
99 && !empty($entityFields['GROUP_ID'])
100 ? EO_WorkgroupFavorites::wakeUp($entityFields)
101 : null
102 );
103 }
104
105 public function wakeUpPinEntityObject(array $groupFields = []): ?EO_WorkgroupPin
106 {
107 $whiteList = [
108 'ID',
109 'USER_ID',
110 'GROUP_ID',
111 ];
112 $entityFields = $this->getEntityFields($groupFields, $whiteList, $this->queryInitAlias . '_PIN_');
113
114 return (!empty($entityFields['ID']) ? EO_WorkgroupPin::wakeUp($entityFields) : null);
115 }
116
117 public function wakeUpViewEntityObject(array $groupFields = []): ?EO_WorkgroupView
118 {
119 $whiteList = [
120 'USER_ID',
121 'GROUP_ID',
122 'DATE_VIEW',
123 ];
124 $entityFields = $this->getEntityFields($groupFields, $whiteList, $this->queryInitAlias . '_VIEW_');
125
126 return (
127 !empty($entityFields['USER_ID'])
128 && !empty($entityFields['GROUP_ID'])
129 ? EO_WorkgroupView::wakeUp($entityFields)
130 : null
131 );
132 }
133
134 protected function getEntityFields($groupFields, array $whiteList = [], string $entityAlias = ''): array
135 {
136 $entityFields = [];
137
138 $map = [];
139 array_walk($whiteList, static function($fieldName) use ($entityAlias, &$map) {
140 $map[$entityAlias . $fieldName] = $fieldName;
141 });
142
143 $groupFields = array_filter($groupFields, static function ($key) use ($map) {
144 return (array_key_exists($key, $map));
145 }, ARRAY_FILTER_USE_KEY);
146
147 foreach ($groupFields as $key => $value)
148 {
149 $entityFields[$map[$key]] = $value;
150 }
151
152 return $entityFields;
153 }
154}
getEntityFields($groupFields, array $whiteList=[], string $entityAlias='')