Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
letter.php
1<?php
3
5use \Bitrix\Main\Localization\Loc;
10
11Loc::loadMessages(__FILE__);
12
29class LetterTable extends Main\Entity\DataManager
30{
31 public static function getTableName()
32 {
33 return 'b_forum_letter';
34 }
35
36 public static function getMap()
37 {
38 return [
39 (new IntegerField("ID", ["primary" => true, "autocomplete" => true])),
40 (new IntegerField("DICTIONARY_ID", ["required" => true])),
41 (new StringField("LETTER", ["required" => true, "size" => 50])),
42 (new StringField("REPLACEMENT", ["size" => 255]))];
43 }
44
45 public static function checkFields(Result $result, $primary, array $data)
46 {
47 parent::checkFields($result, $primary, $data);
48
49 if ($result->isSuccess())
50 {
51 if (isset($data["LETTER"]) || isset($data["DICTIONARY_ID"]))
52 {
53 $filter = [
54 "DICTIONARY_ID" => isset($data["DICTIONARY_ID"]) ? $data["DICTIONARY_ID"] : null,
55 "LETTER" => isset($data["LETTER"]) ? $data["LETTER"] : null
56 ];
57
58 if ($result instanceof UpdateResult)
59 {
60 if (
61 ($filter["DICTIONARY_ID"] === null || $filter["LETTER"] === null) &&
62 ($letter = self::getById($primary["ID"])->fetch())
63 )
64 {
65 if ($filter["LETTER"] === null)
66 $filter["LETTER"] = $letter["LETTER"];
67 if ($filter["DICTIONARY_ID"] === null)
68 $filter["DICTIONARY_ID"] = $letter["DICTIONARY_ID"];
69 }
70 $filter["!=ID"] = $primary["ID"];
71 }
72 if ($res = self::getList(["select" => ["ID"], "filter" => $filter])->fetch())
73 {
74 $result->addError(new Main\Error(Loc::getMessage("FLT_ALREADY_EXIST"), "doubleLetter"));
75 }
76 }
77 }
78 }
79}
static checkFields(Result $result, $primary, array $data)
Definition letter.php:45
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
isSuccess($internalCall=false)
Definition result.php:52
addError(Error $error)
Definition result.php:50