Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/model/actor/actor.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 AnModelActor extends AnModelNode implements AnModelActorInterface
{
	protected static $_actor_alias; 
	
	static public function namespacefield($string)
	{
		return self::$_actor_alias.'.'.$string;
	}
	
	static function describe($model)
	{
		$name = $model->getModelIdentifier()->name;
		
		self::$_actor_alias = $name == 'actor' ? 'actor' : $model->getModelIdentifier()->name.'_actor';
					
		$model->useTable("socialengine_nodes AS ".self::$_actor_alias);

		$model->property('id', 			  	array('field'=>self::$_actor_alias.'.socialengine_node_id', 'unique'=>true));		
		$model->property('type', 		  	array('field'=>self::$_actor_alias.'.actor_type'));		
		$model->property('profileURL', 		array('field'=>self::$_actor_alias.'.actor_profile_url'));
		$model->property('gender', 		   	array('field'=>self::$_actor_alias.'.actor_gender'));
		$model->property('name'  , 		   	array('required'=>true, 'field'=>self::$_actor_alias.'.actor_title'));
		$model->property('avatar',  	   	array('class'=>'lib.anahita.model.avatar',	  'initialize_with'=>array('name' =>self::$_actor_alias.'.actor_thumbnail_url')));
		;

		
		$model->belongsTo('author',	   array('required'=>true,  'model'=>'lib.anahita.model.actor',	 'child_key'=>self::$_actor_alias.'.created_by'));
		
		$model->belongsTo('editor',	   array('model'=>'lib.anahita.model.actor',	 'child_key'=>self::$_actor_alias.'.modified_by'));
				
		$model->property('status',		  	 		 array('field'=>self::$_actor_alias.'.actor_latest_story','filter'=>'string'));
		
		$model->property('statusUpdatedTime',		 array('class'=>'lib.anahita.type.date', 'initialize_with' => array('date'=>self::$_actor_alias.'.actor_latest_story_created_on')));
		
		$model->belongsTo('application',	  		 array('required'=>true,
						'model'	     => 'lib.anahita.model.application'	   , 
						'child_key'  => self::$_actor_alias.'.actor_component'			   ,
						'parent_key' => 'component'));
		
		$model->setRepository('lib.anahita.model.actor.repository');
		
	}
	
	protected $_avatar_manager;
	

	protected function _registerHooks()
	{
		parent::_registerHooks();
		$this->registerFunctionAfter('insert','__hookSetProfileUrlAfterInsert');
		$this->registerFunctionAfter('delete','__hookDeleteAvatarAfterDelete');
	}
	
	/**
	 * Called when an new actor has been instantiated
	 * @return 
	 */
	public function awakeFromInsert()
	{		
		$this->type = (string) $this->getIdentifier();
	}
	
	/**
	 * Return the title of the actor sanitized using the alias filtered
	 * @return String
	 */
	public function getAlias()
	{
		return KFactory::get('lib.anahita.util.filter.alias')->sanitize($this->name);
	}
		
	/**
	 * update a status of an actor
	 * @return 
	 * @param $status Object
	 */	
	public function setStatus($status)
	{
		$this->_set('status', $status);
		$this->statusUpdatedTime = KFactory::tmp('lib.anahita.type.date');
	}
		
	/**
	 * Set avatar manager
	 * @param $manaer AnModelAvatarManager Object
	 */
	public function setAvatarManager(AnModelAvatarManager $manaer)
	{
		$this->_avatar_manager = $manager;
	}
	
	/**
	 * Get avatar manager
	 * @return AnModelAvatarManager Object
	 */
	public function getAvatarManager()
	{
		if ( !isset($this->_avatar_manager) ) {
			$this->_avatar_manager = KFactory::get('lib.anahita.model.avatar.manager');
		}
		return $this->_avatar_manager;
	}
				
	public function __hookSetProfileUrlAfterInsert()
	{
		$type = new KIdentifier($this->type);
		
		if ( $type->package == 'anahita' )
			$type->package = 'socialengine';
			
		$name = $type->name;
		$id	  = $this->id;
		$component = $type->package;
		$this->profileURL = "index.php?option=com_$component&view=$name&id=$id";
	}
	
	/**
	 * If an actor is deleted, delete it's avatar
	 * @return 
	 * @param $context Object
	 */
	public function __hookDeleteAvatarAfterDelete()
	{
		$this->getAvatarManager()->deleteAvatar($this);
	}
		
//end class	

}
Return current item: Anahita Social Engine