class_CatchInfoboxDataTMC.inc.php 8.68 KB
<?php
/**
 * @file	class_CatchInfoboxDataTMC.inc.php
 * @category freeSN
 * @mailto	code [at] netz.coop
 * @version 0.4.200901
 * @link http://netz.coop
 * 
 *  @copyright Copyright by netz.coop e.G. 2015
 *  
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
class CatchInfoboxDataTMC extends aTreeManipulatorCallback {
	public static $count_callbackFunction = 0;
	public function callbackFunction(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_RootArray, &$param_return) {
		//		D::show($param_RootArray);
		CatchInfoboxDataTMC::$count_callbackFunction++;
		//D::ulli($param_RootArray['ID']);
		if(array_key_exists('ID', $param_RootArray) && $param_RootArray['ID']) {

			if(!is_array($param_return)) {
				$param_return = array();
			}

			if(array_key_exists('result', $param_return) && is_array($param_return['result'])) {
				$var_root = false;
			} else {
				$var_root = true;
				$param_return['result'] = array();
			}

			$var_CurrentElement = array('Action' 	=> 	array());

			$var_CurrentElement['_attributes'] = array();
			foreach($param_RootArray as $fe_key => $fe_value) {
				$var_CurrentElement['_attributes'][$fe_key] = $fe_value;
			}

			/**
			 * showSingle Action
			 */
			{
				$var_result_NumberOfShowSingle = $param_iStorable->getObjVar('SRequest')->getNumberOfShowSingle($param_RootArray['ID']);
				$var_result_LastShowSingleAction = $param_iStorable->getObjVar('SRequest')->getLastAction($param_RootArray['ID'], 'showSingle');

				if(is_array($var_result_NumberOfShowSingle) || is_array($var_result_LastShowSingleAction)) {
					$var_CurrentElement['Action']['showSingle'] = array();
					$var_Language_showSingle = Language::getClassLinks('Infobox', 'showSingle');
				}

				if(is_array($var_result_NumberOfShowSingle)) {
					$var_CurrentElement['Action']['showSingle']['_attributes'] = array('label' =>  $var_Language_showSingle['label'], 'image' =>$var_Language_showSingle['image']) ;

					$var_CurrentElement['Action']['showSingle']['General_NumberOf'] = array();
					$var_CurrentElement['Action']['showSingle']['General_NumberOf']['_attributes'] = array(
																										'label' => 	$var_Language_showSingle['General_NumberOf']['label'],
																										'image' =>	$var_Language_showSingle['General_NumberOf']['image'],
																										'value'=> $var_result_NumberOfShowSingle['Count_General']
					) ;
					$var_CurrentElement['Action']['showSingle']['Login_NumberOf'] = array();
					$var_CurrentElement['Action']['showSingle']['Login_NumberOf']['_attributes'] = array(
																										'label' => 	$var_Language_showSingle['Login_NumberOf']['label'],
																										'image' =>	$var_Language_showSingle['Login_NumberOf']['image'],
																										'value'=> $var_result_NumberOfShowSingle['Count_Login']
					) ;
				}

				if(is_array($var_result_LastShowSingleAction)) {
					$var_CurrentElement['Action']['showSingle']['LastAction'] = array();
					$var_CurrentElement['Action']['showSingle']['LastAction']['_attributes'] = array('label' =>  $var_Language_showSingle['LastAction']['label'], 'image' =>$var_Language_showSingle['LastAction']['image']) ;

					$var_CurrentElement['Action']['showSingle']['LastAction']['ProfileID'] = array();
					$var_CurrentElement['Action']['showSingle']['LastAction']['ProfileID']['_attributes'] = array(
																										'label' => 	$var_Language_showSingle['LastAction']['ProfileID']['label'],
																										'image' =>	$var_Language_showSingle['LastAction']['ProfileID']['image'],
																										'value'=> $var_result_LastShowSingleAction['ProfileID']
					) ;
					$var_CurrentElement['Action']['showSingle']['LastAction']['NickName'] = array();
					$var_CurrentElement['Action']['showSingle']['LastAction']['NickName']['_attributes'] = array(
																										'label' => 	$var_Language_showSingle['LastAction']['NickName']['label'],
																										'image' =>	$var_Language_showSingle['LastAction']['NickName']['image'],
																										'value'=> Profile::IDToNickName($param_iStorable, $var_result_LastShowSingleAction['ProfileID'])
					) ;
					$var_CurrentElement['Action']['showSingle']['LastAction']['CDate'] = array();
					$var_CurrentElement['Action']['showSingle']['LastAction']['CDate']['_attributes'] = array(
																										'label' => 	$var_Language_showSingle['LastAction']['CDate']['label'],
																										'image' =>	$var_Language_showSingle['LastAction']['CDate']['image'],
																										'value'=> $var_result_LastShowSingleAction['CDate']
					) ;
				}
			}

			/**
			 *	edit Action
			 */
			{
				$var_result_LastEditAction = $param_iStorable->getObjVar('SRequest')->getLastAction($param_RootArray['ID'], 'edit');
				if(is_array($var_result_LastEditAction)) {
					$var_Language_Edit = Language::getClassLinks('Infobox', 'edit');
					$var_CurrentElement['Action']['edit'] = array();
					$var_CurrentElement['Action']['edit']['LastAction'] = array();

					$var_CurrentElement['Action']['edit']['LastAction']['_attributes'] = array('label' =>  $var_Language_Edit['LastAction']['label'], 'image' =>$var_Language_Edit['LastAction']['image']) ;

					$var_CurrentElement['Action']['edit']['LastAction']['ProfileID'] = array();
					$var_CurrentElement['Action']['edit']['LastAction']['ProfileID']['_attributes'] = array(
																										'label' => 	$var_Language_Edit['LastAction']['ProfileID']['label'],
																										'image' =>	$var_Language_Edit['LastAction']['ProfileID']['image'],
																										'value'=> $var_result_LastEditAction['ProfileID']
					) ;
					$var_CurrentElement['Action']['edit']['LastAction']['NickName'] = array();
					$var_CurrentElement['Action']['edit']['LastAction']['NickName']['_attributes'] = array(
																										'label' => 	$var_Language_Edit['LastAction']['NickName']['label'],
																										'image' =>	$var_Language_Edit['LastAction']['NickName']['image'],
																										'value'=> Profile::IDToNickName($param_iStorable, $var_result_LastEditAction['ProfileID'])
					) ;
					$var_CurrentElement['Action']['edit']['LastAction']['CDate'] = array();
					$var_CurrentElement['Action']['edit']['LastAction']['CDate']['_attributes'] = array(
																										'label' => 	$var_Language_Edit['LastAction']['CDate']['label'],
																										'image' =>	$var_Language_Edit['LastAction']['CDate']['image'],
																										'value'=> $var_result_LastEditAction['CDate']
					) ;
				}
			}

			{
				$param_ConditionArray = array();
				$param_ConditionArray['column'] = 'CDate';
				$param_ConditionArray['operator'] = '>';

				if(array_key_exists('showSingle', $var_CurrentElement['Action']) && $var_CurrentElement['Action']['showSingle']['LastAction']['CDate']['_attributes']['value']) {
					$var_sinceDateTimoe = $var_CurrentElement['Action']['showSingle']['LastAction']['CDate']['_attributes']['value'];
				} else {
					$var_sinceDateTimoe = MySqlHelper::addToDateTime(MySqlHelper::unixTimestampToDateTime(time()),  CONFIG::getConfig('InfoboxBasisClipboardPeriod'));
				}

				$param_ConditionArray['from'] =  $var_sinceDateTimoe;

				$var_ClipboardIDArray = $param_iStorable->getFromClipboard($param_HostAccount, $param_RootArray['ID'], $param_PartOfObjVar=null, $param_KindOfObj=null, $param_State=null, $param_ConditionArray, $param_checkWrite=null);
				$var_CurrentElement['NewSubElements'] = array();
				foreach($var_ClipboardIDArray as $var_key => $var_value) {
					$var_CurrentElement['NewSubElements'][] = array('_attributes' => $var_value);
					//					$var_CurrentElement['NewSubElements'][] = $var_value;
				}
				//				D::show($var_CurrentElement, '$var_CurrentElement count('.count($var_ClipboardIDArray).')');
				//				D::show($var_ClipboardIDArray);
			}

			if($var_root) {
				$param_return['result']['ROOT'] = $var_CurrentElement;
			} else {

				if(!array_key_exists('CHILDREN', $param_return['result']) || !is_array($param_return['result']['CHILDREN'])) {
					$param_return['result']['CHILDREN'] = array();
				}
				$param_return['result']['CHILDREN'][$param_RootArray['ID']] = $var_CurrentElement;
			}
		}
	}
}
?>