<?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 ComSocialengineControllerSocialgraph extends ComSocialengineControllerBase
{
public function __construct($options=array())
{
parent::__construct($options);
$this->layout = KRequest::get('get.layout','cmd');
$this->person = $this->getOwner('pid');
$this->registerAuthentication(array('add','confirmAdd','remove','confirmRemove'));
$this->registerFunctionBefore(array('add','confirmAdd'), array('validateAdd'));
}
public function _actionBrowse()
{
$this->execute('read');
}
public function _actionRead()
{
if ( $this->getOwner()->isGuest() ) {
$this->authenticate();
return;
}
$params = JComponentHelper::getParams('com_socialengine');
$searchQuery = KRequest::get('get.q', KFactory::get('site::com.socialengine.filter.search'), '');
$owner = $this->getOwner();
$owner->getSocialGraph()
->query()
->setSearchQuery($searchQuery)
->order('lastvisitDate', 'DESC')
->limit( $this->getLimit(), $this->getOffset() )
;
$this->view()->assign('owner', $owner)->setLayout(KRequest::get('get.layout', 'cmd', 'default'))->display();
}
/**
* Method to execute a socialgraph actions
* @param string action { follow, unfollow, block, unblock }
* @return TRUE ON SUCCESS;
*/
public function execute($action = null)
{
if (empty($action)) {
$layout = KRequest::get('get.layout','cmd');
if ( $layout == 'follow' || $layout == 'block' ) {
return parent::execute('confirmAdd');
} else if ($layout == 'unfollow' || $layout == 'unblock' ) {
return parent::execute('confirmRemove');
}
}
return parent::execute($action);
}
public function _actionConfirmremove()
{
$this->_displayConfirmation($this->layout, $this->person);
}
/*
* method to confirm that a person has been added to a socialgraph
* @param string layout name
* @return TRUE ON SUCCESS
*/
public function _actionConfirmadd()
{
$this->_displayConfirmation($this->layout, $this->person);
}
/*
* Method to remove a person from the social graph
* @return ???
*/
public function _actionRemove()
{
$this->getViewer()->disconnect($this->person);
if( KFactory::get('lib.anahita.domain.context')->save() )
print KFactory::get('lib.anahita.uikit.prompt.message')->setBody( sprintf(JText::_('AN-SE-SOCIALGRAPH-UNFOLLOW-FORM-SUCCESS'), $this->person->name));
else
print KFactory::get('lib.anahita.uikit.prompt.error')->setBody(JText::_('AN-SE-PROMPT-SAVED-ERROR'));
}
/*
* Method to add a person to the socialgraph
* @return ???
*/
public function _actionAdd()
{
$edge = $this->getViewer()->{$this->type}($this->person);
$message = KRequest::get('post.optional_message', 'string', null);
if ( $edge && $this->type == 'follow' )
$this->getApplication()
->publishFollowStory($edge->nodeB, $message);
$msg = ($this->type == 'follow') ? JText::_('AN-SE-SOCIALGRAPH-FOLLOW-FORM-SUCCESS') : JText::_('AN-SE-SOCIALGRAPH-BLOCK-FORM-SUCCESS');
if( $edge && KFactory::get('lib.anahita.domain.context')->save() )
print KFactory::get('lib.anahita.uikit.prompt.message')->setBody( sprintf($msg, $this->person->name));
else
print KFactory::get('lib.anahita.uikit.prompt.error')->setBody(JText::_('AN-SE-PROMPT-SAVED-ERROR'));
}
public function validateAdd()
{
if ( KRequest::has('request.block') )
$this->type = KRequest::get('request.block','cmd') ? 'block' : 'follow';
else
$this->type = $this->layout;
$method = 'can'.ucfirst($this->type);
return $this->getViewer()->$method($this->person);
}
/*
* method to display confirmation
* @param STRING layout name
* @param OBJECT person node
*/
protected function _displayConfirmation($layout, $person)
{
$owner = AnModelAnahita::getSessionViewer();
$this->view()->assign(array('owner'=>$owner,'person'=>$person))->setLayout($layout)->display();
}
//end class
}