public function fetch($condition = null, $mode = AnDomain::FETCH_ENTITY)
    {
        $query = AnDomainQuery::getInstance($this, $condition);
        $context = $this->getCommandContext();
        $context->operation = AnDomain::OPERATION_FETCH;
        $context->query = $query;
        $context->mode = $mode;
        $query->fetch_mode = $mode;

        if ($mode & AnDomain::FETCH_ITEM) {
            $context->query->limit(1);
        }

        $disable_chain = $query->disable_chain;

        if ($disable_chain) {
            $this->getCommandChain()->disable();
        }

        if ($this->getCommandChain()->run('before.fetch', $context) !== false) {
            $result = $context->result ? $context['result'] : $this->_fetchResult($context->query, $mode);
            $context->result = $result;
            switch ($mode) {
                case AnDomain::FETCH_ENTITY     :
                    $context->data = $result ? $this->_createEntity($result) : $result;
                    break;
                case AnDomain::FETCH_ENTITY_SET  :
                case AnDomain::FETCH_ENTITY_LIST :
                    $list = array();
                    foreach ($result as $data) {
                        $list[] = $this->_createEntity($data);
                    }
                    if ($mode == AnDomain::FETCH_ENTITY_SET) {
                        $list = $this->getService($this->_entityset, array('repository' => $this, 'query' => $context->query, 'data' => $list));
                    }
                    $context->data = $list;
                    break;
                default :
                    $context->data = $result;
            }

            $this->getCommandChain()->run('after.fetch', $context);
        }

        if ($disable_chain) {
            $this->getCommandChain()->enable();
        }

        return AnConfig::unbox($context->data);
    }
public function fetch($condition = null, $mode = AnDomain::FETCH_ENTITY)
    {
        $query = AnDomainQuery::getInstance($this, $condition);
        $context = $this->getCommandContext();
        $context->operation = AnDomain::OPERATION_FETCH;
        $context->query = $query;
        $context->mode = $mode;
        $query->fetch_mode = $mode;

        if ($mode & AnDomain::FETCH_ITEM) {
            $context->query->limit(1);
        }

        $disable_chain = $query->disable_chain;

        if ($disable_chain) {
            $this->getCommandChain()->disable();
        }

        if ($this->getCommandChain()->run('before.fetch', $context) !== false) {
            $result = $context->result ? $context['result'] : $this->_fetchResult($context->query, $mode);
            $context->result = $result;
            switch ($mode) {
                case AnDomain::FETCH_ENTITY     :
                    $context->data = $result ? $this->_createEntity($result) : $result;
                    break;
                case AnDomain::FETCH_ENTITY_SET  :
                case AnDomain::FETCH_ENTITY_LIST :
                    $list = array();
                    foreach ($result as $data) {
                        $list[] = $this->_createEntity($data);
                    }
                    if ($mode == AnDomain::FETCH_ENTITY_SET) {
                        $list = $this->getService($this->_entityset, array('repository' => $this, 'query' => $context->query, 'data' => $list));
                    }
                    $context->data = $list;
                    break;
                default :
                    $context->data = $result;
            }

            $this->getCommandChain()->run('after.fetch', $context);
        }

        if ($disable_chain) {
            $this->getCommandChain()->enable();
        }

        return AnConfig::unbox($context->data);
    }
public function fetch ( $ condition = null , $ mode = AnDomain :: FETCH_ENTITY ) { $ query = AnDomainQuery :: getInstance ( $ this , $ condition ) ; $ context = $ this -> getCommandContext ( ) ; $ context -> operation = AnDomain :: OPERATION_FETCH ; $ context -> query = $ query ; $ context -> mode = $ mode ; $ query -> fetch_mode = $ mode ; if ( $ mode & AnDomain :: FETCH_ITEM ) { $ context -> query -> limit ( 1 ) ; } $ disable_chain = $ query -> disable_chain ; if ( $ disable_chain ) { $ this -> getCommandChain ( ) -> disable ( ) ; } if ( $ this -> getCommandChain ( ) -> run ( 'before.fetch' , $ context ) !== false ) { $ result = $ context -> result ? $ context [ 'result' ] : $ this -> _fetchResult ( $ context -> query , $ mode ) ; $ context -> result = $ result ; switch ( $ mode ) { case AnDomain :: FETCH_ENTITY : $ context -> data = $ result ? $ this -> _createEntity ( $ result ) : $ result ; break ; case AnDomain :: FETCH_ENTITY_SET : case AnDomain :: FETCH_ENTITY_LIST : $ list = array ( ) ; foreach ( $ result as $ data ) { $ list [ ] = $ this -> _createEntity ( $ data ) ; } if ( $ mode == AnDomain :: FETCH_ENTITY_SET ) { $ list = $ this -> getService ( $ this -> _entityset , array ( 'repository' => $ this , 'query' => $ context -> query , 'data' => $ list ) ) ; } $ context -> data = $ list ; break ; default : $ context -> data = $ result ; } $ this -> getCommandChain ( ) -> run ( 'after.fetch' , $ context ) ; } if ( $ disable_chain ) { $ this -> getCommandChain ( ) -> enable ( ) ; } return AnConfig :: unbox ( $ context -> data ) ; }
Fetch an entity. The condition can be a query object, an associative array or an id
of an entity.

@param mixed $condition The condition for fetching data
@param int   $mode      The mode of fetching data. Can be single entity, entity set, value, etc

@return mixed
Fetch an entity . The condition can be a query object an associative array or an id of an entity .