<?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 AnUikitNodeMixin extends KMixinAbstract
{
/**
* Return the viewer which is alwyas a person actor node
* @return
*/
public function getViewer()
{
return AnModelAnahita::getSessionViewer();
}
/**
* Return owner using the id from the request. if $return_viewer_if_null is true, then it will return the viewer if there's no owner
* @return
* @param $request_param String
* @param $return_viewer_if_null Boolean
*/
public function getOwner( $request_param = 'oid' , $return_viewer_if_null = true)
{
$owner = $this->getNode($request_param, 'lib.anahita.model.actor');
if ( is_null($owner) && $return_viewer_if_null)
$owner = $this->getViewer();
return $owner;
}
/**
* Return medium using id from the request parameter
* @param $request_param
* @param $medium_model
* @return AnModelMedium
*/
public function getMedium( $request_param = 'id')
{
return $this->getNode($request_param, 'lib.anahita.model.medium');
}
/**
* Get a node based with id passed by $request_param
*
* @param $request_param
* @return mixed
*/
public function getNode($request_param = 'id', $base_node_identifier = 'lib.anahita.model.node')
{
$id = KRequest::get("request.$request_param", 'int', 0);
$node = null;
if ( $id ) {
try {
$node = KFactory::get('lib.anahita.domain.factory.query')->get( $base_node_identifier )
->where('id','=',$id)
->fetch();
$node = KFactory::get('lib.anahita.domain.factory.query')->get( $node->type )
->where('id','=',$id)
->fetch();
} catch(Exception $e) {
$node = null;
}
}
return $node;
}
}