Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/model/story/data/data.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 AnModelStoryData extends KObject implements ArrayAccess
{

	/**
	 * Story Data Array
	 */	
	public $data;
	
	/**
	 * 
	 * @return 
	 * @param $options Object[optional]
	 */
	public function __construct(array $options = array())
	{
		$options = $this->_initialize($options);
		
		if ( is_string($options['data']) )
			$options['data'] = unserialize($options['data']);
		
		$this->data = $options['data'];
	}
	
	/**
	 * Short method to add a text data object @see AnModelDataText
	 * @return 
	 * @param $key  String
	 * @param $text String
	 * @param $href String[optional]
	 */
	public function addText($key, $text, $href = null)
	{
		$data = KFactory::tmp('lib.anahita.model.story.data.text', array('text'=>$text, 'href'=>$href));
		$this->data[$key] = $data;
		return $data;
	}
	
	/**
	 * 
	 * @return 
	 * @param $src Object
	 * @param $href Object[optional]
	 */
	public function addImage($src, $alt, $href = null)
	{
		$data = KFactory::tmp('lib.anahita.model.story.data.image', array('src'=>$src, 'alt'=>$alt, 'href'=>$href));
		$this->data['images'][] = $data;
		return $data;
	}
	
	/**
	 * Initialize the object
	 * @return 
	 * @param $options Object
	 */
	protected function  _initialize($options)
	{
		$default = array(
			'data' => array()
		);
		
		return array_merge($default, $options);
	}
	
	/**
	 * Check offset exists in object var $data
	 * @return mixed
	 * @param $offset String
	 */		
	public function offsetExists($offset)
	{
		return isset($this->data[$offset]);
	}
	
	/**
	 * Check offset in $data
	 * @return mixed
	 * @param $offset String
	 */
	public function offsetGet($offset)
	{
		return $this->data[$offset];
	}

	/**
	 * Set offset in $data with $value. $value must implement the interface AnModelStoryDataInterface
	 * @return 
	 * @param $offset Object
	 * @param $value mixed
	 */
	public function offsetSet($offset, $value)
	{
		if ( is_array($value) ) {
			foreach($value as $v) 
				if ( !$v instanceof AnModelStoryDataInterface )
					throw new InvalidArgumentException("$offset must implement interface method AnModelStoryDataInterface");
			
		} else if ( !$value instanceof AnModelStoryDataInterface )
			throw new InvalidArgumentException("$offset must implement interface method AnModelStoryDataInterface");
			
		$this->data[$offset] = $value;
	}
	
	/**
	 * Unset $offset in $data
	 * @return 
	 * @param $offset String
	 */
	public function offsetUnSet($offset)
	{
		unset($this->data[$offset]);
	}
	
	/**
	 * Serial the object for database storage
	 * @return Array 
	 * @param $data AnModelStoryData
	 */
	public function serialize()
	{		
		return array('data' => serialize($this->data));
	}
}
Return current item: Anahita Social Engine