class_InfoboxBEADB.inc.php 6.28 KB
<?php
/**
 * @file	class_InfoboxBEADB.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 InfoboxBEADB extends aBasisElementAddonDataBase {

	protected function loadObjectLight(Account &$param_HostAccount, iStorable &$param_iStorable, aBasisElementAddon & $param_Object, $param_Parameter=null) {

	}

	protected function loadObjectFull(Account &$param_HostAccount, iStorable &$param_iStorable, aBasisElementAddon & $param_Object, $param_Parameter=null) {

		if(is_subclass_of($param_Object->getObjVar('Obj'), 'BasisElement')) {
			$param_Object->setObjVar('BEInfoData', self::getBEInfoData($param_iStorable->getObjVar('SRequest'), $param_Object->getObjVar('Obj')));
			$param_Object->setObjVar('BEHistory', self::getBEHistory($param_iStorable, $param_Object->getObjVar('Obj')));
			$param_Object->setObjVar('BELastEdits', self::getBELastEdits($param_iStorable, $param_Object->getObjVar('Obj')));


			$var_InfoboxConfig = CONFIG::getAddonPreferencs('Infobox', 'Config');

			/**
			 * load the last BasisElement objects which was add on this BasisElement (not from the CONFIG Special NoInfo BasisClipboards)
			 */
			{
				$var_ConditionArray= array(
					'direction' => 'desc',
					'column' => 'CDate',
					'limit' =>'5',
				);

				if(is_array($var_InfoboxConfig) && array_key_exists('Special', $var_InfoboxConfig) && array_key_exists('NoInfo', $var_InfoboxConfig['Special'])) {

					$var_ConditionArray['secConditionArrays'] = array();
					foreach($var_InfoboxConfig['Special']['NoInfo'] as $var_NoBC => $var_null) {
						$FncVar_BasisClipboardnameArray = CONFIG::transformStringToArray($var_NoBC, 'category');
						$var_ConditionArray['secConditionArrays'][] = array(
							'column' => array('PartOfObjVar',),
							'operator' => '!=',
							'from' => array($FncVar_BasisClipboardnameArray[0], ),
							'nexus' => 'AND',
						);
						if( array_key_exists(1, $FncVar_BasisClipboardnameArray) &&  $FncVar_BasisClipboardnameArray[1]) {
							$var_count = count($var_ConditionArray['secConditionArrays'])-1;
							$var_ConditionArray['secConditionArrays'][$var_count]['column'][] = 'CategoryName';
							$var_ConditionArray['secConditionArrays'][$var_count]['from'][] = $FncVar_BasisClipboardnameArray[1];
							$var_ConditionArray['secConditionArrays'][$var_count]['innerNexus'] = 'AND';
						}
					}
				}

				$var_LastBasisElementBC = &BasisClipboard::load($param_HostAccount, $param_iStorable, 'LinkList::SPECIAL:NoPartOfVar', $param_Object->getObjVar('Obj')->getObjVar('ID'), $param_State=null, $var_ConditionArray, $param_PartOfBasisClipboard=false);

				$param_Object->setObjVar('LastBasisElementBC',$var_LastBasisElementBC);
			}

			/**
			 *	load this last BasisElement Objects which was linked from this profil
			 */
			if($param_Object->getObjVar('Obj')->getObjVar('ThisClassName') =='Profile' ){

				$var_ConditionArray['secConditionArrays'][] = array(
					'column' => 'LinkerProfileID',
					'operator' => '=',
					'from' => $param_Object->getObjVar('Obj')->getObjVar('ID'),
					'nexus' => 'AND',
				);
				$var_ConditionArray['secConditionArrays'][] =		array(
					'column' => 'PartOfID',
					'operator' => '!=',
					'from' => $param_Object->getObjVar('Obj')->getObjVar('ID'),
					'nexus' => 'AND',
				);

				$var_LastLinkerBC= &BasisClipboard::load($param_HostAccount, $param_iStorable, 'LinkList::SPECIAL:NoPartOfVar:NoPartOfID', $param_Object->getObjVar('Obj')->getObjVar('ID'), $param_State=null, $var_ConditionArray, $param_PartOfBasisClipboard=false);
				$param_Object->setObjVar('LastLinkerBC',$var_LastLinkerBC);

			}



		} else if (is_subclass_of($param_Object->getObjVar('Obj'), 'BasisClipboard')) {

		}
	}

	public function saveObject(Account &$param_HostAccount, iStorable &$param_iStorable, aBasisElementAddon & $param_Object) {
	}


	private static function getBEInfoData(iBasicSql &$param_DB, BasisElement &$param_Object){
		$var_query = 'select * from losp_BE_SREQUEST_visited where MTextID=\''.$param_Object->getObjVar('ID').'\'';

		$var_result = array();

		$Resource = $param_DB->PDO_query($var_query);
		foreach($param_DB->PDO_fetchAll($Resource) as $row) {
			$var_result[] = $row;
		}

		return $var_result;
	}

	private static function getBELastEdits(iBasicSql &$param_DB, BasisElement &$param_Object) {
		$var_query = 'select * from losp_BE_SREQUEST_history where MTextID=\''.$param_Object->getObjVar('ID').'\' and Action=\'Edit\' order by CDate desc limit 5';

		$var_result = array();

		$Resource = $param_DB->getObjVar('SRequest')->PDO_query($var_query);

		foreach($param_DB->getObjVar('SRequest')->PDO_fetchAll($Resource) as $row) {
			if(array_key_exists('ProfileID',$row)){
				$row['NickName']=Profile::IDToNickName($param_DB, $row['ProfileID']);
			}
			$var_result[] = $row;
		}

		return $var_result;
	}

	private static function getBEHistory(iBasicSql &$param_DB, BasisElement &$param_Object) {
		//		$var_query = 'select * from losp_BE_SREQUEST_history where MTextID=\''.$param_Object->getObjVar('ID').'\' order by CDate desc limit 10;';
		$var_query = 'select ProfileID, MTextID, Action, max(NumberOfAction) as NumberOfAction, Url, CDate from losp_BE_SREQUEST_history where MTextID=\''.$param_Object->getObjVar('ID').'\' group by Action, ProfileID  order by CDate  desc limit 10';

		$var_result = array();

		$Resource = $param_DB->getObjVar('SRequest')->PDO_query($var_query);

		foreach($param_DB->getObjVar('SRequest')->PDO_fetchAll($Resource) as $row) {
			if(array_key_exists('ProfileID',$row)){
				$row['NickName']=Profile::IDToNickName($param_DB, $row['ProfileID']);
			}
			$var_result[] = $row;
		}

		return $var_result;
	}

}
?>