Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/model/person/person.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 AnModelPerson extends AnModelActor 
{	
	static function describe($model)
	{

		parent::describe($model);

		$model->joinTable('socialengine_people AS person', array('person.socialengine_actor_id'=>self::namespacefield('socialengine_node_id')))
			  ->joinTable('users AS user',	array( 'user.id' => 'person.user_id'), true)
		;
		

		$model->property('userId',			array('field'=>'person.user_id', 'unique'=>true));
		$model->property('userType',		array('field'=>'user.usertype'));
		$model->property('email', 			array('field'=>'user.email'));
		$model->property('lastvisitDate',	array('field'=>'user.lastvisitDate'));
		
		$model->getProperty('author')->setRequired(false);

		$model->property('information', array('class'=>'lib.anahita.model.person.information', 'initialize_with' => array(
							'givenName' => 'person.given_name',
							'familyName' => 'person.family_name',
							'honorificPrefix' => 'person.honorific_prefix',
							'honorificSuffix' => 'person.honorific_suffix',
							'build' => 'person.build',
							'eyeColor' => 'person.eye_color',
							'hairColor' => 'person.hair_color',
							'height' => 'person.height',
							'weight' => 'person.weight',
							'aboutMe' => 'person.about_me',
							'activities' => 'person.activities',
							'books' => 'person.books',
							'cars' => 'person.cars',
							'children' => 'person.children',
							'dateOfBirth' => 'person.date_of_birth',
							'drinker' => 'person.drinker',
							'ethnicity' => 'person.ethnicity',
							'fashion' => 'person.fashion',
							'food' => 'person.food',
							'gender' => 'person.gender',
							'happiestWhen' => 'person.happiest_when',
							'heroes' => 'person.heroes',
							'humor' => 'person.humor',
							'interests' => 'person.interests',
							'jobInterests' => 'person.job_interests',
							'livingArrangement' => 'person.living_arrangement',
							'lookingFor' => 'person.looking_for',
							'movies' => 'person.movies',
							'music' => 'person.music',
							'networkPresence' => 'person.network_presence',
							'nickname' => 'person.nickname',
							'pets' => 'person.pets',
							'politicalViews' => 'person.political_views',
							'profileSong' => 'person.profile_song',
							'profileUrl' => 'person.profile_url',
							'profileVideo' => 'person.profile_video',
							'quotes' => 'person.quotes',
							'relationshipStatus' => 'person.relationship_status',
							'religion' => 'person.religion',
							'romance' => 'person.romance',
							'scaredOf' => 'person.scared_of',
							'sexualOrientation' => 'person.sexual_orientation',
							'smoker' => 'person.smoker',
							'sports' => 'person.sports',
							'turnOffs' => 'person.turn_offs',
							'turnOns' => 'person.turn_ons',
							'tvShows' => 'person.tv_shows',
							'urls' => 'person.urls'
			)));
		
				
		$model->setRepository('lib.anahita.model.person.repository');
		
		$model->setQuery('lib.anahita.model.person.query');
		
		KFactory::get('lib.anahita.model.acl.rules')->add('lib.anahita.model.person', KFactory::tmp('lib.anahita.model.person.acl'));
	}
		
	
	/**
	 * Perform initial operation on the person object once it has been retrieved from the database
	 * @return 
	 */	
	public function awakeFromFetch() 
	{	
		$this->information->setPerson($this);
	}
		
	public function initialize()
	{
		
	}
	
	/**
	 * Return whether this person is a guest
	 * @return BOOL
	 */				
	public function isGuest()
	{
		return $this->userType == 'Guest';	
	}
	
	/**
	 * Return whether this person is an admin of the site
	 * @return BOOL
	 */
	public function isAdmin()
	{		
		return $this->userType == 'Administrator' || $this->userType == 'Super Administrator';
	}
		
	/**
	 * Get person's applications. The applications are the applications that have been added to 
	 * 
	 * person's profile or globally enabled
	 * @return Array
	 */
	public function getApplications()
	{
		if ( !isset($this->_applications) ) {
						
			$query = KFactory::get('lib.anahita.domain.factory.query')->get('lib.anahita.model.application')
			;
			
			$appIdField = KFactory::get('lib.anahita.domain.factory.mapper')->get('lib.anahita.model.application')->getProperty('id')->getField();

			$query->where[] = "a.enabled = 1 AND (component LIKE 'com_socialengine' OR global = 1 OR EXISTS(SELECT added_to_profile FROM #__socialengine_actor_application_relations AS r where r.actor_node_id = {$this->id} AND added_to_profile = 1))";
			$query->order('order','ASC');
			$applications = $query->fetchAll();
					
			$this->_applications = $applications;							
		}
		
		return $this->_applications;
	}
	
	/**
	 * Return this person's socialgraph object. Socialgraph object can be used to retrieve a person's 
	 * followers, leaders, muutla friends
	 * @return AnModelPersonGraph Object
	 */
	public function getSocialGraph()
	{
		return KFactory::tmp('lib.anahita.model.person.graph', array('owner'=>$this));
	}		
	
//end class	
}
Return current item: Anahita Social Engine