-
Notifications
You must be signed in to change notification settings - Fork 3
/
element.php
352 lines (342 loc) · 11.2 KB
/
element.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
namespace Bitrix\Iblock;
use Bitrix\Main;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
/**
* Class ElementTable
*
* Fields:
* <ul>
* <li> ID int mandatory
* <li> TIMESTAMP_X datetime optional
* <li> MODIFIED_BY int optional
* <li> DATE_CREATE datetime optional
* <li> CREATED_BY int optional
* <li> IBLOCK_ID int mandatory
* <li> IBLOCK_SECTION_ID int optional
* <li> ACTIVE bool optional default 'Y'
* <li> ACTIVE_FROM datetime optional
* <li> ACTIVE_TO datetime optional
* <li> SORT int optional default 500
* <li> NAME string(255) mandatory
* <li> PREVIEW_PICTURE int optional
* <li> PREVIEW_TEXT string optional
* <li> PREVIEW_TEXT_TYPE enum ('text', 'html') optional default 'text'
* <li> DETAIL_PICTURE int optional
* <li> DETAIL_TEXT string optional
* <li> DETAIL_TEXT_TYPE enum ('text', 'html') optional default 'text'
* <li> SEARCHABLE_CONTENT string optional
* <li> WF_STATUS_ID int optional default 1
* <li> WF_PARENT_ELEMENT_ID int optional
* <li> WF_NEW enum ('N', 'Y') optional
* <li> WF_LOCKED_BY int optional
* <li> WF_DATE_LOCK datetime optional
* <li> WF_COMMENTS string optional
* <li> IN_SECTIONS bool optional default 'N'
* <li> XML_ID string(255) optional
* <li> CODE string(255) optional
* <li> TAGS string(255) optional
* <li> TMP_ID string(40) optional
* <li> WF_LAST_HISTORY_ID int optional
* <li> SHOW_COUNTER int optional
* <li> SHOW_COUNTER_START datetime optional
* <li> PREVIEW_PICTURE_FILE reference to {@link \Bitrix\File\FileTable}
* <li> DETAIL_PICTURE_FILE reference to {@link \Bitrix\File\FileTable}
* <li> IBLOCK reference to {@link \Bitrix\Iblock\IblockTable}
* <li> WF_PARENT_ELEMENT reference to {@link \Bitrix\Iblock\IblockElementTable}
* <li> IBLOCK_SECTION reference to {@link \Bitrix\Iblock\IblockSectionTable}
* <li> MODIFIED_BY_USER reference to {@link \Bitrix\User\UserTable}
* <li> CREATED_BY_USER reference to {@link \Bitrix\User\UserTable}
* <li> WF_LOCKED_BY_USER reference to {@link \Bitrix\User\UserTable}
* </ul>
*
* @package Bitrix\Iblock
**/
class ElementTable extends Main\Entity\DataManager
{
const TYPE_TEXT = 'text';
const TYPE_HTML = 'html';
/**
* Returns DB table name for entity.
*
* @return string
*/
public static function getTableName()
{
return 'b_iblock_element';
}
/**
* Returns entity map definition.
*
* @return array
*/
public static function getMap()
{
return array(
'ID' => new Main\Entity\IntegerField('ID', array(
'primary' => true,
'autocomplete' => true,
'title' => Loc::getMessage('ELEMENT_ENTITY_ID_FIELD'),
)),
'TIMESTAMP_X' => new Main\Entity\DatetimeField('TIMESTAMP_X', array(
'default_value' => new Main\Type\DateTime(),
'title' => Loc::getMessage('ELEMENT_ENTITY_TIMESTAMP_X_FIELD'),
)),
'MODIFIED_BY' => new Main\Entity\IntegerField('MODIFIED_BY', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_MODIFIED_BY_FIELD'),
)),
'DATE_CREATE' => new Main\Entity\DatetimeField('DATE_CREATE', array(
'default_value' => new Main\Type\DateTime(),
'title' => Loc::getMessage('ELEMENT_ENTITY_DATE_CREATE_FIELD'),
)),
'CREATED_BY' => new Main\Entity\IntegerField('CREATED_BY', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_CREATED_BY_FIELD'),
)),
'IBLOCK_ID' => new Main\Entity\IntegerField('IBLOCK_ID', array(
'required' => true,
'title' => Loc::getMessage('ELEMENT_ENTITY_IBLOCK_ID_FIELD'),
)),
'IBLOCK_SECTION_ID' => new Main\Entity\IntegerField('IBLOCK_SECTION_ID', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_IBLOCK_SECTION_ID_FIELD'),
)),
'ACTIVE' => new Main\Entity\BooleanField('ACTIVE', array(
'values' => array('N', 'Y'),
'default_value' => 'Y',
'title' => Loc::getMessage('ELEMENT_ENTITY_ACTIVE_FIELD'),
)),
'ACTIVE_FROM' => new Main\Entity\DatetimeField('ACTIVE_FROM', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_ACTIVE_FROM_FIELD'),
)),
'ACTIVE_TO' => new Main\Entity\DatetimeField('ACTIVE_TO', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_ACTIVE_TO_FIELD'),
)),
'SORT' => new Main\Entity\IntegerField('SORT', array(
'default_value' => 500,
'title' => Loc::getMessage('ELEMENT_ENTITY_SORT_FIELD'),
)),
'NAME' => new Main\Entity\StringField('NAME', array(
'required' => true,
'validation' => array(__CLASS__, 'validateName'),
'title' => Loc::getMessage('ELEMENT_ENTITY_NAME_FIELD'),
)),
'PREVIEW_PICTURE' => new Main\Entity\IntegerField('PREVIEW_PICTURE', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_PREVIEW_PICTURE_FIELD'),
)),
'PREVIEW_TEXT' => new Main\Entity\TextField('PREVIEW_TEXT', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_PREVIEW_TEXT_FIELD'),
)),
'PREVIEW_TEXT_TYPE' => new Main\Entity\EnumField('PREVIEW_TEXT_TYPE', array(
'values' => array(self::TYPE_TEXT, self::TYPE_HTML),
'default_value' => self::TYPE_TEXT,
'title' => Loc::getMessage('ELEMENT_ENTITY_PREVIEW_TEXT_TYPE_FIELD'),
)),
'DETAIL_PICTURE' => new Main\Entity\IntegerField('DETAIL_PICTURE', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_DETAIL_PICTURE_FIELD'),
)),
'DETAIL_TEXT' => new Main\Entity\TextField('DETAIL_TEXT', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_DETAIL_TEXT_FIELD'),
)),
'DETAIL_TEXT_TYPE' => new Main\Entity\EnumField('DETAIL_TEXT_TYPE', array(
'values' => array(self::TYPE_TEXT, self::TYPE_HTML),
'default_value' => self::TYPE_TEXT,
'title' => Loc::getMessage('ELEMENT_ENTITY_DETAIL_TEXT_TYPE_FIELD'),
)),
'SEARCHABLE_CONTENT' => new Main\Entity\TextField('SEARCHABLE_CONTENT', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_SEARCHABLE_CONTENT_FIELD'),
)),
'WF_STATUS_ID' => new Main\Entity\IntegerField('WF_STATUS_ID', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_WF_STATUS_ID_FIELD'),
)),
'WF_PARENT_ELEMENT_ID' => new Main\Entity\IntegerField('WF_PARENT_ELEMENT_ID', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_WF_PARENT_ELEMENT_ID_FIELD'),
)),
'WF_NEW' => new Main\Entity\EnumField('WF_NEW', array(
'values' => array('N', 'Y'),
'title' => Loc::getMessage('ELEMENT_ENTITY_WF_NEW_FIELD'),
)),
'WF_LOCKED_BY' => new Main\Entity\IntegerField('WF_LOCKED_BY', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_WF_LOCKED_BY_FIELD'),
)),
'WF_DATE_LOCK' => new Main\Entity\DatetimeField('WF_DATE_LOCK', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_WF_DATE_LOCK_FIELD'),
)),
'WF_COMMENTS' => new Main\Entity\TextField('WF_COMMENTS', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_WF_COMMENTS_FIELD'),
)),
'IN_SECTIONS' => new Main\Entity\BooleanField('IN_SECTIONS', array(
'values' => array('N', 'Y'),
'title' => Loc::getMessage('ELEMENT_ENTITY_IN_SECTIONS_FIELD'),
)),
'XML_ID' => new Main\Entity\StringField('XML_ID', array(
'validation' => array(__CLASS__, 'validateXmlId'),
'title' => Loc::getMessage('ELEMENT_ENTITY_XML_ID_FIELD'),
)),
'CODE' => new Main\Entity\StringField('CODE', array(
'validation' => array(__CLASS__, 'validateCode'),
'title' => Loc::getMessage('ELEMENT_ENTITY_CODE_FIELD'),
)),
'TAGS' => new Main\Entity\StringField('TAGS', array(
'validation' => array(__CLASS__, 'validateTags'),
'title' => Loc::getMessage('ELEMENT_ENTITY_TAGS_FIELD'),
)),
'TMP_ID' => new Main\Entity\StringField('TMP_ID', array(
'validation' => array(__CLASS__, 'validateTmpId'),
'title' => Loc::getMessage('ELEMENT_ENTITY_TMP_ID_FIELD'),
)),
'SHOW_COUNTER' => new Main\Entity\IntegerField('SHOW_COUNTER', array(
'default_value' => 0,
'title' => Loc::getMessage('ELEMENT_ENTITY_SHOW_COUNTER_FIELD'),
)),
'SHOW_COUNTER_START' => new Main\Entity\DatetimeField('SHOW_COUNTER_START', array(
'title' => Loc::getMessage('ELEMENT_ENTITY_SHOW_COUNTER_START_FIELD'),
)),
'PREVIEW_PICTURE_FILE' => new Main\Entity\ReferenceField(
'PREVIEW_PICTURE_FILE',
'Bitrix\File\File',
array('=this.PREVIEW_PICTURE' => 'ref.ID'),
array('join_type' => 'LEFT')
),
'DETAIL_PICTURE_FILE' => new Main\Entity\ReferenceField(
'DETAIL_PICTURE_FILE',
'Bitrix\File\File',
array('=this.DETAIL_PICTURE' => 'ref.ID'),
array('join_type' => 'LEFT')
),
'IBLOCK' => new Main\Entity\ReferenceField(
'IBLOCK',
'Bitrix\Iblock\Iblock',
array('=this.IBLOCK_ID' => 'ref.ID'),
array('join_type' => 'LEFT')
),
'WF_PARENT_ELEMENT' => new Main\Entity\ReferenceField(
'WF_PARENT_ELEMENT',
'Bitrix\Iblock\IblockElement',
array('=this.WF_PARENT_ELEMENT_ID' => 'ref.ID'),
array('join_type' => 'LEFT')
),
'IBLOCK_SECTION' => new Main\Entity\ReferenceField(
'IBLOCK_SECTION',
'Bitrix\Iblock\IblockSection',
array('=this.IBLOCK_SECTION_ID' => 'ref.ID'),
array('join_type' => 'LEFT')
),
'MODIFIED_BY_USER' => new Main\Entity\ReferenceField(
'MODIFIED_BY_USER',
'Bitrix\User\User',
array('=this.MODIFIED_BY' => 'ref.ID'),
array('join_type' => 'LEFT')
),
'CREATED_BY_USER' => new Main\Entity\ReferenceField(
'CREATED_BY_USER',
'Bitrix\User\User',
array('=this.CREATED_BY' => 'ref.ID'),
array('join_type' => 'LEFT')
),
'WF_LOCKED_BY_USER' => new Main\Entity\ReferenceField(
'WF_LOCKED_BY_USER',
'Bitrix\User\User',
array('=this.WF_LOCKED_BY' => 'ref.ID'),
array('join_type' => 'LEFT')
),
);
}
/**
* Returns validators for NAME field.
*
* @return array
*/
public static function validateName()
{
return array(
new Main\Entity\Validator\Length(null, 255),
);
}
/**
* Returns validators for XML_ID field.
*
* @return array
*/
public static function validateXmlId()
{
return array(
new Main\Entity\Validator\Length(null, 255),
);
}
/**
* Returns validators for CODE field.
*
* @return array
*/
public static function validateCode()
{
return array(
new Main\Entity\Validator\Length(null, 255),
);
}
/**
* Returns validators for TAGS field.
*
* @return array
*/
public static function validateTags()
{
return array(
new Main\Entity\Validator\Length(null, 255),
);
}
/**
* Returns validators for TMP_ID field.
*
* @return array
*/
public static function validateTmpId()
{
return array(
new Main\Entity\Validator\Length(null, 40),
);
}
/**
* Add iblock element.
*
* @param array $data Element data.
* @return Main\Entity\AddResult
*/
public static function add(array $data)
{
$result = new Main\Entity\AddResult();
$result->addError(new Main\Entity\EntityError(
Loc::getMessage('ELEMENT_ENTITY_MESS_ADD_BLOCKED')
));
return $result;
}
/**
* Updates iblock element by primary key.
*
* @param mixed $primary Element primary key.
* @param array $data Element data.
* @return Main\Entity\UpdateResult
*/
public static function update($primary, array $data)
{
$result = new Main\Entity\UpdateResult();
$result->addError(new Main\Entity\EntityError(
Loc::getMessage('ELEMENT_ENTITY_MESS_UPDATE_BLOCKED')
));
return $result;
}
/**
* Deletes iblock element by primary key.
*
* @param mixed $primary Element primary key.
* @return Main\Entity\DeleteResult
*/
public static function delete($primary)
{
$result = new Main\Entity\DeleteResult();
$result->addError(new Main\Entity\EntityError(
Loc::getMessage('ELEMENT_ENTITY_MESS_DELETE_BLOCKED')
));
return $result;
}
}