Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/uikit/story/controller.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 AnUikitStoryController extends AnUikitController
{
	/**
	 * 
	 * */
	protected $_story_model;
	
	/**
	 * 
	 * */
	protected $_story_comment_model;
			
	/**
	 * 
	 * @return 
	 * @param $options Object
	 */
	public function __construct($options)
	{
		$default = array(
			'story_model' 		  => null,
			'story_comment_model' => 'lib.anahita.model.comment'
		);
		
		$options = array_merge($default, $options);
		
		$this->_story_model 		= $options['story_model'];
		
		$this->_story_comment_model = $options['story_comment_model'];
				
		parent::__construct($options);
		
		KFactory::get('lib.anahita.model.application.context')->setActor( $this->getOwner() );
		
		$this->registerAuthentication(array('delete','comment','add','deleteComment'));
		
		$this->registerFunctionBefore(array('read','delete','comment','deleteComment'), 'getStory');
				
	}
	
	/**
	 * Get a list of owner's stories and assign it to the view
	 * @return 
	 */
	public function _actionBrowse()
	{			
		$owner   = $this->getOwner();
		
		KFactory::get('lib.anahita.model.application.context')->setActor( $owner );
		
		$stories = KFactory::get('lib.anahita.domain.factory.query')
				->get($this->_story_model)
				->where('owner',	  '=',  $owner )
				->order('date', 	  'DESC')
				->limit( $this->getLimit() , $this->getOffset() )
				->fetchAll()
				;
		
		foreach($stories as $story) {			
			$story->mixin( KFactory::tmp('lib.anahita.uikit.story.action.story', array('mixer'=>$story, 'view'=>$this->view())) );
		}
		
		$this->view()->assign('owner', $this->getOwner());
		
		$this->view()->assign('stories', $stories);
		
		parent::_actionBrowse();
	}
	
	/**
	 * Save context and render story after it has been added
	 * @return 
	 * @param $context Object
	 */
	public function _actionAdd($story)
	{
		$context  = KFactory::tmp('lib.koowa.command.context');
		
		if ( KFactory::get('lib.anahita.domain.context')->save($context) ) {
			$story->mixin( KFactory::tmp('lib.anahita.uikit.story.action.story', array('mixer'=>$story, 'view'=>$this->view())) );
			KFactory::get('lib.anahita.uikit.story')->setParentView($this->view())->setStory($story)->setLayout('story_list_item')->display();
		} else 		
			print $context->getError();
	}
		
	/**
	 * Read a story
	 * @return 
	 */
	public function _actionRead()
	{
		$this->story->comments->limit(null);
		$this->story->mixin( KFactory::tmp('lib.anahita.uikit.story.action.story', array('mixer'=>$this->story, 'view'=>$this->view())) );
		parent::_actionRead();
	}
			
	/**
	 * Comment on a story
	 * @return 
	 */
	public function _actionComment()
	{	
		
		$comment = KFactory::get('lib.anahita.domain.factory.model')->get($this->_story_comment_model, array(
			'node'      => $this->story ,
			'author'    => $this->getViewer() ,
			'body'      => KRequest::get('request.body', 'string')
		));
		
		if ( KFactory::get('lib.anahita.domain.context')->save() ) {
			
			$app = $this->getApplication();
			
			$comment->mixin( KFactory::tmp('lib.anahita.uikit.story.action.comment', array('mixer'=>$comment,'view'=>$this->view())) );
						
			KFactory::get('lib.anahita.uikit.comment')
				->setComment($comment)->display();
			
			return $comment;
		}
		
		return false;
	}
		
	/**
	 * Delete a story comment
	 * @return 
	 */
	public function _actionDeletecomment()
	{
		$comment = $this->story->comments
				->where('id','=', KRequest::get('request.cid','int',0))->fetch();
		
		if ( !$comment ) 
			return;
		
		$comment->markDeleted();

		KFactory::get('lib.anahita.domain.context')->save();
	}
		
	/**
	 * Delete a story
	 * @return 
	 */
	public function _actionDelete()
	{
		$this->story->markDeleted();
		
		KFactory::get('lib.anahita.domain.context')->save();
	}
		
	/**
	 * Get Story Filter - If story found, it will set it to the view
	 * @return 
	 */
	public function getStory()
	{
				
		$id 		 = KRequest::get('request.id', 'int', 0);

		$this->story = KFactory::get('lib.anahita.domain.factory.query')->get($this->_story_model)->where('id','=',$id)->fetch();
		
		if ( is_null($this->story) )
			return false;
		
		$this->view()->assign('story', $this->story);
	}
	

}
Return current item: Anahita Social Engine