Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/model/story/template/template.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 AnModelStoryTemplate extends AnModelStoryTemplateAbstract
{	
	/**
	 * Template title
	 * 
	 * @var string
	 */		
	protected $_title;
	
	/**
	 * Template body
	 * 
	 * @var string
	 */
	protected $_body;	
	
	/**
	 * Template component
	 * 
	 * @var string
	 */
	protected $_component;
	
	/**
	 * Template icon url
	 * 
	 * @var string
	 */
	protected $_icon;
		
	/**
	 * 
	 * @var string
	 */
	protected $_commentable;
	
	
	/**
	 * hide the story of this template
	 * 
	 * @var boolean
	 */
	protected $_hide;
	
	/**
	 * Return a new template object
	 * @return AnModelStoryTemplate
	 * @param $options array
	 */	
	public static function factory($options)
	{
		$default = array(
			'name' 		=> null,
			'component' => null,
			'type'      => null
		);
		
		$options = array_merge($default, $options);
		
		if ( !$options['name'] || !$options['component'] || !$options['type'] ) {
			return new AnModelStoryTemplate();
		}
		
		$app = KFactory::get('lib.anahita.domain.factory.repository')
				->get('lib.anahita.model.application')
				->getApplicationByComponent( $options['component'] );

		$template = null;
		
		if ( $app )	
			$template = $app->getStoryTemplate($options['type'], $options['name']);
		
		if ( !$template ) 
			$template = new AnModelStoryTemplate();
			
		return $template;
	}
	
	/**
	 * 
	 * @return 
	 * @param $options Object[optional]
	 */
	public function __construct($options=array())
	{
		$options = $this->_initialize($options);
		
		$this->_name      = $options['name'];

		$this->_title     = JText::_($options['title']);
		
		$this->_sub_title = $options['sub_title'];
		
		$this->_body 	  = JText::_($options['body']);
		
		$this->_type	  = $options['type'];
		
		$this->_icon	  = $options['icon'];
		
		$this->_component = $options['component'];
		
		$this->_commentable = $options['commentable'];
		
		$this->_hide	    = $options['hide'];
		
	}
	
	/**
	 * 
	 * @return 
	 * @param $options Object
	 */
	protected function _initialize($options)
	{
		$default = array(
			'body'  	=> '',
			'title' 	=> '',
			'sub_title' => '',
			'type'  => '',
			'name'	=> '',
			'icon'  => null,
			'commentable' => true,
			'component'   => ''  ,
			'hide'		  => false
		);
		
		return array_merge($default, $options);
	}
		
	/**
	 * Return component
	 * @return 
	 */
	public function getComponent()
	{
		return $this->_component;
	}
		
	/**
	 * 
	 * @return string
	 */
	public function getTitle()
	{
		return $this->_title;
	}
	
	/**
	 * 
	 * @return string
	 */
	public function getSubTitle()
	{
		return $this->_sub_title;
	}
	
	/**
	 * Return body
	 * @return string
	 */
	public function getBody()
	{
		return $this->_body;
	}
	
	/**
	 * Return icon url
	 * @return 
	 */
	public function getIcon()
	{		
		return $this->_icon;
	}
	
	/**
	 * 
	 * @return 
	 */
	public function isCommentable()
	{
		return $this->_commentable;
	}
	
	/**
	 * Serialize Template information for database storage
	 * @return 
	 * @param $object Object
	 */
	public function serialize()
	{
		return array('component'=>$this->getComponent(), 'type'=>$this->getType(), 'name'=>$this->getName());
	}
	
	/**
	 * Parse the title of the template using the story data
	 * @return 
	 * @param $story Object
	 */
	public function parseTitle($story)
	{
		$title = $this->getTitle();
		$this->_parse($title, $story);
		return $title;
	}
	
	/**
	 * Parse the subtitle of the template using the story data
	 * @return 
	 * @param $story Object
	 */	
	public function parseSubTitle($story)
	{
		$sub_title = $this->_sub_title;
		$this->_parse($sub_title, $story);
		return $sub_title;
	}
		
	/**
	 * Parse the body of the template using the story data
	 * @return 
	 * @param $story Object
	 */
	public function parseBody($story)
	{
		$body    = $this->getBody();
		$this->_parse($body, $story);
		return $body;
	}	

}
Return current item: Anahita Social Engine