* @access public
* @modulegroup elearning_interface_modules
* @module Ilias3Soap
* @package ELearning-Interface
*/
class Ilias3Soap extends StudipSoapClient
{
var $cms_type;
var $admin_sid;
var $user_sid;
var $user_type;
var $soap_cache;
var $caching_active = false;
/**
* constructor
*
* init class.
* @access
* @param string $cms system-type
*/
function __construct($cms)
{
global $ELEARNING_INTERFACE_MODULES, $connected_cms;
$this->cms_type = $cms;
parent::__construct($ELEARNING_INTERFACE_MODULES[$cms]["ABSOLUTE_PATH_SOAP"]);
$this->user_type = "admin";
$this->loadCacheData($cms);
}
/**
* set usertype
*
* sets usertype fpr soap-calls
* @access public
* @param string user_type usertype (admin or user)
*/
function setUserType($user_type)
{
$this->user_type = $user_type;
}
/**
* get sid
*
* returns soap-session-id
* @access public
* @return string session-id
*/
function getSID()
{
if ($this->user_type == "admin")
{
if ($this->admin_sid == false)
$this->login();
// echo "a";
return $this->admin_sid;
}
if ($this->user_type == "user")
{
if ($this->user_sid == false)
$this->login();
// echo "u";
return $this->user_sid;
}
return false;
}
/**
* call soap-function
*
* calls soap-function with given parameters
* @access public
* @param string method method-name
* @param string params parameters
* @return mixed result
*/
function call($method, $params)
{
$index = md5($method . ":" . implode($params, "-"));
// return false if no session_id is given
if (($method != "login") AND ($params["sid"] == ""))
return false;
// echo $this->caching_active;
if (($this->caching_active == true) AND (isset($this->soap_cache[$index])))
{
// echo $index;
// echo " from Cache
";
$result = $this->soap_cache[$index];
}
else
{
$result = $this->_call($method, $params);
// if Session is expired, re-login and try again
if (($method != "login") AND $this->soap_client->fault AND in_array(mb_strtolower($this->faultstring), ["session not valid","session invalid", "session idled"]) )
{
// echo "LOGIN AGAIN.";
$caching_status = $this->caching_active;
$this->caching_active = false;
$params["sid"] = $this->login();
$result = $this->_call($method, $params);
$this->caching_active = $caching_status;
}
elseif (! $this->soap_client->fault)
$this->soap_cache[$index] = $result;
}
return $result;
}
/**
* load cache
*
* load soap-cache
* @access public
* @param string cms cms-type
*/
function loadCacheData($cms)
{
$this->soap_cache = (array)$_SESSION["cache_data"][$cms];
}
/**
* get caching status
*
* gets caching-status
* @access public
* @return boolean status
*/
function getCachingStatus()
{
return $this->caching_active;
}
/**
* set caching status
*
* sets caching-status
* @access public
* @param boolean bool_value status
*/
function setCachingStatus($bool_value)
{
$this->caching_active = $bool_value;
// echo "SET:".$this->caching_active."
";
}
/**
* clear cache
*
* clears cache
* @access public
*/
function clearCache()
{
$this->soap_cache = [];
$_SESSION["cache_data"][$this->cms_type] = [];
}
/**
* save cache
*
* saves soap-cache in session-variable
* @access public
*/
function saveCacheData()
{
$_SESSION["cache_data"][$this->cms_type] = $this->soap_cache;
}
/**
* parse xml
*
* use xml-parser
* @access public
* @param string data xml-data
* @return array object
*/
function ParseXML($data)
{
$xml_parser = new Ilias3ObjectXMLParser($data);
$xml_parser->startParsing();
return $xml_parser->getObjectData();
}
/**
* login
*
* login to soap-webservice
* @access public
* @return string result
*/
function login()
{
global $ELEARNING_INTERFACE_MODULES, $connected_cms;
if ($this->user_type == "admin")
$param = [
'client' => $ELEARNING_INTERFACE_MODULES[$this->cms_type]["soap_data"]["client"],
'username' => $ELEARNING_INTERFACE_MODULES[$this->cms_type]["soap_data"]["username"],
'password' => $ELEARNING_INTERFACE_MODULES[$this->cms_type]["soap_data"]["password"]
];
elseif ($this->user_type == "user")
$param = [
'client' => $ELEARNING_INTERFACE_MODULES[$this->cms_type]["soap_data"]["client"],
'username' => $connected_cms[$this->cms_type]->user->getUsername(),
'password' => $connected_cms[$this->cms_type]->user->getPassword()
];
$result = $this->call('login', $param);
if ($this->user_type == "admin")
$this->admin_sid = $result;
if ($this->user_type == "user")
$this->user_sid = $result;
// if ($this->user_type == "user") echo "SID".$this->call('login', $param).$param["username"];
return $result;
}
/**
* logout
*
* logout from soap-webservice
* @access public
* @return boolean result
*/
function logout()
{
$param = [
'sid' => $this->getSID()
];
return $this->call('logout', $param);
}
///////////////////////////
// OBJECT-FUNCTIONS //
//////////////////////////
/**
* search objects
*
* search for ilias-objects
* @access public
* @param array types types
* @param string key keyword
* @param string combination search-combination
* @param string user_id ilias-user-id
* @return array objects
*/
function searchObjects($types, $key, $combination, $user_id = "")
{
$param = [
'sid' => $this->getSID(),
'types' => $types,
'key' => $key,
'combination' => $combination
];
if ($user_id != "")
$param["user_id"] = $user_id;
$result = $this->call('searchObjects', $param);
if ($result != false)
{
$objects = $this->parseXML($result);
$all_objects = [];
foreach($objects as $count => $object_data){
if (is_array($object_data["references"]))
{
foreach($object_data["references"] as $ref_data)
if ($ref_data["accessInfo"] == "granted"
&& (count($all_objects[$object_data["obj_id"]]["operations"]) < count($ref_data["operations"])))
{
$all_objects[$object_data["obj_id"]] = $object_data;
unset($all_objects[$object_data["obj_id"]]["references"]);
$all_objects[$object_data["obj_id"]]["ref_id"] = $ref_data["ref_id"];
$all_objects[$object_data["obj_id"]]["accessInfo"] = $ref_data["accessInfo"];
$all_objects[$object_data["obj_id"]]["operations"] = $ref_data["operations"];
}
}
}
if (count($all_objects)){
foreach($all_objects as $one_object){
$ret[$one_object['ref_id']] = $one_object;
}
return $ret;
}
}
return false;
}
/**
* get object by reference
*
* gets object by reference-id
* @access public
* @param ref reference_id
* @param string user_id ilias-user-id
* @return array object
*/
function getObjectByReference($ref, $user_id = "")
{
$param = [
'sid' => $this->getSID(),
'reference_id' => $ref
];
if ($user_id != "")
$param["user_id"] = $user_id;
$result = $this->call('getObjectByReference', $param);
if ($result != false)
{
$objects = $this->parseXML($result);
foreach($objects as $count => $object_data)
if (is_array($object_data["references"]))
{
foreach($object_data["references"] as $ref_data)
if ($ref_data["accessInfo"] != "object_deleted" && $ref == $ref_data["ref_id"])
{
$all_objects[$ref_data["ref_id"]] = $object_data;
unset($all_objects[$ref_data["ref_id"]]["references"]);
$all_objects[$ref_data["ref_id"]]["ref_id"] = $ref_data["ref_id"];
$all_objects[$ref_data["ref_id"]]["accessInfo"] = $ref_data["accessInfo"];
$all_objects[$ref_data["ref_id"]]["operations"] = $ref_data["operations"];
}
}
return $all_objects[$ref];
}
return false;
}
/**
* get object by title
*
* gets object by title
* @access public
* @param string key keyword
* @param string type object-type
* @return array object
*/
function getObjectByTitle($key, $type = "")
{
$param = [
'sid' => $this->getSID(),
'title' => $key
];
$result = $this->call('getObjectsByTitle', $param);
if ($result != false)
{
$objects = $this->parseXML($result);
foreach($objects as $index => $object_data)
{
if (($type != "") AND ($object_data["type"] != $type))
unset($objects[$index]);
elseif (! (mb_strpos(mb_strtolower($object_data["title"]), mb_strtolower(trim($key)) ) === 0))
unset($objects[$index]);
}
reset($objects);
if (sizeof($objects) > 0)
return current($objects);
}
return false;
}
/**
* get reference by title
*
* gets reference-id by object-title
* @access public
* @param string key keyword
* @param string type object-type
* @return string reference-id
*/
function getReferenceByTitle($key, $type = "")
{
$param = [
'sid' => $this->getSID(),
'title' => $key
];
$result = $this->call('getObjectsByTitle', $param);
if ($result != false)
{
$objects = $this->parseXML($result);
foreach($objects as $index => $object_data)
{
if (($type != "") AND ($object_data["type"] != $type))
unset($objects[$index]);
elseif (mb_strpos(mb_strtolower($object_data["title"]), mb_strtolower(trim($key)) ) === false)
unset($objects[$index]);
}
if (sizeof($objects) > 0)
foreach($objects as $object_data)
if (sizeof($object_data["references"]) > 0)
{
return $object_data["references"][0]["ref_id"];
}
}
return false;
}
/**
* add object
*
* adds new ilias-object
* @access public
* @param array object_data object-data
* @param string ref_id reference-id
* @return string result
*/
function addObject($object_data, $ref_id)
{
$type = $object_data["type"];
$title = htmlReady($object_data["title"]);
$description = htmlReady($object_data["description"]);
$xml = "
".print_r($objects,1); //echo "\n