/** * Return the entityset query. If $clone is passed it will return a clone instance of the entityset * query is returned * * @param boolean $clone If set to true then it will return a new clone instance of entityset * @param boolean $disable_chain Disable the chain * * @return AnDomainQuery */ public function getQuery($clone = false, $disable_chain = false) { if (!isset($this->_set_query) || $clone) { if ($this->_query instanceof AnDomainQuery) { $query = clone $this->_query; } else { $query = $this->_repository->getQuery(); AnDomainQueryHelper::applyFilters($query, $this->_query); } //if clone is set, then return the qury object if ($clone) { if ($disable_chain) { $query->disableChain(); } return $query; } //if not then set the entity query object $this->_set_query = $query; } return $this->_set_query; }
/** * Constructor. * * @param object An optional KConfig object with configuration options */ public function __construct(KConfig $config) { parent::__construct($config); $this->_repository = $config->repository; $this->operation = array('type' => self::QUERY_SELECT_DEFAULT, 'value' => ''); $this->_prefix = $config->resource_prefix; $this->_state = $config->state; if ($config['query_options'] instanceof Closure) { $config['query_options']($this); } else { AnDomainQueryHelper::applyFilters($this, $config['query_options']); } }
/** * 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; }