/** * {@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 contains(IObject $object) { return $object->getCollection() === $this; }
/** * Возвращает объект содержащий в себе свойства связи (объект 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 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; }