ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $rbacsystem;
61
62 if (!$target_obj =&ilObjectFactory::getInstanceByRefId($target_id, false)) {
63 return $this->__raiseError('No valid target given.', 'Client');
64 }
65
67 return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
68 }
69
70 if (!$rbacsystem->checkAccess('create', $target_id, 'crs')) {
71 return $this->__raiseError('Check access failed. No permission to create courses', 'Server');
72 }
73
74
75 // Start import
76 include_once("Modules/Course/classes/class.ilObjCourse.php");
77
78 $newObj = new ilObjCourse();
79 $newObj->setType('crs');
80 $newObj->setTitle('dummy');
81 $newObj->setDescription("");
82 $newObj->create(true); // true for upload
83 $newObj->createReference();
84 $newObj->putInTree($target_id);
85 $newObj->setPermissions($target_id);
86
87 include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
88
89 $xml_parser = new ilCourseXMLParser($newObj);
90 $xml_parser->setXMLContent($crs_xml);
91 $xml_parser->startParsing();
92 return $newObj->getRefId() ? $newObj->getRefId() : "0";
93 }
94
95 public function deleteCourse($sid, $course_id)
96 {
97 $this->initAuth($sid);
98 $this->initIlias();
99
100 if (!$this->__checkSession($sid)) {
101 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
102 }
103
104 if (!is_numeric($course_id)) {
105 return $this->__raiseError(
106 'No valid course id given. Please choose an existing reference id of an ILIAS course',
107 'Client'
108 );
109 }
110
111 include_once "./Services/Utilities/classes/class.ilUtil.php";
112 global $rbacsystem;
113
114 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
115 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
116 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
117 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
118 }
119 }
120
121 if (!$rbacsystem->checkAccess('delete', $course_id)) {
122 return $this->__raiseError('Check access failed. No permission to delete course', 'Server');
123 }
124
125
126 global $tree,$rbacadmin,$log;
127
128 if ($tree->isDeleted($course_id)) {
129 return $this->__raiseError('Node already deleted', 'Server');
130 }
131
132 $subnodes = $tree->getSubtree($tree->getNodeData($course_id));
133 foreach ($subnodes as $subnode) {
134 $rbacadmin->revokePermission($subnode["child"]);
135
136 // remove item from all user desktops
137 $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
138 }
139 if (!$tree->saveSubTree($course_id, true)) {
140 return $this->__raiseError('Node already deleted', 'Client');
141 }
142
143 // write log entry
144 $log->write("SOAP ilObjectGUI::confirmedDeleteObject(), moved ref_id " . $course_id . " to trash");
145
146 // remove item from all user desktops
147 $affected_users = ilUtil::removeItemFromDesktops($course_id);
148
149 return true;
150 }
151
152 public function assignCourseMember($sid, $course_id, $user_id, $type)
153 {
154 $this->initAuth($sid);
155 $this->initIlias();
156
157 if (!$this->__checkSession($sid)) {
158 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
159 }
160
161 if (!is_numeric($course_id)) {
162 return $this->__raiseError(
163 'No valid course id given. Please choose an existing reference id of an ILIAS course',
164 'Client'
165 );
166 }
167
168 global $rbacsystem;
169
170 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
171 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
172 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
173 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
174 }
175 }
176
177 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
178 return $this->__raiseError('Check access failed. No permission to write to course', 'Server');
179 }
180
181
182 if (ilObject::_lookupType($user_id) != 'usr') {
183 return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
184 }
185 if ($type != 'Admin' and
186 $type != 'Tutor' and
187 $type != 'Member') {
188 return $this->__raiseError('Invalid type given. Parameter "type" must be "Admin", "Tutor" or "Member"', 'Client');
189 }
190
191 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
192 return $this->__raiseError('Cannot create course instance!', 'Server');
193 }
194
195 if (!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id, false)) {
196 return $this->__raiseError('Cannot create user instance!', 'Server');
197 }
198
199 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
200
201 $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
202
203 switch ($type) {
204 case 'Admin':
205 require_once("Services/Administration/classes/class.ilSetting.php");
206 $settings = new ilSetting();
207 $course_members->add($tmp_user->getId(), IL_CRS_ADMIN);
208 $course_members->updateNotification($tmp_user->getId(), $settings->get('mail_crs_admin_notification', true));
209 break;
210
211 case 'Tutor':
212 $course_members->add($tmp_user->getId(), IL_CRS_TUTOR);
213 break;
214
215 case 'Member':
216 $course_members->add($tmp_user->getId(), IL_CRS_MEMBER);
217 break;
218 }
219
220 return true;
221 }
222
223 public function excludeCourseMember($sid, $course_id, $user_id)
224 {
225 $this->initAuth($sid);
226 $this->initIlias();
227
228 if (!$this->__checkSession($sid)) {
229 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
230 }
231 if (!is_numeric($course_id)) {
232 return $this->__raiseError(
233 'No valid course id given. Please choose an existing reference id of an ILIAS course',
234 'Client'
235 );
236 }
237
238 global $rbacsystem;
239
240 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
241 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
242 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
243 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
244 }
245 }
246
247 if (ilObject::_lookupType($user_id) != 'usr') {
248 return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
249 }
250
251 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
252 return $this->__raiseError('Cannot create course instance!', 'Server');
253 }
254
255 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
256 return $this->__raiseError('Check access failed. No permission to write to course', 'Server');
257 }
258
259 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
260
261 $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
262 if (!$course_members->checkLastAdmin(array($user_id))) {
263 return $this->__raiseError('Cannot deassign last administrator from course', 'Server');
264 }
265
266 $course_members->delete($user_id);
267
268 return true;
269 }
270
271
272 public function isAssignedToCourse($sid, $course_id, $user_id)
273 {
274 $this->initAuth($sid);
275 $this->initIlias();
276
277 if (!$this->__checkSession($sid)) {
278 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
279 }
280 if (!is_numeric($course_id)) {
281 return $this->__raiseError(
282 'No valid course id given. Please choose an existing reference id of an ILIAS course',
283 'Client'
284 );
285 }
286 global $rbacsystem;
287
288 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
289 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
290 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
291 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
292 }
293 }
294
295 if (ilObject::_lookupType($user_id) != 'usr') {
296 return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
297 }
298
299 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
300 return $this->__raiseError('Cannot create course instance!', 'Server');
301 }
302
303 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
304 return $this->__raiseError('Check access failed. No permission to write to course', 'Server');
305 }
306
307 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
308 $crs_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
309
310 if ($crs_members->isAdmin($user_id)) {
311 return IL_CRS_ADMIN;
312 }
313 if ($crs_members->isTutor($user_id)) {
314 return IL_CRS_TUTOR;
315 }
316 if ($crs_members->isMember($user_id)) {
317 return IL_CRS_MEMBER;
318 }
319
320 return "0";
321 }
322
323
324 public function getCourseXML($sid, $course_id)
325 {
326 $this->initAuth($sid);
327 $this->initIlias();
328
329 if (!$this->__checkSession($sid)) {
330 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
331 }
332 if (!is_numeric($course_id)) {
333 return $this->__raiseError(
334 'No valid course id given. Please choose an existing reference id of an ILIAS course',
335 'Client'
336 );
337 }
338
339 global $rbacsystem;
340
341 $tmp_course = $this->checkObjectAccess($course_id, "crs", "read", true);
342 if ($this->isFault($tmp_course)) {
343 return $tmp_course;
344 }
345
346 /*if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
347 {
348 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
349 if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
350 {
351 return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
352 }
353 }
354
355 if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
356 {
357 return $this->__raiseError('Cannot create course instance!','Server');
358 }
359
360 if(!$rbacsystem->checkAccess('read',$course_id))
361 {
362 return $this->__raiseError('Check access failed. No permission to read course','Server');
363 }*/
364
365 include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
366
367 $xml_writer = new ilCourseXMLWriter($tmp_course);
368 $xml_writer->start();
369
370 return $xml_writer->getXML();
371 }
372
373 public function updateCourse($sid, $course_id, $xml)
374 {
375 $this->initAuth($sid);
376 $this->initIlias();
377
378 if (!$this->__checkSession($sid)) {
379 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
380 }
381
382 if (!is_numeric($course_id)) {
383 return $this->__raiseError(
384 'No valid course id given. Please choose an existing reference id of an ILIAS course',
385 'Client'
386 );
387 }
388
389 global $rbacsystem;
390
391 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
392 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
393 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
394 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
395 }
396 }
397
398 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
399 return $this->__raiseError('Cannot create course instance!', 'Server');
400 }
401
402 if (!$rbacsystem->checkAccess('write', $course_id)) {
403 return $this->__raiseError('Check access failed. No permission to write course', 'Server');
404 }
405
406
407 // First delete old meta data
408 include_once 'Services/MetaData/classes/class.ilMD.php';
409
410 $md = new ilMD($tmp_course->getId(), 0, 'crs');
411 $md->deleteAll();
412
413 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
414 ilCourseParticipants::_deleteAllEntries($tmp_course->getId());
415
416
417 include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
418 ilCourseWaitingList::_deleteAll($tmp_course->getId());
419
420 include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
421
422 $xml_parser = new ilCourseXMLParser($tmp_course);
423 $xml_parser->setXMLContent($xml);
424
425 $xml_parser->startParsing();
426
427 $tmp_course->MDUpdateListener('General');
428
429 return true;
430 }
431
432 // PRIVATE
433
441 public function getCoursesForUser($sid, $parameters)
442 {
443 $this->initAuth($sid);
444 $this->initIlias();
445
446 if (!$this->__checkSession($sid)) {
447 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
448 }
449
450 global $rbacreview, $ilObjDataCache, $tree;
451
452 include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
453 $parser = new ilXMLResultSetParser($parameters);
454 try {
455 $parser->startParsing();
456 } catch (ilSaxParserException $exception) {
457 return $this->__raiseError($exception->getMessage(), "Client");
458 }
459 $xmlResultSet = $parser->getXMLResultSet();
460
461 if (!$xmlResultSet->hasColumn("user_id")) {
462 return $this->__raiseError("parameter user_id is missing", "Client");
463 }
464
465 if (!$xmlResultSet->hasColumn("status")) {
466 return $this->__raiseError("parameter status is missing", "Client");
467 }
468
469 $user_id = (int) $xmlResultSet->getValue(0, "user_id");
470 $status = (int) $xmlResultSet->getValue(0, "status");
471
472 $ref_ids = array();
473
474 // get roles
475 #var_dump($xmlResultSet);
476 #echo "uid:".$user_id;
477 #echo "status:".$status;
481 foreach ($rbacreview->assignedRoles($user_id) as $role_id) {
482 if ($role = ilObjectFactory::getInstanceByObjId($role_id, false)) {
483 #echo $role->getType();
484 if ($role->getType() != "role") {
485 continue;
486 }
487 if ($role->getParent() == ROLE_FOLDER_ID) {
488 continue;
489 }
490 $role_title = $role->getTitle();
491
492 if ($ref_id = ilUtil::__extractRefId($role_title)) {
493 if (!ilObject::_exists($ref_id, true) || ilObject::_isInTrash($ref_id)) {
494 continue;
495 }
496
497 #echo $role_title;
498 if (ilSoapCourseAdministration::MEMBER == ($status & ilSoapCourseAdministration::MEMBER) && strpos($role_title, "member") !== false) {
499 $ref_ids [] = $ref_id;
500 } elseif (ilSoapCourseAdministration::TUTOR == ($status & ilSoapCourseAdministration::TUTOR) && strpos($role_title, "tutor") !== false) {
501 $ref_ids [] = $ref_id;
502 } elseif (ilSoapCourseAdministration::ADMIN == ($status & ilSoapCourseAdministration::ADMIN) && strpos($role_title, "admin") !== false) {
503 $ref_ids [] = $ref_id;
504 } elseif (($status & ilSoapCourseAdministration::OWNER) == ilSoapCourseAdministration::OWNER && $ilObjDataCache->lookupOwner($ilObjDataCache->lookupObjId($ref_id)) == $user_id) {
505 $ref_ids [] = $ref_id;
506 }
507 }
508 }
509 }
510 }
512 $owned_objects = ilObjectFactory::getObjectsForOwner("crs", $user_id);
513 foreach ($owned_objects as $obj_id) {
514 $allrefs = ilObject::_getAllReferences($obj_id);
515 foreach ($allrefs as $r) {
516 if ($tree->isDeleted($r)) {
517 continue;
518 }
519 if ($tree->isInTree($r)) {
520 $refs[] = $r;
521 }
522 }
523 if (count($refs) > 0) {
524 $ref_ids[] = array_pop($refs);
525 }
526 }
527 }
528 $ref_ids = array_unique($ref_ids);
529
530
531
532 $ref_ids = array_unique($ref_ids);
533 #print_r($ref_ids);
534 include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
535 include_once 'Modules/Course/classes/class.ilObjCourse.php';
536 include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
537
538 $xmlResultSet = new ilXMLResultSet();
539 $xmlResultSet->addColumn("ref_id");
540 $xmlResultSet->addColumn("xml");
541 $xmlResultSet->addColumn("parent_ref_id");
542
543 global $ilUser;
544 //#18004
545 // Enable to see own participations by reducing the needed permissions
546 $permission = $user_id == $ilUser->getId() ? 'read' : 'write';
547
548 foreach ($ref_ids as $course_id) {
549 $course_obj = $this->checkObjectAccess($course_id, "crs", $permission, true);
550 if ($course_obj instanceof ilObjCourse) {
551 $row = new ilXMLResultSetRow();
552 $row->setValue("ref_id", $course_id);
553 $xmlWriter = new ilCourseXMLWriter($course_obj);
554 $xmlWriter->setAttachUsers(false);
555 $xmlWriter->start();
556 $row->setValue("xml", $xmlWriter->getXML());
557 $row->setValue("parent_ref_id", $tree->getParentId($course_id));
558 $xmlResultSet->addRow($row);
559 }
560 }
561 $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
562 $xmlResultSetWriter->start();
563 return $xmlResultSetWriter->getXML();
564 }
565}
$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
$xml
Definition: metadata.php:240
$type
$ilUser
Definition: imgupload.php:18