Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgroupsubject.php
1<?php
9
11
13{
14 public static function syncSiteId($params = array())
15 {
16 if (!is_array($params))
17 {
18 return false;
19 }
20
21 $subjectId = (isset($params['subjectId']) && intval($params['subjectId']) > 0 ? intval($params['subjectId']) : false);
22 $groupSiteIdList = (isset($params['siteId']) && is_array($params['siteId']) && !empty($params['siteId']) ? $params['siteId'] : array());
23
24 foreach($groupSiteIdList as $key => $siteId)
25 {
26 if (empty($siteId))
27 {
28 unset($groupSiteIdList[$key]);
29 }
30 }
31
32 if (
33 empty($subjectId)
34 || empty($groupSiteIdList)
35 )
36 {
37 return false;
38 }
39
40 $subjectSiteList = array();
41
42 $res = WorkgroupSubjectSiteTable::getList(array(
43 'filter' => array(
44 'SUBJECT_ID' => $subjectId
45 ),
46 'select' => array('SITE_ID')
47 ));
48
49 while ($subjectSite = $res->fetch())
50 {
51 $subjectSiteList[] = $subjectSite['SITE_ID'];
52 }
53
54 $addSubjectSiteList = array_diff($groupSiteIdList, $subjectSiteList);
55 $addSubjectSiteList = array_unique($addSubjectSiteList);
56
57 if (!empty($addSubjectSiteList))
58 {
59 foreach ($addSubjectSiteList as $siteId)
60 {
61 WorkgroupSubjectSiteTable::add(array(
62 'SUBJECT_ID' => $subjectId,
63 'SITE_ID' => $siteId
64 ));
65 }
66 }
67
68 return true;
69 }
70}