1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
usertousergroup.php
См. документацию.
1<?php
2
4
6{
7 public static function GetList($arOrder = array(), $arFilter = array())
8 {
9 global $DB;
11 'GROUP_ID' => array(
12 'TABLE_ALIAS' => 'UG',
13 'FIELD_NAME' => 'UG.GROUP_ID',
14 'FIELD_TYPE' => 'int', //int, double, file, enum, int, string, date, datetime
15 'JOIN' => false,
16 ),
17 'USER_ID' => array(
18 'TABLE_ALIAS' => 'UG',
19 'FIELD_NAME' => 'UG.USER_ID',
20 'FIELD_TYPE' => 'int', //int, double, file, enum, int, string, date, datetime
21 'JOIN' => false,
22 ),
23 'CAN_VIEW_GROUP_MESSAGES' => array(
24 'TABLE_ALIAS' => 'UG',
25 'FIELD_NAME' => 'UG.CAN_VIEW_GROUP_MESSAGES',
26 'FIELD_TYPE' => 'string', //int, double, file, enum, int, string, date, datetime
27 'JOIN' => false,
28 ),
29 'CAN_MAIL_GROUP_MESSAGES' => array(
30 'TABLE_ALIAS' => 'UG',
31 'FIELD_NAME' => 'UG.CAN_MAIL_GROUP_MESSAGES',
32 'FIELD_TYPE' => 'string', //int, double, file, enum, int, string, date, datetime
33 'JOIN' => false,
34 ),
35 'CAN_MAIL_UPDATE_GROUP_MESSAGES' => array(
36 'TABLE_ALIAS' => 'UG',
37 'FIELD_NAME' => 'UG.CAN_MAIL_UPDATE_GROUP_MESSAGES',
38 'FIELD_TYPE' => 'string', //int, double, file, enum, int, string, date, datetime
39 'JOIN' => false,
40 ),
41 'GROUP_NAME' => array(
42 'TABLE_ALIAS' => 'G',
43 'FIELD_NAME' => 'G.NAME',
44 'FIELD_TYPE' => 'string', //int, double, file, enum, int, string, date, datetime
45 'JOIN' => false,
46 ),
47 'IS_TEAM_GROUP' => array(
48 'TABLE_ALIAS' => 'G',
49 'FIELD_NAME' => 'G.IS_TEAM_GROUP',
50 'FIELD_TYPE' => 'string', //int, double, file, enum, int, string, date, datetime
51 'JOIN' => false,
52 ),
53
54 'LOGIN' => array(
55 'TABLE_ALIAS' => 'U',
56 'FIELD_NAME' => 'U.LOGIN',
57 'FIELD_TYPE' => 'string', //int, double, file, enum, int, string, date, datetime
58 'JOIN' => false,
59 ),
60 'FIRST_NAME' => array(
61 'TABLE_ALIAS' => 'U',
62 'FIELD_NAME' => 'U.NAME',
63 'FIELD_TYPE' => 'string', //int, double, file, enum, int, string, date, datetime
64 'JOIN' => false,
65 ),
66 'LAST_NAME' => array(
67 'TABLE_ALIAS' => 'U',
68 'FIELD_NAME' => 'U.LAST_NAME',
69 'FIELD_TYPE' => 'string', //int, double, file, enum, int, string, date, datetime
70 'JOIN' => false,
71 ),
72
73 );
74
75 $strOrder = '';
76 if (is_array($arOrder) && count($arOrder) > 0)
77 {
78 foreach ($arOrder as $k => $v)
79 {
80 if (array_key_exists($k, $arFields))
81 {
82 $v = mb_strtoupper($v);
83 if($v != 'DESC')
84 {
85 $v ='ASC';
86 }
87 if ($strOrder <> '')
88 {
89 $strOrder .= ', ';
90 }
91 $strOrder .= $arFields[$k]['FIELD_NAME'] . ' ' . $v;
92 }
93 }
94 }
95
96 $obQueryWhere = new CSQLWhere;
97 $obQueryWhere->SetFields($arFields);
98
99 $where = $obQueryWhere->GetQuery($arFilter);
100
101 $strQuery = 'SELECT ' .
102 'UG.GROUP_ID,
103 UG.USER_ID,
104 UG.CAN_VIEW_GROUP_MESSAGES,
105 UG.CAN_MAIL_GROUP_MESSAGES,
106 UG.CAN_MAIL_UPDATE_GROUP_MESSAGES as UG_CMUGM, '.
107 'G.NAME GROUP_NAME, G.IS_TEAM_GROUP, '.
108 'U.LOGIN, U.NAME FIRST_NAME, U.LAST_NAME ' .
109 'FROM b_ticket_user_ugroup UG ' .
110 'INNER JOIN b_ticket_ugroups G ON (UG.GROUP_ID=G.ID) ' .
111 'INNER JOIN b_user U ON (UG.USER_ID=U.ID) ';
112
113 if ($where <> '')
114 {
115 $strQuery .= ' WHERE ' . $where;
116 }
117 if ($strOrder <> '')
118 {
119 $strQuery .= ' ORDER BY ' . $strOrder;
120 }
121
122 $res = $DB->Query($strQuery);
123 $res->arReplacedAliases = array('UG_CMUGM' => 'CAN_MAIL_UPDATE_GROUP_MESSAGES');
124
125 return $res;
126 }
127
128 public static function Add($arFields)
129 {
130 global $DB;
132 {
133 $arInsert = $DB->PrepareInsert('b_ticket_user_ugroup', $arFields);
134 return $DB->Query('INSERT INTO b_ticket_user_ugroup ('.$arInsert[0].') VALUES ('.$arInsert[1].')');
135 }
136 return false;
137 }
138
139 public static function Update($groupID, $userID, $arFields)
140 {
141 if (CSupportUser2UserGroup::CheckFields($arFields, $groupID, $userID))
142 {
143 global $DB;
144 $groupID = intval($groupID);
145 $userID = intval($userID);
146
147 $strUpdate = $DB->PrepareUpdate('b_ticket_user_ugroup', $arFields);
148 if ($strUpdate <> '')
149 {
150 $strSql = "UPDATE b_ticket_user_ugroup SET $strUpdate WHERE USER_ID=$userID AND GROUP_ID=$groupID";
151 return $DB->Query($strSql);
152 }
153 }
154 return false;
155 }
156
157 public static function CheckFields(&$arFields, $groupID = 0, $userID = 0)
158 {
159 global $APPLICATION, $DB, $USER;
160 $groupID = intval($groupID);
161 $userID = intval($userID);
162 if (!is_array($arFields))
163 {
164 $arFields = array();
165 }
166
167 //if update
168 if ($userID > 0 || $groupID > 0)
169 {
170 if ($userID <= 0)
171 {
172 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_USER_ID_EMPTY'));
173 return false;
174 }
175 if ($groupID <= 0)
176 {
177 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_GROUP_ID_EMPTY'));
178 return false;
179 }
180
181 if (array_key_exists('GROUP_ID', $arFields))
182 {
183 unset($arFields['GROUP_ID']);
184 }
185 if (array_key_exists('USER_ID', $arFields))
186 {
187 unset($arFields['USER_ID']);
188 }
189 }
190
191 //if add
192 if ($userID <= 0 && $groupID <= 0)
193 {
194 $arFields['GROUP_ID'] = array_key_exists('GROUP_ID', $arFields) ? intval($arFields['GROUP_ID']) : 0;
195 $arFields['USER_ID'] = array_key_exists('USER_ID', $arFields) ? intval($arFields['USER_ID']) : 0;
196
197 if ($arFields['USER_ID'] <= 0)
198 {
199 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_USER_ID_EMPTY'));
200 return false;
201 }
202 if ($arFields['GROUP_ID'] <= 0)
203 {
204 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_GROUP_ID_EMPTY'));
205 return false;
206 }
207
208 $rs = $USER->GetByID($arFields['USER_ID']);
209 if (!$rs->Fetch())
210 {
211 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_NO_USER'));
212 return false;
213 }
214 $rs = CSupportUserGroup::GetList(false, array('ID' => $arFields['GROUP_ID']));
215 if(!$arGroup = $rs->Fetch())
216 {
217 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_NO_GROUP'));
218 return false;
219 }
220 if (CTicket::IsAdmin($arFields['USER_ID']) || CTicket::IsSupportTeam($arFields['USER_ID']))
221 {
222 if ($arGroup['IS_TEAM_GROUP'] <> 'Y')
223 {
224 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_USER_NO_CLIENT'));
225 return false;
226 }
227 }
229 {
230 if ($arGroup['IS_TEAM_GROUP'] == 'Y')
231 {
232 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_USER_NO_TEAM'));
233 return false;
234 }
235 }
236 else
237 {
238 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_NO_SUPPORT_USER'));
239 return false;
240 }
241
242 $rs = CSupportUser2UserGroup::GetList(false, array('GROUP_ID' => $arFields['GROUP_ID'], 'USER_ID' => $arFields['USER_ID']));
243 if ($rs->Fetch())
244 {
245 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_USERGROUP_EXISTS'));
246 return false;
247 }
248 }
249
250 if (array_key_exists('CAN_VIEW_GROUP_MESSAGES', $arFields))
251 {
252 $arFields['CAN_VIEW_GROUP_MESSAGES'] = $arFields['CAN_VIEW_GROUP_MESSAGES'] == 'Y' ? 'Y' : 'N';
253 }
254 elseif ($userID <= 0 && $groupID <= 0)
255 {
256 $arFields['CAN_VIEW_GROUP_MESSAGES'] = 'N';
257 }
258
259 if (array_key_exists('CAN_MAIL_GROUP_MESSAGES', $arFields))
260 {
261 $arFields['CAN_MAIL_GROUP_MESSAGES'] = $arFields['CAN_MAIL_GROUP_MESSAGES'] == 'Y' ? 'Y' : 'N';
262 }
263 elseif ($userID <= 0 && $groupID <= 0)
264 {
265 $arFields['CAN_MAIL_GROUP_MESSAGES'] = 'N';
266 }
267
268 return true;
269 }
270
271 public static function Delete($groupID, $userID)
272 {
273 $groupID = intval($groupID);
274 $userID = intval($userID);
275 if ($groupID > 0 && $userID > 0)
276 {
277 global $DB;
278 return $DB->Query("DELETE FROM b_ticket_user_ugroup WHERE USER_ID=$userID AND GROUP_ID=$groupID");
279 }
280 return false;
281 }
282
283 public static function SetGroupUsers($groupID, $arUsers)
284 {
285 global $APPLICATION;
286 $groupID = intval($groupID);
287
288 $ret = array();
289
290 if ($groupID > 0)
291 {
292 global $DB;
293 $DB->Query('DELETE FROM b_ticket_user_ugroup WHERE GROUP_ID=' . $groupID);
294 if (is_array($arUsers) && count($arUsers) > 0)
295 {
296 foreach ($arUsers as $user)
297 {
298 if (is_array($user) && isset($user['USER_ID']) && intval($user['USER_ID']) > 0)
299 {
300 $arr = array(
301 'GROUP_ID' => $groupID,
302 'USER_ID' => $user['USER_ID'],
303 'CAN_VIEW_GROUP_MESSAGES' => $user['CAN_VIEW_GROUP_MESSAGES'] == 'Y' ? 'Y' : 'N',
304 'CAN_MAIL_GROUP_MESSAGES' => $user['CAN_MAIL_GROUP_MESSAGES'] == 'Y' ? 'Y' : 'N',
305 'CAN_MAIL_UPDATE_GROUP_MESSAGES' => $user['CAN_MAIL_UPDATE_GROUP_MESSAGES'] == 'Y' ? 'Y' : 'N'
306 );
307
309 {
310 if ($e = $APPLICATION->GetException())
311 {
312 $ret[] = $e->GetString();
313 }
314 }
315 }
316 }
317 }
318 }
319
320 return $ret;
321 }
322}
global $APPLICATION
Определения include.php:80
SetFields($arFields)
Определения sqlwhere.php:239
static IsSupportTeam($userID=false)
Определения support.php:114
static IsAdmin($userID=false)
Определения support.php:94
static IsSupportClient($userID=false)
Определения support.php:121
Определения sqlwhere.php:1359
static Update($groupID, $userID, $arFields)
Определения usertousergroup.php:139
static CheckFields(&$arFields, $groupID=0, $userID=0)
Определения usertousergroup.php:157
static Add($arFields)
Определения usertousergroup.php:128
static Delete($groupID, $userID)
Определения usertousergroup.php:271
static SetGroupUsers($groupID, $arUsers)
Определения usertousergroup.php:283
static GetList($arOrder=array(), $arFilter=array())
Определения usertousergroup.php:7
static GetList($arOrder=array(), $arFilter=array())
Определения usergroup.php:7
$arFields
Определения dblapprove.php:5
$arr
Определения file_new.php:624
</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
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</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
$rs
Определения action.php:82
$k
Определения template_pdf.php:567
$arFilter
Определения user_search.php:106