Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
department.php
1<?php
3
5
7{
8 const CACHE_TOKEN_TTL = 2592000; // 1 month
9
10 public static function checkModules()
11 {
12 return \Bitrix\Main\Loader::includeModule('intranet') && \Bitrix\Main\Loader::includeModule("iblock") && \Bitrix\Main\Loader::includeModule("socialnetwork");
13 }
14
15 public static function getList()
16 {
17 if (!self::checkModules())
18 return false;
19
20 if (\Bitrix\Im\User::getInstance()->isExtranet())
21 return Array();
22
23 $departmentIblockId = (int)\Bitrix\Main\Config\Option::get('intranet', 'iblock_structure', 0);
24 if ($departmentIblockId <= 0)
25 return Array();
26
27 $cacheId = 'im_structure_'.$departmentIblockId;
28 $cachePath = '/bx/imc/intranet/department/';
29
30 $cache = \Bitrix\Main\Application::getInstance()->getCache();
31 $taggedCache = \Bitrix\Main\Application::getInstance()->getTaggedCache();
32
33 if($cache->initCache(self::CACHE_TOKEN_TTL, $cacheId, $cachePath) && false)
34 {
35 return $cache->getVars();
36 }
37
38 $taggedCache->startTagCache($cachePath);
39
40 $sec = \CIBlockSection::GetList(
41 Array("left_margin"=>"asc", "SORT"=>"ASC"),
42 Array("ACTIVE"=>"Y", "IBLOCK_ID"=>$departmentIblockId),
43 false,
44 Array('ID', 'NAME', 'DEPTH_LEVEL', 'UF_HEAD', 'IBLOCK_SECTION_ID')
45 );
46
47 $departments = Array();
48
49 while($ar = $sec->GetNext(true, false))
50 {
51 $departments[$ar['ID']] = Array(
52 'ID' => (int)$ar['ID'],
53 'NAME' => $ar['NAME'],
54 'FULL_NAME' => $ar['DEPTH_LEVEL'] > 1? $ar['NAME'].' / '.$departments[$ar['IBLOCK_SECTION_ID']]['FULL_NAME']: $ar['NAME'],
55 'MANAGER_USER_ID' => (int)$ar['UF_HEAD'],
56 );
57 }
58
59 $taggedCache->registerTag('iblock_id_'.$departmentIblockId);
60 $taggedCache->endTagCache();
61
62 $cache->startDataCache();
63 $cache->endDataCache($departments);
64
65 return $departments;
66 }
67
68 public static function getGroup($params)
69 {
70 if (!self::checkModules())
71 return false;
72
73 $params = is_array($params)? $params: Array();
74
75 if (!isset($params['CURRENT_USER']) && is_object($GLOBALS['USER']))
76 {
77 $params['CURRENT_USER'] = $GLOBALS['USER']->GetID();
78 }
79
80 $userId = intval($params['CURRENT_USER']);
81 if ($userId <= 0)
82 {
83 return false;
84 }
85
86 $cacheId = 'im_sonet_extranet_v3_'.$userId;
87 $cachePath = '/bx/imc/sonet/extranet'.\Bitrix\Im\Common::getCacheUserPostfix($userId);
88
89 $cache = \Bitrix\Main\Application::getInstance()->getCache();
90 $taggedCache = \Bitrix\Main\Application::getInstance()->getTaggedCache();
91
92 if($cache->initCache(self::CACHE_TOKEN_TTL, $cacheId, $cachePath))
93 {
94 return $cache->getVars();
95 }
96
97 $taggedCache->startTagCache($cachePath);
98
99 $db = \CSocNetUserToGroup::GetList(
100 array(),
101 array(
102 "USER_ID" => $userId,
103 "<=ROLE" => SONET_ROLES_USER,
104 "GROUP_SITE_ID" => \CExtranet::GetExtranetSiteID(),
105 "GROUP_ACTIVE" => "Y",
106 "GROUP_CLOSED" => "N"
107 ),
108 false,
109 false,
110 array("ID", "GROUP_ID", "GROUP_NAME")
111 );
112
113 $groups = Array();
114 $groupIds = Array();
115 while ($row = $db->GetNext(true, false))
116 {
117 $groupIds[] = $row["GROUP_ID"];
118 $groups['SG'.$row['GROUP_ID']] = array(
119 'ID' => 'SG'.$row['GROUP_ID'],
120 'NAME' => Loc::getMessage('IM_INT_SN_GROUP_EXTRANET', Array('#GROUP_NAME#' => $row['GROUP_NAME'])),
121 'USERS' => Array()
122 );
123
124 $taggedCache->registerTag('sonet_group_'.$row['GROUP_ID']);
125 $taggedCache->registerTag('sonet_user2group_G'.$row['GROUP_ID']);
126 }
127
128 if (count($groups) <= 0)
129 {
130 return false;
131 }
132
133 $taggedCache->endTagCache();
134
135 $db = \CSocNetUserToGroup::GetList(
136 array(),
137 array(
138 "GROUP_ID" => $groupIds,
139 "<=ROLE" => SONET_ROLES_USER,
140 "USER_ACTIVE" => "Y",
141 "USER_CONFIRM_CODE" => false
142 ),
143 false,
144 false,
145 array("ID", "USER_ID", "GROUP_ID")
146 );
147 while ($ar = $db->GetNext(true, false))
148 {
149 if($ar["USER_ID"] == $userId)
150 continue;
151
152 $groups['SG'.$row['GROUP_ID']]['USERS'][] = $ar["USER_ID"];
153 }
154
155 $cache->startDataCache();
156 $cache->endDataCache($groups);
157
158 return $groups;
159 }
160}
161
162
163
static getInstance($userId=null)
Definition user.php:44
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
$GLOBALS['____1444769544']
Definition license.php:1