1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
eventmessage.php
См. документацию.
1<?php
8
12
13IncludeModuleLangFile(__FILE__);
14
19{
21
22 public function CheckFields($arFields, $ID = false)
23 {
25 global $APPLICATION;
26 $this->LAST_ERROR = "";
27 $arMsg = [];
28
29 if (is_set($arFields, "EMAIL_FROM") && mb_strlen($arFields["EMAIL_FROM"]) < 3)
30 {
31 $this->LAST_ERROR .= GetMessage("BAD_EMAIL_FROM") . "<br>";
32 $arMsg[] = ["id" => "EMAIL_FROM", "text" => GetMessage("BAD_EMAIL_FROM")];
33 }
34 if (is_set($arFields, "EMAIL_TO") && mb_strlen($arFields["EMAIL_TO"]) < 3)
35 {
36 $this->LAST_ERROR .= GetMessage("BAD_EMAIL_TO") . "<br>";
37 $arMsg[] = ["id" => "EMAIL_TO", "text" => GetMessage("BAD_EMAIL_TO")];
38 }
39
40 if ($ID === false && !is_set($arFields, "EVENT_NAME"))
41 {
42 $this->LAST_ERROR .= GetMessage("MAIN_BAD_EVENT_NAME_NA") . "<br>";
43 $arMsg[] = ["id" => "EVENT_NAME", "text" => GetMessage("MAIN_BAD_EVENT_NAME_NA")];
44 }
45 if (is_set($arFields, "EVENT_NAME"))
46 {
47 $r = CEventType::GetListEx([], ["EVENT_NAME" => $arFields["EVENT_NAME"]], ["type" => "none"]);
48 if (!$r->Fetch())
49 {
50 $this->LAST_ERROR .= GetMessage("BAD_EVENT_TYPE") . "<br>";
51 $arMsg[] = ["id" => "EVENT_NAME", "text" => GetMessage("BAD_EVENT_TYPE")];
52 }
53 }
54
55 if (
56 ($ID === false && !is_set($arFields, "LID")) ||
57 (is_set($arFields, "LID")
58 && (
59 (is_array($arFields["LID"]) && empty($arFields["LID"]))
60 ||
61 (!is_array($arFields["LID"]) && $arFields["LID"] == '')
62 )
63 )
64 )
65 {
66 $this->LAST_ERROR .= GetMessage("MAIN_BAD_SITE_NA") . "<br>";
67 $arMsg[] = ["id" => "LID", "text" => GetMessage("MAIN_BAD_SITE_NA")];
68 }
69 elseif (is_set($arFields, "LID"))
70 {
71 if (!is_array($arFields["LID"]))
72 {
73 $arFields["LID"] = [$arFields["LID"]];
74 }
75
76 foreach ($arFields["LID"] as $v)
77 {
78 $r = CSite::GetByID($v);
79 if (!$r->Fetch())
80 {
81 $this->LAST_ERROR .= "'" . $v . "' - " . GetMessage("MAIN_EVENT_BAD_SITE") . "<br>";
82 $arMsg[] = ["id" => "LID", "text" => GetMessage("MAIN_EVENT_BAD_SITE")];
83 }
84 }
85 }
86
87 if (!empty($arMsg))
88 {
89 $e = new CAdminException($arMsg);
90 $APPLICATION->ThrowException($e);
91 }
92
93 if ($this->LAST_ERROR <> '')
94 {
95 return false;
96 }
97
98 return true;
99 }
100
102 // New event message template
104 public function Add($arFields)
105 {
106 unset($arFields["ID"]);
107
108 if (!$this->CheckFields($arFields))
109 {
110 return false;
111 }
112
113 if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y")
114 {
115 $arFields["ACTIVE"] = "N";
116 }
117
118 $arLID = [];
119 if (is_set($arFields, "LID"))
120 {
121 if (is_array($arFields["LID"]))
122 {
123 $arLID = $arFields["LID"];
124 }
125 else
126 {
127 $arLID[] = $arFields["LID"];
128 }
129
130 $arFields["LID"] = false;
131 foreach ($arLID as $v)
132 {
133 $arFields["LID"] = $v;
134 }
135 }
136
137 $arATTACHMENT_FILE = [];
138 if (is_set($arFields, "ATTACHMENT_FILE"))
139 {
140 if (is_array($arFields["ATTACHMENT_FILE"]))
141 {
142 $arATTACHMENT_FILE = $arFields["ATTACHMENT_FILE"];
143 }
144 else
145 {
146 $arATTACHMENT_FILE[] = $arFields["ATTACHMENT_FILE"];
147 }
148
149 $arATTACHMENT_FILE_tmp = [];
150 foreach ($arATTACHMENT_FILE as $v)
151 {
152 $v = intval($v);
153 $arATTACHMENT_FILE_tmp[] = $v;
154 }
155 $arATTACHMENT_FILE = $arATTACHMENT_FILE_tmp;
156
157 unset($arFields['ATTACHMENT_FILE']);
158 }
159
160 $arDeleteFields = [
161 'EVENT_MESSAGE_TYPE_ID', 'EVENT_MESSAGE_TYPE_ID',
162 'EVENT_MESSAGE_TYPE_NAME', 'EVENT_MESSAGE_TYPE_EVENT_NAME',
163 'SITE_ID', 'EVENT_TYPE',
164 ];
165 foreach ($arDeleteFields as $deleteField)
166 {
167 if (array_key_exists($deleteField, $arFields))
168 {
169 unset($arFields[$deleteField]);
170 }
171 }
172
173 $ID = false;
174
176
177 if ($result->isSuccess())
178 {
179 $ID = $result->getId();
180
181 if (!empty($arLID))
182 {
183 static::UpdateSites($ID, $arLID);
184 }
185
186 if (!empty($arATTACHMENT_FILE))
187 {
188 foreach ($arATTACHMENT_FILE as $file_id)
189 {
191 'EVENT_MESSAGE_ID' => $ID,
192 'FILE_ID' => $file_id,
193 ]);
194 }
195 }
196 }
197
198 return $ID;
199 }
200
201 public function Update($ID, $arFields)
202 {
203 if (!$this->CheckFields($arFields, $ID))
204 {
205 return false;
206 }
207
208 if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y")
209 {
210 $arFields["ACTIVE"] = "N";
211 }
212
213 $arLID = [];
214 if (is_set($arFields, "LID"))
215 {
216 if (is_array($arFields["LID"]))
217 {
218 $arLID = $arFields["LID"];
219 }
220 else
221 {
222 $arLID[] = $arFields["LID"];
223 }
224
225 $arFields["LID"] = false;
226 foreach ($arLID as $v)
227 {
228 $arFields["LID"] = $v;
229 }
230 }
231
232 $arATTACHMENT_FILE = [];
233 if (is_set($arFields, "ATTACHMENT_FILE"))
234 {
235 if (is_array($arFields["ATTACHMENT_FILE"]))
236 {
237 $arATTACHMENT_FILE = $arFields["ATTACHMENT_FILE"];
238 }
239 else
240 {
241 $arATTACHMENT_FILE[] = $arFields["ATTACHMENT_FILE"];
242 }
243
244 $arATTACHMENT_FILE_tmp = [];
245 foreach ($arATTACHMENT_FILE as $v)
246 {
247 $v = intval($v);
248 $arATTACHMENT_FILE_tmp[] = $v;
249 }
250 $arATTACHMENT_FILE = $arATTACHMENT_FILE_tmp;
251
252 unset($arFields['ATTACHMENT_FILE']);
253 }
254
255 if (array_key_exists('NAME', $arFields))
256 {
257 unset($arFields['NAME']);
258 }
259
260 $ID = intval($ID);
261
263
264 if (!empty($arLID))
265 {
266 static::UpdateSites($ID, $arLID);
267 }
268
269 if (!empty($arATTACHMENT_FILE))
270 {
271 foreach ($arATTACHMENT_FILE as $file_id)
272 {
274 'EVENT_MESSAGE_ID' => $ID,
275 'FILE_ID' => $file_id,
276 ]);
277 }
278 }
279
280 return true;
281 }
282
283 protected static function UpdateSites(int $ID, array $arLID)
284 {
285 Mail\Internal\EventMessageSiteTable::deleteByFilter(['=EVENT_MESSAGE_ID' => $ID]);
286
288 'select' => ['LID'],
289 'filter' => ['=LID' => $arLID],
290 ]);
291 while ($arResultSite = $resultDb->fetch())
292 {
294 'EVENT_MESSAGE_ID' => $ID,
295 'SITE_ID' => $arResultSite['LID'],
296 ]);
297 }
298 }
299
301 // Query
303 public static function GetByID($ID)
304 {
305 return CEventMessage::GetList('', '', ["ID" => $ID]);
306 }
307
308 public static function GetSite($event_message_id)
309 {
310 $event_message_id = intval($event_message_id);
311
313 'select' => ['*', '' => 'SITE.*'],
314 'filter' => ['=EVENT_MESSAGE_ID' => $event_message_id],
315 'runtime' => [
316 'SITE' => [
317 'data_type' => 'Bitrix\Main\Site',
318 'reference' => ['=this.SITE_ID' => 'ref.LID'],
319 ],
320 ],
321 ]);
322
323 return new CDBResult($resultDb);
324 }
325
326 public static function GetLang($event_message_id)
327 {
328 return CEventMessage::GetSite($event_message_id);
329 }
330
331 public static function Delete($ID)
332 {
337 global $APPLICATION;
338 $ID = intval($ID);
339
340 foreach (GetModuleEvents("main", "OnBeforeEventMessageDelete", true) as $arEvent)
341 {
342 if (ExecuteModuleEventEx($arEvent, [$ID]) === false)
343 {
344 $err = GetMessage("MAIN_BEFORE_DEL_ERR1") . ' ' . $arEvent['TO_NAME'];
345 if ($ex = $APPLICATION->GetException())
346 {
347 $err .= ': ' . $ex->GetString();
348 }
349 $APPLICATION->throwException($err);
350 return false;
351 }
352 }
353
354 //check module event for OnDelete
355 foreach (GetModuleEvents("main", "OnEventMessageDelete", true) as $arEvent)
356 {
357 ExecuteModuleEventEx($arEvent, [$ID]);
358 }
359
360 Mail\Internal\EventMessageSiteTable::deleteByFilter(['=EVENT_MESSAGE_ID' => $ID]);
362
363 if ($result->isSuccess())
364 {
366 $res->affectedRowsCount = 1;
367 }
368 else
369 {
370 $res = false;
371 }
372
373 return $res;
374 }
375
376 public static function GetListDataModifier($data)
377 {
378 if (!isset($data['EVENT_MESSAGE_TYPE_ID']) || intval($data['EVENT_MESSAGE_TYPE_ID']) <= 0)
379 {
380 $data['EVENT_TYPE'] = $data['EVENT_NAME'];
381 }
382 else
383 {
384 $data['EVENT_TYPE'] = '[ ' . $data['EVENT_MESSAGE_TYPE_EVENT_NAME'] . ' ] ' . $data['EVENT_MESSAGE_TYPE_NAME'];
385
386 unset($data['EVENT_MESSAGE_TYPE_ID']);
387 unset($data['EVENT_MESSAGE_TYPE_NAME']);
388 unset($data['EVENT_MESSAGE_TYPE_EVENT_NAME']);
389 }
390
391 if (!empty($data['ADDITIONAL_FIELD']) && is_array($data['ADDITIONAL_FIELD']))
392 {
393 foreach ($data['ADDITIONAL_FIELD'] as $index => $aField)
394 {
395 $index++;
396 $oldKeyName = "FIELD{$index}_NAME";
397 $oldKeyValue = "FIELD{$index}_VALUE";
398 if (!array_key_exists($oldKeyName, $data))
399 {
400 continue;
401 }
402
403 if (!empty($data[$oldKeyName]))
404 {
405 continue;
406 }
407
408 $data[$oldKeyName] = $aField['NAME'];
409 $data[$oldKeyValue] = $aField['VALUE'];
410 }
411 }
412
413 return $data;
414 }
415
416 public static function GetList($by = 'id', $order = 'desc', $arFilter = [])
417 {
418 $arSearch = [];
419 $arSqlSearch = [];
420 $bIsLang = false;
421 if (is_array($arFilter))
422 {
423 static $map = [
424 'TYPE_ID' => 'EVENT_NAME',
425 'FROM' => 'EMAIL_FROM',
426 'TO' => 'EMAIL_TO',
427 'BODY' => 'MESSAGE',
428 ];
429
430 foreach ($arFilter as $key => $val)
431 {
432 if (is_array($val))
433 {
434 if (empty($val))
435 {
436 continue;
437 }
438 }
439 else
440 {
441 if ((string)$val == '' || $val === "NOT_REF")
442 {
443 continue;
444 }
445 }
446 $key = strtoupper($key);
447 switch ($key)
448 {
449 case "ID":
450 case "EVENT_NAME":
451 case "TYPE_ID":
452 $operation = (isset($arFilter[$key . "_EXACT_MATCH"]) && $arFilter[$key . "_EXACT_MATCH"] == "N" ? '%' : '=');
453 $field = $map[$key] ?? $key;
454 $arSearch[$operation . $field] = $val;
455 break;
456 case "FROM":
457 case "TO":
458 case "BCC":
459 case "SUBJECT":
460 case "BODY":
461 $operation = (isset($arFilter[$key . "_EXACT_MATCH"]) && $arFilter[$key . "_EXACT_MATCH"] == "Y" ? '=' : '%');
462 $field = $map[$key] ?? $key;
463 $arSearch[$operation . $field] = $val;
464 break;
465 case "TYPE":
466 $operation = (isset($arFilter[$key . "_EXACT_MATCH"]) && $arFilter[$key . "_EXACT_MATCH"] == "Y" ? '=' : '%');
467 $arSearch[] = [
468 'LOGIC' => 'OR',
469 $operation . 'EVENT_NAME' => $val,
470 $operation . 'EVENT_MESSAGE_TYPE.NAME' => $val
471 ];
472 break;
473 case "TIMESTAMP_1":
474 $arSqlSearch[] = "M.TIMESTAMP_X>=TO_DATE('" . FmtDate($val, "D.M.Y") . " 00:00:00','dd.mm.yyyy hh24:mi:ss')";
475 $arSearch['>=TIMESTAMP_X'] = $val . " 00:00:00";
476 break;
477 case "TIMESTAMP_2":
478 $arSqlSearch[] = "M.TIMESTAMP_X<=TO_DATE('" . FmtDate($val, "D.M.Y") . " 23:59:59','dd.mm.yyyy hh24:mi:ss')";
479 $arSearch['<=TIMESTAMP_X'] = $val . " 23:59:59";
480 break;
481 case "LID":
482 case "LANG":
483 case "SITE_ID":
484 $bIsLang = true;
485 $arSearch["=SITE_ID"] = $val;
486 break;
487 case "LANGUAGE_ID":
488 case "ACTIVE":
489 $arSearch['=' . $key] = $val;
490 break;
491 case "BODY_TYPE":
492 $arSearch['=' . $key] = ($val == "text") ? 'text' : 'html';
493 break;
494 }
495 }
496 }
497
498 if ($by == "id")
499 {
500 $strSqlOrder = "ID";
501 }
502 elseif ($by == "active")
503 {
504 $strSqlOrder = "ACTIVE";
505 }
506 elseif ($by == "event_name")
507 {
508 $strSqlOrder = "EVENT_NAME";
509 }
510 elseif ($by == "from")
511 {
512 $strSqlOrder = "EMAIL_FROM";
513 }
514 elseif ($by == "to")
515 {
516 $strSqlOrder = "EMAIL_TO";
517 }
518 elseif ($by == "bcc")
519 {
520 $strSqlOrder = "BCC";
521 }
522 elseif ($by == "body_type")
523 {
524 $strSqlOrder = "BODY_TYPE";
525 }
526 elseif ($by == "subject")
527 {
528 $strSqlOrder = "SUBJECT";
529 }
530 elseif ($by == "language_id")
531 {
532 $strSqlOrder = "LANGUAGE_ID";
533 }
534 else
535 {
536 $strSqlOrder = "ID";
537 }
538
539 if ($order != "asc")
540 {
541 $strSqlOrderBy = "DESC";
542 }
543 else
544 {
545 $strSqlOrderBy = "ASC";
546 }
547
548 $arSelect = [
549 '*',
550 'EVENT_MESSAGE_TYPE_ID' => 'EVENT_MESSAGE_TYPE.ID',
551 'EVENT_MESSAGE_TYPE_NAME' => 'EVENT_MESSAGE_TYPE.NAME',
552 'EVENT_MESSAGE_TYPE_EVENT_NAME' => 'EVENT_MESSAGE_TYPE.EVENT_NAME',
553 ];
554
555 if ($bIsLang)
556 {
557 $arSelect['SITE_ID'] = 'EVENT_MESSAGE_SITE.SITE_ID';
558 }
559 else
560 {
561 $arSelect['SITE_ID'] = 'LID';
562 }
563
565 'select' => $arSelect,
566 'filter' => $arSearch,
567 'order' => [$strSqlOrder => $strSqlOrderBy],
568 'runtime' => [
569 'EVENT_MESSAGE_TYPE' => [
570 'data_type' => 'Bitrix\Main\Mail\Internal\EventType',
571 'reference' => ['=this.EVENT_NAME' => 'ref.EVENT_NAME', '=ref.LID' => new \Bitrix\Main\DB\SqlExpression('?', LANGUAGE_ID)],
572 ],
573 ],
574 ]);
575 $resultDb->addFetchDataModifier(['CEventMessage', 'GetListDataModifier']);
576 $res = new CDBResult($resultDb);
577
578 $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
579 $res->is_filtered = (IsFiltered($strSqlSearch));
580
581 return $res;
582 }
583}
584
586{
587}
588
590{
591 public static function CheckFields($arFields = [], $action = "ADD", $ID = [])
592 {
594 global $APPLICATION;
595
596 $arFilter = [];
597 $aMsg = [];
598 //ID, LID, EVENT_NAME, NAME, DESCRIPTION, SORT
599 if ($action == "ADD")
600 {
601 if (empty($arFields["EVENT_NAME"]))
602 {
603 $aMsg[] = ["id" => "EVENT_NAME_EMPTY", "text" => GetMessage("EVENT_NAME_EMPTY")];
604 }
605
606 if (!is_set($arFields, "LID") && is_set($arFields, "SITE_ID"))
607 {
608 $arFields["LID"] = $arFields["SITE_ID"];
609 }
610 if (is_set($arFields, "LID") && empty($arFields["LID"]))
611 {
612 $aMsg[] = ["id" => "LID_EMPTY", "text" => GetMessage("LID_EMPTY")];
613 }
614
615 if (empty($aMsg))
616 {
617 $db_res = CEventType::GetList(["LID" => $arFields["LID"], "EVENT_NAME" => $arFields["EVENT_NAME"]]);
618 if ($db_res && $db_res->Fetch())
619 {
620 $aMsg[] = ["id" => "EVENT_NAME_EXIST", "text" => str_replace(
621 ["#SITE_ID#", "#EVENT_NAME#"],
622 [$arFields["LID"], $arFields["EVENT_NAME"]],
623 GetMessage("EVENT_NAME_EXIST"))];
624 }
625 }
626 }
627 elseif ($action == "UPDATE")
628 {
629 if (empty($ID))
630 {
631 $aMsg[] = ["id" => "EVENT_ID_EMPTY", "text" => GetMessage("EVENT_ID_EMPTY")];
632 }
633
634 if (isset($arFields["EVENT_TYPE"]) && $arFields["EVENT_TYPE"] == '')
635 {
636 $aMsg[] = ["id" => "EVENT_TYPE_EMPTY", "text" => GetMessage('EVENT_TYPE_EMPTY')];
637 }
638
639 if (empty($aMsg) && is_set($arFields, "EVENT_NAME") && (is_set($arFields, "LID")))
640 {
641 if (is_set($arFields, "EVENT_NAME"))
642 {
643 $arFilter["EVENT_NAME"] = $arFields["EVENT_NAME"];
644 }
645 if (is_set($arFields, "LID"))
646 {
647 $arFilter["LID"] = $arFields["LID"];
648 }
649
650 if (!empty($arFilter) && (count($arFilter) < 2) && is_set($arFilter, "LID"))
651 {
652 unset($arFields["LID"]);
653 }
654 else
655 {
657
658 if ($db_res && ($res = $db_res->Fetch()))
659 {
660 if ((is_set($ID, "EVENT_NAME") && is_set($ID, "LID") &&
661 (($res["EVENT_NAME"] != $ID["EVENT_NAME"]) || ($res["LID"] != $ID["LID"]))) ||
662 (is_set($ID, "ID") && $res["ID"] != $ID["ID"]) ||
663 (is_set($ID, "EVENT_NAME") && ($res["EVENT_NAME"] != $ID["EVENT_NAME"])))
664 {
665 $aMsg[] = ["id" => "EVENT_NAME_EXIST", "text" => str_replace(
666 ["#SITE_ID#", "#EVENT_NAME#"],
667 [$arFields["LID"], $arFields["EVENT_NAME"]],
668 GetMessage("EVENT_NAME_EXIST"))];
669 }
670 }
671 }
672 }
673 }
674 else
675 {
676 $aMsg[] = ["id" => "ACTION_EMPTY", "text" => GetMessage("ACTION_EMPTY")];
677 }
678
679 if (!empty($aMsg))
680 {
681 $e = new CAdminException($aMsg);
682 $APPLICATION->ThrowException($e);
683 return false;
684 }
685 return true;
686 }
687
688 public static function Add($arFields)
689 {
690 if (!is_set($arFields, "LID") && is_set($arFields, "SITE_ID"))
691 {
692 $arFields["LID"] = $arFields["SITE_ID"];
693 }
694
695 if (!isset($arFields["EVENT_TYPE"]))
696 {
697 //compatibility
698 $arFields["EVENT_TYPE"] = EventTypeTable::TYPE_EMAIL;
699 }
700
701 unset($arFields["ID"]);
702
704 {
706
707 return $result->getId();
708 }
709 return false;
710 }
711
712 public static function Update($arID = [], $arFields = [])
713 {
714 $ID = [];
715
716 // update event type by ID, or (LID+EVENT_NAME)
717 if (is_array($arID) && !empty($arID))
718 {
719 foreach ($arID as $key => $val)
720 {
721 if (in_array($key, ["ID", "LID", "EVENT_NAME"]))
722 {
723 $ID[$key] = $val;
724 }
725 }
726 }
727 if (!empty($ID) && CEventType::CheckFields($arFields, "UPDATE", $ID))
728 {
729 unset($arFields["ID"]);
730
731 $affectedRowsCount = 0;
733 'select' => ['ID'],
734 'filter' => $ID,
735 ]);
736 while ($arListId = $listDb->fetch())
737 {
739 $affectedRowsCount += $result->getAffectedRowsCount();
740 }
741
743 $res->affectedRowsCount = $affectedRowsCount;
744
745 return $res;
746 }
747 return false;
748 }
749
750 public static function Delete($arID)
751 {
752 $ID = [];
753 if (!is_array($arID))
754 {
755 $arID = ["EVENT_NAME" => $arID];
756 }
757 foreach ($arID as $k => $v)
758 {
759 if (!in_array(mb_strtoupper($k), ["ID", "LID", "EVENT_NAME", "NAME", "SORT"]))
760 {
761 continue;
762 }
763 $ID[$k] = $v;
764 }
765
766 if (!empty($ID))
767 {
768 $res = null;
769 $affectedRowsCount = 0;
771 'select' => ['ID'],
772 'filter' => $ID,
773 ]);
774 while ($arListId = $listDb->fetch())
775 {
777 if ($result->isSuccess())
778 {
779 $affectedRowsCount++;
780 }
781 else
782 {
783 $res = false;
784 break;
785 }
786 }
787
788 if ($res === null)
789 {
791 $res->affectedRowsCount = $affectedRowsCount;
792 }
793
794 return $res;
795 }
796 return false;
797 }
798
799 public static function GetList($arFilter = [], $arOrder = [])
800 {
801 $arSqlSearch = $arSqlOrder = [];
802
803 foreach ($arFilter as $key => $val)
804 {
805 if ((string)$val == '')
806 {
807 continue;
808 }
809
810 $key = strtoupper($key);
811 switch ($key)
812 {
813 case "EVENT_NAME":
814 case "TYPE_ID":
815 $arSqlSearch["=EVENT_NAME"] = (string)$val;
816 break;
817 case "EVENT_TYPE":
818 $arSqlSearch["=EVENT_TYPE"] = (string)$val;
819 break;
820 case "LID":
821 $arSqlSearch["=LID"] = (string)$val;
822 break;
823 case "ID":
824 $arSqlSearch["=ID"] = (int)$val;
825 break;
826 }
827 }
828
829 if (is_array($arOrder))
830 {
831 static $arFields = ["ID" => 1, "LID" => 1, "EVENT_NAME" => 1, "NAME" => 1, "SORT" => 1];
832 foreach ($arOrder as $by => $ord)
833 {
834 $by = strtoupper($by);
835 $ord = strtoupper($ord);
836 if (array_key_exists($by, $arFields))
837 {
838 $arSqlOrder[$by] = ($ord == "DESC" ? "DESC" : "ASC");
839 }
840 }
841 }
842 if (empty($arSqlOrder))
843 {
844 $arSqlOrder['ID'] = 'ASC';
845 }
846
848 'select' => ['ID', 'LID', 'EVENT_NAME', 'EVENT_TYPE', 'NAME', 'DESCRIPTION', 'SORT'],
849 'filter' => $arSqlSearch,
850 'order' => $arSqlOrder,
851 ]);
852
853 $res = new CDBResult($result);
854
855 return $res;
856 }
857
858 public static function GetListExFetchDataModifier($data)
859 {
860 if (isset($data['ID1']) && !isset($data['ID']))
861 {
862 $data['ID'] = $data['ID1'];
863 unset($data['ID1']);
864 }
865
866 if (isset($data['EVENT_NAME1']) && !isset($data['EVENT_NAME']))
867 {
868 $data['EVENT_NAME'] = $data['EVENT_NAME1'];
869 unset($data['EVENT_NAME1']);
870 }
871
872 return $data;
873 }
874
875 public static function GetListEx($arOrder = [], $arFilter = [], $arParams = [])
876 {
877 global $DB;
878
879 $arSearch = $arSearch1 = $arSearch2 = [];
880
881 $arSqlOrder = [];
882 foreach ($arFilter as $key => $val)
883 {
884 if ((string)$val == '')
885 {
886 continue;
887 }
888 $val = $DB->ForSql($val);
890 $key = mb_strtoupper($key_res["FIELD"]);
891 $strOperation = $key_res["OPERATION"];
892 $strNOperation = $key_res["NOPERATION"];
893
894 switch ($key)
895 {
896 case "EVENT_NAME":
897 case "TYPE_ID":
898 if ($strOperation == "LIKE")
899 {
900 $val = "%" . $val . "%";
901 }
902 $arSearch[] = [$strNOperation . 'EVENT_NAME' => $val];
903 break;
904 case "DESCRIPTION":
905 case "NAME":
906 if ($strOperation == "LIKE")
907 {
908 $val = "%" . $val . "%";
909 }
910 $arSearch1[] = [$strNOperation . 'EVENT_MESSAGE_TYPE.' . $key => $val];
911 $arSearch2[] = [$strNOperation . $key => $val];
912 break;
913 case "LID":
914 $arSearch1[] = [$strNOperation . 'EVENT_MESSAGE_TYPE.' . $key => $val];
915 $arSearch2[] = [$strNOperation . $key => $val];
916 break;
917 case "ID":
918 $val = intval($val);
919 $arSearch1[] = [$strNOperation . 'EVENT_MESSAGE_TYPE.' . $key => $val];
920 $arSearch2[] = [$strNOperation . $key => $val];
921 break;
922 case "MESSAGE_ID":
923 $val = intval($val);
924 $arSearch1[] = [$strNOperation . "ID" => $val];
925 $arSearch2[] = [$strNOperation . 'EVENT_MESSAGE.ID' => $val];
926 break;
927 }
928 }
929
930 if (is_array($arOrder))
931 {
932 foreach ($arOrder as $by => $order)
933 {
934 $by = mb_strtoupper($by);
935 $order = mb_strtoupper($order);
936 $order = ($order <> "DESC" ? "ASC" : "DESC");
937 if ($by == "EVENT_NAME" || $by == "ID")
938 {
939 $arSqlOrder["EVENT_NAME"] = "EVENT_NAME1 " . $order;
940 }
941 }
942 }
943 if (empty($arSqlOrder))
944 {
945 $arSqlOrder["EVENT_NAME"] = "EVENT_NAME1 ASC";
946 }
947 $strSqlOrder = " ORDER BY " . implode(", ", $arSqlOrder);
948
949 $arSearch['!EVENT_NAME'] = null;
950 $arQuerySelect = ['ID1' => 'EVENT_NAME', 'EVENT_NAME1' => 'EVENT_NAME'];
951 $query1 = new Query(Mail\Internal\EventMessageTable::getEntity());
952 $query1->setSelect($arQuerySelect);
953 $query1->setFilter(array_merge($arSearch, $arSearch1));
954 $query1->registerRuntimeField('EVENT_MESSAGE_TYPE', [
955 'data_type' => 'Bitrix\Main\Mail\Internal\EventType',
956 'reference' => ['=this.EVENT_NAME' => 'ref.EVENT_NAME'],
957 ]);
958
959 $query2 = new Query(Mail\Internal\EventTypeTable::getEntity());
960 $query2->setSelect($arQuerySelect);
961 $query2->setFilter(array_merge($arSearch, $arSearch2));
962 $query2->registerRuntimeField('EVENT_MESSAGE', [
963 'data_type' => 'Bitrix\Main\Mail\Internal\EventMessage',
964 'reference' => ['=this.EVENT_NAME' => 'ref.EVENT_NAME'],
965 ]);
966
968 $strSql = $query1->getQuery() . " UNION " . $query2->getQuery() . " " . $strSqlOrder;
969 $db_res = $connection->query($strSql);
970 $db_res->addFetchDataModifier(['CEventType', 'GetListExFetchDataModifier']);
971
973 return $db_res;
974 }
975
977 // selecting type
979 public static function GetByID($ID, $LID)
980 {
982 'filter' => ['=LID' => $LID, '=EVENT_NAME' => $ID],
983 ]);
984
985 return new CDBResult($result);
986 }
987
988 public static function GetFilterOperation($key)
989 {
990 $strNegative = "N";
991 if (str_starts_with($key, "!"))
992 {
993 $key = substr($key, 1);
994 $strNegative = "Y";
995 }
996
997 $strOrNull = "N";
998 if (str_starts_with($key, "+"))
999 {
1000 $key = substr($key, 1);
1001 $strOrNull = "Y";
1002 }
1003
1004 if (str_starts_with($key, ">="))
1005 {
1006 $key = substr($key, 2);
1007 $strOperation = ">=";
1008 $strNOperation = ($strNegative == "Y" ? '<' : $strOperation);
1009 }
1010 elseif (str_starts_with($key, ">"))
1011 {
1012 $key = substr($key, 1);
1013 $strOperation = ">";
1014 $strNOperation = ($strNegative == "Y" ? '<=' : $strOperation);
1015 }
1016 elseif (str_starts_with($key, "<="))
1017 {
1018 $key = substr($key, 2);
1019 $strOperation = "<=";
1020 $strNOperation = ($strNegative == "Y" ? '>' : $strOperation);
1021 }
1022 elseif (str_starts_with($key, "<"))
1023 {
1024 $key = substr($key, 1);
1025 $strOperation = "<";
1026 $strNOperation = ($strNegative == "Y" ? '>=' : $strOperation);
1027 }
1028 elseif (str_starts_with($key, "@"))
1029 {
1030 $key = substr($key, 1);
1031 $strOperation = "IN";
1032 $strNOperation = '';
1033 }
1034 elseif (str_starts_with($key, "~"))
1035 {
1036 $key = substr($key, 1);
1037 $strOperation = "LIKE";
1038 $strNOperation = ($strNegative == "Y" ? '!=%' : '=%');
1039 }
1040 elseif (str_starts_with($key, "%"))
1041 {
1042 $key = substr($key, 1);
1043 $strOperation = "QUERY";
1044 $strNOperation = '';
1045 }
1046 else
1047 {
1048 $strOperation = "=";
1049 $strNOperation = ($strNegative == "Y" ? '!=' : '=');
1050 }
1051
1052 return ["FIELD" => $key, "NEGATIVE" => $strNegative, "OPERATION" => $strOperation, "NOPERATION" => $strNOperation, "OR_NULL" => $strOrNull];
1053 }
1054}
1055
1057{
1059 var $LID;
1061
1062 public function __construct($res, $arParams = [])
1063 {
1064 $language = (defined("LANGUAGE_ID") ? LANGUAGE_ID : 'en');
1065 $site = (defined("SITE_ID") ? SITE_ID : 's1');
1066
1067 $this->type = empty($arParams["type"]) ? "type" : $arParams["type"];
1068 $this->LID = empty($arParams["LID"]) ? $language : $arParams["LID"];
1069 $this->SITE_ID = empty($arParams["SITE_ID"]) ? $site : $arParams["SITE_ID"];
1070
1071 parent::__construct($res);
1072 }
1073
1074 function Fetch()
1075 {
1076 $arr = [];
1077 $arr_lid = [];
1078 $arr_lids = [];
1079
1080 if ($res = parent::Fetch())
1081 {
1082 if ($this->type != "none")
1083 {
1084 $eventType = EventTypeTable::TYPE_EMAIL;
1085 $db_res_ = CEventType::GetList(["EVENT_NAME" => $res["EVENT_NAME"]]);
1086 if ($db_res_ && $res_ = $db_res_->Fetch())
1087 {
1088 do
1089 {
1090 $arr[$res_["ID"]] = $res_;
1091 $arr_lid[] = $res_["LID"];
1092 $arr_lids[$res_["LID"]] = $res_;
1093 $eventType = $res_["EVENT_TYPE"];
1094 }
1095 while ($res_ = $db_res_->Fetch());
1096 }
1097 $res["ID"] = array_keys($arr);
1098 $res["LID"] = $arr_lid;
1099 $res["EVENT_TYPE"] = $eventType;
1100
1101 $res["NAME"] = empty($arr_lids[$this->LID]["NAME"]) ? $arr_lids["en"]["NAME"] : $arr_lids[$this->LID]["NAME"];
1102 $res["SORT"] = empty($arr_lids[$this->LID]["SORT"]) ? $arr_lids["en"]["SORT"] : $arr_lids[$this->LID]["SORT"];
1103 $res["DESCRIPTION"] = empty($arr_lids[$this->LID]["DESCRIPTION"]) ? $arr_lids["en"]["DESCRIPTION"] : $arr_lids[$this->LID]["DESCRIPTION"];
1104 $res["TYPE"] = $arr;
1105 if ($this->type != "type")
1106 {
1107 $arr = [];
1108 $db_res_ = CEventMessage::GetList('', '', ["EVENT_NAME" => $res["EVENT_NAME"]]);
1109 if ($db_res_ && $res_ = $db_res_->Fetch())
1110 {
1111 do
1112 {
1113 $arr[$res_["ID"]] = $res_;
1114 }
1115 while ($res_ = $db_res_->Fetch());
1116 }
1117 $res["TEMPLATES"] = $arr;
1118 }
1119 }
1120 }
1121 return $res;
1122 }
1123}
1124
1126{
1128
1129 public function AffectedRowsCount()
1130 {
1131 if ($this->affectedRowsCount !== false)
1132 {
1134 }
1135 else
1136 {
1137 return parent::AffectedRowsCount();
1138 }
1139 }
1140}
$arParams
Определения access_dialog.php:21
$connection
Определения actionsdefinitions.php:38
$db_res
Определения options_user_settings.php:8
global $APPLICATION
Определения include.php:80
__construct($res, $arParams=[])
Определения eventmessage.php:1062
Fetch()
Определения eventmessage.php:1074
static getConnection($name="")
Определения application.php:638
static getList(array $parameters=array())
Определения datamanager.php:431
static delete($primary)
Определения datamanager.php:1644
static add(array $data)
Определения datamanager.php:877
static update($primary, array $data)
Определения datamanager.php:1256
static GetSite($event_message_id)
Определения eventmessage.php:308
static GetLang($event_message_id)
Определения eventmessage.php:326
CheckFields($arFields, $ID=false)
Определения eventmessage.php:22
static UpdateSites(int $ID, array $arLID)
Определения eventmessage.php:283
static Delete($ID)
Определения eventmessage.php:331
static GetByID($ID)
Определения eventmessage.php:303
static GetListDataModifier($data)
Определения eventmessage.php:376
$LAST_ERROR
Определения eventmessage.php:20
Add($arFields)
Определения eventmessage.php:104
Update($ID, $arFields)
Определения eventmessage.php:201
static GetList($by='id', $order='desc', $arFilter=[])
Определения eventmessage.php:416
Определения dbresult.php:88
Определения eventmessage.php:586
Определения eventmessage.php:590
static GetFilterOperation($key)
Определения eventmessage.php:988
static CheckFields($arFields=[], $action="ADD", $ID=[])
Определения eventmessage.php:591
static Add($arFields)
Определения eventmessage.php:688
static GetByID($ID, $LID)
Определения eventmessage.php:979
static GetList($arFilter=[], $arOrder=[])
Определения eventmessage.php:799
static Update($arID=[], $arFields=[])
Определения eventmessage.php:712
static Delete($arID)
Определения eventmessage.php:750
static GetListEx($arOrder=[], $arFilter=[], $arParams=[])
Определения eventmessage.php:875
static GetListExFetchDataModifier($data)
Определения eventmessage.php:858
$arFields
Определения dblapprove.php:5
$data['IS_AVAILABLE']
Определения .description.php:13
$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
GetFilterSqlSearch($arSqlSearch=array(), $FilterLogic="FILTER_logic")
Определения filter_tools.php:397
IsFiltered($strSqlSearch)
Определения filter_tools.php:337
$result
Определения get_property_values.php:14
if($ajaxMode) $ID
Определения get_user.php:27
global $DB
Определения cron_frame.php:29
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
FmtDate($str_date, $format=false, $site=false, $bSearchInSitesOnly=false)
Определения tools.php:745
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$map
Определения config.php:5
Определения arrayresult.php:2
Определения address.php:8
Определения chain.php:3
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
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
const SITE_ID
Определения sonet_set_content_view.php:12
$k
Определения template_pdf.php:567
$action
Определения file_dialog.php:21
$arFilter
Определения user_search.php:106
$site
Определения yandex_run.php:614