<?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 ComSocialengineControllerPerson extends ComSocialengineControllerBase
{
public function __construct($options=array())
{
parent::__construct($options);
$this->registerAuthentication('edit');
if ( $this->getOwner('id')->isGuest() )
$this->registerAuthentication('read');
$this->registerFunctionBefore(array('read','edit','deletestatus'), 'validateRead');
}
public function validateRead()
{
$owner = $this->getOwner('id');
return !$owner->isGuest();
}
public function _actionBrowse()
{
$params = JComponentHelper::getParams('com_socialengine');
$searchQuery = KRequest::get('get.q', KFactory::get('site::com.socialengine.filter.search'), '');
$people = KFactory::get('lib.anahita.domain.factory.query')
->get('lib.anahita.model.person')
->order('lastvisitDate', 'DESC')
->limit( $this->getLimit(), $this->getOffset() )
->setSearchQuery( $searchQuery )
->fetchAll()
;
$this->view()
->setLayout(KRequest::get('get.layout', 'cmd', 'default'))
->assign('people', $people)
->display();
}
public function _actionRead()
{
$owner = $this->getOwner('id');
if ( KRequest::get('request.layout', 'cmd') == 'edit' && !$owner->getAcl()->canUpdateInformation()) {
return false;
}
$this->view()->assign('owner', $owner)->setLayout(KRequest::get('get.layout', 'cmd', 'default'))->display();
}
public function _actionDeletestatus()
{
$owner = $this->getOwner('id');
if ( !$owner->getAcl()->canUpdateInformation() ) return false;
$owner->status = null;
KFactory::get('lib.anahita.domain.context')->save();
KRequest::set('get.layout','status');
$this->execute('read');
}
public function _actionEdit()
{
$owner = $this->getOwner('id');
$fields = KRequest::get('post.params', 'string');
$data = KRequest::get('post.dateOfBirth', 'string');
if ( $data['year'] || $data['month'] || $data['day'] ) {
$date = new KDate();
$date->year($data['year']);
$date->month($data['month']);
$date->day($data['day']);
$date->hour(0);
$date->minute(0);
$date->second(0);
$fields['dateOfBirth'] = $date;
}
//@TODO run this throuhg the looking for filter
$lookingfor = KRequest::get('post.lookingFor', 'string');
if ( $lookingfor ) {
$fields['lookingFor'] = implode(',', $lookingfor);
}
$updated = array();
foreach($fields as $key => $value) {
$currValue = $owner->information[$key];
if ( $currValue != $value ) {
$updated[] = $key;
$owner->information->setInfo($key, $value);
}
}
$app = $this->getApplication();
$context = KFactory::tmp('lib.koowa.command.context');
if ( $owner->isValid($context) ) {
$story = $app->publishProfileUpdateStory($owner, $updated);
KFactory::get('lib.anahita.domain.context')->save($context);
}
KRequest::set('get.view', 'person.info');
KRequest::set('get.layout', 'default');
$this->execute('read');
}
//end class
}