class_ProfileMT.inc.php 8.77 KB
<?php
/**
 * @file	Profile.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/>.
 * 
 */

/**
 *	Diese Klasse stellt ein Profil dar,
 *		kann eine Gruppe oder eine Einzelperson sein
 *		dies wird über das Objekt der Klasse @see MultimediaText geregelt
 *
 *	@version 		0.1.0803
 *	@author			dev [at] mensch [dot] coop
 */

class Profile extends ProfilePreferenceManager {

	public static function getCheckWriteColumnValue() {
		self::$checkWriteColumnValue["Profile"] = array();
		return parent::getCheckWriteColumnValue();
	}

	/*
	 * Profile Elements
	 */
	protected 	$NickName 			=	FALSE;
	protected 	$EMail 				=	FALSE;
	protected 	$OnlineState		=	1;
	protected 	$OnlineSince;
	protected	$Fingerprint		= null;
	protected	$Url				= null;
	protected	$Jabber				= null;
	protected	$Avatar				= FALSE;
	protected	$Signature			= FALSE;
	protected	$TopicBEID;
	protected	$MTextID			= FALSE;



	/**
	 *	@var array $MemberProfileIDList[ID] = array( NickName='Nickname' )
	 */
	protected		$MemberProfileIDList = false;

	/* alte Fruppen Funktion
	 * 100214 müsste raus können um
	 */
	private function addProfileIDToMemberProfileIDList($param_ProfileID, $param_NickName='') {

		if(is_array($this->MemberProfileIDList)) {
			$this->MemberProfileIDList = array();
		}

		$this->MemberProfileIDList[$param_ProfileID] = array( 'NickName' => $param_NickName );
	}
	/* alte Fruppen Funktion
	 * 100214 müsste raus können um
	 */
	public function setData(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_Data) {
		if(array_key_exists('CreatorProfileID', $param_Data) && $param_Data['CreatorProfileID']) {
			$this->addProfileIDToMemberProfileIDList($param_Data['CreatorProfileID']);
		}
		return parent::setData($param_HostAccount, $param_iStorable, $param_Data);
	}


	private 	$CountNewMessage = FALSE;
	protected 	$AspirantForGroup 		= FALSE;


	protected	static	$CACHE_IDNickName = array();
	protected	static	$CACHE_IDAvatar = array();
	protected	static	$CACHE_IDSignature = array();

	/**
	 *	Funktion wandelt NickName in Profile ID um
	 *
	 *	@static
	 *
	 *	@param	iBasicSql $param_DB
	 *	@param	String $param_ProfileNickName
	 *	@return Integer
	 *
	 */
	public static function NickNameToID($param_DB, $param_ProfileNickName){
		if(is_numeric($param_ProfileNickName)) {
			return $param_ProfileNickName;
		}
		$var_id = array_search($param_ProfileNickName, self::$CACHE_IDNickName);
		if($var_id) {
		} else {
			$var_id = $param_DB->Profile_NickNameToID($param_ProfileNickName);
			self::$CACHE_IDNickName[$var_id] = $param_ProfileNickName;
		}
		return $var_id;
	}


	/**
	 *	Funktion wandelt Profile ID in NickName um
	 *
	 *	@static
	 *
	 *	@param	iBasicSql $param_DB
	 *	@param	Integer $param_ProfileID
	 *	@return String
	 *
	 */
	public static function IDToNickName($param_DB, $param_ProfileID){
		if($param_ProfileID) {
			if(array_key_exists($param_ProfileID, self::$CACHE_IDNickName)) {
			} else {
				self::$CACHE_IDNickName[$param_ProfileID] = $param_DB->Profile_IDToNickName($param_ProfileID);
			}
			return self::$CACHE_IDNickName[$param_ProfileID];
		} else {
			return false;
		}
	}
	public static function IDToAvatar($param_DB, $param_ProfileID){
		if($param_ProfileID) {
			if(array_key_exists($param_ProfileID, self::$CACHE_IDAvatar)) {
			} else {
				self::$CACHE_IDAvatar[$param_ProfileID] = $param_DB->Profile_IDToAvatar($param_ProfileID);
			}
			return self::$CACHE_IDAvatar[$param_ProfileID];
		} else {
			return false;
		}
	}
	public static function IDToSignature($param_DB, $param_ProfileID){
		if($param_ProfileID) {
			if(array_key_exists($param_ProfileID, self::$CACHE_IDSignature)) {
			} else {
				self::$CACHE_IDSignature[$param_ProfileID] = $param_DB->Profile_IDToSignature($param_ProfileID);
			}
			return self::$CACHE_IDSignature[$param_ProfileID];
		} else {
			return false;
		}
	}

	public function import( $param_ImportData) {
		parent::import( $param_ImportData);
		self::$CACHE_IDNickName[$this->ID] = $this->NickName;
	}


