/** * {@inheritdoc} */ public function calculateDBValue(IObject $object, $localeId = null) { if (!$object instanceof IHierarchicObject) { throw new RuntimeException($this->translate('Cannot calculate materialized path value for nonhierarchical object.')); } if ($parent = $object->getParent()) { return $parent->getMaterializedPath() . self::MPATH_SEPARATOR . $object->getId(); } else { return self::MPATH_START_SYMBOL . $object->getId(); } }
/** * {@inheritdoc} */ public function calculateDBValue(IObject $object, $localeId = null) { $setValue = $object->getValue($this->getName(), $localeId); return $setValue ?: $object->getId(); }
/** * {@inheritdoc} */ public function unloadObject(IObject $object) { $collectionName = $object->getCollection()->getName(); if (isset($this->objectsById[$collectionName][$object->getId()])) { unset($this->objectsById[$collectionName][$object->getId()]); } if (isset($this->objectsByGuid[$object->getGUID()])) { unset($this->objectsByGuid[$object->getGUID()]); } $this->getObjectPersister()->clearObjectState($object); return $this; }
/** * {@inheritdoc} */ public function fullyLoadObject(IObject $object, $localization = ILocalesService::LOCALE_CURRENT) { if (!$object->getId()) { throw new LoadEntityException($this->translate('Cannot load object. Object id required.')); } $fieldsToLoad = []; $loadedValues = $object->getInitialValues(); foreach ($object->getType()->getFields() as $fieldName => $field) { if (!array_key_exists($fieldName, $loadedValues) || $localization === ILocalesService::LOCALE_ALL && $field->getIsLocalized()) { $fieldsToLoad[] = $fieldName; } } if (count($fieldsToLoad)) { $pkFiledName = $this->getIdentifyField()->getName(); $objectsSet = $this->select()->fields($fieldsToLoad)->localization($localization)->where($pkFiledName)->equals($object->getId())->result(); if (!$objectsSet->fetch()) { throw new LoadEntityException($this->translate('Cannot load object with id "{id}" from collection "{collection}".', ['id' => $object->getId(), 'collection' => $this->getName()])); } } }
/** * {@inheritdoc} */ public function preparePropertyValue(IObject $object, $internalDbValue) { $targetFieldName = $this->getTargetFieldName(); return $this->getTargetCollection()->select()->where($targetFieldName)->equals($object->getId())->result(); }