37 $newIblockSectionId = (int) $iblockSectionId;
38 $actualIblockSectionId = 0;
40 if ($this->state !== State::RAW)
42 $this->fill(
'IBLOCK_SECTION_ID');
43 $actualIblockSectionId = $this->remindActual(
'IBLOCK_SECTION_ID');
46 if ($newIblockSectionId !== $actualIblockSectionId)
49 if ($actualIblockSectionId > 0)
52 $this->removeFrom(
'SECTIONS', $oldSection);
56 if ($newIblockSectionId > 0)
59 $this->addTo(
'SECTIONS', $newSection);
63 parent::sysSetValue(
'IBLOCK_SECTION_ID', $newIblockSectionId);
79 public function sysSetValue($fieldName, $value)
81 $field = $this->entity->getField($fieldName);
86 $value = $this->sysConvertPropertyValue($value, $field);
89 $currentValue = $this->
get($fieldName);
91 if (empty($currentValue))
93 parent::sysSetValue($fieldName, $value);
98 $currentValue->set(
'VALUE', $value->get(
'VALUE'));
100 if ($this->entity->hasField(
'DESCRIPTION') && $value->sysHasValue(
'DESCRIPTION'))
102 $currentValue->set(
'DESCRIPTION', $value->get(
'DESCRIPTION'));
107 if ($this->state === State::ACTUAL)
109 $this->sysChangeState(State::CHANGED);
115 return parent::sysSetValue($fieldName, $value);
128 public function sysAddToCollection($fieldName, $remoteObject)
130 $fieldName = StringHelper::strtoupper($fieldName);
131 $field = $this->entity->getField($fieldName);
133 if ($field instanceof PropertyOneToMany)
136 $remoteObject = $this->sysConvertPropertyValue($remoteObject, $field);
140 $field->getIblockElementProperty()->getPropertyType(),
151 $collection = $this->
get($fieldName);
154 if (empty($collection) || !$collection->sysIsFilled())
156 $collection = $this->
fill($fieldName);
159 foreach ($collection as $refObject)
162 if ($refObject->get(
'VALUE') === $remoteObject->get(
'VALUE'))
171 return parent::sysAddToCollection($fieldName, $remoteObject);
184 public function sysRemoveFromCollection($fieldName, $remoteObject)
186 $fieldName = StringHelper::strtoupper($fieldName);
187 $field = $this->entity->getField($fieldName);
189 if ($field instanceof PropertyOneToMany)
192 $valueObject = $this->sysConvertPropertyValue($remoteObject, $field);
194 if ($valueObject->sysHasPrimary())
197 $remoteObject = $valueObject;
203 $collection = $this->
get($fieldName);
206 if (empty($collection) || !$collection->sysIsFilled())
208 $collection = $this->
fill($fieldName);
213 foreach ($collection as $refObject)
216 if ($valueObject->get(
'VALUE') === $refObject->get(
'VALUE'))
219 $remoteObject = $refObject;
232 return parent::sysRemoveFromCollection($fieldName, $remoteObject);
251 protected function sysConvertPropertyValue($value, $field)
253 $valueEntity = $field->getRefEntity();
254 $valueObjectClass = $valueEntity->getObjectClass();
256 if ($value instanceof $valueObjectClass)
263 $valueObject = $valueEntity->createObject();
266 if ($this->state == State::RAW)
268 $this->sysAddOnPrimarySetListener(
function (
EntityObject $localObject) use ($valueObject) {
269 $valueObject->set(
'IBLOCK_ELEMENT_ID', $localObject->
get(
'ID'));
275 $valueObject->set(
'IBLOCK_ELEMENT_ID', $this->
get(
'ID'));
278 if ($valueEntity->hasField(
'IBLOCK_PROPERTY_ID'))
280 $valueObject->set(
'IBLOCK_PROPERTY_ID', $field->getIblockElementProperty()->getId());
284 if ($value instanceof PropertyValue)
286 $valueObject->set(
'VALUE', $value->getValue());
288 if ($value->hasDescription())
290 $valueObject->set(
'DESCRIPTION', $value->getDescription());
295 $valueObject->set(
'VALUE', $value);