ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSoapCourseAdministration.php
Go to the documentation of this file.
1<?php
2
26{
27 public const int MEMBER = 1;
28 public const int TUTOR = 2;
29 public const int ADMIN = 4;
30 public const int OWNER = 8;
31
35 public function addCourse(string $sid, int $target_id, string $crs_xml)
36 {
37 $this->initAuth($sid);
38 $this->initIlias();
39
40 if (!$this->checkSession($sid)) {
41 return $this->raiseError($this->getMessage(), $this->getMessageCode());
42 }
43
44 global $DIC;
45
46 $rbacsystem = $DIC['rbacsystem'];
47
48 if (!$target_obj = ilObjectFactory::getInstanceByRefId($target_id, false)) {
49 return $this->raiseError('No valid target given.', 'Client');
50 }
51
52 if (ilObject::_isInTrash($target_id)) {
53 return $this->raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
54 }
55
56 if (!$rbacsystem->checkAccess('create', $target_id, 'crs')) {
57 return $this->raiseError('Check access failed. No permission to create courses', 'Server');
58 }
59
60 $newObj = new ilObjCourse();
61 $newObj->setType('crs');
62 $newObj->setTitle('dummy');
63 $newObj->setDescription("");
64 $newObj->create(); // true for upload
65 $newObj->createReference();
66 $newObj->putInTree($target_id);
67 $newObj->setPermissions($target_id);
68
69 $xml_parser = new ilCourseXMLParser($newObj);
70 $xml_parser->setMode(ilCourseXMLParser::MODE_SOAP);
71 $xml_parser->setXMLContent($crs_xml);
72 $xml_parser->startParsing();
73 return $newObj->getRefId() ?: "0";
74 }
75
79 public function deleteCourse(string $sid, int $course_id)
80 {
81 $this->initAuth($sid);
82 $this->initIlias();
83
84 if (!$this->checkSession($sid)) {
85 return $this->raiseError($this->getMessage(), $this->getMessageCode());
86 }
87
88 global $DIC;
89
90 $rbacsystem = $DIC['rbacsystem'];
91
92 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
93 $ref_ids = ilObject::_getAllReferences($course_id);
94 $course_id = end($ref_ids);
95 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
96 return $this->raiseError(
97 'Invalid course id. Object with id "' . $course_id . '" is not of type "course"',
98 'Client'
99 );
100 }
101 }
102
103 if (!$rbacsystem->checkAccess('delete', $course_id)) {
104 return $this->raiseError('Check access failed. No permission to delete course', 'Server');
105 }
106
107 global $DIC;
108 $tree = $DIC->repositoryTree();
109 $user = $DIC->user();
110 $rbacadmin = $DIC['rbacadmin'];
111 $log = $DIC['log'];
112
113 if ($tree->isDeleted($course_id)) {
114 return $this->raiseError('Node already deleted', 'Server');
115 }
116
117 $subnodes = $tree->getSubTree($tree->getNodeData($course_id));
118 foreach ($subnodes as $subnode) {
119 $rbacadmin->revokePermission($subnode["child"]);
120 }
121 if (!$tree->moveToTrash($course_id, true, $user->getId())) {
122 return $this->raiseError('Node already deleted', 'Client');
123 }
124
125 $log->write("SOAP ilObjectGUI::confirmedDeleteObject(), moved ref_id " . $course_id . " to trash");
126 return true;
127 }
128
132 public function assignCourseMember(string $sid, int $course_id, int $user_id, string $type)
133 {
134 $this->initAuth($sid);
135 $this->initIlias();
136
137 if (!$this->checkSession($sid)) {
138 return $this->raiseError($this->getMessage(), $this->getMessageCode());
139 }
140
141 global $DIC;
142
143 $rbacsystem = $DIC['rbacsystem'];
144
145 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
146 $ref_ids = ilObject::_getAllReferences($course_id);
147 $course_id = end($ref_ids);
148 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
149 return $this->raiseError(
150 'Invalid course id. Object with id "' . $course_id . '" is not of type "course"',
151 'Client'
152 );
153 }
154 }
155
156 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
157 return $this->raiseError('Check access failed. No permission to write to course', 'Server');
158 }
159
160 if (ilObject::_lookupType($user_id) !== 'usr') {
161 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
162 }
163 if ($type !== 'Admin' &&
164 $type !== 'Tutor' &&
165 $type !== 'Member') {
166 return $this->raiseError(
167 'Invalid type given. Parameter "type" must be "Admin", "Tutor" or "Member"',
168 'Client'
169 );
170 }
171
172 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
173 return $this->raiseError('Cannot create course instance!', 'Server');
174 }
175
176 if (!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id, false)) {
177 return $this->raiseError('Cannot create user instance!', 'Server');
178 }
179
180 $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
181
182 switch ($type) {
183 case 'Admin':
184 $settings = new ilSetting();
185 $course_members->add($tmp_user->getId(), ilParticipants::IL_CRS_ADMIN);
186 $course_members->updateNotification(
187 $tmp_user->getId(),
188 (bool) $settings->get('mail_crs_admin_notification', "1")
189 );
190 break;
191
192 case 'Tutor':
193 $course_members->add($tmp_user->getId(), ilParticipants::IL_CRS_TUTOR);
194 break;
195
196 case 'Member':
197 $course_members->add($tmp_user->getId(), ilParticipants::IL_CRS_MEMBER);
198 break;
199 }
200 return true;
201 }
202
206 public function excludeCourseMember(string $sid, int $course_id, int $user_id)
207 {
208 $this->initAuth($sid);
209 $this->initIlias();
210
211 if (!$this->checkSession($sid)) {
212 return $this->raiseError($this->getMessage(), $this->getMessageCode());
213 }
214
215 global $DIC;
216
217 $rbacsystem = $DIC['rbacsystem'];
218
219 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
220 $ref_ids = ilObject::_getAllReferences($course_id);
221 $course_id = end($ref_ids);
222 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
223 return $this->raiseError(
224 'Invalid course id. Object with id "' . $course_id . '" is not of type "course"',
225 'Client'
226 );
227 }
228 }
229
230 if (ilObject::_lookupType($user_id) !== 'usr') {
231 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
232 }
233
234 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
235 return $this->raiseError('Cannot create course instance!', 'Server');
236 }
237
238 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
239 return $this->raiseError('Check access failed. No permission to write to course', 'Server');
240 }
241
242 $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
243 if (!$course_members->checkLastAdmin(array($user_id))) {
244 return $this->raiseError('Cannot deassign last administrator from course', 'Server');
245 }
246 $course_members->delete($user_id);
247 return true;
248 }
249
253 public function isAssignedToCourse(string $sid, int $course_id, int $user_id)
254 {
255 $this->initAuth($sid);
256 $this->initIlias();
257
258 if (!$this->checkSession($sid)) {
259 return $this->raiseError($this->getMessage(), $this->getMessageCode());
260 }
261
262 global $DIC;
263
264 $rbacsystem = $DIC['rbacsystem'];
265
266 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
267 $ref_ids = ilObject::_getAllReferences($course_id);
268 $course_id = end($ref_ids);
269 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
270 return $this->raiseError(
271 'Invalid course id. Object with id "' . $course_id . '" is not of type "course"',
272 'Client'
273 );
274 }
275 }
276
277 if (ilObject::_lookupType($user_id) !== 'usr') {
278 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
279 }
280
282 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
283 return $this->raiseError('Cannot create course instance!', 'Server');
284 }
285
286 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
287 return $this->raiseError('Check access failed. No permission to write to course', 'Server');
288 }
289
290 $crs_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
291
292 if ($crs_members->isAdmin($user_id)) {
294 }
295 if ($crs_members->isTutor($user_id)) {
297 }
298 if ($crs_members->isMember($user_id)) {
300 }
301 return "0";
302 }
303
307 public function getCourseXML(string $sid, int $course_id)
308 {
309 $this->initAuth($sid);
310 $this->initIlias();
311
312 if (!$this->checkSession($sid)) {
313 return $this->raiseError($this->getMessage(), $this->getMessageCode());
314 }
315
316 global $DIC;
317
318 $rbacsystem = $DIC['rbacsystem'];
319
321 $tmp_course = $this->checkObjectAccess($course_id, ['crs'], "read", true);
322 if ($this->isFault($tmp_course)) {
323 return $tmp_course;
324 }
325
326 $xml_writer = new ilCourseXMLWriter($tmp_course);
327 $xml_writer->start();
328 return $xml_writer->getXML();
329 }
330
334 public function updateCourse(string $sid, int $course_id, string $xml)
335 {
336 $this->initAuth($sid);
337 $this->initIlias();
338
339 if (!$this->checkSession($sid)) {
340 return $this->raiseError($this->getMessage(), $this->getMessageCode());
341 }
342
343 global $DIC;
344
345 $rbacsystem = $DIC['rbacsystem'];
346
347 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
348 $ref_ids = ilObject::_getAllReferences($course_id);
349 $course_id = end($ref_ids);
350 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
351 return $this->raiseError(
352 'Invalid course id. Object with id "' . $course_id . '" is not of type "course"',
353 'Client'
354 );
355 }
356 }
357
359 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
360 return $this->raiseError('Cannot create course instance!', 'Server');
361 }
362
363 if (!$rbacsystem->checkAccess('write', $course_id)) {
364 return $this->raiseError('Check access failed. No permission to write course', 'Server');
365 }
366
367 ilCourseParticipants::_deleteAllEntries($tmp_course->getId());
368
369 ilCourseWaitingList::_deleteAll($tmp_course->getId());
370
371
372 $xml_parser = new ilCourseXMLParser($tmp_course);
373 $xml_parser->setMode(ilCourseXMLParser::MODE_SOAP);
374 $xml_parser->setXMLContent($xml);
375 $xml_parser->startParsing();
376 $tmp_course->MDUpdateListener('General');
377
378 return true;
379 }
380
384 public function getCoursesForUser(string $sid, string $parameters)
385 {
386 $this->initAuth($sid);
387 $this->initIlias();
388
389 if (!$this->checkSession($sid)) {
390 return $this->raiseError($this->getMessage(), $this->getMessageCode());
391 }
392
393 global $DIC;
394
395 $rbacreview = $DIC['rbacreview'];
396 $ilObjDataCache = $DIC['ilObjDataCache'];
397 $tree = $DIC['tree'];
398
399 $parser = new ilXMLResultSetParser($parameters);
400 try {
401 $parser->startParsing();
402 } catch (ilSaxParserException $exception) {
403 return $this->raiseError($exception->getMessage(), "Client");
404 }
405 $xmlResultSet = $parser->getXMLResultSet();
406
407 if (!$xmlResultSet->hasColumn("user_id")) {
408 return $this->raiseError("parameter user_id is missing", "Client");
409 }
410
411 if (!$xmlResultSet->hasColumn("status")) {
412 return $this->raiseError("parameter status is missing", "Client");
413 }
414
415 $user_id = (int) $xmlResultSet->getValue(0, "user_id");
416 $status = (int) $xmlResultSet->getValue(0, "status");
417
418 $ref_ids = array();
419
420 if (self::MEMBER == ($status & self::MEMBER) ||
421 self::TUTOR == ($status & self::TUTOR) ||
422 self::ADMIN == ($status & self::ADMIN)) {
423 foreach ($rbacreview->assignedRoles($user_id) as $role_id) {
424 if ($role = ilObjectFactory::getInstanceByObjId($role_id, false)) {
425 #echo $role->getType();
426 if ($role->getType() !== "role") {
427 continue;
428 }
429 if ($role->getParent() == ROLE_FOLDER_ID) {
430 continue;
431 }
432 $role_title = $role->getTitle();
433
434 if ($ref_id = ilUtil::__extractRefId($role_title)) {
436 continue;
437 }
438
439 if (self::MEMBER == ($status & self::MEMBER) && strpos(
440 $role_title,
441 "member"
442 ) !== false) {
443 $ref_ids [] = $ref_id;
444 } elseif (self::TUTOR == ($status & self::TUTOR) && strpos(
445 $role_title,
446 "tutor"
447 ) !== false) {
448 $ref_ids [] = $ref_id;
449 } elseif (self::ADMIN == ($status & self::ADMIN) && strpos(
450 $role_title,
451 "admin"
452 ) !== false) {
453 $ref_ids [] = $ref_id;
454 } elseif (($status & self::OWNER) == self::OWNER && $ilObjDataCache->lookupOwner($ilObjDataCache->lookupObjId($ref_id)) == $user_id) {
455 $ref_ids [] = $ref_id;
456 }
457 }
458 }
459 }
460 }
461 if (($status & self::OWNER) == self::OWNER) {
462 $owned_objects = ilObjectFactory::getObjectsForOwner("crs", $user_id);
463 $refs = [];
464 foreach ($owned_objects as $obj_id) {
465 $allrefs = ilObject::_getAllReferences($obj_id);
466 foreach ($allrefs as $r) {
467 if ($tree->isDeleted($r)) {
468 continue;
469 }
470 if ($tree->isInTree($r)) {
471 $refs[] = $r;
472 }
473 }
474 if (count($refs) > 0) {
475 $ref_ids[] = array_pop($refs);
476 }
477 }
478 }
479 $ref_ids = array_unique($ref_ids);
480
481 $ref_ids = array_unique($ref_ids);
482
483 $xmlResultSet = new ilXMLResultSet();
484 $xmlResultSet->addColumn("ref_id");
485 $xmlResultSet->addColumn("xml");
486 $xmlResultSet->addColumn("parent_ref_id");
487
488 global $DIC;
489
490 $ilUser = $DIC['ilUser'];
491 //#18004
492 // Enable to see own participations by reducing the needed permissions
493 $permission = $user_id === $ilUser->getId() ? 'read' : 'write';
494
495 foreach ($ref_ids as $course_id) {
496 $course_obj = $this->checkObjectAccess($course_id, ['crs'], $permission, true);
497 if ($course_obj instanceof ilObjCourse) {
498 $row = new ilXMLResultSetRow();
499 $row->setValue("ref_id", $course_id);
500 $xmlWriter = new ilCourseXMLWriter($course_obj);
501 $xmlWriter->setAttachUsers(false);
502 $xmlWriter->start();
503 $row->setValue("xml", $xmlWriter->getXML());
504 $row->setValue("parent_ref_id", $tree->getParentId($course_id));
505 $xmlResultSet->addRow($row);
506 }
507 }
508 $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
509 $xmlResultSetWriter->start();
510 return $xmlResultSetWriter->getXML();
511 }
512}
static _getInstanceByObjId(int $a_obj_id)
XML writer class Class to simplify manual writing of xml documents.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getObjectsForOwner(string $object_type, int $owner_id)
returns all objects of an owner, filtered by type, objects are not deleted!
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _isInTrash(int $ref_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupObjId(int $ref_id)
static _deleteAllEntries(int $a_obj_id)
Delete all entries Normally called in case of object deletion.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Setting Class.
raiseError(string $a_message, $a_code)
checkObjectAccess(int $ref_id, array $expected_type, string $permission, bool $returnObject=false)
check access for ref id: expected type, permission, return object instance if returnobject is true
addCourse(string $sid, int $target_id, string $crs_xml)
deleteCourse(string $sid, int $course_id)
assignCourseMember(string $sid, int $course_id, int $user_id, string $type)
getCoursesForUser(string $sid, string $parameters)
excludeCourseMember(string $sid, int $course_id, int $user_id)
static __extractRefId(string $role_title)
extract ref id from role title, e.g.
static _deleteAll(int $a_obj_id)
Row Class for XMLResultSet.
XML Writer for XMLResultSet.
const ROLE_FOLDER_ID
Definition: constants.php:34
$ref_id
Definition: ltiauth.php:66
$log
Definition: ltiresult.php:34
global $DIC
Definition: shib_login.php:26