* @access public
* @modulegroup ilias_interface_modules
* @module IliasSoap
* @package ILIAS-Interface
*/
class IliasSoap extends StudipSoapClient
{
private $index;
private $ilias_client;
private $ilias_version;
private $admin_login;
private $admin_password;
private $admin_sid;
private $user_sid;
private $user_type;
private $soap_cache;
public $separator_string;
private $caching_active = false;
/**
* constructor
*
* init class.
* @access public
* @param string $index ILIAS installation index
* @param string $soap_path SOAP url
* @param string $ilias_client ILIAS client
* @param string $ilias_version ILIAS int client
* @param string $admin_login ILIAS admin account login
* @param string $admin_password ILIAS admin account password
*/
public function __construct($index, $soap_path, $ilias_client = '', $ilias_version = '', $admin_login = '', $admin_password = '', $http_connection_timeout = NULL, $http_request_timeout = NULL)
{
$this->index = $index;
$this->ilias_client = $ilias_client;
$this->ilias_version= $ilias_version;
$this->admin_login = $admin_login;
$this->admin_password = $admin_password;
$this->separator_string = " / ";
$stream_context = get_default_http_stream_context($soap_path);
if (is_int($http_request_timeout)) {
stream_context_set_option(
$stream_context,
'http',
'timeout',
$http_request_timeout
);
}
$options = [
'trace' => 0,
'stream_context' => $stream_context
];
if (is_int($http_connection_timeout)) {
$options['connection_timeout'] = $http_connection_timeout;
}
parent::__construct($soap_path, $options);
$this->user_type = "admin";
$this->loadCacheData();
}
/**
* set usertype
*
* sets usertype for 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->loginAdmin();
return $this->admin_sid;
}
if ($this->user_type == "user") {
if ($this->user_sid == false) {
throw new Exception('Not implemented');
}
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)
{
// return false if no session_id is given
if ($method !== 'login' && $method !== 'getInstallationInfoXML' && $method !== 'getClientInfoXML' && $params['sid'] == '') {
return false;
}
$cache_index = md5($method . ':' . json_encode($params));
if ($this->caching_active && isset($this->soap_cache[$cache_index]) && $method !== 'login') {
$result = $this->soap_cache[$cache_index];
} else {
$result = $this->_call($method, $params);
// if Session is expired, re-login and try again
if ($method !== 'login' && !empty($this->soap_client->fault) && in_array(mb_strtolower($this->faultstring), ['session not valid', 'session invalid', 'session idled'])) {
$caching_status = $this->caching_active;
$this->caching_active = false;
$params["sid"] = $this->getSID();
$result = $this->_call($method, $params);
$this->caching_active = $caching_status;
} elseif (empty($this->soap_client->fault)) {
$this->soap_cache[$cache_index] = $result;
if ($this->caching_active == true) {
$this->saveCacheData();
}
}
}
return $result;
}
/**
* load cache
*
* load soap-cache
* @access public
* @param string cms cms-type
*/
function loadCacheData()
{
$this->soap_cache = (array) ($_SESSION['cache_data'][$this->index] ?? []);
}
/**
* 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;
}
/**
* clear cache
*
* clears cache
* @access public
*/
function clearCache()
{
$this->soap_cache = [];
$_SESSION["cache_data"][$this->index] = [];
}
/**
* save cache
*
* saves soap-cache in session-variable
* @access public
*/
function saveCacheData()
{
$_SESSION["cache_data"][$this->index] = $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 = new ilObjectXMLParser($data);
$xml_parser->startParsing();
return $xml_parser->getObjectData();
}
/**
* login with admin account
*
* login to ILIAS soap webservice with admin account
* @access public
* @return string result
*/
function loginAdmin()
{
$param = [
'client' => $this->ilias_client,
'username' => $this->admin_login,
'password' => $this->admin_password
];
$result = $this->call('login', $param);
$this->admin_sid = $result;
return $result;
}
/**
* login with admin account
*
* login to ILIAS soap webservice with current user
* @access public
* @return string result
*/
function loginUser($username, $password)
{
if ($this->ilias_version < 50305) {
// ILIAS-Versions below 5.3.5 (use LoginStudipUser)
$param = [
'client' => $this->ilias_client,
'username' => $username,
'password' => $password
];
$result = $this->call('loginStudipUser', $param);
$this->user_sid = $result;
return $result;
} else {
// ILIAS-Versions 5.3.5 and above (use StudipAuthPlugin)
$param = [
'client' => $this->ilias_client,
'username' => $username,
'password' => $password
];
$result = $this->call('login', $param);
$this->user_sid = $result;
return $result;
}
}
/**
* logout
*
* logout from soap-webservice
* @access public
* @return boolean result
*/
function logout()
{
$param = [
'sid' => $this->getSID()
];
return $this->call('logout', $param);
}
/**
* Check Auth
*
* login to soap-webservice
* @access public
* @return string result
*/
function checkPassword($username, $password)
{
$param = [
'client' => $this->ilias_client,
'username' => $username,
'password' => $password
];
$result = $this->call('login', $param);
return $result;
}
///////////////////////////
// OBJECT-FUNCTIONS //
//////////////////////////
/**
* parse ILIAS object
*
* parse XML and return ilias object(s)
* @access public
* @param string xml xml data
* @param string parent_id get data for child references of parent_id
* @return array objects
*/
function parseIliasObject($xml, $condition_field = '', $condition_value = '')
{
$s = simplexml_load_string($xml);
$objects = [];
if (is_object($s->Object)) {
foreach ($s->Object as $object) {
$single_object = [];
$single_object['type'] = (string)$object[0]['type'];
$single_object['offline'] = (string)$object[0]['offline'];
$single_object['obj_id'] = (string)$object[0]['obj_id'];
$single_object['title'] = (string)$object->Title;
$single_object['description'] = (string)$object->Description;
$single_object['owner'] = (string)$object->Owner;
$single_object['create_date'] = (string)$object->CreateDate;
$single_object['last_update'] = (string)$object->LastUpdate;
$single_object['ref_count'] = count($object->References);
foreach ($object->References as $reference) {
//$single_object['references'][(string)$reference[0]['ref_id']]['ref_id'] = (string)$reference[0]['ref_id'];
if ($condition_field && ($reference[0][$condition_field] == $condition_value)) {
$single_object['ref_id'] = (string)$reference[0]['ref_id'];
$single_object['parent_id'] = (string)$reference[0]['parent_id'];
$single_object['accessInfo'] = (string)$reference[0]['accessInfo'];
foreach ($reference->Operation as $operation) {
$single_object['operations'][] = (string)$operation;
}
}
$single_object['references'][(string)$reference[0]['ref_id']]['parent_id'] = (string)$reference[0]['parent_id'];
$single_object['references'][(string)$reference[0]['ref_id']]['accessInfo'] = (string)$reference[0]['accessInfo'];
foreach ($reference->Operation as $operation) {
$single_object['references'][(string)$reference[0]['ref_id']]['operations'][] = (string)$operation;
}
foreach ($reference->Path->Element as $element) {
$single_object['references'][(string)$reference[0]['ref_id']]['path_names'][] = (string)$element;
$single_object['references'][(string)$reference[0]['ref_id']]['path_ids'][] = (string)$element[0]['ref_id'];
$single_object['references'][(string)$reference[0]['ref_id']]['path_types'][] = (string)$element[0]['type'];
}
}
if (!empty($single_object['ref_id'])) {
$objects[$single_object['ref_id']] = $single_object;
} elseif (!$condition_field) {
$objects[] = $single_object;
}
}
}
return $objects;
}
/**
* 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,
'user_id' => !empty($user_id) ? (int)$user_id : null
];
$result = $this->call('searchObjects', $param);
if ($result)
{
return $this->parseIliasObject($result);
}
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 = false)
{
$param = [
'sid' => $this->getSID(),
'reference_id' => $ref,
'user_id' => !empty($user_id) ? (int)$user_id : null
];
$result = $this->call('getObjectByReference', $param);
if ($result != false)
{
$objects = $this->parseIliasObject($result, 'ref_id', $ref);
return $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,
'user_id' => null
];
$result = $this->call('getObjectsByTitle', $param);
if ($result != false)
{
$objects = $this->parseIliasObject($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,
'user_id' => null
];
$result = $this->call('getObjectsByTitle', $param);
if ($result != false)
{
$objects = $this->parseIliasObject($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 key($object_data["references"]);
}
}
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)
{
$this->clearCache();
$type = $object_data["type"];
$title = htmlReady($object_data["title"]);
$description = htmlReady($object_data["description"]);
$xml = "
";
$param = [
'sid' => $this->getSID(),
'target_id' => $ref_id,
'object_xml' => $xml
];
return $this->call('addObject', $param);
}
/**
* delete object
*
* deletes ilias-object
* @access public
* @param string ref_id reference-id
* @return boolean result
*/
function deleteObject($reference_id)
{
$this->clearCache();
$param = [
'sid' => $this->getSID(),
'reference_id' => $reference_id
];
return $this->call('deleteObject', $param);
}
/**
* add reference
*
* add a new reference to an existing ilias-object
* @access public
* @param string object_id source-object-id
* @param string ref_id target-id
* @return string created reference-id
*/
function addReference($object_id, $ref_id)
{
$this->clearCache();
$param = [
'sid' => $this->getSID(),
'source_id' => $object_id,
'target_id' => $ref_id
];
return $this->call('addReference', $param);
}
/**
* add references to desktop
*
* adds references to personal desktop
* @access public
* @param string object_id source-object-id
* @param string ref_id target-id
* @return string created reference-id
*/
function addDesktopItems($user_id, $ref_ids)
{
$this->clearCache();
$param = [
'sid' => $this->getSID(),
'user_id' => $user_id,
'reference_ids' => $ref_ids
];
return $this->call('addDesktopItems', $param);
}
/**
* get tree childs
*
* gets child-objects of the given tree node
* @access public
* @param string ref_id reference-id
* @param array types show only childs with these types
* @param string user_id user-id for permissions
* @return array objects
*/
function getTreeChilds($ref_id, $types, $user_id)
{
$param = [
'sid' => $this->getSID(),
'ref_id' => (int)$ref_id,
'types' => (array)$types,
'user_id' => (int)$user_id
];
$result = $this->call('getTreeChilds', $param);
$tree_childs = [];
if ($result != false) {
$tree_childs = $this->parseIliasObject($result, 'parent_id', $ref_id);
}
return $tree_childs;
}
/////////////////////////
// RBAC-FUNCTIONS //
///////////////////////
/**
* get operation
*
* gets all ilias operations
* @access public
* @return array operations
*/
function getOperations()
{
$param = [
'sid' => $this->getSID()
];
$result = $this->call('getOperations', $param);
if (is_array($result))
foreach ($result as $operation_set)
$operations[$operation_set["operation"]] = $operation_set["ops_id"];
return $operations;
}
/**
* get object tree operations
*
* gets permissions for object at given tree-node
* @access public
* @param string ref_id reference-id
* @param string user_id user-id for permissions
* @return array operation-ids
*/
function getObjectTreeOperations($ref_id, $user_id)
{
$param = [
'sid' => $this->getSID(),
'ref_id' => $ref_id,
'user_id' => $user_id
];
$result = $this->call('getObjectTreeOperations', $param);
if ($result != false)
{
$ops_ids = [];
foreach ($result as $operation_set)
$ops_ids[] = $operation_set["ops_id"];
return $ops_ids;
}
return false;
}
/**
* get user roles
*
* gets user roles
* @access public
* @param string user_id user-id
* @return array role-ids
*/
function getUserRoles($user_id)
{
$param = [
'sid' => $this->getSID(),
'user_id' => $user_id
];
$result = $this->call('getUserRoles', $param);
if ($result != false)
{
$objects = $this->parseIliasObject($result);
$roles = [];
foreach ($objects as $count => $role)
$roles[$count] = $role["obj_id"];
return $roles;
}
return false;
}
/**
* get local roles
*
* gets local roles for given object
* @access public
* @param string course_id object-id
* @return array role-objects
*/
function getLocalRoles($course_id)
{
$param = [
'sid' => $this->getSID(),
'ref_id' => $course_id
];
$result = $this->call('getLocalRoles', $param);
if ($result != false)
{
$objects = $this->parseIliasObject($result);
return $objects;
}
return false;
}
/**
* get roles
*
* gets roles of given type for given object
*
* @param string $role_type type of role (global|local|user|user_login|template or empty)
* @param string $id reference id, user id, or -1 for all available roles of given type
* @return array|false role-objects
*/
public function getRoles(string $role_type, string $id)
{
$param = [
'sid' => $this->getSID(),
'role_type' => $role_type,
'id' => $id
];
$result = $this->call('getRoles', $param);
if ($result) {
$s = simplexml_load_string($result);
$role_array = [];
foreach ($s->Role as $role) {
$id_parts = explode('_role_', (string) $role->attributes()->id);
$role_array[$id_parts[1]] = [
'id' => $id_parts[1],
'type' => (string) $role->attributes()->role_type,
'name' => (string) $role->Title,
'description' => (string) $role->Description,
];
}
return $role_array;
}
return false;
}
/**
* add role
*
* adds a new role
* @access public
* @param array role_data data for role-object
* @param string ref_id reference-id
* @return string role-id
*/
function addRole($role_data, $ref_id)
{
$this->clearCache();
$type = "role";
$title = htmlReady($role_data["title"]);
$description = htmlReady($role_data["description"]);
$xml = "
";
$param = [
'sid' => $this->getSID(),
'target_id' => $ref_id,
'obj_xml' => $xml
];
$result = $this->call('addRole', $param);
if (is_array($result))
return current($result);
else
return false;
}
/**
* add role from tremplate
*
* adds a new role and adopts properties of the given role template
* @access public
* @param array role_data data for role-object
* @param string ref_id reference-id
* @param string role_id role-template-id
* @return string role-id
*/
function addRoleFromTemplate($role_data, $ref_id, $role_id)
{
$this->clearCache();
$type = "role";
$title = htmlReady($role_data["title"]);
$description = htmlReady($role_data["description"]);
$xml = "
";
$param = [
'sid' => $this->getSID(),
'target_id' => $ref_id,
'obj_xml' => $xml,
'role_template_id' => $role_id
];
$result = $this->call('addRoleFromTemplate', $param);
if (is_array($result))
return current($result);
else
return false;
}
/**
* delete user role entry
*
* deletes a role entry from the given user
* @access public
* @param string user_id user-id
* @param string role_id role-id
* @return boolean result
*/
function deleteUserRoleEntry($user_id, $role_id)
{
$this->clearCache();
$param = [
'sid' => $this->getSID(),
'user_id' => $user_id,
'role_id' => $role_id
];
return $this->call('deleteUserRoleEntry', $param);
}
/**
* add user role entry
*
* adds a role entry for the given user
* @access public
* @param string user_id user-id
* @param string role_id role-id
* @return boolean result
*/
function addUserRoleEntry($user_id, $role_id)
{
$this->clearCache();
$param = [
'sid' => $this->getSID(),
'user_id' => $user_id,
'role_id' => $role_id
];
return $this->call('addUserRoleEntry', $param);
}
/**
* get users for role entry
*
* returns all users associated with given role id
* @access public
* @param string role_id role-id
* @return array result
*/
function getUsersForRole($role_id)
{
$param = [
'sid' => $this->getSID(),
'role_id' => $role_id,
'attach_roles' => 0,
'active' => 1,
];
$result = $this->call('getUsersForRole', $param);
$user_array = [];
if ($result) {
$s = simplexml_load_string($result);
foreach ($s->User as $user) {
$id_parts = explode('usr_', $user->attributes()->Id);
$user_array[$id_parts[1]] = trim((string)$user->Title . ' ' . (string)$user->Firstname . ' ' .(string)$user->Lastname);
}
}
return $user_array;
}
/**
* grant permissions
*
* grants permissions for given operations at role-id and ref-id
* @access public
* @param array operations operation-array
* @param string role_id role-id
* @param string ref_id reference-id
* @return boolean result
*/
function grantPermissions($operations, $role_id, $ref_id)
{
$this->clearCache();
$param = [
'sid' => $this->getSID(),
'ref_id' => $ref_id,
'role_id' => $role_id,
'operations' => $operations,
];
return $this->call('grantPermissions', $param);
}
/**
* revoke permissions
*
* revokes all permissions role-id and ref-id
* @access public
* @param string role_id role-id
* @param string ref_id reference-id
* @return boolean result
*/
function revokePermissions($role_id, $ref_id)
{
$this->clearCache();
$param = [
'sid' => $this->getSID(),
'ref_id' => $ref_id,
'role_id' => $role_id,
];
return $this->call('revokePermissions', $param);
}
/////////////////////////
// USER-FUNCTIONS //
///////////////////////
/**
* lookup user
*
* gets user-id for given username
* @access public
* @param string username username
* @return string user-id
*/
function lookupUser($username)
{
$param = [
'sid' => $this->getSID(),
'user_name' => $username,
];
return $this->call('lookupUser', $param); // returns user_id
}
/**
* get user
*
* gets user-data for given user-id
* @access public
* @param string $user_id user-id
* @return array user-data
*/
function getUser($user_id)
{
if ($this->ilias_version < 80000) {
$param = [
'sid' => $this->getSID(),
'user_id' => $user_id
];
$result = $this->call('getUser', $param); // returns user data array
return $result;
} else {
$param = [
'sid' => $this->getSID(),
'user_ids' => [$user_id],
'attach_roles' => 0,
];
$result = $this->call('getUserXML', $param); // returns user xml data
if ($result) {
$s = simplexml_load_string($result);
$user_array = [];
foreach ($s->User as $user) {
$id_parts = explode('usr_', $user->attributes()->Id);
if ($id_parts[1] == $user_id) {
$user_array['usr_id'] = $user_id;
$user_array['user_language'] = (string)$user->attributes()->Language;
$user_array['login'] = (string)$user->Login;
$user_array['firstname'] = (string)$user->Firstname;
$user_array['lastname'] = (string)$user->Lastname;
$user_array['title'] = (string)$user->Title;
$user_array['email'] = (string)$user->Email;
$user_array['active'] = (string)$user->Active;
$user_array['authmode'] = (string)$user->AuthMode->attributes()->type;
if (isset($user->UserDefinedField)) {
foreach ($user->UserDefinedField as $field) {
$user_array['udfs'][] = ['id' => (string)$field->attributes()->Id, 'name' => (string)$field->attributes()->Name];
}
}
return $user_array;
}
}
}
return false;
}
}
/**
* get user fullname
*
* gets user-data for given user-id
* @access public
* @param string user_id user-id
* @return string full name
*/
function getUserFullname($user_id)
{
$result = $this->getUser($user_id);
return !empty($result) ? trim(sprintf('%s %s %s', $result['title'], $result['firstname'], $result['lastname'])) : '';
}
/**
* search users
*
* search for ilias users
* @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 searchUser($user_id)
{
if ($user_id != "") {
$param = [
'sid' => $this->getSID(),
'user_ids' => [$user_id],
'attach_roles' => null
];
$result = $this->call('getUserXML', $param);
if ($result != false)
{
$objects = $this->parseIliasObject($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;
}
/**
* add user by importUsers
*
* adds new user and sets role-id
* @access public
* @param array user_data user-data
* @param string role_id global role-id for new user
* @return string user-id
*/
function addUser($user_data, $role_id)
{
$this->clearCache();
foreach($user_data as $key => $value) {
if (!is_array($value)) {
$user_data[$key] = htmlReady($user_data[$key]);
}
}
$update = $user_data["id"];
$usr_xml = "
".$user_data["login"]."
".$user_data["passwd"]."
".$user_data["firstname"]."
".$user_data["lastname"]."
".$user_data["title"]."
".$user_data["gender"]."
".$user_data["email"]."
".$user_data["street"]."
".$user_data["phone_home"]."";
if ($user_data["matriculation"] !== '') {
$usr_xml .= "".(int)$user_data["matriculation"]."";
}
$usr_xml .= "
true
".$user_data["time_limit_unlimited"]."
0
".$user_data["approve_date"]."
".$user_data["agree_date"]."";
if (!empty($user_data['user_skin']) || !empty($user_data['user_style'])) {
$usr_xml .= "";
}
$usr_xml .= "
".$user_data["external_account"]."";
if (array_key_exists('UDF', $user_data) && is_array($user_data['UDF'])) {
foreach ($user_data['UDF'] as $udf_id => $udf_content) {
$usr_xml .= "".htmlReady($udf_content['value'])."";
}
}
$usr_xml .= "
";
$param = [
'sid' => $this->getSID(),
'folder_id' => -1,
'usr_xml' => $usr_xml,
'conflict_rule' => 1,
'send_account_mail' => 0
];
$result = $this->call('importUsers', $param);
$s = simplexml_load_string($result);
if ((string)$s->rows->row->column[3] == "successful")
return (string)$s->rows->row->column[0];
else
return false;
}
///////////////////////////////////////////////////
/**
* copy object
*
* copy ilias-object
* @access public
* @param string source_id reference-id
* @param string target_id reference-id
* @return string result
*/
function copyObject($source_id, $target_id)
{
$this->clearCache();
$xml = "";
$param = [
'sid' => $this->getSID(),
'xml' => $xml
];
return $this->call('copyObject', $param);
}
/**
* get structure
*
* returns structure for ilias content object
* @access public
* @param string ref_id reference id
* @return array result
*/
function getStructure($ref_id)
{
$param = [
'sid' => $this->getSID(),
'ref_id' => $ref_id
];
$result = $this->call('getStructureObjects', $param);
$structure = [];
if ($result) {
$s = simplexml_load_string($result);
foreach ($s->StructureObjects->StructureObject as $object) {
$structure[] = (string)$object->Title;
}
}
return $structure;
}
/**
* get path
*
* returns repository-path to ilias-object
* @access public
* @param string ref_id reference id
* @return string result
*/
function getPath($ref_id)
{
$param = [
'sid' => $this->getSID(),
'ref_id' => $ref_id
];
$result = $this->call('getPathForRefId', $param);
if ($result) {
$s = simplexml_load_string($result);
foreach ($s->rows->row as $row) {
$path[] = (string)$row->column[2];
}
}
if (is_array($path)) {
return implode($this->separator_string, $path);
} else {
return false;
}
}
/**
*
* returns repository-path to ilias-object
*
* @access public
* @param string ref_id reference id
* @return string result
*/
function getRawPath($ref_id)
{
$param = [
'sid' => $this->getSID(),
'ref_id' => $ref_id
];
$result = $this->call('getPathForRefId', $param);
if ($result) {
$s = simplexml_load_string($result);
foreach ($s->rows->row as $row) {
$path[] = (string)$row->column[0];
}
}
if (is_array($path)) {
return implode('_', $path);
} else {
return false;
}
}
/**
*
* returns ILIAS-Server-Info
*
* @access public
* @return string result
*/
function getInstallationInfoXML()
{
$data = [];
$this->clearCache();
$param = [
];
$result = $this->call('getInstallationInfoXML', $param);
if ($result) {
$s = simplexml_load_string($result);
$version_info = (string)$s[0]['version'];
$version_parts = explode(' ', $version_info);
$data['version'] = $version_parts[0];
$data['version_date'] = $version_parts[1];
foreach($s->Clients->Client as $client) {
$data['clients'][] = (string)$client[0]['id'];
}
}
return $data;
}
//////////////////////////////////////////
/**
* update user
*
* update user-data
* @access public
* @param array user_data user-data
* @return string result
*/
/* function updateUser($user_data)
{
$this->clearCache();
$param = array(
'sid' => $this->getSID(),
'user_data' => $user_data
);
return $this->call('updateUser', $param); // returns boolean
}
/**/
/**
* update password
*
* update password with given string and write it uncrypted to the ilias-database
* @access public
* @param string user_id user-id
* @param string password password
* @return string result
*/
/* function updatePassword($user_id, $password)
{
$this->clearCache();
$param = array(
'sid' => $this->getSID(),
'user_id' => $user_id,
'new_password' => $password
);
return $this->call('updatePassword', $param); // returns boolean
}
/**/
/**
* delete user
*
* deletes user-account
* @access public
* @param string $user_id user-id
* @return string result
*/
function deleteUser($user_id)
{
$this->clearCache();
if ($this->ilias_version < 80000) {
$param = [
'sid' => $this->getSID(),
'user_id' => $user_id
];
return $this->call('deleteUser', $param); // returns boolean
} else {
$user_data = $this->getUser($user_id);
if (!$user_data['login']) {
return false;
}
$usr_xml = '
' . $user_data['login'] . '
';
$param = [
'sid' => $this->getSID(),
'folder_id' => -1,
'usr_xml' => $usr_xml,
'conflict_rule' => 1,
'send_account_mail' => 0
];
$result = $this->call('importUsers', $param);
$s = simplexml_load_string($result);
if ((string)$s->rows->row->column[3] == "successful") {
return (string)$s->rows->row->column[0];
}
return false;
}
}
////////////////////////////
// COURSE-FUNCTIONS //
//////////////////////////
/**
* is course member
*
* checks if user is course-member
* @access public
* @param string user_id user-id
* @param string course_id course-id
* @return boolean result
*/
function isMember($user_id, $course_id)
{
$param = [
'sid' => $this->getSID(),
'course_id' => $course_id,
'user_id' => $user_id
];
$status = $this->call('isAssignedToCourse', $param); // returns 0 if not assigned, 1 => course admin, 2 => course member or 3 => course tutor
if ($status == 0)
return false;
else
return true;
}
/**
* add course member
*
* adds user to course
* @access public
* @param string user_id user-id
* @param string type member-type (Admin, Tutor or Member)
* @param string course_id course-id
* @return boolean result
*/
function addMember($user_id, $type, $course_id)
{
$this->clearCache();
$param = [
'sid' => $this->getSID(),
'course_id' => $course_id,
'user_id' => $user_id,
'type' => $type
];
return $this->call('assignCourseMember', $param);
}
/**
* add course
*
* adds course
* @access public
* @param array course_data course-data
* @param string ref_id target-id
* @return string course-id
*/
function addCourse($course_data, $ref_id)
{
$this->clearCache();
foreach($course_data as $key => $value) {
$course_data[$key] = htmlReady($course_data[$key]);
}
$xml = $this->getCourseXML($course_data);
$param = [
'sid' => $this->getSID(),
'target_id' => $ref_id,
'crs_xml' => $xml
];
$crs_id = $this->call('addCourse', $param);
return $crs_id;
}
/**
* add group
*
* adds group
* @access public
* @param array group_data group data
* @param string ref_id target id
* @return string group id
*/
function addGroup($group_data, $ref_id)
{
$this->clearCache();
foreach($group_data as $key => $value) {
$group_data[$key] = htmlReady($group_data[$key]);
}
$xml = $this->getGroupXML($group_data);
$param = [
'sid' => $this->getSID(),
'target_id' => $ref_id,
'group_xml' => $xml
];
$group_id = $this->call('addGroup', $param);
return $group_id;
}
/**
* update group
*
* updates group
* @access public
* @param array group_data group data
* @param string ref_id group id
* @return string result
*/
function updateGroup($group_data, $ref_id)
{
$this->clearCache();
foreach($group_data as $key => $value) {
$group_data[$key] = htmlReady($group_data[$key]);
}
$xml = $this->getGroupXML($group_data);
$param = [
'sid' => $this->getSID(),
'ref_id' => $ref_id,
'xml' => $xml
];
$result = $this->call('updateGroup', $param);
return $result;
}
/**
* assign group member
*
* assigns user to group
* @access public
* @param string group_id group id
* @param string user_id user id
* @param string type type
*/
function assignGroupMember($group_id, $user_id, $type = "Member")
{
$this->clearCache();
$param = [
'sid' => $this->getSID(),
'group_id' => $group_id,
'user_id' => $user_id,
'type' => $type
];
return $this->call('assignGroupMember', $param);
}
/**
* exclude group member
*
* removes user from group
* @access public
* @param string group_id group id
* @param string user_id user id
*/
function excludeGroupMember($group_id, $user_id)
{
$this->clearCache();
$param = [
'sid' => $this->getSID(),
'group_id' => $group_id,
'user_id' => $user_id
];
return $this->call('excludeGroupMember', $param);
}
/**
* get group
*
* returns group xml
* @access public
* @param string group_id group id
* @return string group xml
*/
function getGroup($group_id)
{
$param = [
'sid' => $this->getSID(),
'ref_id' => $group_id
];
$result = $this->call('getGroup', $param);
if ($result) {
$s = simplexml_load_string($result);
$data['title'] = (string)$s->title;
$data['members'] = [];
foreach($s->member as $member) {
$member_parts = explode('_usr_', (string)$member[0]['id']);
$data['members'][] = $member_parts[1];
}
}
return $data;
}
/**
* get course-xml
*
* gets course xml-object for given course-data
* @access public
* @param array course_data course-data
* @return string course-xml
*/
function getCourseXML($course_data)
{
$crs_language = $course_data["language"];
$crs_admin_id = $course_data["admin_id"];
$crs_title = $course_data["title"];
$crs_desc = $course_data["description"];
$xml = "
$crs_title
$crs_desc
";
return $xml;
}
/**
* get group xml
*
* gets group xml object for given group data
* @access public
* @param array group_data group data
* @return string group xml
*/
function getGroupXML($group_data)
{
$xml = '
'.$group_data['title'].'
0
0
0
1
0
0
1
0
0
0
0
0
0
0
';
return $xml;
}
/**/
/**
* get courses for given user
*
* gets course xml-object for given course-data
* @access public
* @param array course_data course-data
* @return string course-xml
*/
function getCoursesForUser($user_id, $status = 1)
{
$xmlrs = '
'.$user_id.'
'.$status.'
';
$param = array(
'sid' => $this->getSID(),
'parameters' => $xmlrs
);
$result = $this->call('getCoursesForUser', $param);
if ($result) {
$s = simplexml_load_string($result);
foreach ($s->rows->row as $row) {
$ref_id = (string)$row->column[0];
$s2 = simplexml_load_string((string)$row->column[1]);
if (is_object($s2->MetaData)) {
$ret[$ref_id] = trim($s2->MetaData->General->Title);
}
}
}
if (!empty($ret)) {
return $ret;
} else {
return false;
}
}
/**
* get courses for given user by status
*
* gets course array for given course data
* @access public
* @param string $user_id ilias user id
* @param string $status MEMBER = 1, TUTOR = 2, ADMIN = 4, OWNER = 8
* @return array course array
*/
public function getCoursesForUserStatus(string $user_id, string $status): array
{
$courses = [];
$xmlrs = '
'.$user_id.'
'.$status.'
';
$param = [
'sid' => $this->getSID(),
'parameters' => $xmlrs
];
$result = $this->call('getCoursesForUser', $param);
if ($result) {
$s = simplexml_load_string($result);
foreach ($s->rows->row as $row) {
$ref_id = (string)$row->column[0];
$courses[$ref_id] = [];
$courses[$ref_id]['title'] = (string)$row->column[2];
$s2 = simplexml_load_string((string)$row->column[1]);
$courses[$ref_id]['title'] = trim((string)$s2->MetaData->General->Title);
$courses[$ref_id]['description'] = trim((string)$s2->MetaData->General->Description);
$courses[$ref_id]['status_text'] = '';
$courses[$ref_id]['status'] = $status;
switch ($status) {
case 1:
$courses[$ref_id]['status_text'] = _('Kursmitglied');
break;
case 2:
$courses[$ref_id]['status_text'] = _('Kurstutor/-in');
break;
case 4:
$courses[$ref_id]['status_text'] = _('Kursadministrator/-in');
break;
}
if (isset($s2->Settings->Availability->Unlimited)) {
$courses[$ref_id]['online'] = 1;
} elseif (isset($s2->Settings->Availability->NotAvailable)) {
$courses[$ref_id]['online'] = 0;
} else {
$courses[$ref_id]['online'] = 1;
}
$courses[$ref_id]['availability'] = $s2->Settings->Availability;
}
}
return $courses;
}
/**
* check reference by title
*
* gets reference id by object id
* @access public
* @param string key keyword
* @param string type object-type
* @return string reference-id
*/
function checkReferenceById($id)
{
$param = [
'sid' => $this->getSID(),
'reference_id' => $id,
'user_id' => null
];
$result = $this->call('getObjectByReference', $param);
if ($result != false)
{
$objects = $this->parseIliasObject($result);
if(is_array($objects)){
foreach($objects as $index => $object_data){
if(is_array($object_data['references'])){
foreach($object_data['references'] as $ref_id => $reference){
if($ref_id == $id && $reference['accessInfo'] != 'object_deleted') return $object_data['obj_id'];
}
}
}
}
}
return false;
}
/**
* @param string $ref_id
* @param bool $sum_only
* @return array|false
* @throws Exception
*/
public function getTestResults($ref_id, $sum_only = true)
{
$param = [
'sid' => $this->getSID(),
'ref_id' => $ref_id,
'sum_only' => $sum_only
];
$result = $this->call('getTestResults', $param);
if ($result !== false) {
$columns = [];
$data = [];
$xml = simplexml_load_string($result);
foreach ($xml->colspecs->colspec as $colspec) {
$columns[] = (string)$colspec['name'];
}
foreach ($xml->rows->row as $row) {
$data_row = [];
$i = 0;
foreach ($row->column as $column) {
$data_row[$columns[$i++]] = (string)$column;
}
if (isset($data_row['user_id'])) {
}
$data[] = $data_row;
}
return $data;
}
return false;
}
}