1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
base.php
См. документацию.
1
<?php
2
3
4
namespace
Bitrix\Rest\Integration\Controller
;
5
6
use
Bitrix\Main\Engine\Controller
;
7
use
Bitrix\Main\Engine
;
8
use
Bitrix\Main\Engine\Action
;
9
use
Bitrix\Main\Engine\ActionFilter\ClosureWrapper
;
10
use
Bitrix\Main\Error
;
11
use
Bitrix\Main\NotImplementedException
;
12
use
Bitrix\Main\Result
;
13
use
Bitrix\Main\SystemException
;
14
use
Bitrix\Main\UI\PageNavigation
;
15
use
Bitrix\Rest\Integration\Externalizer
;
16
use
Bitrix\Rest\Integration\Internalizer
;
17
use
Bitrix\Rest\Integration\ModificationFieldsBase
;
18
use
Bitrix\Rest\Integration\ViewManager
;
19
20
class
Base
extends
Controller
21
{
22
protected
$viewManager
;
23
29
protected
function
create
($actionName)
30
{
31
$action
= parent::create($actionName);
32
33
$this->viewManager = $this->
createViewManager
(
$action
);
34
35
return
$action
;
36
}
37
42
protected
function
createViewManager
(
Action
$action
)
43
{
44
throw
new
NotImplementedException
(
'The method createViewManager is not implemented.'
);
45
}
46
47
51
public
function
getViewManager
()
52
{
53
return
$this->viewManager
;
54
}
55
62
protected
function
processBeforeAction
(
Engine
\
Action
$action
)
63
{
64
$r = $this->checkPermission(
$action
->getName(),
$action
->getArguments());
65
66
if
($r->isSuccess())
67
{
68
$internalizer =
new
Internalizer
(
69
$this->
getViewManager
()
70
);
71
72
$r = $internalizer->process();
73
74
if
($r->isSuccess())
75
{
76
$action
->setArguments($r->getData()[
'data'
]);
77
return
parent::processBeforeAction(
$action
);
78
}
79
else
80
{
81
$this->
addErrors
($r->getErrors());
82
return
null
;
83
}
84
}
85
else
86
{
87
$this->
addErrors
($r->getErrors());
88
return
null
;
89
}
90
}
91
92
protected
function
processAfterAction
(
Engine
\
Action
$action
,
$result
)
93
{
94
$externalizer =
null
;
95
if
($this->errorCollection->count()==0)
96
{
97
if
(
$result
instanceof
Engine
\
Response
\DataType\
Page
|| is_array(
$result
))
98
{
99
$data
=
$result
instanceof
Engine\Response\DataType\Page
?
100
$result
->toArray():
$result
;
101
102
$externalizer =
new
Externalizer
(
103
$this->
getViewManager
(),
104
$data
105
);
106
}
107
108
if
($externalizer instanceof
ModificationFieldsBase
)
109
{
110
if
($this->
getScope
() ==
Engine
\Controller::SCOPE_REST)
111
{
112
return
$result
instanceof
Engine\Response\DataType\Page
?
113
$externalizer->getPage(
$result
):$externalizer;
114
}
115
else
if
($this->
getScope
() ==
Engine
\Controller::SCOPE_AJAX)
116
{
117
return
$externalizer;
118
}
119
}
120
}
121
122
return
parent::processAfterAction(
$action
,
$result
);
123
}
124
131
private
function
checkPermission(
$name
, $arguments=[])
132
{
133
if
(
$name
==
'add'
)
134
{
135
$r = $this->
checkCreatePermissionEntity
();
136
}
137
elseif
(
$name
==
'update'
)
138
{
139
$r = $this->
checkUpdatePermissionEntity
();
140
}
141
elseif
(
$name
==
'list'
)
142
{
143
$r = $this->
checkReadPermissionEntity
();
144
}
145
elseif
(
$name
==
'getfields'
)
146
{
147
$r = $this->
checkGetFieldsPermissionEntity
();
148
}
149
elseif
(
$name
==
'get'
)
150
{
151
$r = $this->
checkReadPermissionEntity
();
152
}
153
elseif
(
$name
==
'delete'
)
154
{
155
$r = $this->
checkDeletePermissionEntity
();
156
}
157
else
158
{
159
$r = $this->
checkPermissionEntity
(
$name
, $arguments);
160
}
161
162
return
$r;
163
}
164
168
protected
function
checkGetFieldsPermissionEntity
()
169
{
170
return
$this->
checkReadPermissionEntity
();
171
}
172
176
protected
function
checkReadPermissionEntity
()
177
{
178
throw
new
NotImplementedException
(
'Check read permission. The method checkReadPermissionEntity is not implemented.'
);
179
}
180
185
protected
function
checkModifyPermissionEntity
()
186
{
187
throw
new
NotImplementedException
(
'Check modify permission. The method checkModifyPermissionEntity is not implemented.'
);
188
}
189
194
protected
function
checkCreatePermissionEntity
()
195
{
196
return
$this->
checkModifyPermissionEntity
();
197
}
198
203
protected
function
checkUpdatePermissionEntity
()
204
{
205
return
$this->
checkModifyPermissionEntity
();
206
}
207
212
protected
function
checkDeletePermissionEntity
()
213
{
214
return
$this->
checkModifyPermissionEntity
();
215
}
216
223
protected
function
checkPermissionEntity
(
$name
, $arguments=[])
224
{
225
throw
new
NotImplementedException
(
'Check permission entity. The method '
.
$name
.
' is not implemented.'
);
226
}
227
232
protected
function
getEntityTable
()
233
{
234
throw
new
NotImplementedException
(
'The method getEntityTable is not implemented.'
);
235
}
236
248
protected
function
getList
(
array
$select
,
array
$filter
,
array
$order
,
PageNavigation
$pageNavigation =
null
):
array
249
{
250
$entityTable = $this->
getEntityTable
();
251
252
$select = empty(
$select
) ? [
'*'
] :
$select
;
253
$order
= empty(
$order
) ? [
'ID'
=>
'ASC'
] :
$order
;
254
$params
= [
255
'select'
=>
$select
,
256
'filter'
=>
$filter
,
257
'order'
=>
$order
,
258
];
259
if
($pageNavigation)
260
{
261
$params
[
'offset'
] = $pageNavigation->getOffset();
262
$params
[
'limit'
] = $pageNavigation->getLimit();
263
}
264
265
return
$entityTable::getList(
$params
)->fetchAll();
266
}
267
275
protected
function
count
(
$filter
)
276
{
277
return
function
() use (
$filter
)
278
{
279
$entityTable = $this->
getEntityTable
();
280
return
$entityTable::getCount([
$filter
]);
281
};
282
}
283
292
protected
function
get
($id)
293
{
294
$entityTable = $this->
getEntityTable
();
295
296
return
$entityTable::getById($id)->fetch();
297
}
298
304
public
function
add
(
array
$fields
)
305
{
306
$entityTable = $this->
getEntityTable
();
307
return
$entityTable::add(
$fields
);
308
}
309
319
protected
function
update($id,
array
$fields
)
320
{
321
$entityTable = $this->
getEntityTable
();
322
324
$r = $this->
exists
($id);
325
if
($r->isSuccess())
326
{
327
return
$entityTable::update($id,
$fields
);
328
}
329
else
330
{
331
$this->
addErrors
($r->getErrors());
332
return
null
;
333
}
334
}
335
344
protected
function
delete
($id)
345
{
346
$entityTable = $this->
getEntityTable
();
347
348
$r = $this->
exists
($id);
349
if
($r->isSuccess())
350
{
351
return
$entityTable::delete($id);
352
}
353
else
354
{
355
$this->
addErrors
($r->getErrors());
356
return
null
;
357
}
358
}
359
368
protected
function
exists
($id)
369
{
370
$r = new \Bitrix\Main\Result();
371
if
(isset($this->
get
($id)[
'ID'
]) ==
false
)
372
$r->addError(
new
Error
(
'Entity is not exists'
));
373
374
return
$r;
375
}
376
385
protected
function
existsByFilter
(
$filter
)
386
{
387
$result
=
new
Result
();
388
$entityData = $this->
getEntityTable
()::
getList
([
'filter'
=>
$filter
,
'limit'
=> 1])->fetch();
389
390
if
(!$entityData)
391
{
392
$result
->addError(
new
Error
(
'Entity is not exists'
));
393
}
394
395
return
$result
;
396
}
397
}
Bitrix\Main\Engine\ActionFilter\ClosureWrapper
Определения
closurewrapper.php:13
Bitrix\Main\Engine\Action
Определения
action.php:17
Bitrix\Main\Engine\Controller\getScope
getScope()
Определения
controller.php:363
Bitrix\Main\Engine\Controller\addErrors
addErrors(array $errors)
Определения
controller.php:1083
Bitrix\Main\Engine\Response\DataType\Page
Определения
page.php:8
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\NotImplementedException
Определения
NotImplementedException.php:9
Bitrix\Main\ORM\Data\Result
Определения
result.php:16
Bitrix\Main\SystemException
Определения
SystemException.php:9
Bitrix\Main\UI\PageNavigation
Определения
pagenavigation.php:27
Bitrix\Rest\Integration\Controller\Base
Определения
base.php:21
Bitrix\Rest\Integration\Controller\Base\checkModifyPermissionEntity
checkModifyPermissionEntity()
Определения
base.php:185
Bitrix\Rest\Integration\Controller\Base\checkDeletePermissionEntity
checkDeletePermissionEntity()
Определения
base.php:212
Bitrix\Rest\Integration\Controller\Base\count
count($filter)
Определения
base.php:275
Bitrix\Rest\Integration\Controller\Base\checkReadPermissionEntity
checkReadPermissionEntity()
Определения
base.php:176
Bitrix\Rest\Integration\Controller\Base\exists
exists($id)
Определения
base.php:368
Bitrix\Rest\Integration\Controller\Base\checkCreatePermissionEntity
checkCreatePermissionEntity()
Определения
base.php:194
Bitrix\Rest\Integration\Controller\Base\checkGetFieldsPermissionEntity
checkGetFieldsPermissionEntity()
Определения
base.php:168
Bitrix\Rest\Integration\Controller\Base\getList
getList(array $select, array $filter, array $order, PageNavigation $pageNavigation=null)
Определения
base.php:248
Bitrix\Rest\Integration\Controller\Base\create
create($actionName)
Определения
base.php:29
Bitrix\Rest\Integration\Controller\Base\getEntityTable
getEntityTable()
Определения
base.php:232
Bitrix\Rest\Integration\Controller\Base\processBeforeAction
processBeforeAction(Engine\Action $action)
Определения
base.php:62
Bitrix\Rest\Integration\Controller\Base\processAfterAction
processAfterAction(Engine\Action $action, $result)
Определения
base.php:92
Bitrix\Rest\Integration\Controller\Base\existsByFilter
existsByFilter($filter)
Определения
base.php:385
Bitrix\Rest\Integration\Controller\Base\add
add(array $fields)
Определения
base.php:304
Bitrix\Rest\Integration\Controller\Base\$viewManager
$viewManager
Определения
base.php:22
Bitrix\Rest\Integration\Controller\Base\getViewManager
getViewManager()
Определения
base.php:51
Bitrix\Rest\Integration\Controller\Base\checkPermissionEntity
checkPermissionEntity($name, $arguments=[])
Определения
base.php:223
Bitrix\Rest\Integration\Controller\Base\createViewManager
createViewManager(Action $action)
Определения
base.php:42
Bitrix\Rest\Integration\Controller\Base\checkUpdatePermissionEntity
checkUpdatePermissionEntity()
Определения
base.php:203
Bitrix\Rest\Integration\Externalizer
Определения
externalizer.php:19
Bitrix\Rest\Integration\Internalizer
Определения
internalizer.php:11
Bitrix\Rest\Integration\ModificationFieldsBase
Определения
modificationfieldsbase.php:10
Bitrix\Rest\Integration\ViewManager
Определения
viewmanager.php:11
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$select
$select
Определения
iblock_catalog_list.php:194
$filter
$filter
Определения
iblock_catalog_list.php:54
$name
$name
Определения
menu_edit.php:35
Bitrix\Main\Controller
Определения
agreement.php:2
Bitrix\Main\Engine\Response
Определения
ajaxjson.php:3
Bitrix\Main\Engine
Определения
action.php:3
Bitrix\Main\Page
Определения
aliases.php:54
Bitrix\Rest\Integration\Controller
Определения
base.php:4
$order
$order
Определения
payment.php:8
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$params
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения
template.php:799
$action
$action
Определения
file_dialog.php:21
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
rest
lib
integration
controller
base.php
Создано системой
1.14.0