ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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(
133 string $sid,
134 int $course_id,
135 int $user_id,
136 string $type,
137 ?bool $notification = null,
138 ?bool $contact_person = null,
139 ?bool $blocked = null
140 ) {
141 $this->initAuth($sid);
142 $this->initIlias();
143
144 if (!$this->checkSession($sid)) {
145 return $this->raiseError($this->getMessage(), $this->getMessageCode());
146 }
147
148 global $DIC;
149
150 $rbacsystem = $DIC['rbacsystem'];
151
152 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
153 $ref_ids = ilObject::_getAllReferences($course_id);
154 $course_id = end($ref_ids);
155 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
156 return $this->raiseError(
157 'Invalid course id. Object with id "' . $course_id . '" is not of type "course"',
158 'Client'
159 );
160 }
161 }
162
163 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
164 return $this->raiseError('Check access failed. No permission to write to course', 'Server');
165 }
166
167 if (ilObject::_lookupType($user_id) !== 'usr') {
168 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
169 }
170 $valid_roles = [
174 ];
175 if (!isset($valid_roles[$type])) {
176 return $this->raiseError('Invalid type. Must be "Admin", "Tutor", or "Member"', 'Client');
177 }
178
179 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
180 return $this->raiseError('Cannot create course instance!', 'Server');
181 }
182
183 if (!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id, false)) {
184 return $this->raiseError('Cannot create user instance!', 'Server');
185 }
186
187 $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
188
189 $course_members->add($tmp_user->getId(), $valid_roles[$type]);
190
191 $course_members->sendNotification(
193 $tmp_user->getId()
194 );
195
196 if ($type === 'Admin' || $type === 'Tutor') {
197 if ($notification !== null) {
198 $course_members->updateNotification($tmp_user->getId(), $notification);
199 }
200
201 if ($contact_person !== null) {
202 $course_members->updateContact($tmp_user->getId(), $contact_person);
203 }
204 } elseif ($type === "Member" && $blocked !== null) {
205 $course_members->updateBlocked($tmp_user->getId(), $blocked);
206 }
207 return true;
208 }
209
213 public function excludeCourseMember(string $sid, int $course_id, int $user_id)
214 {
215 $this->initAuth($sid);
216 $this->initIlias();
217
218 if (!$this->checkSession($sid)) {
219 return $this->raiseError($this->getMessage(), $this->getMessageCode());
220 }
221
222 global $DIC;
223
224 $rbacsystem = $DIC['rbacsystem'];
225
226 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
227 $ref_ids = ilObject::_getAllReferences($course_id);
228 $course_id = end($ref_ids);
229 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
230 return $this->raiseError(
231 'Invalid course id. Object with id "' . $course_id . '" is not of type "course"',
232 'Client'
233 );
234 }
235 }
236
237 if (ilObject::_lookupType($user_id) !== 'usr') {
238 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
239 }
240
241 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
242 return $this->raiseError('Cannot create course instance!', 'Server');
243 }
244
245 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
246 return $this->raiseError('Check access failed. No permission to write to course', 'Server');
247 }
248
249 $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
250 if (!$course_members->checkLastAdmin(array($user_id))) {
251 return $this->raiseError('Cannot deassign last administrator from course', 'Server');
252 }
253 $course_members->delete($user_id);
254 return true;
255 }
256
260 public function isAssignedToCourse(string $sid, int $course_id, int $user_id)
261 {
262 $this->initAuth($sid);
263 $this->initIlias();
264
265 if (!$this->checkSession($sid)) {
266 return $this->raiseError($this->getMessage(), $this->getMessageCode());
267 }
268
269 global $DIC;
270
271 $rbacsystem = $DIC['rbacsystem'];
272
273 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
274 $ref_ids = ilObject::_getAllReferences($course_id);
275 $course_id = end($ref_ids);
276 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
277 return $this->raiseError(
278 'Invalid course id. Object with id "' . $course_id . '" is not of type "course"',
279 'Client'
280 );
281 }
282 }
283
284 if (ilObject::_lookupType($user_id) !== 'usr') {
285 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
286 }
287
289 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
290 return $this->raiseError('Cannot create course instance!', 'Server');
291 }
292
293 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
294 return $this->raiseError('Check access failed. No permission to write to course', 'Server');
295 }
296
297 $crs_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
298
299 if ($crs_members->isAdmin($user_id)) {
301 }
302 if ($crs_members->isTutor($user_id)) {
304 }
305 if ($crs_members->isMember($user_id)) {
307 }
308 return "0";
309 }
310
314 public function getCourseXML(string $sid, int $course_id)
315 {
316 $this->initAuth($sid);
317 $this->initIlias();
318
319 if (!$this->checkSession($sid)) {
320 return $this->raiseError($this->getMessage(), $this->getMessageCode());
321 }
322
323 global $DIC;
324
325 $rbacsystem = $DIC['rbacsystem'];
326
328 $tmp_course = $this->checkObjectAccess($course_id, ['crs'], "read", true);
329 if ($this->isFault($tmp_course)) {
330 return $tmp_course;
331 }
332
333 $xml_writer = new ilCourseXMLWriter($tmp_course);
334 $xml_writer->start();
335 return $xml_writer->getXML();
336 }
337
341 public function updateCourse(string $sid, int $course_id, string $xml)
342 {
343 $this->initAuth($sid);
344 $this->initIlias();
345
346 if (!$this->checkSession($sid)) {
347 return $this->raiseError($this->getMessage(), $this->getMessageCode());
348 }
349
350 global $DIC;
351
352 $rbacsystem = $DIC['rbacsystem'];
353
354 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
355 $ref_ids = ilObject::_getAllReferences($course_id);
356 $course_id = end($ref_ids);
357 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) !== 'crs') {
358 return $this->raiseError(
359 'Invalid course id. Object with id "' . $course_id . '" is not of type "course"',
360 'Client'
361 );
362 }
363 }
364
366 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
367 return $this->raiseError('Cannot create course instance!', 'Server');
368 }
369
370 if (!$rbacsystem->checkAccess('write', $course_id)) {
371 return $this->raiseError('Check access failed. No permission to write course', 'Server');
372 }
373
374 ilCourseParticipants::_deleteAllEntries($tmp_course->getId());
375
376 ilCourseWaitingList::_deleteAll($tmp_course->getId());
377
378
379 $xml_parser = new ilCourseXMLParser($tmp_course);
380 $xml_parser->setMode(ilCourseXMLParser::MODE_SOAP);
381 $xml_parser->setXMLContent($xml);
382 $xml_parser->startParsing();
383 $tmp_course->MDUpdateListener('General');
384
385 return true;
386 }
387
391 public function getCoursesForUser(string $sid, string $parameters)
392 {
393 $this->initAuth($sid);
394 $this->initIlias();
395
396 if (!$this->checkSession($sid)) {
397 return $this->raiseError($this->getMessage(), $this->getMessageCode());
398 }
399
400 global $DIC;
401
402 $rbacreview = $DIC['rbacreview'];
403 $ilObjDataCache = $DIC['ilObjDataCache'];
404 $tree = $DIC['tree'];
405
406 $parser = new ilXMLResultSetParser($parameters);
407 try {
408 $parser->startParsing();
409 } catch (ilSaxParserException $exception) {
410 return $this->raiseError($exception->getMessage(), "Client");
411 }
412 $xmlResultSet = $parser->getXMLResultSet();
413
414 if (!$xmlResultSet->hasColumn("user_id")) {
415 return $this->raiseError("parameter user_id is missing", "Client");
416 }
417
418 if (!$xmlResultSet->hasColumn("status")) {
419 return $this->raiseError("parameter status is missing", "Client");
420 }
421
422 $user_id = (int) $xmlResultSet->getValue(0, "user_id");
423 $status = (int) $xmlResultSet->getValue(0, "status");
424
425 $ref_ids = array();
426
427 if (
428 self::MEMBER == ($status & self::MEMBER) ||
429 self::TUTOR == ($status & self::TUTOR) ||
430 self::ADMIN == ($status & self::ADMIN)
431 ) {
432 foreach ($rbacreview->assignedRoles($user_id) as $role_id) {
433 if ($role = ilObjectFactory::getInstanceByObjId($role_id, false)) {
434 #echo $role->getType();
435 if ($role->getType() !== "role") {
436 continue;
437 }
438 if ($role->getParent() == ROLE_FOLDER_ID) {
439 continue;
440 }
441 $role_title = $role->getTitle();
442
443 if ($ref_id = ilUtil::__extractRefId($role_title)) {
445 continue;
446 }
447
448 if (
449 self::MEMBER == ($status & self::MEMBER) && strpos(
450 $role_title,
451 "member"
452 ) !== false
453 ) {
454 $ref_ids[] = $ref_id;
455 } elseif (
456 self::TUTOR == ($status & self::TUTOR) && strpos(
457 $role_title,
458 "tutor"
459 ) !== false
460 ) {
461 $ref_ids[] = $ref_id;
462 } elseif (
463 self::ADMIN == ($status & self::ADMIN) && strpos(
464 $role_title,
465 "admin"
466 ) !== false
467 ) {
468 $ref_ids[] = $ref_id;
469 } elseif (($status & self::OWNER) == self::OWNER && $ilObjDataCache->lookupOwner($ilObjDataCache->lookupObjId($ref_id)) == $user_id) {
470 $ref_ids[] = $ref_id;
471 }
472 }
473 }
474 }
475 }
476 if (($status & self::OWNER) == self::OWNER) {
477 $owned_objects = ilObjectFactory::getObjectsForOwner("crs", $user_id);
478 $refs = [];
479 foreach ($owned_objects as $obj_id) {
480 $allrefs = ilObject::_getAllReferences($obj_id);
481 foreach ($allrefs as $r) {
482 if ($tree->isDeleted($r)) {
483 continue;
484 }
485 if ($tree->isInTree($r)) {
486 $refs[] = $r;
487 }
488 }
489 if (count($refs) > 0) {
490 $ref_ids[] = array_pop($refs);
491 }
492 }
493 }
494 $ref_ids = array_unique($ref_ids);
495
496 $ref_ids = array_unique($ref_ids);
497
498 $xmlResultSet = new ilXMLResultSet();
499 $xmlResultSet->addColumn("ref_id");
500 $xmlResultSet->addColumn("xml");
501 $xmlResultSet->addColumn("parent_ref_id");
502
503 global $DIC;
504
505 $ilUser = $DIC['ilUser'];
506 //#18004
507 // Enable to see own participations by reducing the needed permissions
508 $permission = $user_id === $ilUser->getId() ? 'read' : 'write';
509
510 foreach ($ref_ids as $course_id) {
511 $course_obj = $this->checkObjectAccess($course_id, ['crs'], $permission, true);
512 if ($course_obj instanceof ilObjCourse) {
513 $row = new ilXMLResultSetRow();
514 $row->setValue("ref_id", $course_id);
515 $xmlWriter = new ilCourseXMLWriter($course_obj);
516 $xmlWriter->setAttachUsers(false);
517 $xmlWriter->start();
518 $row->setValue("xml", $xmlWriter->getXML());
519 $row->setValue("parent_ref_id", $tree->getParentId($course_id));
520 $xmlResultSet->addRow($row);
521 }
522 }
523 $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
524 $xmlResultSetWriter->start();
525 return $xmlResultSetWriter->getXML();
526 }
527}
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...
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)
getCoursesForUser(string $sid, string $parameters)
assignCourseMember(string $sid, int $course_id, int $user_id, string $type, ?bool $notification=null, ?bool $contact_person=null, ?bool $blocked=null)
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