1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
IBlockElementToAdd.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Lists\Api\Data\IBlockService;
4
5
use Bitrix\Lists\Api\Request\IBlockService\AddIBlockElementRequest;
6
use Bitrix\Lists\Api\Response\IBlockService\IBlockElementToAddValues;
7
use Bitrix\Lists\Api\Response\IBlockService\IBlockElementToUpdateValues;
8
use Bitrix\Lists\UI\Fields\Field;
9
use Bitrix\Main\ArgumentOutOfRangeException;
10
11
final
class
IBlockElementToAdd
extends
IBlockElementToUpdate
12
{
13
private
int
$createdBy;
14
15
protected
function
init
(): void
16
{
17
$this->elementId = 0;
18
$this->createdBy =
$this->modifiedBy
;
19
}
20
26
public
static
function
createFromRequest
(
$request
): self
27
{
28
$iBlockId
=
self::validateId
(
$request
->iBlockId);
29
if
(
$iBlockId
===
null
||
$iBlockId
=== 0)
30
{
31
throw
new
ArgumentOutOfRangeException
(
'iBlockId'
, 1,
null
);
32
}
33
34
$sectionId
=
self::validateId
(
$request
->sectionId);
35
if
(
$sectionId
===
null
)
36
{
37
throw
new
ArgumentOutOfRangeException
(
'sectionId'
, 0,
null
);
38
}
39
40
$createdBy =
self::validateId
(
$request
->createdByUserId);
41
if
($createdBy ===
null
|| $createdBy === 0)
42
{
43
throw
new
ArgumentOutOfRangeException
(
'createdBy'
, 1,
null
);
44
}
45
46
$values
=
self::validateValues
(
$request
->values,
$iBlockId
,
$sectionId
);
47
48
return
new
self
($createdBy, 0,
$iBlockId
,
$sectionId
,
$values
);
49
}
50
51
public
function
getCreatedBy
(): int
52
{
53
return
$this->createdBy;
54
}
55
56
public
function
getElementValues
(
array
$fields
,
array
$props
):
IBlockElementToAddValues
57
{
58
$result
=
new
IBlockElementToAddValues
();
59
$result
60
->setHasChangedFields(
true
)
61
->setHasChangedProps(
true
)
62
;
63
64
$element = [
65
'IBLOCK_ID'
=> $this->
getIBlockId
(),
66
'IBLOCK_SECTION_ID'
=> $this->
getSectionId
(),
67
'MODIFIED_BY'
=> $this->
getCreatedBy
(),
68
];
69
70
$preparedFields = $this->
prepareFields
($fields,
$result
);
71
$element = array_merge($element, $preparedFields);
72
unset($element[
'TIMESTAMP_X'
]);
73
74
$preparedProps = $this->
prepareProps
($props,
$result
);
75
if
($preparedProps)
76
{
77
$element[
'PROPERTY_VALUES'
] = $preparedProps;
78
}
79
80
return
$result
->setElementData($element);
81
}
82
83
protected
function
prepareFields
(
array
$fields
,
IBlockElementToUpdateValues
$result
):
array
84
{
85
$prepared = [];
86
foreach
(
$fields
as $fieldId => $property)
87
{
88
$field =
new
Field
($property);
89
90
if
(in_array($fieldId, [
'PREVIEW_TEXT'
,
'DETAIL_TEXT'
],
true
))
91
{
92
$useEditor = isset($property[
'SETTINGS'
][
'USE_EDITOR'
]) && $property[
'SETTINGS'
][
'USE_EDITOR'
] ===
'Y'
;
93
$prepared[$fieldId .
'_TYPE'
] = $useEditor ?
'html'
:
'text'
;
94
}
95
96
// calculated value
97
if
($field->getId() ===
'ACTIVE_FROM'
&& $field->isAddReadOnlyField())
98
{
99
$prepared[$fieldId] = $field->getDefaultValue();
100
if
($field->isShowInAddForm() && $this->getFieldValueById($fieldId))
101
{
102
$prepared[$fieldId] = $this->
getFieldValueById
($fieldId);
103
}
104
105
continue
;
106
}
107
108
$prepared[$fieldId] =
109
$field->isShowInAddForm() && !$field->isAddReadOnlyField()
110
? $this->
getFieldValueById
($fieldId)
111
: $field->getDefaultValue()
112
;
113
}
114
115
return
$prepared;
116
}
117
118
protected
function
prepareProps
(
array
$props
,
IBlockElementToUpdateValues
$result
):
array
119
{
120
$prepared = [];
121
foreach
(
$props
as $propId => $property)
122
{
123
$showAddForm =
124
isset($property[
'SETTINGS'
][
'SHOW_ADD_FORM'
]) && $property[
'SETTINGS'
][
'SHOW_ADD_FORM'
] ===
'Y'
125
;
126
$defaultValue
= ($property[
'DEFAULT_VALUE'
] ??
null
);
127
$requestValues = $this->
getFieldValueById
($propId);
128
129
if
($property[
'TYPE'
] ===
'N:Sequence'
&& !$showAddForm && empty(
$defaultValue
))
130
{
131
$defaultValue
= (new \CIBlockSequence($this->
getIBlockId
(), $property[
'ID'
]))->GetNext();
132
}
133
134
if
($showAddForm && is_array($requestValues))
135
{
136
$prepared[$property[
'ID'
]] = $this->
preparePropValue
($requestValues, $property,
$result
);
137
}
138
elseif
(array_key_exists(
'DEFAULT_VALUE'
, $property) || (
$defaultValue
!==
null
))
139
{
140
if
(is_array(
$defaultValue
) && in_array($property[
'PROPERTY_TYPE'
], [
'L'
,
'E'
,
'G'
]))
141
{
142
$prepared[$property[
'ID'
]] = [];
143
foreach
(
$defaultValue
as
$key
=> $value)
144
{
145
$prepared[$property[
'ID'
]][
$key
] = $value;
146
}
147
}
148
else
149
{
150
$prepared[$property[
'ID'
]] = [
'n0'
=> [
'VALUE'
=>
$defaultValue
]];
151
}
152
}
153
}
154
155
return
$prepared;
156
}
157
158
public
function
getChangedFieldsAfterUpdate
():
array
159
{
160
return
[];
161
}
162
}
$defaultValue
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
Определения
options.php:32
$request
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения
catalog_reindex.php:36
Bitrix\Lists\Api\Data\Data\validateId
static validateId(int $id)
Определения
Data.php:9
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToAdd
Определения
IBlockElementToAdd.php:12
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToAdd\createFromRequest
static createFromRequest($request)
Определения
IBlockElementToAdd.php:26
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToAdd\prepareProps
prepareProps(array $props, IBlockElementToUpdateValues $result)
Определения
IBlockElementToAdd.php:118
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToAdd\init
init()
Определения
IBlockElementToAdd.php:15
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToAdd\getCreatedBy
getCreatedBy()
Определения
IBlockElementToAdd.php:51
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToAdd\getElementValues
getElementValues(array $fields, array $props)
Определения
IBlockElementToAdd.php:56
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToAdd\getChangedFieldsAfterUpdate
getChangedFieldsAfterUpdate()
Определения
IBlockElementToAdd.php:158
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToAdd\prepareFields
prepareFields(array $fields, IBlockElementToUpdateValues $result)
Определения
IBlockElementToAdd.php:83
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToUpdate
Определения
IBlockElementToUpdate.php:15
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToUpdate\$modifiedBy
int $modifiedBy
Определения
IBlockElementToUpdate.php:17
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToUpdate\getIBlockId
getIBlockId()
Определения
IBlockElementToUpdate.php:105
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToUpdate\validateValues
static validateValues(array $values, int $iBlockId, int $sectionId)
Определения
IBlockElementToUpdate.php:86
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToUpdate\$iBlockId
int $iBlockId
Определения
IBlockElementToUpdate.php:19
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToUpdate\getSectionId
getSectionId()
Определения
IBlockElementToUpdate.php:100
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToUpdate\$sectionId
int $sectionId
Определения
IBlockElementToUpdate.php:20
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToUpdate\preparePropValue
preparePropValue(array $requestValues, array $property, Result $result)
Определения
IBlockElementToUpdate.php:259
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToUpdate\getFieldValueById
getFieldValueById(string $fieldsId)
Определения
IBlockElementToUpdate.php:115
Bitrix\Lists\Api\Data\IBlockService\IBlockElementToUpdate\$values
array $values
Определения
IBlockElementToUpdate.php:21
Bitrix\Lists\Api\Response\IBlockService\IBlockElementToAddValues
Определения
IBlockElementToAddValues.php:6
Bitrix\Lists\Api\Response\IBlockService\IBlockElementToUpdateValues
Определения
IBlockElementToUpdateValues.php:8
Bitrix\Lists\UI\Fields\Field
Определения
Field.php:6
Bitrix\Main\ArgumentOutOfRangeException
Определения
ArgumentOutOfRangeException.php:9
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
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
$props
$props
Определения
template.php:269
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
lists
lib
Api
Data
IBlockService
IBlockElementToAdd.php
Создано системой
1.14.0