Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/uikit/avatar/controller.php
<?php
/**
 * @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 AnUikitAvatarController extends AnUikitController
{	
	protected $_identifier;
			
	public function __construct($options=array())
	{			
		parent::__construct($options);			
	
		$this->registerFunctionBefore(array('select','add','delete'), 'getActor');
		
		$this->registerFunctionBefore(array('select'), 'setView');
				
		$this->_manager = KFactory::get('lib.anahita.model.avatar.manager');
	}
	
	/**
	 * Render the select
	 * @return 
	 */	
	public function _actionSelect()
	{	
		$this->view->setLayout('select')->assign('actor', $this->getActor())->display();
	}
	
	/**
	 * Set an actor avatar
	 * @return 
	 */	
	public function _actionAdd()
	{
		$file   = KRequest::get('files.avatar_file','raw');

		$data	= AnUtilData::dataWithContentsOfFile($file['tmp_name'], $file['type']);
		
		if ( $this->_manager->setAvatar($this->getActor(), $data) ) {
			
			$this->getApplication()->publishAvatarStory( $this->getActor() );
		}
						
		KFactory::get('lib.anahita.domain.context')->save();		
		
		print KFactory::get('lib.anahita.uikit.actor')->toJson( $this->getActor() );
	}
	
	
	/**
	 * Delete an actor avatar
	 * @return 
	 */
	public function _actionDelete()
	{
		$this->_manager->deleteAvatar($this->getActor());
		
		KFactory::get('lib.anahita.domain.context')->save();
		
		print KFactory::get('lib.anahita.uikit.actor')->toJson( $this->getActor() );
	}
	
	/**
	 * Get the actor using the oid - subclasses can override this method
	 * @return 
	 */	
	public function getActor()
	{
		$package = $this->getIdentifier()->package;
		if ( $package == 'socialengine' ) {
			$model = 'lib.anahita.model.person';
		} else {
			$model = clone $this->getIdentifier();
			$model->path =  array('model');
			$model->name = KInflector::singularize($package);
		}
		$query = KFactory::get('lib.anahita.domain.factory.query')->get($model)->where('id','=', KRequest::get('request.oid', 'cmd', 0));
		$actor = $query->fetch();
		if ( is_null($actor) )
			return false;
		else {
			return $actor;
		}
	}
	
	/**
	 * 
	 * @return 
	 */
	public function setView()
	{
		$path = KLoader::path($this->getView());
		
		if ( !file_exists( $path ) ) {
			
			$this->view = KFactory::get('lib.anahita.uikit.avatar.'.$this->getView()->name);
;
		}		
	}
	

}
Return current item: Anahita Social Engine