1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
externalizer.php
См. документацию.
1
<?php
2
3
4
namespace
Bitrix\Sale\Rest;
5
6
7
use Bitrix\Main\Engine\Controller;
8
use Bitrix\Main\Engine\Response\DataType\Page;
9
use Bitrix\Main\Type\Contract\Arrayable;
10
use Bitrix\Sale\Result;
11
17
class
Externalizer
extends
ModificationFieldsBase
18
implements
Arrayable
19
{
20
public
function
__construct
(
$name
,
$arguments
,
$controller
,
$data
= [],
$scope
=
''
)
21
{
22
$this->
setFormat
([
23
self::TO_WHITE_LIST,
24
self::TO_CAMEL,
25
self::SORTING_KEYS
26
]);
27
28
parent::__construct(
$name
,
$arguments
,
$controller
,
$data
,
$scope
);
29
}
30
31
public
function
process
()
32
{
33
$r =
new
Result
();
34
35
$data
= $this->
getData
();
36
$id = $this->getIdList(
$data
);
37
38
$data
=
$data
[$id];
39
if
(in_array(self::TO_WHITE_LIST, $this->format))
40
{
41
$data
= $this->externalize(
$data
);
42
}
43
44
if
(in_array(self::TO_CAMEL, $this->format))
45
{
46
$data
= $this->
convertKeysToCamelCase
([$id=>
$data
]);
47
}
48
49
if
(in_array(self::SORTING_KEYS, $this->format))
50
{
51
$data
= $this->
multiSortKeysArray
(
$data
);
52
}
53
54
return
$r->setData([
'data'
=>
$data
]);
55
}
56
57
public
function
toArray
()
58
{
59
return
$this->
process
()->getData()[
'data'
];
60
}
61
62
protected
function
multiSortKeysArray
(
array
$data
)
63
{
64
ksort(
$data
);
65
66
foreach
(
$data
as
$k
=>&$item)
67
{
68
if
(is_array($item))
69
$item = $this->
multiSortKeysArray
($item);
70
}
71
72
return
$data
;
73
}
74
80
private
function
externalize(
$fields
)
81
{
82
$name
= $this->
getName
();
83
$controller
= $this->
getController
();
84
$entity
= $this->
getEntity
(
$controller
);
85
86
if
(
$name
==
'getfields'
){}
87
elseif
(
$name
==
'delete'
){}
88
elseif
(
$name
==
'get'
89
||
$name
==
'add'
90
||
$name
==
'update'
91
||
$name
==
'tryadd'
92
||
$name
==
'tryupdate'
)
93
{
94
$fields
=
$entity
->externalizeFields(
$fields
);
95
}
96
elseif
(
$name
==
'list'
)
97
{
98
$fields
=
$entity
->externalizeListFields(
$fields
);
99
}
100
elseif
(
$name
==
'modify'
)
101
{
102
$fields
=
$entity
->externalizeFieldsModify(
$fields
);
103
}
104
elseif
(
$name
==
'trymodify'
)
105
{
106
$fields
=
$entity
->externalizeFieldsTryModify(
$fields
);
107
}
108
else
109
{
110
$fields
=
$entity
->externalizeResult(
$name
,
$fields
);
111
}
112
113
return
$fields
;
114
}
115
121
private
function
getIdList(
$data
)
122
{
123
return
key(
$data
);
124
}
125
126
protected
function
convertKeysToCamelCase
(
$fields
)
127
{
128
$controller
= $this->
getController
();
129
$entity
= $this->
getEntity
(
$controller
);
130
131
return
$entity
->convertKeysToCamelCase(
$fields
);
132
}
133
134
public
function
getPage
(
Page
$page
)
135
{
136
$id = $this->
convertKeysToCamelCase
($page->
getId
());
137
return
new
Page
($id, $this->
toArray
()[$id],
$page
->getTotalCount());
138
}
139
}
Bitrix\Main\Engine\Response\DataType\Page
Определения
page.php:8
Bitrix\Main\Engine\Response\DataType\Page\getId
getId()
Определения
page.php:64
Bitrix\Sale\Rest\Externalizer
Определения
externalizer.php:19
Bitrix\Sale\Rest\Externalizer\getPage
getPage(Page $page)
Определения
externalizer.php:134
Bitrix\Sale\Rest\Externalizer\__construct
__construct($name, $arguments, $controller, $data=[], $scope='')
Определения
externalizer.php:20
Bitrix\Sale\Rest\Externalizer\multiSortKeysArray
multiSortKeysArray(array $data)
Определения
externalizer.php:62
Bitrix\Sale\Rest\Externalizer\convertKeysToCamelCase
convertKeysToCamelCase($fields)
Определения
externalizer.php:126
Bitrix\Sale\Rest\Externalizer\toArray
toArray()
Определения
externalizer.php:57
Bitrix\Sale\Rest\Externalizer\process
process()
Определения
externalizer.php:31
Bitrix\Sale\Rest\ModificationFieldsBase
Определения
modificationfieldsbase.php:10
Bitrix\Sale\Rest\ModificationFieldsBase\$scope
$scope
Определения
modificationfieldsbase.php:22
Bitrix\Sale\Rest\ModificationFieldsBase\getName
getName()
Определения
modificationfieldsbase.php:39
Bitrix\Sale\Rest\ModificationFieldsBase\getEntity
getEntity(Controller $controller)
Определения
modificationfieldsbase.php:82
Bitrix\Sale\Rest\ModificationFieldsBase\$name
string $name
Определения
modificationfieldsbase.php:17
Bitrix\Sale\Rest\ModificationFieldsBase\$data
$data
Определения
modificationfieldsbase.php:21
Bitrix\Sale\Rest\ModificationFieldsBase\getData
getData()
Определения
modificationfieldsbase.php:72
Bitrix\Sale\Rest\ModificationFieldsBase\$arguments
array $arguments
Определения
modificationfieldsbase.php:18
Bitrix\Sale\Rest\ModificationFieldsBase\$controller
Controller $controller
Определения
modificationfieldsbase.php:19
Bitrix\Sale\Rest\ModificationFieldsBase\getController
getController()
Определения
modificationfieldsbase.php:62
Bitrix\Sale\Rest\ModificationFieldsBase\setFormat
setFormat($format)
Определения
modificationfieldsbase.php:57
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$entity
$entity
Определения
group_bizproc_workflow_delete.php:17
Bitrix\Main\Type\Contract\Arrayable
Определения
arrayable.php:6
$name
$name
Определения
menu_edit.php:35
Bitrix\Sale\Discount\Result
Определения
compatibleformat.php:2
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$page
$page
Определения
order_form.php:33
$k
$k
Определения
template_pdf.php:567
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
sale
lib
rest
externalizer.php
Создано системой
1.14.0