Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
user.php
1<?php
9
10use Bitrix\Main;
12
13Loc::loadMessages(__FILE__);
14
15class User
16{
17 static $moduleAdminListCache = array();
18
19 public static function getModuleAdminList($siteIdList)
20 {
21 global $DB;
22
23 $cacheKey = serialize($siteIdList);
24 if (!array_key_exists($cacheKey, self::$moduleAdminListCache))
25 {
26 $cache = new \CPHPCache;
27 $cacheTime = 31536000;
28 $cacheId = 'site'.($siteIdList ? '_'.implode('|', $siteIdList) : '').'new';
29 $cachePath = "/sonet/user_admin/";
30
31 $adminList = $moduleAdminList = array();
32
33 if ($cache->initCache($cacheTime, $cacheId, $cachePath))
34 {
35 $cacheVars = $cache->getVars();
36 $adminList = $cacheVars["ADMIN"];
37 $moduleAdminList = $cacheVars["MODULE_ADMIN"];
38 }
39 else
40 {
41 $cache->startDataCache($cacheTime, $cacheId, $cachePath);
42
43 $connection = Main\HttpApplication::getConnection();
44 $helper = $connection->getSqlHelper();
45
46 $sql = "SELECT
47 UG.USER_ID U_ID,
48 MAX(".$DB->datetimeToTimestampFunction("UG.DATE_ACTIVE_FROM").") UG_DATE_FROM_TS,
49 MAX(".$DB->datetimeToTimestampFunction("UG.DATE_ACTIVE_TO").") UG_DATE_TO_TS
50 FROM
51 b_user_group UG
52 WHERE
53 UG.GROUP_ID = 1
54 GROUP BY
55 UG.USER_ID";
56
57 $result = $connection->query($sql);
58
59 while($ar = $result->fetch())
60 {
61 if(!array_key_exists($ar["U_ID"], $moduleAdminList))
62 {
63 $adminList[$ar["U_ID"]] = array(
64 "USER_ID" => $ar["U_ID"],
65 "DATE_FROM_TS" => $ar["UG_DATE_FROM_TS"],
66 "DATE_TO_TS" => $ar["UG_DATE_TO_TS"]
67 );
68 }
69 }
70
71 if(!$siteIdList)
72 {
73 $sqlSite = "AND MG.SITE_ID IS NULL";
74 }
75 else
76 {
77 $sqlSite = " AND (";
78 foreach($siteIdList as $i => $siteId)
79 {
80 if($i > 0)
81 {
82 $sqlSite .= " OR ";
83 }
84
85 $sqlSite .= "MG.SITE_ID " . ($siteId ? "= '" . $helper->forSQL($siteId) . "'" : "IS NULL");
86 }
87 $sqlSite .= ")";
88 }
89
90 $sql = "SELECT
91 UG.USER_ID U_ID,
92 G.ID G_ID,
93 MAX(".$DB->datetimeToTimestampFunction("UG.DATE_ACTIVE_FROM").") UG_DATE_FROM_TS,
94 MAX(".$DB->datetimeToTimestampFunction("UG.DATE_ACTIVE_TO").") UG_DATE_TO_TS,
95 MAX(MG.G_ACCESS) G_ACCESS
96 FROM
97 b_user_group UG,
98 b_module_group MG,
99 b_group G
100 WHERE
101 G.ID = UG.GROUP_ID
102 AND (
103 G.ID = MG.GROUP_ID
104 AND MG.MODULE_ID = 'socialnetwork'
105 AND G.ACTIVE = 'Y'
106 AND G_ACCESS >= 'W'
107 AND (
108 G.ANONYMOUS <> 'Y'
109 OR G.ANONYMOUS IS NULL
110 ) ".
111 $sqlSite ."
112 )
113 GROUP BY
114 UG.USER_ID, G.ID";
115
116 $result = $connection->query($sql);
117
118 while($ar = $result->fetch())
119 {
120 if(!array_key_exists($ar["U_ID"], $moduleAdminList))
121 {
122 $moduleAdminList[$ar["U_ID"]] = array(
123 "USER_ID" => $ar["U_ID"],
124 "DATE_FROM_TS" => $ar["UG_DATE_FROM_TS"],
125 "DATE_TO_TS" => $ar["UG_DATE_TO_TS"]
126 );
127 }
128 }
129 }
130
131 $cacheData = Array(
132 "ADMIN" => $adminList,
133 "MODULE_ADMIN" => $moduleAdminList
134 );
135
136 $cache->endDataCache($cacheData);
137
138 foreach ($adminList as $key => $arUserData)
139 {
140 if (
141 (
142 !empty($arUserData["DATE_FROM_TS"])
143 && $arUserData["DATE_FROM_TS"] > time()
144 )
145 || (
146 !empty($arUserData["DATE_TO_TS"])
147 && $arUserData["DATE_TO_TS"] < time()
148 )
149 )
150 {
151 unset($adminList[$key]);
152 }
153 }
154
155 foreach ($moduleAdminList as $key => $arUserData)
156 {
157 if (
158 (
159 !empty($arUserData["DATE_FROM_TS"])
160 && $arUserData["DATE_FROM_TS"] > time()
161 )
162 || (
163 !empty($arUserData["DATE_TO_TS"])
164 && $arUserData["DATE_TO_TS"] < time()
165 )
166 || (
167 isset($adminList[$key])
168 && (
169 empty($adminList[$key]["DATE_TO_TS"])
170 || $adminList[$key]["DATE_TO_TS"] > $arUserData["DATE_FROM_TS"]
171 )
172 )
173 )
174 {
175 unset($moduleAdminList[$key]);
176 }
177 }
178
179 self::$moduleAdminListCache[$cacheKey] = $adminList + $moduleAdminList;
180 }
181
182 return self::$moduleAdminListCache[$cacheKey];
183 }
184}
static loadMessages($file)
Definition loc.php:64
static getModuleAdminList($siteIdList)
Definition user.php:19
static $moduleAdminListCache
Definition user.php:17