1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
IBlockElementToAdd.php
См. документацию.
1<?php
2
3namespace Bitrix\Lists\Api\Data\IBlockService;
4
5use Bitrix\Lists\Api\Request\IBlockService\AddIBlockElementRequest;
6use Bitrix\Lists\Api\Response\IBlockService\IBlockElementToAddValues;
7use Bitrix\Lists\Api\Response\IBlockService\IBlockElementToUpdateValues;
8use Bitrix\Lists\UI\Fields\Field;
9use Bitrix\Main\ArgumentOutOfRangeException;
10
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 {
29 if ($iBlockId === null || $iBlockId === 0)
30 {
31 throw new ArgumentOutOfRangeException('iBlockId', 1, null);
32 }
33
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
47
48 return new self($createdBy, 0, $iBlockId, $sectionId, $values);
49 }
50
51 public function getCreatedBy(): int
52 {
53 return $this->createdBy;
54 }
55
57 {
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
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
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
159 {
160 return [];
161 }
162}
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
Определения options.php:32
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static validateId(int $id)
Определения Data.php:9
prepareProps(array $props, IBlockElementToUpdateValues $result)
Определения IBlockElementToAdd.php:118
getElementValues(array $fields, array $props)
Определения IBlockElementToAdd.php:56
prepareFields(array $fields, IBlockElementToUpdateValues $result)
Определения IBlockElementToAdd.php:83
static validateValues(array $values, int $iBlockId, int $sectionId)
Определения IBlockElementToUpdate.php:86
preparePropValue(array $requestValues, array $property, Result $result)
Определения IBlockElementToUpdate.php:259
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$props
Определения template.php:269
$fields
Определения yandex_run.php:501