Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
folder.php
1
<?php
2
namespace
Bitrix\Landing\Internals
;
3
4
use
Bitrix\Landing\Manager
;
5
use
Bitrix\Main\Localization\Loc
;
6
use
Bitrix\Main\Entity
;
7
8
Loc::loadMessages
(__FILE__);
9
10
class
FolderTable
extends
Entity\DataManager
11
{
15
const
ACTION_TYPE_ADD
=
'add'
;
16
20
const
ACTION_TYPE_UPDATE
=
'update'
;
21
26
public
static
function
getTableName
()
27
{
28
return
'b_landing_folder'
;
29
}
30
35
public
static
function
getMap
()
36
{
37
return
array(
38
'ID'
=>
new
Entity
\
IntegerField
(
'ID'
, array(
39
'primary'
=>
true
,
40
'autocomplete'
=>
true
,
41
'title'
=>
'ID'
42
)),
43
'PARENT_ID'
=>
new
Entity
\
IntegerField
(
'PARENT_ID'
, array(
44
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_FOLDER_PARENT_ID'
)
45
)),
46
'SITE_ID'
=>
new
Entity
\
IntegerField
(
'SITE_ID'
, array(
47
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_FOLDER_SITE_ID'
),
48
'required'
=>
true
49
)),
50
'INDEX_ID'
=>
new
Entity
\
IntegerField
(
'INDEX_ID'
, array(
51
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_FOLDER_INDEX_ID'
)
52
)),
53
'ACTIVE'
=>
new
Entity
\
StringField
(
'ACTIVE'
, array(
54
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_FOLDER_ACTIVE'
),
55
'default_value'
=>
'N'
56
)),
57
'DELETED'
=>
new
Entity
\
StringField
(
'DELETED'
, array(
58
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_FOLDER_DELETED'
),
59
'default_value'
=>
'N'
60
)),
61
'TITLE'
=>
new
Entity
\
StringField
(
'TITLE'
, array(
62
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_FOLDER_TITLE'
),
63
'required'
=>
true
64
)),
65
'CODE'
=>
new
Entity
\
StringField
(
'CODE'
, array(
66
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_FOLDER_CODE'
),
67
'required'
=>
true
68
)),
69
'CREATED_BY_ID'
=>
new
Entity
\
IntegerField
(
'CREATED_BY_ID'
, array(
70
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_CREATED_BY_ID'
),
71
'required'
=>
true
72
)),
73
'MODIFIED_BY_ID'
=>
new
Entity
\
IntegerField
(
'MODIFIED_BY_ID'
, array(
74
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_MODIFIED_BY_ID'
),
75
'required'
=>
true
76
)),
77
'DATE_CREATE'
=>
new
Entity
\
DatetimeField
(
'DATE_CREATE'
, array(
78
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_DATE_CREATE'
),
79
'required'
=>
true
80
)),
81
'DATE_MODIFY'
=>
new
Entity
\
DatetimeField
(
'DATE_MODIFY'
, array(
82
'title'
=>
Loc::getMessage
(
'LANDING_TABLE_FIELD_DATE_MODIFY'
),
83
'required'
=>
true
84
))
85
);
86
}
87
94
protected
static
function
prepareChange
(
Entity
\
Event
$event,
string
$actionType):
Entity
\
EventResult
95
{
96
$result =
new
Entity\EventResult();
97
$primary = $event->getParameter(
'primary'
);
98
$fields = $event->getParameter(
'fields'
);
99
$modifyFields = [];
100
101
// check that index landing is exists in folder's site
102
/*if ($fields['INDEX_ID'] ?? 0)
103
{
104
if (!array_key_exists('SITE_ID', $fields))
105
{
106
$fields['SITE_ID'] = self::getList([
107
'select' => [
108
'SITE_ID'
109
],
110
'filter' => [
111
'ID' => $primary['ID'] ?? 0
112
]
113
])->fetch()['SITE_ID'] ?? 0;
114
}
115
$res = LandingTable::getList([
116
'select' => [
117
'ID'
118
],
119
'filter' => [
120
'SITE_ID' => $fields['SITE_ID'],
121
'ID' => $fields['INDEX_ID'],
122
'FOLDER_ID' => $primary['ID'] ?? 0
123
]
124
]);
125
if (!$res->fetch())
126
{
127
$result->setErrors([
128
new Entity\EntityError(
129
Loc::getMessage('LANDING_TABLE_ERROR_FOLDER_INDEX_OUT_OF_SITE'),
130
'FOLDER_INDEX_OUT_OF_SITE'
131
)
132
]);
133
return $result;
134
}
135
}*/
136
137
// translit the code from title
138
if
(
139
$actionType == self::ACTION_TYPE_ADD && array_key_exists(
'TITLE'
, $fields) &&
140
(!array_key_exists(
'CODE'
, $fields) || trim($fields[
'CODE'
]) ==
''
)
141
)
142
{
143
$fields[
'CODE'
] = \CUtil::translit(
144
trim($fields[
'TITLE'
]),
145
LANGUAGE_ID,
146
[
147
'replace_space'
=>
''
,
148
'replace_other'
=>
''
149
]
150
);
151
if
(!$fields[
'CODE'
])
152
{
153
$fields[
'CODE'
] =
Manager::getRandomString
(12);
154
}
155
$modifyFields[
'CODE'
] = $fields[
'CODE'
];
156
}
157
158
// for update always we need the code
159
if
(isset($primary[
'ID'
]) && !array_key_exists(
'CODE'
, $fields))
160
{
161
$res = self::getList([
162
'select'
=> [
163
'CODE'
164
],
165
'filter'
=> [
166
'ID'
=> $primary[
'ID'
]
167
]
168
]);
169
if
($row = $res->fetch())
170
{
171
$fields[
'CODE'
] = $row[
'CODE'
];
172
}
173
}
174
175
// check unique folder
176
if
(
177
array_key_exists(
'CODE'
, $fields) &&
178
array_key_exists(
'SITE_ID'
, $fields) &&
179
\
Bitrix
\
Landing
\
Landing::isCheckUniqueAddress
()
180
)
181
{
182
$filter = [
183
'=CODE'
=> $fields[
'CODE'
],
184
'SITE_ID'
=> $fields[
'SITE_ID'
],
185
'PARENT_ID'
=> $fields[
'PARENT_ID'
] ?? null
186
];
187
if
(isset($primary[
'ID'
]))
188
{
189
$filter[
'!ID'
] = $primary[
'ID'
];
190
}
191
$res = self::getList([
192
'select'
=> [
193
'ID'
194
],
195
'filter'
=> $filter
196
]);
197
if
($res->fetch())
198
{
199
$result->setErrors([
200
new
Entity
\
EntityError
(
201
Loc::getMessage
(
'LANDING_TABLE_ERROR_FOLDER_IS_NOT_UNIQUE'
),
202
'FOLDER_IS_NOT_UNIQUE'
203
)
204
]);
205
return
$result;
206
}
207
}
208
209
// check correct folder path
210
if
(array_key_exists(
'CODE'
, $fields))
211
{
212
if
(mb_strpos($fields[
'CODE'
],
'/'
) !==
false
)
213
{
214
$result->setErrors([
215
new
Entity
\
EntityError
(
216
Loc::getMessage
(
'LANDING_TABLE_ERROR_FOLDER_SLASH_IS_NOT_ALLOWED'
),
217
'SLASH_IS_NOT_ALLOWED'
218
)
219
]);
220
return
$result;
221
}
222
}
223
224
$result->modifyFields($modifyFields);
225
226
return
$result;
227
}
228
234
public
static
function
onBeforeAdd
(
Entity
\
Event
$event):
Entity
\
EventResult
235
{
236
return
self::prepareChange
($event, self::ACTION_TYPE_ADD);
237
}
238
244
public
static
function
onBeforeUpdate
(
Entity
\
Event
$event):
Entity
\
EventResult
245
{
246
return
self::prepareChange
($event, self::ACTION_TYPE_UPDATE);
247
}
248
}
Bitrix\Landing\Assets\Manager
Definition
manager.php:20
Bitrix\Landing\Controller\Landing
Definition
landing.php:8
Bitrix\Landing\Internals\FolderTable
Definition
folder.php:11
Bitrix\Landing\Internals\FolderTable\onBeforeUpdate
static onBeforeUpdate(Entity\Event $event)
Definition
folder.php:244
Bitrix\Landing\Internals\FolderTable\getMap
static getMap()
Definition
folder.php:35
Bitrix\Landing\Internals\FolderTable\prepareChange
static prepareChange(Entity\Event $event, string $actionType)
Definition
folder.php:94
Bitrix\Landing\Internals\FolderTable\ACTION_TYPE_UPDATE
const ACTION_TYPE_UPDATE
Definition
folder.php:20
Bitrix\Landing\Internals\FolderTable\onBeforeAdd
static onBeforeAdd(Entity\Event $event)
Definition
folder.php:234
Bitrix\Landing\Internals\FolderTable\ACTION_TYPE_ADD
const ACTION_TYPE_ADD
Definition
folder.php:15
Bitrix\Landing\Internals\FolderTable\getTableName
static getTableName()
Definition
folder.php:26
Bitrix\Landing\Landing\isCheckUniqueAddress
static isCheckUniqueAddress()
Definition
landing.php:505
Bitrix\Landing\Manager\getRandomString
static getRandomString(int $length)
Definition
manager.php:551
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\EntityError
Definition
entityerror.php:12
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Main\ORM\Fields\DatetimeField
Definition
datetimefield.php:22
Bitrix\Main\ORM\Fields\IntegerField
Definition
integerfield.php:20
Bitrix\Main\ORM\Fields\StringField
Definition
stringfield.php:20
Bitrix\Landing\Internals
Definition
base.php:2
Bitrix
modules
landing
lib
internals
folder.php
Создано системой
1.10.0