/** * Set the owner of the object. If multiple owners are passed then the first owner is the * primary owner and the rest just share the object with the owner * * @param ComActorsDomainEntityActor $owner The owner object * * @return ComBaseDomainEntityNode Return the ownable object */ public function setOwner($owner) { //multiple owners are passed $owner = KConfig::unbox($owner); if (is_array($owner)) { deprecated('array as owner'); } if (is_array($owner) && $this->isSharable()) { $owners = AnHelperArray::unique($owner); //remove the first owner as the primary owner $owner = array_shift($owners); //create an edge with the story for each secondary owner //$this->addOwner($owners); } $this->_mixer->set('owner', $owner); return $this; }
/** * Insert an entity to the aggregation. If multiple target is passed then * add the all of them to the collection. It prevents adding the same * entity into the its existing collection. * * @param AnDomainEntityAbstract|array $target * @param array $config * * @return AnDomainEntityAbstract */ public function insert($target, $config = array()) { if (AnHelperArray::isIterable($target)) { $targets = AnHelperArray::unique($target); $relations = new AnObjectSet(); foreach ($target as $target) { $relations->insert($this->insert($target, $config)); } return $relations; } $data = array($this->_property => $this->_root, $this->_target_property => $target); //shouldn't be able to add the same entity into the same collection $relation = $this->_child->findOrAddNew($data, $config); return $relation; }
/** * Get the proxied entity. Since there could many entities proxied. The getObject method will try to * load all the proxied entities of the same type in order to reduce the number of calls * to the storage later on. * * @return AnDomainEntityAbstract */ public function getObject() { //security check if (!isset($this->_object)) { $condition = array($this->_property => $this->_value); $repository = AnDomain::getRepository($this->getIdentifier()); //check if an entity exiting in the repository with $condition if ($data = $repository->find($condition, false)) { $this->_object = $data; return $this->_object; } //now time to fetch the object from the database //but lets grab all the similar entities all together $handle = $this->getIdentifier() . $this->_property; $values = isset(self::$_values[$handle]) ? self::$_values[$handle] : array(); if (empty($values)) { return; } $values = AnHelperArray::unique($values); $query = $repository->getQuery(); AnDomainQueryHelper::applyFilters($query, $this->_relationship->getQueryFilters()); $query->where(array($this->_property => $values)); $entities = $repository->fetchSet($query); //the object must have been fetched with the set //in the previous line //if the object is still not fetched, then the object //doesn't exists in the databse $this->_object = $repository->find($condition, false); if (!$this->_object) { //lets cache the null result to prevent re-fetching //the same result $query = $repository->getQuery()->where($condition)->limit(1); if ($repository->hasBehavior('cachable')) { $repository->emptyCache($query); } $this->_object = false; //if it's a required one-to-one relationship //then instantaite a new entity if the entity doesn't exists if ($this->_relationship->isOneToOne()) { if ($this->_relationship->isRequired()) { $this->_object = $repository->getEntity(array('data' => array($this->_property => $this->_value))); } } } unset(self::$_values[$handle]); } return $this->_object; }