1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
rubric.php
См. документацию.
1<?php
3
4class CRubric
5{
6 public $LAST_ERROR = '';
7
8 //Get list
9 public static function GetList($aSort=[], $aFilter=[])
10 {
11 global $DB;
12
13 $arFilter = [];
14 foreach ($aFilter as $key => $val)
15 {
16 if ($val == '')
17 {
18 continue;
19 }
20
21 $key = mb_strtoupper($key);
22 switch ($key)
23 {
24 case 'ID':
25 case 'ACTIVE':
26 case 'VISIBLE':
27 case 'LID':
28 case 'AUTO':
29 case 'CODE':
30 $arFilter[] = 'R.' . $key . " = '" . $DB->ForSql($val) . "'";
31 break;
32 case 'NAME':
33 $arFilter[] = "R.NAME like '%" . $DB->ForSql($val) . "%'";
34 break;
35 }
36 }
37
38 $arOrder = [];
39 foreach ($aSort as $key => $val)
40 {
41 $ord = (mb_strtoupper($val) !== 'ASC' ? 'DESC' : 'ASC');
42 $key = mb_strtoupper($key);
43
44 switch ($key)
45 {
46 case 'ID':
47 case 'NAME':
48 case 'SORT':
49 case 'LAST_EXECUTED':
50 case 'VISIBLE':
51 case 'LID':
52 case 'AUTO':
53 case 'CODE':
54 $arOrder[] = 'R.' . $key . ' ' . $ord;
55 break;
56 case 'ACT':
57 $arOrder[] = 'R.ACTIVE ' . $ord;
58 break;
59 }
60 }
61 if (count($arOrder) == 0)
62 {
63 $arOrder[] = 'R.ID DESC';
64 }
65 $sOrder = "\nORDER BY " . implode(', ',$arOrder);
66
67 if (count($arFilter) == 0)
68 {
69 $sFilter = '';
70 }
71 else
72 {
73 $sFilter = "\nWHERE " . implode("\nAND ", $arFilter);
74 }
75
76 $strSql = '
77 SELECT
78 R.ID
79 ,R.NAME
80 ,R.CODE
81 ,R.SORT
82 ,R.LID
83 ,R.ACTIVE
84 ,R.DESCRIPTION
85 ,R.AUTO
86 ,R.VISIBLE
87 ,' . $DB->DateToCharFunction('R.LAST_EXECUTED', 'FULL') . ' AS LAST_EXECUTED
88 ,R.FROM_FIELD
89 ,R.DAYS_OF_MONTH
90 ,R.DAYS_OF_WEEK
91 ,R.TIMES_OF_DAY
92 ,R.TEMPLATE
93 FROM
94 b_list_rubric R
95 ' . $sFilter . $sOrder;
96
97 return $DB->Query($strSql);
98 }
99
100 //Get by ID
101 public static function GetByID($ID)
102 {
103 global $DB;
104 $ID = intval($ID);
105
106 $strSql = '
107 SELECT
108 R.*
109 ,' . $DB->DateToCharFunction('R.LAST_EXECUTED', 'FULL') . ' AS LAST_EXECUTED
110 FROM b_list_rubric R
111 WHERE R.ID = ' . $ID . '
112 ';
113
114 return $DB->Query($strSql);
115 }
116
117 //Count of subscribers
118 public static function GetSubscriptionCount($ID)
119 {
120 global $DB;
121 $ID = intval($ID);
122
123 $strSql = "
124 SELECT COUNT('x') AS CNT
125 FROM b_subscription_rubric SR
126 WHERE SR.LIST_RUBRIC_ID = " . $ID . '
127 ';
128
129 $res = $DB->Query($strSql);
130 if ($res_arr = $res->Fetch())
131 {
132 return intval($res_arr['CNT']);
133 }
134 else
135 {
136 return 0;
137 }
138 }
139
140 // delete
141 public static function Delete($ID)
142 {
143 global $DB;
144 $ID = intval($ID);
145
146 $DB->StartTransaction();
147
148 $res = $DB->Query('DELETE FROM b_subscription_rubric WHERE LIST_RUBRIC_ID=' . $ID);
149 if ($res)
150 {
151 $res = $DB->Query('DELETE FROM b_posting_rubric WHERE LIST_RUBRIC_ID=' . $ID);
152 }
153 if ($res)
154 {
155 $res = $DB->Query('DELETE FROM b_list_rubric WHERE ID=' . $ID);
156 }
157
158 if ($res)
159 {
160 $DB->Commit();
161 }
162 else
163 {
164 $DB->Rollback();
165 }
166
167 return $res;
168 }
169
170 public static function OnBeforeLangDelete($lang)
171 {
172 global $DB, $APPLICATION;
173 $rs = $DB->Query("SELECT count(*) C FROM b_list_rubric WHERE LID='" . $DB->ForSql($lang, 2) . "'");
174 $ar = $rs->Fetch();
175 if ($ar['C'] > 0)
176 {
177 $APPLICATION->ThrowException(GetMessage('class_rub_err_exists', ['#COUNT#' => $ar['C']]));
178 return false;
179 }
180 else
181 {
182 return true;
183 }
184 }
185
186 //check fields before writing
187 public function CheckFields($arFields)
188 {
189 global $DB;
190 $this->LAST_ERROR = '';
191 $aMsg = [];
192
193 if ($arFields['NAME'] == '')
194 {
195 $aMsg[] = ['id' => 'NAME', 'text' => GetMessage('class_rub_err_name')];
196 }
197 if ($arFields['LID'] <> '')
198 {
199 $r = CLang::GetByID($arFields['LID']);
200 if (!$r->Fetch())
201 {
202 $aMsg[] = ['id' => 'LID', 'text' => GetMessage('class_rub_err_lang')];
203 }
204 }
205 else
206 {
207 $aMsg[] = ['id' => 'LID', 'text' => GetMessage('class_rub_err_lang2')];
208 }
209 if ($arFields['DAYS_OF_MONTH'] <> '')
210 {
211 $arDoM = explode(',', $arFields['DAYS_OF_MONTH']);
212 $arFound = [];
213 foreach ($arDoM as $strDoM)
214 {
215 if (preg_match('/^(\d{1,2})$/', trim($strDoM), $arFound))
216 {
217 if (intval($arFound[1]) < 1 || intval($arFound[1]) > 31)
218 {
219 $aMsg[] = ['id' => 'DAYS_OF_MONTH', 'text' => GetMessage('class_rub_err_dom')];
220 break;
221 }
222 }
223 elseif (preg_match('/^(\d{1,2})-(\d{1,2})$/', trim($strDoM), $arFound))
224 {
225 if (intval($arFound[1]) < 1 || intval($arFound[1]) > 31 || intval($arFound[2]) < 1 || intval($arFound[2]) > 31 || intval($arFound[1]) >= intval($arFound[2]))
226 {
227 $aMsg[] = ['id' => 'DAYS_OF_MONTH', 'text' => GetMessage('class_rub_err_dom')];
228 break;
229 }
230 }
231 else
232 {
233 $aMsg[] = ['id' => 'DAYS_OF_MONTH', 'text' => GetMessage('class_rub_err_dom2')];
234 break;
235 }
236 }
237 }
238 if ($arFields['DAYS_OF_WEEK'] <> '')
239 {
240 $arDoW = explode(',', $arFields['DAYS_OF_WEEK']);
241 $arFound = [];
242 foreach ($arDoW as $strDoW)
243 {
244 if (preg_match('/^(\d)$/', trim($strDoW), $arFound))
245 {
246 if (intval($arFound[1]) < 1 || intval($arFound[1]) > 7)
247 {
248 $aMsg[] = ['id' => 'DAYS_OF_WEEK', 'text' => GetMessage('class_rub_err_dow')];
249 break;
250 }
251 }
252 else
253 {
254 $aMsg[] = ['id' => 'DAYS_OF_WEEK', 'text' => GetMessage('class_rub_err_dow2')];
255 break;
256 }
257 }
258 }
259 if ($arFields['TIMES_OF_DAY'] <> '')
260 {
261 $arToD = explode(',', $arFields['TIMES_OF_DAY']);
262 $arFound = [];
263 foreach ($arToD as $strToD)
264 {
265 if (preg_match('/^(\d{1,2}):(\d{1,2})$/', trim($strToD), $arFound))
266 {
267 if (intval($arFound[1]) > 23 || intval($arFound[2]) > 59)
268 {
269 $aMsg[] = ['id' => 'TIMES_OF_DAY', 'text' => GetMessage('class_rub_err_tod')];
270 break;
271 }
272 }
273 else
274 {
275 $aMsg[] = ['id' => 'TIMES_OF_DAY', 'text' => GetMessage('class_rub_err_tod2')];
276 break;
277 }
278 }
279 }
280 if ($arFields['TEMPLATE'] <> '' && !CPostingTemplate::IsExists($arFields['TEMPLATE']))
281 {
282 $aMsg[] = ['id' => 'TEMPLATE', 'text' => GetMessage('class_rub_err_wrong_templ')];
283 }
284 if ($arFields['AUTO'] == 'Y')
285 {
286 if ((mb_strlen($arFields['FROM_FIELD']) < 3) || !check_email($arFields['FROM_FIELD']))
287 {
288 $aMsg[] = ['id' => 'FROM_FIELD', 'text' => GetMessage('class_rub_err_email')];
289 }
290 if (mb_strlen($arFields['DAYS_OF_MONTH']) + mb_strlen($arFields['DAYS_OF_WEEK']) <= 0)
291 {
292 $aMsg[] = ['id' => 'DAYS_OF_MONTH', 'text' => GetMessage('class_rub_err_days_missing')];
293 }
294 if ($arFields['TIMES_OF_DAY'] == '')
295 {
296 $aMsg[] = ['id' => 'TIMES_OF_DAY', 'text' => GetMessage('class_rub_err_times_missing')];
297 }
298 if ($arFields['TEMPLATE'] == '')
299 {
300 $aMsg[] = ['id' => 'TEMPLATE', 'text' => GetMessage('class_rub_err_templ_missing')];
301 }
302 if (is_set($arFields, 'FROM_FIELD') && $arFields['FROM_FIELD'] == '')
303 {
304 $aMsg[] = ['id' => 'FROM_FIELD', 'text' => GetMessage('class_rub_err_from')];
305 }
306 if ($arFields['LAST_EXECUTED'] == '')
307 {
308 $aMsg[] = ['id' => 'LAST_EXECUTED', 'text' => GetMessage('class_rub_err_le_missing')];
309 }
310 elseif (is_set($arFields, 'LAST_EXECUTED') && $arFields['LAST_EXECUTED'] !== false && $DB->IsDate($arFields['LAST_EXECUTED'], false, false, 'FULL') !== true)
311 {
312 $aMsg[] = ['id' => 'LAST_EXECUTED', 'text' => GetMessage('class_rub_err_le_wrong')];
313 }
314 }
315
316 if (!empty($aMsg))
317 {
318 $e = new CAdminException($aMsg);
319 $GLOBALS['APPLICATION']->ThrowException($e);
320 $this->LAST_ERROR = $e->GetString();
321 return false;
322 }
323 return true;
324 }
325
326 //add
327 public function Add($arFields)
328 {
329 global $DB;
330
331 if (!$this->CheckFields($arFields))
332 {
333 return false;
334 }
335
336 $ID = $DB->Add('b_list_rubric', $arFields);
337
338 if ($ID > 0 && $arFields['ACTIVE'] == 'Y' && $arFields['AUTO'] == 'Y' && COption::GetOptionString('subscribe', 'subscribe_template_method') !== 'cron')
339 {
340 CAgent::AddAgent('CPostingTemplate::Execute();', 'subscribe', 'N', COption::GetOptionString('subscribe', 'subscribe_template_interval'));
341 }
342 return $ID;
343 }
344
345 //update
346 public function Update($ID, $arFields)
347 {
348 global $DB;
349 $ID = intval($ID);
350
351 if (!$this->CheckFields($arFields))
352 {
353 return false;
354 }
355
356 $strUpdate = $DB->PrepareUpdate('b_list_rubric', $arFields);
357 if ($strUpdate != '')
358 {
359 $strSql = 'UPDATE b_list_rubric SET ' . $strUpdate . ' WHERE ID=' . $ID;
360 $DB->Query($strSql);
361 if ($ID > 0 && $arFields['ACTIVE'] == 'Y' && $arFields['AUTO'] == 'Y' && COption::GetOptionString('subscribe', 'subscribe_template_method') !== 'cron')
362 {
363 CAgent::AddAgent('CPostingTemplate::Execute();', 'subscribe', 'N', COption::GetOptionString('subscribe', 'subscribe_template_interval'));
364 }
365 }
366 return true;
367 }
368}
global $APPLICATION
Определения include.php:80
static IsExists($path='')
Определения template.php:52
Определения rubric.php:5
static GetSubscriptionCount($ID)
Определения rubric.php:118
static Delete($ID)
Определения rubric.php:141
CheckFields($arFields)
Определения rubric.php:187
static GetByID($ID)
Определения rubric.php:101
$LAST_ERROR
Определения rubric.php:6
static OnBeforeLangDelete($lang)
Определения rubric.php:170
static GetList($aSort=[], $aFilter=[])
Определения rubric.php:9
Add($arFields)
Определения rubric.php:327
Update($ID, $arFields)
Определения rubric.php:346
$arFields
Определения dblapprove.php:5
$res
Определения filter_act.php:7
if($ajaxMode) $ID
Определения get_user.php:27
global $DB
Определения cron_frame.php:29
if(!defined('SITE_ID')) $lang
Определения include.php:91
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
check_email($email, $strict=false, $domainCheck=false)
Определения tools.php:4571
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
</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
$val
Определения options.php:1793
$rs
Определения action.php:82
$GLOBALS['_____370096793']
Определения update_client.php:1
$arFilter
Определения user_search.php:106