Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
block.php
1<?php
3
4use \Bitrix\Main\Localization\Loc;
5use \Bitrix\Main\Entity;
6
7Loc::loadMessages(__FILE__);
8
25class BlockTable extends Entity\DataManager
26{
31 public static function getTableName()
32 {
33 return 'b_landing_block';
34 }
35
40 public static function getMap()
41 {
42 return array(
43 'ID' => new Entity\IntegerField('ID', array(
44 'primary' => true,
45 'autocomplete' => true,
46 'title' => 'ID'
47 )),
48 'PARENT_ID' => new Entity\IntegerField('PARENT_ID', array(
49 'title' => Loc::getMessage('LANDING_TABLE_FIELD_PARENT_ID')
50 )),
51 'LID' => new Entity\IntegerField('LID', array(
52 'title' => Loc::getMessage('LANDING_TABLE_FIELD_LID'),
53 'required' => true
54 )),
55 'LANDING' => new Entity\ReferenceField(
56 'LANDING',
57 '\Bitrix\Landing\Internals\LandingTable',
58 array('=this.LID' => 'ref.ID')
59 ),
60 'CODE' => new Entity\StringField('CODE', array(
61 'title' => Loc::getMessage('LANDING_TABLE_FIELD_CODE'),
62 'required' => true
63 )),
64 'TPL_CODE' => new Entity\StringField('TPL_CODE', array(
65 'title' => Loc::getMessage('LANDING_TABLE_FIELD_TPL_CODE'),
66 )),
67 'XML_ID' => new Entity\StringField('XML_ID', array(
68 'title' => Loc::getMessage('LANDING_TABLE_FIELD_XML_ID')
69 )),
70 'INITIATOR_APP_CODE' => new Entity\StringField('INITIATOR_APP_CODE', array(
71 'title' => Loc::getMessage('LANDING_TABLE_FIELD_INITIATOR_APP_CODE'),
72 'default_value' => ''
73 )),
74 'ANCHOR' => new Entity\StringField('ANCHOR', array(
75 'title' => Loc::getMessage('LANDING_TABLE_FIELD_ANCHOR')
76 )),
77 'MANIFEST_DB' => new Entity\ReferenceField(
78 'MANIFEST_DB',
79 '\Bitrix\Landing\Internals\ManifestTable',
80 array('=this.CODE' => 'ref.CODE')
81 ),
82 'SORT' => new Entity\IntegerField('SORT', array(
83 'title' => Loc::getMessage('LANDING_TABLE_FIELD_SORT')
84 )),
85 'ACTIVE' => new Entity\StringField('ACTIVE', array(
86 'title' => Loc::getMessage('LANDING_TABLE_FIELD_ACTIVE'),
87 'default_value' => 'Y'
88 )),
89 'PUBLIC' => new Entity\StringField('PUBLIC', array(
90 'title' => Loc::getMessage('LANDING_TABLE_FIELD_PUBLIC'),
91 'default_value' => 'Y'
92 )),
93 'DELETED' => new Entity\StringField('DELETED', array(
94 'title' => Loc::getMessage('LANDING_TABLE_FIELD_DELETED'),
95 'default_value' => 'N'
96 )),
97 'DESIGNED' => new Entity\StringField('DESIGNED', array(
98 'title' => Loc::getMessage('LANDING_TABLE_FIELD_DESIGNED'),
99 'default_value' => 'N'
100 )),
101 'ACCESS' => new Entity\StringField('ACCESS', array(
102 'title' => Loc::getMessage('LANDING_TABLE_FIELD_ACCESS'),
103 'default_value' => 'X'
104 )),
105 'SOURCE_PARAMS' => (new \Bitrix\Main\ORM\Fields\ArrayField('SOURCE_PARAMS', array(
106 'title' => Loc::getMessage('LANDING_TABLE_FIELD_SOURCE_PARAMS')
107 )))->configureSerializationPhp(),
108 'CONTENT' => new Entity\StringField('CONTENT', array(
109 'title' => Loc::getMessage('LANDING_TABLE_FIELD_CONTENT'),
110 'required' => true,
111 'save_data_modification' => array('\Bitrix\Main\Text\Emoji', 'getSaveModificator'),
112 'fetch_data_modification' => array('\Bitrix\Main\Text\Emoji', 'getFetchModificator'),
113 )),
114 'SEARCH_CONTENT' => new Entity\StringField('SEARCH_CONTENT', array(
115 'title' => Loc::getMessage('LANDING_TABLE_FIELD_SEARCH_CONTENT')
116 )),
117 'ASSETS' => (new \Bitrix\Main\ORM\Fields\ArrayField('ASSETS', array(
118 'title' => Loc::getMessage('LANDING_TABLE_FIELD_SOURCE_PARAMS')
119 )))->configureSerializationPhp(),
120 'FAVORITE_META' => (new \Bitrix\Main\ORM\Fields\ArrayField('FAVORITE_META', array(
121 'title' => Loc::getMessage('LANDING_TABLE_FIELD_FAVORITE_META')
122 )))->configureSerializationPhp(),
123 'HISTORY_STEP_DESIGNER' => new Entity\IntegerField('HISTORY_STEP_DESIGNER', array(
124 'title' => 'History step for design block',
125 'default_value' => 0,
126 )),
127 'CREATED_BY_ID' => new Entity\IntegerField('CREATED_BY_ID', array(
128 'title' => Loc::getMessage('LANDING_TABLE_FIELD_CREATED_BY_ID'),
129 'required' => true
130 )),
131 'MODIFIED_BY_ID' => new Entity\IntegerField('MODIFIED_BY_ID', array(
132 'title' => Loc::getMessage('LANDING_TABLE_FIELD_MODIFIED_BY_ID'),
133 'required' => true
134 )),
135 'DATE_CREATE' => new Entity\DatetimeField('DATE_CREATE', array(
136 'title' => Loc::getMessage('LANDING_TABLE_FIELD_DATE_CREATE'),
137 'required' => true
138 )),
139 'DATE_MODIFY' => new Entity\DatetimeField('DATE_MODIFY', array(
140 'title' => Loc::getMessage('LANDING_TABLE_FIELD_DATE_MODIFY'),
141 'required' => true
142 ))
143 );
144 }
145
151 protected static function prepareChange(Entity\Event $event): Entity\EventResult
152 {
153 $result = new Entity\EventResult();
154 $primary = $event->getParameter('primary');
155 $fields = $event->getParameter('fields');
156 $modifyFields = [];
157
158 // calculate filter hash
159 if (($primary['ID'] ?? null) && array_key_exists('SOURCE_PARAMS', $fields))
160 {
161 \Bitrix\Landing\Source\FilterEntity::setFilter(
162 $primary['ID'],
163 $fields['SOURCE_PARAMS']
164 );
165 $modifyFields['SOURCE_PARAMS'] = $fields['SOURCE_PARAMS'];
166 }
167
168 // work with content
169 if (array_key_exists('CONTENT', $fields))
170 {
171 $replaced = false;
172 $oldContent = null;
173
174 if ($primary['ID'] ?? null)
175 {
176 $res = self::getList([
177 'select' => [
178 'CONTENT'
179 ],
180 'filter' => [
181 'ID' => $primary['ID']
182 ]
183 ]);
184 $oldContent = $res->fetch()['CONTENT'] ?? null;
185 }
186
187 $fields['CONTENT'] = \Bitrix\Landing\Connector\Disk::sanitizeContent($fields['CONTENT'], $oldContent, $replaced);
188 if ($replaced)
189 {
190 $modifyFields['CONTENT'] = $fields['CONTENT'];
191 }
192 }
193
194 if ($modifyFields)
195 {
196 $result->modifyFields($modifyFields);
197 }
198
199 return $result;
200 }
201
207 public static function onBeforeAdd(Entity\Event $event): Entity\EventResult
208 {
209 return self::prepareChange($event);
210 }
211
217 public static function onBeforeUpdate(Entity\Event $event): Entity\EventResult
218 {
219 return self::prepareChange($event);
220 }
221
227 public static function onAfterDelete(Entity\Event $event): Entity\EventResult
228 {
229 $result = new Entity\EventResult();
230 $primary = $event->getParameter('primary');
231
232 if ($primary)
233 {
234 \Bitrix\Landing\File::deleteFromBlock($primary['ID']);
235 \Bitrix\Landing\Source\FilterEntity::removeBlock($primary['ID']);
236 \Bitrix\Landing\Chat\Binding::unbindingBlock($primary['ID']);
237 }
238
239 return $result;
240 }
241}
static onBeforeUpdate(Entity\Event $event)
Definition block.php:217
static prepareChange(Entity\Event $event)
Definition block.php:151
static onBeforeAdd(Entity\Event $event)
Definition block.php:207
static onAfterDelete(Entity\Event $event)
Definition block.php:227
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29