1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
log_rights.php
См. документацию.
1<?
3
5{
6 private static array $state = [];
7
8 public static function Add($LOG_ID, $GROUP_CODE, $bShare = false, $followSet = true)
9 {
10 global $DB, $CACHE_MANAGER;
11
12 static $logDataCache = array();
13
14 if (is_array($GROUP_CODE))
15 {
16 // fill the current state
17 self::$state[(int)$LOG_ID]['current'] = $GROUP_CODE;
18
19 foreach($GROUP_CODE as $GROUP_CODE_TMP)
20 {
21 CSocNetLogRights::Add($LOG_ID, $GROUP_CODE_TMP, $bShare, $followSet);
22 }
23
24 self::unsubscribeExcludedUsers((int)$LOG_ID);
25 unset(self::$state[(int)$LOG_ID]);
26
27 return false;
28 }
29 else
30 {
31 $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetLogRightsAdd");
32 while ($arEvent = $db_events->Fetch())
33 {
34 if (ExecuteModuleEventEx($arEvent, array($LOG_ID, $GROUP_CODE)) === false)
35 {
36 return false;
37 }
38 }
39
40 if (!isset($logDataCache[$LOG_ID]))
41 {
42 $res = LogTable::getList(array(
43 'filter' => array(
44 'ID' => $LOG_ID
45 ),
46 'select' => array('LOG_UPDATE')
47 ));
48 if ($logEntry = $res->fetch())
49 {
50 $logDataCache[$LOG_ID] = $logEntry;
51 }
52 }
53
54 $fields = array(
55 "LOG_ID" => $LOG_ID,
56 "GROUP_CODE" => $GROUP_CODE,
57 );
58
59 if (
60 !empty($logDataCache[$LOG_ID])
61 && !empty($logDataCache[$LOG_ID]['LOG_UPDATE'])
62 && ($logDataCache[$LOG_ID]['LOG_UPDATE'] instanceof \Bitrix\Main\Type\DateTime)
63 )
64 {
65 $fields['LOG_UPDATE'] = $logDataCache[$LOG_ID]['LOG_UPDATE']->toString();
66 }
67
68 $NEW_RIGHT_ID = $DB->add(
69 "b_sonet_log_right",
70 $fields,
71 array(),
72 "",
73 true // ignore errors
74 );
75
76 if ($NEW_RIGHT_ID)
77 {
78 if (preg_match('/^U(\d+)$/', $GROUP_CODE, $matches))
79 {
80 if($followSet)
81 {
83 'logId' => $LOG_ID,
84 'userId' => $matches[1],
85 'typeList' => array(
86 'FOLLOW',
87 ),
88 'followDate' => 'CURRENT'
89 ));
90 }
91 }
92 elseif (
93 $bShare
94 && preg_match('/^SG(\d+)$/', $GROUP_CODE, $matches)
95 )
96 {
97 // get all members who unfollow and set'em unfollow from the date
98 $arUserIDToCheck = array();
99
100 $rsGroupMembers = CSocNetUserToGroup::GetList(
101 array(),
102 array(
103 "GROUP_ID" => $matches[1],
104 "USER_ACTIVE" => "Y",
105 "<=ROLE" => SONET_ROLES_USER
106 ),
107 false,
108 false,
109 array("USER_ID")
110 );
111
112 while ($arGroupMembers = $rsGroupMembers->Fetch())
113 {
114 $arUserIDToCheck[] = $arGroupMembers["USER_ID"];
115 }
116
117 if (!empty($arUserIDToCheck))
118 {
119 $arUserIDFollowDefault = array(
120 "Y" => array(),
121 "N" => array()
122 );
123 $arUserIDAlreadySaved = array();
124 $default_follow_type = COption::GetOptionString("socialnetwork", "follow_default_type", "Y");
125
126 $rsFollow = CSocNetLogFollow::GetList(
127 array(
128 "USER_ID" => $arUserIDToCheck,
129 "CODE" => "**"
130 ),
131 array("USER_ID", "TYPE")
132 );
133 while($arFollow = $rsFollow->Fetch())
134 {
135 $arUserIDFollowDefault[$arFollow["TYPE"]][] = $arFollow["USER_ID"];
136 }
137
138 $rsFollow = CSocNetLogFollow::GetList(
139 array(
140 "USER_ID" => $arUserIDToCheck,
141 "CODE" => "L".$LOG_ID
142 ),
143 array("USER_ID")
144 );
145 while($arFollow = $rsFollow->Fetch())
146 {
147 $arUserIDAlreadySaved[] = $arFollow["USER_ID"];
148 }
149
150 foreach($arUserIDToCheck as $iUserID)
151 {
152 // for them who not followed by default and not already saved follow/unfollow for the log entry
153 if (
154 !in_array($iUserID, $arUserIDAlreadySaved)
155 && (
156 (
157 $default_follow_type == "N"
158 && !in_array($iUserID, $arUserIDFollowDefault["Y"])
159 )
160 || (
161 $default_follow_type == "Y"
162 && in_array($iUserID, $arUserIDFollowDefault["N"])
163 )
164 )
165 )
166 {
167 CSocNetLogFollow::Add(
168 $iUserID,
169 "L".$LOG_ID,
170 "N",
171 ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL", SITE_ID)
172 );
173 }
174 }
175 }
176 }
177 }
178
179 if(defined("BX_COMP_MANAGED_CACHE"))
180 {
181 $CACHE_MANAGER->ClearByTag("SONET_LOG_".intval($LOG_ID));
182 }
183 if (\Bitrix\Main\Loader::includeModule('landing'))
184 {
186 }
187
188 return $NEW_RIGHT_ID;
189 }
190 }
191
192 function Update($RIGHT_ID, $GROUP_CODE)
193 {
194 global $DB;
195 $RIGHT_ID = intval($RIGHT_ID);
196
197 if (is_array($GROUP_CODE))
198 {
199 foreach($GROUP_CODE as $GROUP_CODE_TMP)
200 {
201 CSocNetLogRights::Update($RIGHT_ID, $GROUP_CODE_TMP);
202 }
203
204 return false;
205 }
206 else
207 {
208 $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetLogRightsUpdate");
209 while ($arEvent = $db_events->Fetch())
210 {
211 if (ExecuteModuleEventEx($arEvent, array($RIGHT_ID, &$GROUP_CODE)) === false)
212 {
213 return false;
214 }
215 }
216
217 $strUpdate = $DB->PrepareUpdate("b_sonet_log_right", array(
218 "GROUP_CODE" => $GROUP_CODE
219 ));
220 $DB->Query("UPDATE b_sonet_log_right SET ".$strUpdate." WHERE ID = ".$RIGHT_ID);
221 return $RIGHT_ID;
222 }
223 }
224
225 function Delete($RIGHT_ID)
226 {
227 global $DB;
228 $RIGHT_ID = intval($RIGHT_ID);
229 $DB->Query("DELETE FROM b_sonet_log_right WHERE ID = ".$RIGHT_ID);
230 }
231
232 public static function DeleteByLogID($LOG_ID)
233 {
234 global $DB;
235
236 $LOG_ID = (int)$LOG_ID;
237
238 // fill the prev state
239 self::$state[$LOG_ID]['prev'] = [];
240 $res = self::GetList([], ['LOG_ID' => $LOG_ID]);
241 while ($row = $res->Fetch())
242 {
243 self::$state[$LOG_ID]['prev'][] = $row['GROUP_CODE'];
244 }
245
246 $LOG_ID = intval($LOG_ID);
247 $DB->Query("DELETE FROM b_sonet_log_right WHERE LOG_ID = ".$LOG_ID);
248
249 $db_events = GetModuleEvents("socialnetwork", "OnSocNetLogRightsDelete");
250 while ($arEvent = $db_events->Fetch())
251 {
252 ExecuteModuleEventEx($arEvent, array($LOG_ID));
253 }
254 }
255
256 public static function GetList($aSort=array(), $aFilter=array())
257 {
258 global $DB;
259
260 $arFilter = array();
261 foreach($aFilter as $key=>$val)
262 {
263 $val = $DB->ForSql($val);
264 if($val == '')
265 {
266 continue;
267 }
268
269 switch(mb_strtoupper($key))
270 {
271 case "ID":
272 $arFilter[] = "R.ID=".intval($val);
273 break;
274 case "LOG_ID":
275 $arFilter[] = "R.LOG_ID=".intval($val);
276 break;
277 case "GROUP_CODE":
278 $arFilter[] = "R.GROUP_CODE='".$val."'";
279 break;
280 }
281 }
282
283 $arOrder = array();
284 foreach($aSort as $key=>$val)
285 {
286 $ord = (mb_strtoupper($val) <> "ASC"?"DESC":"ASC");
287 switch(mb_strtoupper($key))
288 {
289 case "ID":
290 $arOrder[] = "R.ID ".$ord;
291 break;
292 case "LOG_ID":
293 $arOrder[] = "R.LOG_ID ".$ord;
294 break;
295 case "GROUP_CODE":
296 $arOrder[] = "R.GROUP_CODE ".$ord;
297 break;
298 }
299 }
300
301 $sOrder = (count($arOrder) > 0 ? "\n ORDER BY ".implode(", ",$arOrder) : "");
302
303 if(count($arFilter) == 0)
304 $sFilter = "";
305 else
306 $sFilter = "\nWHERE ".implode("\nAND ", $arFilter);
307
308 $strSql = "
309 SELECT
310 R.ID
311 ,R.LOG_ID
312 ,R.GROUP_CODE
313 FROM
314 b_sonet_log_right R
315 ".$sFilter.$sOrder;
316
317 return $DB->Query($strSql);
318 }
319
320 public static function SetForSonet($logID, $entity_type, $entity_id, $feature, $operation, $bNew = false)
321 {
322 $bFlag = true;
323 if (!$bNew)
324 {
325 $rsRights = CSocNetLogRights::GetList(array(), array("LOG_ID" => $logID));
326 if ($arRights = $rsRights->Fetch())
327 {
328 $bFlag = false;
329 }
330 }
331
332 if ($bFlag)
333 {
334 $bExtranet = false;
335 $perm = CSocNetFeaturesPerms::GetOperationPerm($entity_type, $entity_id, $feature, $operation);
336 if ($perm)
337 {
338 $extranet_site_id = false;
339 if (CModule::IncludeModule("extranet") && $extranet_site_id = CExtranet::GetExtranetSiteID())
340 {
341 $arLogSites = array();
342 $rsLogSite = CSocNetLog::GetSite($logID);
343 while($arLogSite = $rsLogSite->Fetch())
344 {
345 $arLogSites[] = $arLogSite["LID"];
346 }
347
348 if (in_array($extranet_site_id, $arLogSites))
349 {
350 $bExtranet = true;
351 }
352 }
353
354 if ($bExtranet && $extranet_site_id)
355 {
356 if ($entity_type == SONET_ENTITY_GROUP && $perm == SONET_ROLES_OWNER)
357 CSocNetLogRights::Add($logID, array("SA", "S".SONET_ENTITY_GROUP.$entity_id, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_OWNER));
359 CSocNetLogRights::Add($logID, array("SA", "S".SONET_ENTITY_GROUP.$entity_id, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_OWNER, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_MODERATOR));
361 CSocNetLogRights::Add($logID, array("SA", "S".SONET_ENTITY_GROUP.$entity_id, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_OWNER, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_MODERATOR, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_USER));
363 CSocNetLogRights::Add($logID, array("SA", "U".$entity_id));
365 {
366 $arCode = array("SA");
367 $arLog = CSocNetLog::GetByID($logID);
368 if ($arLog)
369 {
370 $dbUsersInGroup = CSocNetUserToGroup::GetList(
371 array(),
372 array(
373 "USER_ID" => $arLog["USER_ID"],
374 "<=ROLE" => SONET_ROLES_USER,
375 "GROUP_SITE_ID" => $extranet_site_id,
376 "GROUP_ACTIVE" => "Y"
377 ),
378 false,
379 false,
380 array("ID", "GROUP_ID")
381 );
382 while ($arUsersInGroup = $dbUsersInGroup->Fetch())
383 {
384 if (!in_array("S".SONET_ENTITY_GROUP.$arUsersInGroup["GROUP_ID"]."_".SONET_ROLES_USER, $arCode))
385 {
386 $arCode = array_merge(
387 $arCode,
388 array(
389 "S".SONET_ENTITY_GROUP.$arUsersInGroup["GROUP_ID"]."_".SONET_ROLES_OWNER,
390 "S".SONET_ENTITY_GROUP.$arUsersInGroup["GROUP_ID"]."_".SONET_ROLES_MODERATOR,
391 "S".SONET_ENTITY_GROUP.$arUsersInGroup["GROUP_ID"]."_".SONET_ROLES_USER
392 )
393 );
394 }
395 }
396
397 CSocNetLogRights::Add($logID, $arCode);
398 }
399 }
400 }
401 else
402 {
403 if ($entity_type == SONET_ENTITY_GROUP && $perm == SONET_ROLES_OWNER)
404 CSocNetLogRights::Add($logID, array("SA", "S".SONET_ENTITY_GROUP.$entity_id, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_OWNER));
406 CSocNetLogRights::Add($logID, array("SA", "S".SONET_ENTITY_GROUP.$entity_id, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_OWNER, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_MODERATOR));
407 elseif ($entity_type == SONET_ENTITY_GROUP && $perm == SONET_ROLES_USER)
408 CSocNetLogRights::Add($logID, array("SA", "S".SONET_ENTITY_GROUP.$entity_id, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_OWNER, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_MODERATOR, "S".SONET_ENTITY_GROUP.$entity_id."_".SONET_ROLES_USER));
410 {
411 $arCodes = array("SA", "U".$entity_id, "S".$entity_type.$entity_id."_".SONET_RELATIONS_TYPE_FRIENDS);
413 }
415 CSocNetLogRights::Add($logID, array("SA", "U".$entity_id));
417 CSocNetLogRights::Add($logID, array("SA", "S".$entity_type.$entity_id, "S".$entity_type.$entity_id."_".SONET_ROLES_USER, "AU"));
419 CSocNetLogRights::Add($logID, array("SA", "AU"));
420 elseif ($entity_type == SONET_ENTITY_GROUP && $perm == SONET_ROLES_ALL)
421 CSocNetLogRights::Add($logID, array("SA", "S".$entity_type.$entity_id, "S".$entity_type.$entity_id."_".SONET_ROLES_USER, "G2"));
423 CSocNetLogRights::Add($logID, array("SA", "G2"));
424 }
425 }
426 }
427 }
428
429 public static function CheckForUser($logID, $userID)
430 {
431 global $DB;
432
433 $userID = intval($userID);
434
435 $strSql = "SELECT SLR.ID FROM b_sonet_log_right SLR
436 WHERE
437 SLR.LOG_ID = ".intval($logID)."
438 AND
439 SLR.GROUP_CODE IN ('G2'".($userID > 0 ? ", 'AU'" : "").")
440
441 ";
442 $result = $DB->Query($strSql);
443 if ($ar = $result->fetch())
444 {
445 return true;
446 }
447
448 if ($userID > 0)
449 {
450 $strSql = "SELECT SLR.ID FROM b_sonet_log_right SLR
451 INNER JOIN b_user_access UA ON UA.ACCESS_CODE = SLR.GROUP_CODE
452 WHERE
453 SLR.LOG_ID = ".intval($logID)."
454 AND UA.USER_ID = ".$userID."
455 ";
456
457 $result = $DB->Query($strSql);
458 if ($ar = $result->fetch())
459 {
460 return true;
461 }
462 }
463
464 return false;
465 }
466
467 public static function CheckForUserAll($logID)
468 {
469 global $DB;
470
471 $strSql = "SELECT SLR.ID FROM b_sonet_log_right SLR
472 WHERE
473 SLR.LOG_ID = ".intval($logID)."
474 AND (
475 (SLR.GROUP_CODE = 'AU')
476 OR (SLR.GROUP_CODE = 'G2')
477 )";
478
479 $result = $DB->Query($strSql);
480 if($ar = $result->Fetch())
481 {
482 return true;
483 }
484
485 return false;
486 }
487
488 public static function CheckForUserOnly($logID, $userID)
489 {
490 global $DB;
491
492 if (
493 intval($logID) <= 0
494 || intval($userID) <= 0
495 )
496 return false;
497
498 $strSql = "SELECT SLR.ID FROM b_sonet_log_right SLR
499 INNER JOIN b_user_access UA ON 0=1 OR (UA.ACCESS_CODE = SLR.GROUP_CODE AND UA.USER_ID = ".intval($userID).")
500 WHERE SLR.LOG_ID = ".intval($logID);
501
502 $result = $DB->Query($strSql);
503 if($ar = $result->Fetch())
504 {
505 return true;
506 }
507
508 return false;
509 }
510
511 private static function unsubscribeExcludedUsers(int $logId): void
512 {
513 $publicRights = ['AU', 'G2'];
514
515 if (empty(self::$state[$logId]['current']) || empty(self::$state[$logId]['prev']))
516 {
517 return;
518 }
519
520 foreach ($publicRights as $publicRight)
521 {
522 if (in_array($publicRight, self::$state[$logId]['current']))
523 {
524 // no need to unsubscribe anyone because it is already available for everyone
525 return;
526 }
527 }
528
529 $tags = (new \Bitrix\Socialnetwork\Integration\Pull\Tag())->getWatchingTagsByLogId($logId);
530 $unsubscribe = new \Bitrix\Socialnetwork\Integration\Pull\Unsubscribe();
531
532 $from = self::$state[$logId]['prev'] ?? [];
533 $to = self::$state[$logId]['current'] ?? [];
534
535 foreach ($publicRights as $publicRight)
536 {
537 if (in_array($publicRight, self::$state[$logId]['prev']))
538 {
539 // it was previously available for everyone but it no longer the case
540 // we need to unsubscribe from pull watch everyone except those in the list
541 $usersToIgnore = self::getUsersToIgnore($from, $to);
542 $unsubscribe->resetAllButIgnored($tags, $usersToIgnore);
543 return;
544 }
545 }
546
547 // at this point we need to unsubscribe those users who are excluded from the list
548 $unsubscribe->resetByTags($tags, self::getUsersToExclude($from, $to));
549 }
550
551 private static function getUsersToIgnore(array $from, array $to): array
552 {
553 $result = [];
554 $ignored = array_unique(array_diff($to, $from));
555 foreach ($ignored as $code)
556 {
557 $matches = [];
558 if (preg_match('/^U(\d+)$/', $code, $matches))
559 {
560 $result[] = (int)$matches[1];
561 }
562 }
563
564 return $result;
565 }
566
567 private static function getUsersToExclude(array $from ,array $to): array
568 {
569 $result = [];
570 $excluded = array_unique(array_diff($from, $to));
571 foreach ($excluded as $code)
572 {
573 $matches = [];
574 if (preg_match('/^U(\d+)$/', $code, $matches))
575 {
576 $result[] = (int)$matches[1];
577 }
578 }
579
580 return $result;
581 }
582}
583?>
static userLogSubscribe($params=array())
Определения componenthelper.php:4799
static onSocNetLogRightsAddHandler($code)
Определения livefeed.php:671
static GetByID($ID)
Определения log.php:228
static GetSite($log_id)
Определения log.php:1025
Определения log_rights.php:5
static SetForSonet($logID, $entity_type, $entity_id, $feature, $operation, $bNew=false)
Определения log_rights.php:320
static CheckForUser($logID, $userID)
Определения log_rights.php:429
static CheckForUserAll($logID)
Определения log_rights.php:467
static DeleteByLogID($LOG_ID)
Определения log_rights.php:232
static GetList($aSort=array(), $aFilter=array())
Определения log_rights.php:256
Update($RIGHT_ID, $GROUP_CODE)
Определения log_rights.php:192
static CheckForUserOnly($logID, $userID)
Определения log_rights.php:488
Delete($RIGHT_ID)
Определения log_rights.php:225
static Add($LOG_ID, $GROUP_CODE, $bShare=false, $followSet=true)
Определения log_rights.php:8
global $CACHE_MANAGER
Определения clear_component_cache.php:7
</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
$perm
Определения options.php:169
$result
Определения get_property_values.php:14
global $DB
Определения cron_frame.php:29
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$arCodes
Определения options.php:154
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
</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
$val
Определения options.php:1793
$matches
Определения index.php:22
const SONET_ROLES_USER
Определения include.php:31
const SONET_ENTITY_GROUP
Определения include.php:117
const SONET_ROLES_AUTHORIZED
Определения include.php:36
const SONET_ENTITY_USER
Определения include.php:118
const SONET_ROLES_MODERATOR
Определения include.php:30
const SONET_ROLES_OWNER
Определения include.php:29
const SONET_RELATIONS_TYPE_FRIENDS
Определения include.php:41
const SONET_ROLES_ALL
Определения include.php:35
const SONET_RELATIONS_TYPE_FRIENDS2
Определения include.php:40
const SONET_RELATIONS_TYPE_ALL
Определения include.php:38
const SONET_RELATIONS_TYPE_AUTHORIZED
Определения include.php:39
const SONET_RELATIONS_TYPE_NONE
Определения include.php:42
const SITE_ID
Определения sonet_set_content_view.php:12
$arFilter
Определения user_search.php:106
$fields
Определения yandex_run.php:501