class_LospService.inc.php 6.71 KB
<?php
/**
 * @file	LospService.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 LospService extends aServiceStorable {

	//	public function &getBasisElementAddonDataBase($param_BEAName) {
	//		return false;
	//	}

	/**
	 * @var array of the BasisElementAddonDataBase
	 */
	private static $BasisElementAddonDataBaseArray = array();

	/**
	 * return the BasisElementAddonDataBase object
	 */
	public function &getBasisElementAddonDataBase($param_BEAName) {
		if(class_exists($param_BEAName.'BEAS')) {
			if(!array_key_exists($param_BEAName, self::$BasisElementAddonDataBaseArray) || !is_object(self::$BasisElementAddonDataBaseArray[$param_BEAName])) {
				$BEADBName = $param_BEAName.'BEAS';
				self::$BasisElementAddonDataBaseArray[$param_BEAName] = new  $BEADBName();
			}
			return self::$BasisElementAddonDataBaseArray[$param_BEAName];
		} else {
			return false;
		}
	}



	public function &loadObject(&$param_Object, Account &$param_HostAccount=null, $param_Parameter=null) {
		if(is_subclass_of($param_Object, 'iBasisElement') && $param_Object->getObjVar('ID')) {
			$param_Object = &$this->getBasisElement($param_Object->getObjVar('ID'), $param_BasisClipboard=null);

		} else if(is_subclass_of($param_Object, 'BasisClipboard')) {
			if($param_Object->getObjVar('CategoryName')) {
				$var_BasisClipbaordName = get_class($param_Object).'::'.$param_Object->getObjVar('CategoryName');
			} else {
				$var_BasisClipbaordName = get_class($param_Object);
			}

			$var_PartOfBE = &$this->getBasisElement($param_Object->getObjVar('PartOfID'), array($var_BasisClipbaordName => true),$param_Object->getObjVar('ConditionArray'));
			if(is_object($var_PartOfBE)) {
				$var_BasisClipboard =&$var_PartOfBE->getClipboard($param_HostAccount, $this, $var_BasisClipbaordName);
				if(is_subclass_of($var_BasisClipboard, 'BasisClipboard')) {
					$var_BasisClipboard->setObjVar('PartOf', $var_PartOfBE);
					$var_BasisClipboard->setObjVar('PartOfID', $var_PartOfBE->getObjVar('ID'));
					$param_Object =&$var_BasisClipboard;
					//				D::backtrace();
					//				D::show($param_Object, $var_BasisClipboard);
				} else {
					D::li('LospService: laden von '.$param_Object.' fehlgeschlagen');
					return false;
				}
			} else {
				D::li('LospService ist noch nicht für '.$param_Object.' implementiert');
				return false;
			}


		} else {
			//			D::li('LospService ist noch nicht für '.$param_Object.' implementiert');
			return false;
		}
		return $param_Object;
	}
	public function saveObject( &$param_Object, Account &$param_HostAccount=null) {

	}

	private $cURLTools;
	private $bool_Login = false;

	public function __construct(array $param_Data, PDO $param_PDO=null) {
		parent::__construct( $param_Data,  $param_PDO);
		$this->cURLTools = new cURLTools('Temp/cookie.txt');
	}

	public function connect() {
		if($this->ConnectionData['user'] && $this->ConnectionData['passwd'] && $this->ConnectionData['host']) {

			$this->cURLTools->curlLogin($this->ConnectionData['user'],$this->ConnectionData['passwd'],$this->ConnectionData['user'],null,$this->ConnectionData['host']);

		} else {
			D::li('anonym');
			return false;
		}
	}

	public function disconnect() {
		if($this->bool_Login) {
			$this->cURLTools->curlLogout();
			$this->bool_Login = false;
		}
	}

	//	public function getBasisClipboard() {
	//
	//	}

	public function &getBasisElement($param_ID, array $param_BasisClipboardArray=null, array $param_ConditionArray = null, $param_GET = null) {
		//		$this->connect();

		$param_host = $this->getConnectionData('host');
		if($param_host && is_numeric($param_ID)) {

			//			if($param_GET) {
			//				D::show($param_GET, '$param_GET');
			//			}

			$var_uri = LinkGenerator::getServiceLinkString('xml', $param_ID, $param_BasisClipboardArray, $param_ConditionArray, $param_GET);
			$param_host .= '/service.php';

			//D::backtrace($var_uri);
			//D::show($param_BasisClipboardArray);
		}

		/**
		 * @param string|| array GET
		 * @param array POST,
		 * @param string $var_website
		 */
		//D::li(date("H:i:s"). " this->cURLTools->curlReceive(); $param_host  <b>$var_uri</b>");
		//		D::show($param_BasisClipboardArray);
		$string_return = $this->cURLTools->curlReceive($var_uri,null,$param_host);
		if($string_return) {
			$var_SimpleXMLElement  = simplexml_load_string(trim($string_return));
			if(get_class($var_SimpleXMLElement)=='SimpleXMLElement') {
				$result = $var_SimpleXMLElement->xpath('/content/BasisElement');
				if(!empty($result)) {
					$var_attr = $result[0]->attributes();
					$var_classname = (string) $var_attr['class'];

					$var_BEobj =& MultimediaText::getFromMTextArray($var_attr['ID']) ;
					//D::ulli($var_attr['ID'].' +++++++ '.$var_BEobj);
					if($var_BEobj===false) {
						//					$var_BEobj = new $var_classname($this, $var_attr['ID']);
						$var_BEobj = BasisElement::createNewInstance($this, $var_classname,  $var_attr['ID']);
					}



					$var_BEobj->import($result[0]);

					//$ClipboardArray = $var_BEobj->getObjVar('ClipboardArray');
					//if($ClipboardArray['ThreadMessageBC::Blog']) {
					//	$var_addonArray = $ClipboardArray['ThreadMessageBC::Blog']->getObjVar('AddonManager')->getObjVar('AddonArray');
					//	D::li('5. '.$var_addonArray['Category']);
					//}

					return $var_BEobj;
					} else {
						//					D::show($var_SimpleXMLElement, '$var_SimpleXMLElement');
						return false;
					}

				} else {
					D::li('FEHLER: konnte Objekt nicht fernladen');
					D::ulli('$string_return('.$string_return.')');
					return false;
				}
			} else {
				D::li('FEHLER: konnte xml Objekt nicht fernladen');
				D::ulli($param_host.''.$var_uri);
				return false;
			}

			//		$this->disconnect();

	 }

	 public function __deconstruct() {

	 }

	 /**
	  * 	@todo function not implemented for LospService
	  */
	 public function BC_getStates() {
	 	return false;
	 }

	 /**
	  * 	@todo function not implemented for LospService
	  */
	 public function Profile_IDToNickName($ProfileID) {
	 	return $ProfileID;
	 }
	 public function getAllBasisElementIDsForBasisClipboard(){
	 	return array();
	 }
	}
?>