1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
blog_user_group.php
См. документацию.
1<?php
2
4
5$GLOBALS["BLOG_USER_GROUP"] = Array();
6
8{
9 /*************** ADD, UPDATE, DELETE *****************/
10 public static function CheckFields($ACTION, &$arFields, $ID = 0)
11 {
12 if ((is_set($arFields, "NAME") || $ACTION=="ADD") && $arFields["NAME"] == '')
13 {
14 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GUG_EMPTY_NAME"), "EMPTY_NAME");
15 return false;
16 }
17
18 if ((is_set($arFields, "BLOG_ID") || $ACTION=="ADD") && intval($arFields["BLOG_ID"]) <= 0)
19 {
20 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GUG_EMPTY_BLOG_ID"), "EMPTY_BLOG_ID");
21 return false;
22 }
23 elseif (is_set($arFields, "BLOG_ID"))
24 {
26 if (!$arResult)
27 {
28 $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["BLOG_ID"], GetMessage("BLG_GUG_ERROR_NO_BLOG")), "ERROR_NO_BLOG");
29 return false;
30 }
31 }
32
33 return True;
34 }
35
36 public static function Delete($ID)
37 {
38 global $DB;
39
40 $ID = intval($ID);
41 if ($ID == 1 || $ID == 2)
42 return False;
43
44 $arGroup = CBlogUserGroup::GetByID($ID);
45 if ($arGroup)
46 {
48 array(),
49 array("USER_GROUP_ID" => $ID, "BLOG_ID" => $arGroup["BLOG_ID"]),
50 false,
51 false,
52 array("ID")
53 );
54 if ($arResult = $dbResult->Fetch())
55 {
57 return False;
58 }
59
60 $DB->Query("DELETE FROM b_blog_user2user_group WHERE USER_GROUP_ID = ".$ID."", true);
61
62 unset($GLOBALS["BLOG_USER_GROUP"]["BLOG_USER_GROUP_CACHE_".$ID]);
63
64 return $DB->Query("DELETE FROM b_blog_user_group WHERE ID = ".$ID."", true);
65 }
66
67 return True;
68 }
69
70 public static function SetGroupPerms($ID, $blogID, $postID = 0, $permission = BLOG_PERMS_DENY, $permsType = BLOG_PERMS_POST)
71 {
72 global $DB;
73
74 $ID = intval($ID);
75 $blogID = intval($blogID);
76 $postID = intval($postID);
77
78 $arAvailPerms = array_keys($GLOBALS["AR_BLOG_PERMS"]);
79 if (!in_array($permission, $arAvailPerms))
80 $permission = $arAvailPerms[0];
81
82 $permsType = (($permsType == BLOG_PERMS_COMMENT) ? BLOG_PERMS_COMMENT : BLOG_PERMS_POST);
83
84 $bSuccess = True;
85
86 $arUserGroup = CBlogUserGroup::GetByID($ID);
87 if (!$arUserGroup)
88 {
89 $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $ID, GetMessage("BLG_GUG_ERROR_NO_USER_GROUP")), "ERROR_NO_USER_GROUP");
90 $bSuccess = False;
91 }
92
93 if ($bSuccess)
94 {
95 $arBlog = CBlog::GetByID($blogID);
96 if (!$arBlog)
97 {
98 $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $blogID, GetMessage("BLG_GUG_ERROR_NO_BLOG")), "ERROR_NO_BLOG");
99 $bSuccess = False;
100 }
101 }
102
103 if ($bSuccess)
104 {
105 if ($postID > 0)
106 {
107 $arPost = CBlogPost::GetByID($postID);
108 if (!$arPost)
109 {
110 $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $postID, GetMessage("BLG_GUG_ERROR_NO_POST")), "ERROR_NO_POST");
111 $bSuccess = False;
112 }
113 }
114 }
115
116 if ($bSuccess)
117 {
118 $oldGroupPerms = CBlogUserGroup::GetGroupPerms(1, $blogID, 0, BLOG_PERMS_POST);
119
120 $currentPerms = CBlogUserGroup::GetGroupPerms($ID, $blogID, $postID, $permsType);
121 if ($currentPerms)
122 {
123 if ($currentPerms != $permission)
124 {
125 if ($postID > 0)
126 $DB->Query(
127 "UPDATE b_blog_user_group_perms SET ".
128 " PERMS = '".$DB->ForSql($permission)."' ".
129 "WHERE BLOG_ID = ".$blogID." ".
130 " AND POST_ID = ".$postID." ".
131 " AND USER_GROUP_ID = ".$ID."".
132 " AND PERMS_TYPE = '".$DB->ForSql($permsType)."'"
133 );
134 else
135 $DB->Query(
136 "UPDATE b_blog_user_group_perms SET ".
137 " PERMS = '".$DB->ForSql($permission)."' ".
138 "WHERE BLOG_ID = ".$blogID." ".
139 " AND USER_GROUP_ID = ".$ID." ".
140 " AND PERMS_TYPE = '".$DB->ForSql($permsType)."'".
141 " AND POST_ID IS NULL "
142 );
143 }
144 }
145 else
146 {
147 if ($postID > 0)
148 $DB->Query(
149 "INSERT INTO b_blog_user_group_perms (BLOG_ID, USER_GROUP_ID, PERMS_TYPE, POST_ID, PERMS) ".
150 "VALUES (".$blogID.", ".$ID.", '".$DB->ForSql($permsType)."', ".$postID.", '".$DB->ForSql($permission)."') "
151 );
152 else
153 $DB->Query(
154 "INSERT INTO b_blog_user_group_perms (BLOG_ID, USER_GROUP_ID, PERMS_TYPE, POST_ID, PERMS) ".
155 "VALUES (".$blogID.", ".$ID.", '".$DB->ForSql($permsType)."', null, '".$DB->ForSql($permission)."') "
156 );
157 }
158
159 unset($GLOBALS["BLOG_USER_GROUP"]["BLOG_GROUP_PERMS_CACHE_".$blogID."_".$postID."_".$permsType."_".$ID]);
160 unset($GLOBALS["BLOG_USER_GROUP"]["BLOG_USER_PERMS_CACHE_".$blogID."_".$postID."_".$permsType]);
161 }
162
163 if ($bSuccess)
164 {
165 if (CModule::IncludeModule("search"))
166 {
167 $newGroupPerms = CBlogUserGroup::GetGroupPerms(1, $blogID, 0, BLOG_PERMS_POST);
168 if ($oldGroupPerms >= BLOG_PERMS_READ && $newGroupPerms < BLOG_PERMS_READ)
169 {
170 CSearch::DeleteIndex("blog", false, $blogID);
171 }
172 elseif ($oldGroupPerms < BLOG_PERMS_READ && $newGroupPerms >= BLOG_PERMS_READ)
173 {
174 }
175 }
176 }
177
178 return $bSuccess;
179 }
180
181 //*************** SELECT *********************/
182 public static function GetByID($ID)
183 {
184 global $DB;
185
186 $ID = intval($ID);
187
188 if (isset($GLOBALS["BLOG_USER_GROUP"]["BLOG_USER_GROUP_CACHE_".$ID]) && is_array($GLOBALS["BLOG_USER_GROUP"]["BLOG_USER_GROUP_CACHE_".$ID]) && is_set($GLOBALS["BLOG_USER_GROUP"]["BLOG_USER_GROUP_CACHE_".$ID], "ID"))
189 {
190 return $GLOBALS["BLOG_USER_GROUP"]["BLOG_USER_GROUP_CACHE_".$ID];
191 }
192 else
193 {
194 $strSql =
195 "SELECT G.ID, G.BLOG_ID, G.NAME ".
196 "FROM b_blog_user_group G ".
197 "WHERE G.ID = ".$ID."";
198 $dbResult = $DB->Query($strSql);
199 if ($arResult = $dbResult->Fetch())
200 {
201 $GLOBALS["BLOG_USER_GROUP"]["BLOG_USER_GROUP_CACHE_".$ID] = $arResult;
202 return $arResult;
203 }
204 }
205
206 return False;
207 }
208
209 public static function GetGroupPerms($ID, $blogID, $postID = 0, $permsType = BLOG_PERMS_POST)
210 {
211 global $DB;
212
213 $ID = intval($ID);
214 $blogID = intval($blogID);
215 $postID = intval($postID);
216 $permsType = (($permsType == BLOG_PERMS_COMMENT) ? BLOG_PERMS_COMMENT : BLOG_PERMS_POST);
217
218 $varName = "BLOG_GROUP_PERMS_CACHE_".$blogID."_".$postID."_".$permsType."_";
219
220 if (isset($GLOBALS["BLOG_USER_GROUP"][$varName.$ID]) && is_array($GLOBALS["BLOG_USER_GROUP"][$varName.$ID]))
221 {
222 return $GLOBALS["BLOG_USER_GROUP"][$varName.$ID];
223 }
224 else
225 {
226 if ($postID > 0)
227 {
228 $strSql =
229 "SELECT P.PERMS ".
230 "FROM b_blog_user_group_perms P ".
231 "WHERE P.BLOG_ID = ".$blogID." ".
232 " AND P.POST_ID = ".$postID." ".
233 " AND P.USER_GROUP_ID = ".$ID." ".
234 " AND P.PERMS_TYPE = '".$DB->ForSql($permsType)."' ";
235 $dbResult = $DB->Query($strSql);
236 if ($arResult = $dbResult->Fetch())
237 {
238 $GLOBALS["BLOG_USER_GROUP"][$varName.$ID] = $arResult["PERMS"];
239 return $arResult["PERMS"];
240 }
241 }
242
243 $strSql =
244 "SELECT P.PERMS ".
245 "FROM b_blog_user_group_perms P ".
246 "WHERE P.BLOG_ID = ".$blogID." ".
247 " AND P.POST_ID IS NULL ".
248 " AND P.USER_GROUP_ID = ".$ID." ".
249 " AND P.PERMS_TYPE = '".$DB->ForSql($permsType)."' ";
250 $dbResult = $DB->Query($strSql);
251 if ($arResult = $dbResult->Fetch())
252 {
253 $GLOBALS["BLOG_USER_GROUP"][$varName.$ID] = $arResult["PERMS"];
254 return $arResult["PERMS"];
255 }
256 }
257
258 return False;
259 }
260}
const BLOG_PERMS_COMMENT
Определения include.php:43
const BLOG_PERMS_POST
Определения include.php:42
const BLOG_PERMS_DENY
Определения include.php:5
const BLOG_PERMS_READ
Определения include.php:6
$arResult
Определения generate_coupon.php:16
static GetByID($ID)
Определения blog.php:931
static SetGroupPerms($ID, $blogID, $postID=0, $permission=BLOG_PERMS_DENY, $permsType=BLOG_PERMS_POST)
Определения blog_user_group.php:70
static Delete($ID)
Определения blog_user_group.php:36
static GetByID($ID)
Определения blog_user_group.php:182
static GetGroupPerms($ID, $blogID, $postID=0, $permsType=BLOG_PERMS_POST)
Определения blog_user_group.php:209
static CheckFields($ACTION, &$arFields, $ID=0)
Определения blog_user_group.php:10
static Delete($ID)
Определения blog_user_group_perms.php:125
static DeleteIndex($MODULE_ID, $ITEM_ID=false, $PARAM1=false, $PARAM2=false, $SITE_ID=false)
Определения search.php:2922
static GetByID($ID)
Определения blog_post.php:511
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения blog_user_group_perms.php:104
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$GLOBALS["BLOG_USER_GROUP"]
Определения blog_user_group.php:5
if($ajaxMode) $ID
Определения get_user.php:27
global $DB
Определения cron_frame.php:29
$ACTION
Определения csv_new_setup.php:27
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$GLOBALS['_____370096793']
Определения update_client.php:1
$dbResult
Определения updtr957.php:3