Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
table.php
1<?php
3
7
8Loc::loadMessages(__FILE__);
9
44class Table extends Entity\DataManager
45{
46 public static function getFilePath()
47 {
48 return __FILE__;
49 }
50
51 public static function getTableName()
52 {
53 return 'b_sale_delivery_es';
54 }
55
56 public static function getMap()
57 {
58 return array(
59 'ID' => array(
60 'data_type' => 'integer',
61 'primary' => true,
62 'autocomplete' => true,
63 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_ID_FIELD'),
64 ),
65 'CODE' => array(
66 'data_type' => 'string',
67 'validation' => array(__CLASS__, 'validateCode'),
68 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_CODE_FIELD'),
69 ),
70 'NAME' => array(
71 'data_type' => 'string',
72 'required' => true,
73 'validation' => array(__CLASS__, 'validateName'),
74 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_NAME_FIELD'),
75 ),
76 'DESCRIPTION' => array(
77 'data_type' => 'string',
78 'validation' => array(__CLASS__, 'validateDescription'),
79 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_DESCRIPTION_FIELD'),
80 ),
81 'CLASS_NAME' => array(
82 'data_type' => 'string',
83 'required' => true,
84 'validation' => array(__CLASS__, 'validateClassName'),
85 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_CLASS_NAME_FIELD'),
86 ),
87 (new ArrayField(
88 'PARAMS',
89 [
90 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_PARAMS_FIELD')
91 ]
92 ))
93 ->configureSerializationPhp()
94 ->configureUnserializeCallback(function ($value) {
95 return unserialize(
96 $value,
97 ['allowed_classes' => false]
98 );
99 }),
100 'RIGHTS' => array(
101 'data_type' => 'string',
102 'required' => true,
103 'validation' => array(__CLASS__, 'validateRights'),
104 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_RIGHTS_FIELD'),
105 ),
106 'DELIVERY_ID' => array(
107 'data_type' => 'integer',
108 'required' => true,
109 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_DELIVERY_ID_FIELD'),
110 ),
111 'INIT_VALUE' => array(
112 'data_type' => 'string',
113 'validation' => array(__CLASS__, 'validateInitial'),
114 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_INITIAL_FIELD'),
115 ),
116 'ACTIVE' => array(
117 'data_type' => 'string',
118 'default_value'=> 'Y',
119 'validation' => array(__CLASS__, 'validateActive'),
120 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_ACTIVE_FIELD'),
121 ),
122 'SORT' => array(
123 'data_type' => 'integer',
124 'title' => Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_SORT_FIELD'),
125 ),
126 'DELIVERY_SERVICE' => array(
127 'data_type' => '\Bitrix\Sale\Delivery\Services\Table',
128 'reference' => array('=this.DELIVERY_ID' => 'ref.ID'),
129 )
130 );
131 }
132 public static function validateCode()
133 {
134 return array(
135 new Entity\Validator\Length(null, 50),
136 );
137 }
138 public static function validateName()
139 {
140 return array(
141 new Entity\Validator\Length(null, 255),
142 );
143 }
144 public static function validateDescription()
145 {
146 return array(
147 new Entity\Validator\Length(null, 255),
148 );
149 }
150 public static function validateClassName()
151 {
152 return array(
153 new Entity\Validator\Length(null, 255),
154 );
155 }
156 public static function validateRights()
157 {
158 return array(
159 new Entity\Validator\Length(null, 3),
160 );
161 }
162 public static function validateInitial()
163 {
164 return array(
165 new Entity\Validator\Length(null, 255),
166 );
167 }
168 public static function validateActive()
169 {
170 return array(
171 new Entity\Validator\Length(null, 1),
172 );
173 }
174
175 public static function onBeforeDelete(Entity\Event $event)
176 {
177 $result = new Entity\EventResult;
178 $primary = $event->getParameter("primary");
179
180 if(intval($primary['ID']) > 0)
181 {
182 $dbRes = \Bitrix\Sale\Internals\ShipmentExtraServiceTable::getList(array(
183 'filter' => array(
184 '=EXTRA_SERVICE_ID' => $primary['ID']
185 )
186 ));
187
188 if($row = $dbRes->fetch())
189 $result->addError(new Entity\EntityError(
190 str_replace('#ID#', $primary['ID'], Loc::getMessage('DELIVERY_EXTRA_SERVICES_ENTITY_ERROR_DELETE'))
191 ));
192 }
193
194 return $result;
195 }
196}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static onBeforeDelete(Entity\Event $event)
Definition table.php:175