Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/domain/collection/page.php
<?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 AnDomainCollectionPage extends KObjectArray 
{	
	/**
	 * Query from which the collection was created. It's used for getting total, offset and limit of the 
	 * collection
	 * 
	 * @var AnDomainQuery
	 */
	protected $_query;
	
	/**
	 * Caches the total number of entities for the query
	 * 
	 * @var int
	 */
	protected $_total;
		
	/**
	 * 
	 * @return 
	 * @param $options Object[optional]
	 */
	public function __construct($options=array())
	{
		$data = array();
		if ( isset($options['query']) ) {
			$this->_query  = $options['query'];
			$data	       = $this->_query->getMapper()->fetchAll($this->_query);
		}
		parent::__construct(array('data'=>$data));
	}
	
	/**
	 * Convert the collection to Array by calling toArray of each of the entities
	 * @return 
	 */		
	public function toArray()
	{
		$result = array();
		foreach($this as $entity) {
			$result[] = $entity->toArray();
		}
		return $result;
	}
	
	/**
	 * Get the total entities for the query of collection
	 * 
	 * 
	 * @return 
	 */
	public function getTotal()
	{
		if ( !$this->_total ) 
			$this->_total = $this->_query->count();
		
		return $this->_total;
	}
	
	/**
	 * Get the offset of the collection
	 * 
	 * @TODO - perhaps a page object to contains these information is better
	 * 
	 * @return 
	 */
	public function getOffset()
	{	
		return $this->_query->offset;
	}
	
	/**
	 * Get the limit of the collection
	 * 
	 * @return 
	 */
	public function getLimit()
	{
		return $this->_query->limit;
	}
	
	/**
     * Retrieve an aggregate the values of the property of all the entities in the collection 
     *
     * @param  	string 	The property name.
     * @return 	array 	An array of all the property values
     */
    public function __get($property)
    {
    	$result = array();
		
    	foreach ($this as $i => $entity) {
            $result [] = $entity->$property;
        }
    	
    	return $result;
    }

	/**
	 * Mark all the entity in the collection as deleted
	 * 
	 * @return void
	 */
	public function markDeleted()
	{
		foreach($this as $entity)
			$entity->markDeleted();
			
		return $this;			
	}
	
    /**
     * Set property value
     *
     * @param  	string 	The property name.
     * @param  	mixed  	The value for the property.
     * @return 	void
     */
    public function __set($property, $value)
    {
    	foreach ($this as $i => $entity) {
            $entity->$property = $value;
        }              
   }
}
Return current item: Anahita Social Engine