Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/model/person/edge/mixin.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 AnModelPersonEdgeMixin extends KMixinAbstract
{	
	/**
	 * 
	 */
	protected $_edges;
	
	/**
	 * 
	 */
	protected $_graph;
	
	/**
	 * 
	 * @return 
	 * @param $options Object[optional]
	 */
	public static function factory(array $options=array())
	{
		$person = $options['mixer'];
		
		if ( !isset($options['edges']) ) {
			
			$query		= KFactory::get('lib.anahita.domain.factory.query')
						->get('lib.anahita.model.person.edge')
					    ->where('nodeA','=',$person)
					    ->where('nodeB','=',$person,'OR')
			;
	
			$options['edges'] = $query->fetchAll();
		}
		
		return new AnModelPersonEdgeMixin( $options );
	}
	
	/**
	 * 
	 * @return 
	 * @param $options Object[optional]
	 */
	public function __construct($options=array())
	{
		parent::__construct($options);
		
		$edges  = $options['edges'];
		
		$person = $this->_mixer;
		
		$this->_edges = array('leading'=>array(),'following'=>array(),'blocking'=>array(),'blocked_by'=>array());
		
		$key = null;		
		$id  = null;
		
		foreach($edges as $edge) {

			if ($person->id == $edge->nodeA->id) {
				$key = $edge->meta == 'block' ?  'blocking'   :   'following';
				$id  = $edge->nodeB->id;
			} else if ($person->id == $edge->nodeB->id) {
				$key = $edge->meta == 'block' ?  'blocked_by' :   'leading';
				$id  = $edge->nodeA->id;	
			} else {
				continue;
			}

			$this->_edges[$key][$id] = $edge;
		}
		
		$this->_graph = KFactory::tmp('lib.anahita.model.person.graph', array('owner'=>$person));
	}
	
	/**
	 * 
	 * @return 
	 * @param $person Object
	 */
	public function disconnect($person)
	{
		return $this->_graph->remove($person);
	}
	
	/**
	 * 
	 * @return 
	 * @param $person Object
	 */
	public function block($person)
	{
		return $this->_graph->add($person,   'block');
	}
	
	/**
	 * 
	 * @return 
	 * @param $person Object
	 */
	public function follow($person)
	{
		return $this->_graph->add($person,    'follow');
	}
	
	/**
	 * 
	 * @return 
	 * @param $person Object
	 */			
	public function canFollow($person)
	{
		return $person->getAcl()->canFollow();
	}
	
	/**
	 * 
	 * @return 
	 * @param $person Object
	 */
	public function canBlock($person)
	{
		return $person->getAcl()->canBlock();
	}
	
	/**
	 * 
	 * @return 
	 * @param $person Object
	 */
	public function isMutuallyLeading($person)
	{
		return $this->leading($person) && $this->following($person);
	}
	
	/**
	 * 
	 * @return 
	 * @param $person Object
	 */
	public function isLeading($person)
	{
		return isset($this->_edges['leading'][$person->id]);
	}
	
	/**
	 * 
	 * @return 
	 * @param $person Object
	 */
	public function isFollowing($person)
	{
		return isset($this->_edges['following'][$person->id]);
	}
	
	/**
	 * 
	 * @return 
	 * @param $person Object
	 */	
	public function isBlocking($person)
	{
		return isset($this->_edges['blocking'][$person->id]);
	}	
	
	/**
	 * 
	 * @return 
	 * @param $person Object
	 */
	public function isBlockedBy($person)
	{	
		return isset($this->_edges['blocked_by'][$person->id]);
	}	
}
Return current item: Anahita Social Engine