	public function getOnline(){
		$difference = time() - $this->OnlineSince;
		if($difference < 600){		// 600 = 10 minuten
			return true;
		} else {
			return FALSE;
		}
	}


	public function setOnlineState($StateID){
		if($this->ID!=0){
			if($StateID){
				$this->OnlineState = $StateID;
			}
			return $this->DB->Profile_setOnlineState($this->ID, $this->OnlineState);
		} else return Error::newError('DevUser',"Object Account hat keine ID","");
	}


	/**
	 *	Funktion speichert Objekt in die Datenbank
	 */
	public function saveObject(Account &$param_HostAccount, iStorable &$param_iStorable){
		if($this->NickName) {
			return parent::saveObject($param_HostAccount, $param_iStorable);
		} else return Error::newError('UserError',"Fehler beim Speichern der Daten, es existiert kein NickName ","");
	}

	/**
	 * return DOMElement Node for mail (listener)
	 *
	 * @param DOMDocument param_DOMDocument
	 * @return DOMElement
	 */
	public function getDOMElementListener(DOMDocument $param_DOMDocument){
		$DOMElement = $param_DOMDocument->createElement('Listener');
		$DOMElement->setAttribute('ID', $this->ID);


		$DOMElement_NickName =$param_DOMDocument->createElement('Element');
		$DescriptData = self::getFormDataFromDB($this->DB, $this, 'NickName');
		$DOMElement_NickName->setAttribute('form_Length', $DescriptData['Length']);
		$DOMElement_NickName->setAttribute('label', Language::getWord('NickName'));
		$DOMElement_NickName->setAttribute('edit', 'true');
		$DOMElement_NickName->setAttribute('type', $DescriptData['Type']);
		$DOMElement_NickName->setAttribute('objvar', 'Listener_NickName');
		$DOMElement_NickName->setAttribute('show', 'true');
		$DOMElement->appendChild($DOMElement_NickName);


		$DOMElement_Friends =$param_DOMDocument->createElement('MyFriends');
		$DOMElement_Friends->setAttribute('label', Language::getWord('Friends'));
		$DOMElement_Friends->setAttribute('objvar', 'Listener_Friends');
		$DOMElement->appendChild($DOMElement_Friends);

		$DOMElement_MyProfiles =$param_DOMDocument->createElement('MyProfiles');
		$DOMElement_MyProfiles->setAttribute('objvar', 'Listener_Groups');
		$DOMElement_MyProfiles->setAttribute('label', Language::getWord('Groups'));
		$DOMElement->appendChild($DOMElement_MyProfiles);

		return $DOMElement;
	}

	public function getObjDOMElement(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, $param_KindOf=null, array $param_DOMElemente=null) {
//		D::backtrace(1,1,1);
		$DOMElement = parent::getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf, $param_DOMElemente);

		$DOMElement_Child = $DOMElement->appendChild($param_DOMDocument->createElement('Online'));
		$DOMElement_Child->setAttribute('OnlineState', $this->getOnline());
		$DOMElement_Child->setAttribute('label', Language::getWord('OnlineSince'));
		$DOMElement_Child->setAttribute('day', 	date('j', $this->OnlineSince));
		$DOMElement_Child->setAttribute('month',date('n', $this->OnlineSince));
		$DOMElement_Child->setAttribute('year', date('Y', $this->OnlineSince));
		$DOMElement_Child->setAttribute('hour', date('G', $this->OnlineSince));
		$DOMElement_Child->setAttribute('min', 	date('i', $this->OnlineSince));

		if($this->CountNewMessage) {
			$DOMElement->appendChild($param_DOMDocument->createElement('CountNewMessage',$this->CountNewMessage));
		}
		if($this->AspirantForGroup) {
			$DOMElement->appendChild($param_DOMDocument->createElement('AspirantForGroup',$this->AspirantForGroup));
		}
		if($this->ID) {
			$DOMElement->appendChild($param_DOMDocument->createElement("Delete", FALSE));
		}

		return $DOMElement;
	}

	/**
	 * Funktion vermerkt Profil als Aspirant zur Gruppe
	 *
	 * @deprecated bzw Konzept müßte sich überholt haben?!?!?!?!	100316@f
	 *
	 *	@param	iBasicSql $param_DB
	 *	@param	Integer $param_GroupID
	 *	@param	Integer $param_ProfileID
	 *
	 */
	public function requestAspirantWrightRightToMText( Account &$param_HostAccount, iStorable &$param_iStorable, $param_PartOfID=false, $param_PartOfID, $param_State=null){
		$param_iStorable->insertMTextIntoClipboard( $param_HostAccount, $param_PartOfID, $this->ID, "AspirantWriteRight", null, $param_State);
	}


}
?>