ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSoapCourseAdministration.php
Go to the documentation of this file.
1<?php
2 /*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22 */
23
24
33include_once './webservice/soap/classes/class.ilSoapAdministration.php';
34
36{
37 const MEMBER = 1;
38 const TUTOR = 2;
39 const ADMIN = 4;
40 const OWNER = 8;
41
42
43 // Service methods
44 public function addCourse($sid, $target_id, $crs_xml)
45 {
46 $this->initAuth($sid);
47 $this->initIlias();
48
49 if (!$this->__checkSession($sid)) {
50 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
51 }
52
53 if (!is_numeric($target_id)) {
54 return $this->__raiseError(
55 'No valid target id given. Please choose an existing reference id of an ILIAS category',
56 'Client'
57 );
58 }
59
60 global $DIC;
61
62 $rbacsystem = $DIC['rbacsystem'];
63
64 if (!$target_obj =&ilObjectFactory::getInstanceByRefId($target_id, false)) {
65 return $this->__raiseError('No valid target given.', 'Client');
66 }
67
69 return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
70 }
71
72 if (!$rbacsystem->checkAccess('create', $target_id, 'crs')) {
73 return $this->__raiseError('Check access failed. No permission to create courses', 'Server');
74 }
75
76
77 // Start import
78 include_once("Modules/Course/classes/class.ilObjCourse.php");
79
80 $newObj = new ilObjCourse();
81 $newObj->setType('crs');
82 $newObj->setTitle('dummy');
83 $newObj->setDescription("");
84 $newObj->create(true); // true for upload
85 $newObj->createReference();
86 $newObj->putInTree($target_id);
87 $newObj->setPermissions($target_id);
88
89 include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
90
91 $xml_parser = new ilCourseXMLParser($newObj);
92 $xml_parser->setXMLContent($crs_xml);
93 $xml_parser->startParsing();
94 return $newObj->getRefId() ? $newObj->getRefId() : "0";
95 }
96
97 public function deleteCourse($sid, $course_id)
98 {
99 $this->initAuth($sid);
100 $this->initIlias();
101
102 if (!$this->__checkSession($sid)) {
103 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
104 }
105
106 if (!is_numeric($course_id)) {
107 return $this->__raiseError(
108 'No valid course id given. Please choose an existing reference id of an ILIAS course',
109 'Client'
110 );
111 }
112
113 include_once "./Services/Utilities/classes/class.ilUtil.php";
114 global $DIC;
115
116 $rbacsystem = $DIC['rbacsystem'];
117
118 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
119 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
120 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
121 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
122 }
123 }
124
125 if (!$rbacsystem->checkAccess('delete', $course_id)) {
126 return $this->__raiseError('Check access failed. No permission to delete course', 'Server');
127 }
128
129
130 global $DIC;
131
132 $tree = $DIC['tree'];
133 $rbacadmin = $DIC['rbacadmin'];
134 $log = $DIC['log'];
135
136 if ($tree->isDeleted($course_id)) {
137 return $this->__raiseError('Node already deleted', 'Server');
138 }
139
140 $subnodes = $tree->getSubtree($tree->getNodeData($course_id));
141 foreach ($subnodes as $subnode) {
142 $rbacadmin->revokePermission($subnode["child"]);
143
144 // remove item from all user desktops
145 $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
146 }
147 if (!$tree->saveSubTree($course_id, true)) {
148 return $this->__raiseError('Node already deleted', 'Client');
149 }
150
151 // write log entry
152 $log->write("SOAP ilObjectGUI::confirmedDeleteObject(), moved ref_id " . $course_id . " to trash");
153
154 // remove item from all user desktops
155 $affected_users = ilUtil::removeItemFromDesktops($course_id);
156
157 return true;
158 }
159
160 public function assignCourseMember($sid, $course_id, $user_id, $type)
161 {
162 $this->initAuth($sid);
163 $this->initIlias();
164
165 if (!$this->__checkSession($sid)) {
166 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
167 }
168
169 if (!is_numeric($course_id)) {
170 return $this->__raiseError(
171 'No valid course id given. Please choose an existing reference id of an ILIAS course',
172 'Client'
173 );
174 }
175
176 global $DIC;
177
178 $rbacsystem = $DIC['rbacsystem'];
179
180 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
181 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
182 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
183 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
184 }
185 }
186
187 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
188 return $this->__raiseError('Check access failed. No permission to write to course', 'Server');
189 }
190
191
192 if (ilObject::_lookupType($user_id) != 'usr') {
193 return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
194 }
195 if ($type != 'Admin' and
196 $type != 'Tutor' and
197 $type != 'Member') {
198 return $this->__raiseError('Invalid type given. Parameter "type" must be "Admin", "Tutor" or "Member"', 'Client');
199 }
200
201 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
202 return $this->__raiseError('Cannot create course instance!', 'Server');
203 }
204
205 if (!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id, false)) {
206 return $this->__raiseError('Cannot create user instance!', 'Server');
207 }
208
209 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
210
211 $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
212
213 switch ($type) {
214 case 'Admin':
215 require_once("Services/Administration/classes/class.ilSetting.php");
216 $settings = new ilSetting();
217 $course_members->add($tmp_user->getId(), IL_CRS_ADMIN);
218 $course_members->updateNotification($tmp_user->getId(), $settings->get('mail_crs_admin_notification', true));
219 break;
220
221 case 'Tutor':
222 $course_members->add($tmp_user->getId(), IL_CRS_TUTOR);
223 break;
224
225 case 'Member':
226 $course_members->add($tmp_user->getId(), IL_CRS_MEMBER);
227 break;
228 }
229
230 return true;
231 }
232
233 public function excludeCourseMember($sid, $course_id, $user_id)
234 {
235 $this->initAuth($sid);
236 $this->initIlias();
237
238 if (!$this->__checkSession($sid)) {
239 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
240 }
241 if (!is_numeric($course_id)) {
242 return $this->__raiseError(
243 'No valid course id given. Please choose an existing reference id of an ILIAS course',
244 'Client'
245 );
246 }
247
248 global $DIC;
249
250 $rbacsystem = $DIC['rbacsystem'];
251
252 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
253 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
254 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
255 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
256 }
257 }
258
259 if (ilObject::_lookupType($user_id) != 'usr') {
260 return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
261 }
262
263 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
264 return $this->__raiseError('Cannot create course instance!', 'Server');
265 }
266
267 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
268 return $this->__raiseError('Check access failed. No permission to write to course', 'Server');
269 }
270
271 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
272
273 $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
274 if (!$course_members->checkLastAdmin(array($user_id))) {
275 return $this->__raiseError('Cannot deassign last administrator from course', 'Server');
276 }
277
278 $course_members->delete($user_id);
279
280 return true;
281 }
282
283
284 public function isAssignedToCourse($sid, $course_id, $user_id)
285 {
286 $this->initAuth($sid);
287 $this->initIlias();
288
289 if (!$this->__checkSession($sid)) {
290 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
291 }
292 if (!is_numeric($course_id)) {
293 return $this->__raiseError(
294 'No valid course id given. Please choose an existing reference id of an ILIAS course',
295 'Client'
296 );
297 }
298 global $DIC;
299
300 $rbacsystem = $DIC['rbacsystem'];
301
302 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
303 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
304 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
305 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
306 }
307 }
308
309 if (ilObject::_lookupType($user_id) != 'usr') {
310 return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
311 }
312
313 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
314 return $this->__raiseError('Cannot create course instance!', 'Server');
315 }
316
317 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
318 return $this->__raiseError('Check access failed. No permission to write to course', 'Server');
319 }
320
321 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
322 $crs_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
323
324 if ($crs_members->isAdmin($user_id)) {
325 return IL_CRS_ADMIN;
326 }
327 if ($crs_members->isTutor($user_id)) {
328 return IL_CRS_TUTOR;
329 }
330 if ($crs_members->isMember($user_id)) {
331 return IL_CRS_MEMBER;
332 }
333
334 return "0";
335 }
336
337
338 public function getCourseXML($sid, $course_id)
339 {
340 $this->initAuth($sid);
341 $this->initIlias();
342
343 if (!$this->__checkSession($sid)) {
344 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
345 }
346 if (!is_numeric($course_id)) {
347 return $this->__raiseError(
348 'No valid course id given. Please choose an existing reference id of an ILIAS course',
349 'Client'
350 );
351 }
352
353 global $DIC;
354
355 $rbacsystem = $DIC['rbacsystem'];
356
357 $tmp_course = $this->checkObjectAccess($course_id, "crs", "read", true);
358 if ($this->isFault($tmp_course)) {
359 return $tmp_course;
360 }
361
362 /*if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
363 {
364 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
365 if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
366 {
367 return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
368 }
369 }
370
371 if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
372 {
373 return $this->__raiseError('Cannot create course instance!','Server');
374 }
375
376 if(!$rbacsystem->checkAccess('read',$course_id))
377 {
378 return $this->__raiseError('Check access failed. No permission to read course','Server');
379 }*/
380
381 include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
382
383 $xml_writer = new ilCourseXMLWriter($tmp_course);
384 $xml_writer->start();
385
386 return $xml_writer->getXML();
387 }
388
389 public function updateCourse($sid, $course_id, $xml)
390 {
391 $this->initAuth($sid);
392 $this->initIlias();
393
394 if (!$this->__checkSession($sid)) {
395 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
396 }
397
398 if (!is_numeric($course_id)) {
399 return $this->__raiseError(
400 'No valid course id given. Please choose an existing reference id of an ILIAS course',
401 'Client'
402 );
403 }
404
405 global $DIC;
406
407 $rbacsystem = $DIC['rbacsystem'];
408
409 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
410 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
411 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
412 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
413 }
414 }
415
416 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
417 return $this->__raiseError('Cannot create course instance!', 'Server');
418 }
419
420 if (!$rbacsystem->checkAccess('write', $course_id)) {
421 return $this->__raiseError('Check access failed. No permission to write course', 'Server');
422 }
423
424
425 // First delete old meta data
426 include_once 'Services/MetaData/classes/class.ilMD.php';
427
428 $md = new ilMD($tmp_course->getId(), 0, 'crs');
429 $md->deleteAll();
430
431 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
432 ilCourseParticipants::_deleteAllEntries($tmp_course->getId());
433
434
435 include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
436 ilCourseWaitingList::_deleteAll($tmp_course->getId());
437
438 include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
439
440 $xml_parser = new ilCourseXMLParser($tmp_course);
441 $xml_parser->setXMLContent($xml);
442
443 $xml_parser->startParsing();
444
445 $tmp_course->MDUpdateListener('General');
446
447 return true;
448 }
449
450 // PRIVATE
451
459 public function getCoursesForUser($sid, $parameters)
460 {
461 $this->initAuth($sid);
462 $this->initIlias();
463
464 if (!$this->__checkSession($sid)) {
465 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
466 }
467
468 global $DIC;
469
470 $rbacreview = $DIC['rbacreview'];
471 $ilObjDataCache = $DIC['ilObjDataCache'];
472 $tree = $DIC['tree'];
473
474 include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
475 $parser = new ilXMLResultSetParser($parameters);
476 try {
477 $parser->startParsing();
478 } catch (ilSaxParserException $exception) {
479 return $this->__raiseError($exception->getMessage(), "Client");
480 }
481 $xmlResultSet = $parser->getXMLResultSet();
482
483 if (!$xmlResultSet->hasColumn("user_id")) {
484 return $this->__raiseError("parameter user_id is missing", "Client");
485 }
486
487 if (!$xmlResultSet->hasColumn("status")) {
488 return $this->__raiseError("parameter status is missing", "Client");
489 }
490
491 $user_id = (int) $xmlResultSet->getValue(0, "user_id");
492 $status = (int) $xmlResultSet->getValue(0, "status");
493
494 $ref_ids = array();
495
496 // get roles
497 #var_dump($xmlResultSet);
498 #echo "uid:".$user_id;
499 #echo "status:".$status;
503 foreach ($rbacreview->assignedRoles($user_id) as $role_id) {
504 if ($role = ilObjectFactory::getInstanceByObjId($role_id, false)) {
505 #echo $role->getType();
506 if ($role->getType() != "role") {
507 continue;
508 }
509 if ($role->getParent() == ROLE_FOLDER_ID) {
510 continue;
511 }
512 $role_title = $role->getTitle();
513
514 if ($ref_id = ilUtil::__extractRefId($role_title)) {
515 if (!ilObject::_exists($ref_id, true) || ilObject::_isInTrash($ref_id)) {
516 continue;
517 }
518
519 #echo $role_title;
520 if (ilSoapCourseAdministration::MEMBER == ($status & ilSoapCourseAdministration::MEMBER) && strpos($role_title, "member") !== false) {
521 $ref_ids [] = $ref_id;
522 } elseif (ilSoapCourseAdministration::TUTOR == ($status & ilSoapCourseAdministration::TUTOR) && strpos($role_title, "tutor") !== false) {
523 $ref_ids [] = $ref_id;
524 } elseif (ilSoapCourseAdministration::ADMIN == ($status & ilSoapCourseAdministration::ADMIN) && strpos($role_title, "admin") !== false) {
525 $ref_ids [] = $ref_id;
526 } elseif (($status & ilSoapCourseAdministration::OWNER) == ilSoapCourseAdministration::OWNER && $ilObjDataCache->lookupOwner($ilObjDataCache->lookupObjId($ref_id)) == $user_id) {
527 $ref_ids [] = $ref_id;
528 }
529 }
530 }
531 }
532 }
534 $owned_objects = ilObjectFactory::getObjectsForOwner("crs", $user_id);
535 foreach ($owned_objects as $obj_id) {
536 $allrefs = ilObject::_getAllReferences($obj_id);
537 foreach ($allrefs as $r) {
538 if ($tree->isDeleted($r)) {
539 continue;
540 }
541 if ($tree->isInTree($r)) {
542 $refs[] = $r;
543 }
544 }
545 if (count($refs) > 0) {
546 $ref_ids[] = array_pop($refs);
547 }
548 }
549 }
550 $ref_ids = array_unique($ref_ids);
551
552
553
554 $ref_ids = array_unique($ref_ids);
555 #print_r($ref_ids);
556 include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
557 include_once 'Modules/Course/classes/class.ilObjCourse.php';
558 include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
559
560 $xmlResultSet = new ilXMLResultSet();
561 $xmlResultSet->addColumn("ref_id");
562 $xmlResultSet->addColumn("xml");
563 $xmlResultSet->addColumn("parent_ref_id");
564
565 global $DIC;
566
567 $ilUser = $DIC['ilUser'];
568 //#18004
569 // Enable to see own participations by reducing the needed permissions
570 $permission = $user_id == $ilUser->getId() ? 'read' : 'write';
571
572 foreach ($ref_ids as $course_id) {
573 $course_obj = $this->checkObjectAccess($course_id, "crs", $permission, true);
574 if ($course_obj instanceof ilObjCourse) {
575 $row = new ilXMLResultSetRow();
576 $row->setValue("ref_id", $course_id);
577 $xmlWriter = new ilCourseXMLWriter($course_obj);
578 $xmlWriter->setAttachUsers(false);
579 $xmlWriter->start();
580 $row->setValue("xml", $xmlWriter->getXML());
581 $row->setValue("parent_ref_id", $tree->getParentId($course_id));
582 $xmlResultSet->addRow($row);
583 }
584 }
585 $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
586 $xmlResultSetWriter->start();
587 return $xmlResultSetWriter->getXML();
588 }
589}
$parser
Definition: BPMN2Parser.php:23
An exception for terminatinating execution or to throw for unit testing.
const IL_CRS_ADMIN
Base class for course and group participants.
const IL_CRS_MEMBER
const IL_CRS_TUTOR
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Class ilObjCourse.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
getObjectsForOwner($object_type, $owner_id)
returns all objects of an owner, filtered by type, objects are not deleted!
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _isInTrash($a_ref_id)
checks wether object is in trash
static _lookupType($a_id, $a_reference=false)
lookup object type
static _deleteAllEntries($a_obj_id)
Delete all entries Normally called for course deletion.
SaxParserException thrown by ilSaxParser if property throwException is set.
ILIAS Setting Class.
initAuth($sid)
Init authentication.
__raiseError($a_message, $a_code)
checkObjectAccess($ref_id, $expected_type, $permission, $returnObject=false)
check access for ref id: expected type, permission, return object instance if returnobject is true
getCoursesForUser($sid, $parameters)
get courses which belong to a specific user, fullilling the status
excludeCourseMember($sid, $course_id, $user_id)
isAssignedToCourse($sid, $course_id, $user_id)
assignCourseMember($sid, $course_id, $user_id, $type)
static __extractRefId($role_title)
extract ref id from role title, e.g.
static removeItemFromDesktops($a_id)
removes object from all user's desktops @access public
static _deleteAll($a_obj_id)
delete all
XML Writer for XMLResultSet.
$r
Definition: example_031.php:79
$target_id
Definition: goto.php:49
$row
$type
$log
Definition: sabredav.php:21
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18