Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/uikit/comment/form.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
 */

/**
 * Render a comment. The comment must already be mixed with @AnUikitAction to support getActions
 */
class AnUikitCommentForm extends AnUikitViewUikit
{
	/**
	 * Initialize a Comment View
	 * @return 
	 * @param $options Object[optional]
	 */
	public function __construct(array $options=array())
	{
		parent::__construct($options);
		$this->setLayout('form');
	}
	
	public function setNode($node)
	{
		$this->assign('node', $node);
		
		$this->assign('comment', null);
				
		unset($this->form_action);						
			
		$this->assign('form_data', array('action'=>'add','node_id'=>$this->node->id));
		
		return $this;
	}
	
	/**
	 * Set the comment to render
	 * @param $comment AnModelComment
	 */
	public function setComment($comment)
	{		
		$this->assign('comment', $comment);
		return $this;
	}
	
	/**
	 * 
	 * @param $action
	 * @return void
	 */
	public function setFormData($action, $data = array())
	{
		settype($data, 'array');								
		$this->assign('form_action', $action);
		$this->assign('form_data',  array_merge($this->form_data, $data));
		return $this;
	}
	
	/**
	 * 
	 * @param $identifier[optional]
	 * @return mixed
	 */	
	public function loadTemplate( $identifier = null)
	{
		if ( !isset($this->comment) ) {
			$comment = KFactory::get('lib.anahita.domain.factory.model')->get('lib.anahita.model.comment');
			$this->assign('comment', $comment);
		}
		
		//if the form action field is not set then set to addComment or editComment
		//depending if the comment is new or not
		if ( !isset($this->form_data['action']) ) { 				
			$this->form_data['action'] = $comment->isNew() ? 'add' : 'delete';
		}
		
		if ( !isset($this->form_action) ) {
			
			$options = array(		
				'view'	 	=> 'comment' ,
				'component' => 'com_'.$this->node->getIdentifier()->package ,
				'id'		=> $comment->id			
			);
			
			$this->assign('form_action',JRoute::_('index.php?option='.$options['component'].'&view='.$options['view'].'&id='.$options['id']));

		}
		
		return parent::loadTemplate($identifier);
	}
	
//end class	
}
Return current item: Anahita Social Engine