1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
usertag.php
См. документацию.
1<?php
8namespace Bitrix\Socialnetwork;
9
10use Bitrix\Main\Entity;
11use Bitrix\Main\NotImplementedException;
12
13
39class UserTagTable extends Entity\DataManager
40{
41 public static function getTableName()
42 {
43 return 'b_sonet_user_tag';
44 }
45
46 public static function getMap()
47 {
48 $fieldsMap = array(
49 'USER_ID' => array(
50 'data_type' => 'integer',
51 'primary' => true
52 ),
53 'USER' => array(
54 'data_type' => 'Bitrix\Main\UserTable',
55 'reference' => array('=this.USER_ID' => 'ref.ID'),
56 ),
57 'NAME' => array(
58 'data_type' => 'string',
59 'primary' => true,
60 'save_data_modification' => function() {
61 return array(
62 function ($text)
63 {
64 return mb_strtolower($text);
65 }
66 );
67 },
68 'fetch_data_modification' => function() {
69 return array(
70 function ($text)
71 {
72 return mb_strtolower($text);
73 }
74 );
75 }
76 )
77 );
78
79 return $fieldsMap;
80 }
81
82 public static function add(array $data)
83 {
84 try
85 {
86 $result = parent::add($data);
87 }
88 catch(\Exception $e)
89 {
90 $result = false;
91 }
92
93 return $result;
94 }
95
96 public static function getUserTagCountData($params = array())
97 {
98 global $DB;
99
101
102 $result = array();
103
104 $userId = (
105 !empty($params['userId'])
106 ? intval($params['userId'])
107 : false
108 );
109
110 $params['tagName'] = $params['tagName'] ?? null;
111
112 $tagName = (
113 (is_array($params['tagName']) && !empty($params['tagName']))
114 || (!is_array($params['tagName']) && $params['tagName'] <> '')
115 ? $params['tagName']
116 : false
117 );
118
119 $nameFilter = (
120 $tagName !== false
121 ? (is_array($tagName)) ? " IN (".implode(',', array_map(function($val) use ($DB) { return "'".$DB->forSql($val)."'"; }, $tagName)).")" : " = '".$DB->forSql($tagName)."'"
122 : ($userId ? ' IN (SELECT NAME FROM '.self::getTableName().' WHERE USER_ID = '.$userId.')' : '')
123 );
124
125 $whereClause = "WHERE U.ACTIVE='Y' ".(!empty($nameFilter) ? 'AND UT.NAME '.$nameFilter : '');
126
127 $sql = '
128 SELECT CASE WHEN (MIN(USER_ID) = 0) THEN COUNT(USER_ID)-1 ELSE COUNT(USER_ID) END AS CNT, UT.NAME AS NAME
129 FROM '.self::getTableName().' UT
130 INNER JOIN b_user U ON U.ID=UT.USER_ID '.
131 $whereClause.'
132 GROUP BY UT.NAME
133 ';
134
135 $res = $connection->query($sql);
136 while ($tagData = $res->fetch())
137 {
138 $result[$tagData['NAME']] = $tagData['CNT'];
139 }
140
141 return $result;
142 }
143
144 public static function getUserTagTopData($params = array())
145 {
146 global $USER, $DB;
147
148 $result = array();
149
150 $userId = (
151 !empty($params['userId'])
152 ? intval($params['userId'])
153 : false
154 );
155
156 $topCount = (
157 isset($params['topCount'])
158 ? intval($params['topCount'])
159 : 0
160 );
161
162 if ($topCount <= 0)
163 {
164 $topCount = 2;
165 }
166
167 if ($topCount > 5)
168 {
169 $topCount = 5;
170 }
171
172 $avatarSize = (
173 isset($params['avatarSize'])
174 ? intval($params['avatarSize'])
175 : 100
176 );
177
179
180 $params['tagName'] = $params['tagName'] ?? null;
181
182 $tagName = (
183 (is_array($params['tagName']) && !empty($params['tagName']))
184 || (!is_array($params['tagName']) && $params['tagName'] <> '')
185 ? $params['tagName']
186 : false
187 );
188
189 $nameFilter = (
190 $tagName !== false
191 ? (is_array($tagName)) ? " NAME IN (".implode(',', array_map(function($val) use ($DB) { return "'".$DB->forSql($val)."'"; }, $tagName)).")" : " NAME = '".$DB->forSql($tagName)."'"
192 : ($userId ? " USER_ID = ".$userId : "")
193 );
194
195 $whereClause = (!empty($nameFilter) ? 'WHERE '.$nameFilter : '');
196
197 $tagsSql = 'SELECT NAME FROM '.self::getTableName().' '.$whereClause;
198
199 if (\Bitrix\Main\ModuleManager::isModuleInstalled('intranet'))
200 {
201 $ratingId = \CRatings::getAuthorityRating();
202 if (intval($ratingId) <= 0)
203 {
204 return $result;
205 }
206
207 $res = $connection->query("
208 SELECT
209 RS1.ENTITY_ID as USER_ID,
210 UT1.NAME as NAME,
211 MAX(RS1.VOTES) as WEIGHT
212 FROM
213 b_rating_subordinate RS1,
214 b_sonet_user_tag UT1
215 INNER JOIN b_user U ON U.ID = UT1.USER_ID
216 WHERE
217 RS1.RATING_ID = ".(int) $ratingId."
218 AND RS1.ENTITY_ID = UT1.USER_ID
219 AND UT1.NAME IN (".$tagsSql.")
220 AND U.ACTIVE = 'Y'
221 GROUP BY
222 UT1.NAME, RS1.ENTITY_ID
223 ORDER BY
224 UT1.NAME,
225 WEIGHT DESC
226 ");
227 }
228 else
229 {
230 $res = $connection->query("
231 SELECT
232 UT1.USER_ID as USER_ID,
233 UT1.NAME as NAME
234 FROM b_sonet_user_tag UT1
235 INNER JOIN b_user U ON U.ID = UT1.USER_ID
236 WHERE
237 UT1.NAME IN (".$tagsSql.")
238 AND U.ACTIVE = 'Y'
239 ORDER BY
240 UT1.NAME
241 ");
242 }
243
244 $userWeightData = $tagUserData = array();
245
246 $currentTagName = false;
247 $hasMine = false;
248
249 while ($resultFields = $res->fetch())
250 {
251 if (
252 !$hasMine
253 && $resultFields['USER_ID'] == $USER->getId()
254 )
255 {
256 $hasMine = true;
257 }
258
259 if ($resultFields['NAME'] != $currentTagName)
260 {
261 $cnt = 0;
262 $hasMine = false;
263 $tagUserData[$resultFields['NAME']] = array();
264 }
265
266 $currentTagName = $resultFields['NAME'];
267 $cnt++;
268
269 if ($cnt > ($hasMine ? $topCount+1 : $topCount))
270 {
271 continue;
272 }
273
274 $tagUserData[$resultFields['NAME']][] = $resultFields['USER_ID'];
275 if (!isset($userWeightData[$resultFields['USER_ID']]))
276 {
277 $userWeightData[$resultFields['USER_ID']] = floatval($resultFields['WEIGHT']);
278 }
279 }
280
282 'userIdList' => array_keys($userWeightData),
283 'avatarSize' => $avatarSize
284 ]);
285
286 foreach($tagUserData as $tagName => $userIdList)
287 {
288 $result[$tagName] = array();
289
290 foreach($userIdList as $userId)
291 {
292 $result[$tagName][] = array(
293 'ID' => $userId,
294 'NAME_FORMATTED' => $userData[$userId]['NAME_FORMATTED'],
295 'PERSONAL_PHOTO' => $userData[$userId]['PERSONAL_PHOTO']['ID'],
296 'PERSONAL_PHOTO_SRC' => $userData[$userId]['PERSONAL_PHOTO']['SRC'],
297 'PERSONAL_GENDER' => $userData[$userId]['PERSONAL_GENDER'],
298 'WEIGHT' => $userWeightData[$userId]
299 );
300 }
301 }
302
303 foreach($result as $tagName => $data)
304 {
305 usort(
306 $data,
307 function($a, $b)
308 {
309 if ($a['WEIGHT'] == $b['WEIGHT'])
310 {
311 return 0;
312 }
313 return ($a['WEIGHT'] > $b['WEIGHT']) ? -1 : 1;
314 }
315 );
316 $result[$tagName] = $data;
317 }
318
319 return $result;
320 }
321
322 public static function update($primary, array $data)
323 {
324 throw new NotImplementedException("Use add() method of the class.");
325 }
326}
$connection
Определения actionsdefinitions.php:38
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getConnection($name="")
Определения application.php:638
static getUserData($params)
Определения usertag.php:124
static getMap()
Определения usertag.php:46
static getUserTagTopData($params=array())
Определения usertag.php:144
static add(array $data)
Определения usertag.php:82
static getUserTagCountData($params=array())
Определения usertag.php:96
static update($primary, array $data)
Определения usertag.php:322
static getTableName()
Определения usertag.php:41
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
return false
Определения prolog_main_admin.php:185
$text
Определения template_pdf.php:79
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
else $a
Определения template.php:137
$val
Определения options.php:1793