<?php
/**
* @version 1.0.0
* @category Anahita Social Engineâ¢
* @copyright Copyright (C) 2008 - 2010 rmdStudio Inc. and Peerglobe Technology Inc. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link http://www.anahitapolis.com
*/
class AnDomainCollectionQueriable extends AnDomainCollectionPage
{
/**
*
*
*/
protected $_entities;
/**
*
* @return
* @param $options Object[optional]
*/
public function __construct($options=array())
{
parent::__construct();
$this->_query = $options['query'];
$this->mixin( $this->_query );
}
/**
* Load the entities before getting count of the entities
* @return
*/
public function count()
{
$this->fetchAll();
return parent::count();
}
/**
* Load the entities before getting an entity of offset
* @return
* @param $offset Object
*/
public function offsetGet($offset)
{
$this->fetchAll();
return parent::offsetGet($offset);
}
/**
* Fetch the queried entities and set them in the collection
* @return
*/
public function fetchAll()
{
if ( !$this->_entities )
{
$this->_entities = $this->getQuery()->getMapper()->fetchAll($this->getQuery());
$this->setArray($this->_entities);
}
return $this;
}
/**
* Get collection query
* @return
*/
public function getQuery()
{
return $this->_query;
}
/**
*
* @return
*/
public function getIterator()
{
$this->fetchAll();
return parent::getIterator();
}
/**
*
* @return
* @param $method Object
* @param $args Object
*/
public function __call($method, $args)
{
$object = parent::__call($method, $args);
if ( $object === $this->getQuery() )
return $this;
return $object;
}
}