/** * {@inheritdoc} */ public function preparePropertyValue(IObject $object, $internalDbValue) { /** * @var IFileProperty $fileProperty */ $fileProperty = $object->getProperty($this->getName()); return new File($fileProperty, $this->sourcePath, $this->sourceURI, $internalDbValue); }
/** * {@inheritdoc} */ public function calculateDBValue(IObject $object, $localeId = null) { if (!$object instanceof IHierarchicObject) { throw new RuntimeException($this->translate('Cannot calculate order value for nonhierarchical object.')); } if (null != ($order = $object->getProperty($this->getName())->getDbValue())) { return $order; } return $object->getCollection()->getMaxOrder($object->getParent()) + 1; }
/** * {@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) { if (!$object instanceof IHierarchicObject) { throw new RuntimeException($this->translate('Cannot calculate level value for nonhierarchical object.')); } /** * @var MaterializedPathField $mpathField */ $mpathField = $object->getProperty(IHierarchicObject::FIELD_MPATH)->getField(); $mpath = $mpathField->calculateDBValue($object); return substr_count($mpath, MaterializedPathField::MPATH_SEPARATOR); }
/** * {@inheritdoc} */ public function calculateDBValue(IObject $object, $localeId = null) { if (!$object instanceof IHierarchicObject) { throw new RuntimeException($this->translate('Cannot calculate URI value for nonhierarchical object.')); } /** * @var SlugField $slugField */ $slugField = $object->getProperty(IHierarchicObject::FIELD_SLUG)->getField(); $slug = $slugField->calculateDBValue($object, $localeId); if ($parent = $object->getParent()) { return $parent->getURI() . '/' . $slug; } else { return self::URI_START_SYMBOL . '/' . $slug; } }
/** * {@inheritdoc} */ public function update($value) { if (!$this->field->compareValue($this->getValue(), $value)) { $this->dbValue = $this->field->prepareDbValue($this->object, $value); $this->value = $value; $this->isModified = true; $this->object->setIsModified(); } return $this; }
/** * Устанавливает в провайдер данных данные в поле типа ManyToManyRelationField. * @param string $dataSource идентификатор источника данных для элемента * @param array $data * @throws UnexpectedValueException если данные в неверном формате */ private function setManyToManyObjectSetData($dataSource, $data) { if (!is_array($data)) { throw new UnexpectedValueException('Cannot set data for ManyToManyRelationField. Data should be an array.'); } $property = $this->data->getPropertyByPath($dataSource); /** * @var ManyToManyRelationField $field */ $field = $property->getField(); $targetCollection = $field->getTargetCollection(); /** * @var IManyToManyObjectSet $objectSet */ $objectSet = $this->data->getValueByPath($dataSource); $objectSet->detachAll(); foreach ($data as $id) { $objectSet->link($targetCollection->getById($id)); } }
/** * {@inheritdoc} */ public function calculateDBValue(IObject $object, $localeId = null) { return $object->getProperty($this->getName(), $localeId)->getDbValue(); }
/** * {@inheritdoc} */ public function calculateDBValue(IObject $object, $localeId = null) { $setValue = $object->getValue($this->getName(), $localeId); return $setValue ?: $object->getId(); }
/** * Проверяет правильность пароля для указанного пользователя. * @param IObject $user пользователь * @param string $password пароль * @return bool true, если пароль верный */ public function checkPassword(IObject $user, $password) { return $user->getProperty($this->passwordField)->getValue() === $password; }
/** * Возвращает объект содержащий в себе свойства связи (объект bridge-коллекции) либо null, если такого нет * @param IObject $object связанный объект (объект target-коллекции) * @throws InvalidArgumentException если передан объект неподходящей коллекции * @return IObject|null */ protected function getLinkObject(IObject $object) { $collectionName = $this->field->getTargetCollectionName(); $collection = $object->getCollection(); if ($collectionName != $collection->getName() && ($collection instanceof ILinkedHierarchicCollection && $collection->getCommonHierarchy()->getName())) { throw new InvalidArgumentException($this->translate('Cannot get linked object. IObject from wrong collection is given.')); } if ($this->set->contains($object) && ($data = $this->set->offsetGet($object))) { return $data['linkObject']; } if ($this->isCompletelyLoaded && !$this->set->contains($object) || $object->getIsNew()) { return null; } $linkObject = $this->getBridgeCollection()->select()->where($this->field->getRelatedFieldName())->equals($this->object)->where($this->field->getTargetFieldName())->equals($object)->limit(1)->result()->fetch(); if (!$linkObject instanceof IObject) { return null; } $this->attachObjectToStorage($object, array('linkObject' => $linkObject, 'deleted' => false)); return $linkObject; }
/** * {@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()])); } } }
/** * Восстанавливает значения полей типа relation * @param IObject $object * @param array $relatedValues */ protected function restoreObjectRelations(IObject $object, array $relatedValues) { foreach ($relatedValues as $propertyName => $value) { $property = $object->getProperty($propertyName); $property->setInitialValue(null); $property->setValue($value); } }
/** * {@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 preparePropertyValue(IObject $object, $internalDbValue) { $targetFieldName = $this->getTargetFieldName(); return $this->getTargetCollection()->select()->where($targetFieldName)->equals($object->getId())->result(); }