ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $tree = $DIC->repositoryTree();
132 $user = $DIC->user();
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 if (!$tree->moveToTrash($course_id, true, $user->getId())) {
145 return $this->__raiseError('Node already deleted', 'Client');
146 }
147
148 // write log entry
149 $log->write("SOAP ilObjectGUI::confirmedDeleteObject(), moved ref_id " . $course_id . " to trash");
150
151 return true;
152 }
153
154 public function assignCourseMember($sid, $course_id, $user_id, $type)
155 {
156 $this->initAuth($sid);
157 $this->initIlias();
158
159 if (!$this->__checkSession($sid)) {
160 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
161 }
162
163 if (!is_numeric($course_id)) {
164 return $this->__raiseError(
165 'No valid course id given. Please choose an existing reference id of an ILIAS course',
166 'Client'
167 );
168 }
169
170 global $DIC;
171
172 $rbacsystem = $DIC['rbacsystem'];
173
174 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
175 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
176 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
177 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
178 }
179 }
180
181 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
182 return $this->__raiseError('Check access failed. No permission to write to course', 'Server');
183 }
184
185
186 if (ilObject::_lookupType($user_id) != 'usr') {
187 return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
188 }
189 if ($type != 'Admin' and
190 $type != 'Tutor' and
191 $type != 'Member') {
192 return $this->__raiseError('Invalid type given. Parameter "type" must be "Admin", "Tutor" or "Member"', 'Client');
193 }
194
195 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
196 return $this->__raiseError('Cannot create course instance!', 'Server');
197 }
198
199 if (!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id, false)) {
200 return $this->__raiseError('Cannot create user instance!', 'Server');
201 }
202
203 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
204
205 $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
206
207 switch ($type) {
208 case 'Admin':
209 require_once("Services/Administration/classes/class.ilSetting.php");
210 $settings = new ilSetting();
211 $course_members->add($tmp_user->getId(), IL_CRS_ADMIN);
212 $course_members->updateNotification($tmp_user->getId(), $settings->get('mail_crs_admin_notification', true));
213 break;
214
215 case 'Tutor':
216 $course_members->add($tmp_user->getId(), IL_CRS_TUTOR);
217 break;
218
219 case 'Member':
220 $course_members->add($tmp_user->getId(), IL_CRS_MEMBER);
221 break;
222 }
223
224 return true;
225 }
226
227 public function excludeCourseMember($sid, $course_id, $user_id)
228 {
229 $this->initAuth($sid);
230 $this->initIlias();
231
232 if (!$this->__checkSession($sid)) {
233 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
234 }
235 if (!is_numeric($course_id)) {
236 return $this->__raiseError(
237 'No valid course id given. Please choose an existing reference id of an ILIAS course',
238 'Client'
239 );
240 }
241
242 global $DIC;
243
244 $rbacsystem = $DIC['rbacsystem'];
245
246 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
247 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
248 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
249 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
250 }
251 }
252
253 if (ilObject::_lookupType($user_id) != 'usr') {
254 return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
255 }
256
257 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
258 return $this->__raiseError('Cannot create course instance!', 'Server');
259 }
260
261 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
262 return $this->__raiseError('Check access failed. No permission to write to course', 'Server');
263 }
264
265 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
266
267 $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
268 if (!$course_members->checkLastAdmin(array($user_id))) {
269 return $this->__raiseError('Cannot deassign last administrator from course', 'Server');
270 }
271
272 $course_members->delete($user_id);
273
274 return true;
275 }
276
277
278 public function isAssignedToCourse($sid, $course_id, $user_id)
279 {
280 $this->initAuth($sid);
281 $this->initIlias();
282
283 if (!$this->__checkSession($sid)) {
284 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
285 }
286 if (!is_numeric($course_id)) {
287 return $this->__raiseError(
288 'No valid course id given. Please choose an existing reference id of an ILIAS course',
289 'Client'
290 );
291 }
292 global $DIC;
293
294 $rbacsystem = $DIC['rbacsystem'];
295
296 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
297 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
298 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
299 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
300 }
301 }
302
303 if (ilObject::_lookupType($user_id) != 'usr') {
304 return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
305 }
306
307 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
308 return $this->__raiseError('Cannot create course instance!', 'Server');
309 }
310
311 if (!$rbacsystem->checkAccess('manage_members', $course_id)) {
312 return $this->__raiseError('Check access failed. No permission to write to course', 'Server');
313 }
314
315 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
316 $crs_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
317
318 if ($crs_members->isAdmin($user_id)) {
319 return IL_CRS_ADMIN;
320 }
321 if ($crs_members->isTutor($user_id)) {
322 return IL_CRS_TUTOR;
323 }
324 if ($crs_members->isMember($user_id)) {
325 return IL_CRS_MEMBER;
326 }
327
328 return "0";
329 }
330
331
332 public function getCourseXML($sid, $course_id)
333 {
334 $this->initAuth($sid);
335 $this->initIlias();
336
337 if (!$this->__checkSession($sid)) {
338 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
339 }
340 if (!is_numeric($course_id)) {
341 return $this->__raiseError(
342 'No valid course id given. Please choose an existing reference id of an ILIAS course',
343 'Client'
344 );
345 }
346
347 global $DIC;
348
349 $rbacsystem = $DIC['rbacsystem'];
350
351 $tmp_course = $this->checkObjectAccess($course_id, "crs", "read", true);
352 if ($this->isFault($tmp_course)) {
353 return $tmp_course;
354 }
355
356 /*if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
357 {
358 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
359 if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
360 {
361 return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
362 }
363 }
364
365 if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
366 {
367 return $this->__raiseError('Cannot create course instance!','Server');
368 }
369
370 if(!$rbacsystem->checkAccess('read',$course_id))
371 {
372 return $this->__raiseError('Check access failed. No permission to read course','Server');
373 }*/
374
375 include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
376
377 $xml_writer = new ilCourseXMLWriter($tmp_course);
378 $xml_writer->start();
379
380 return $xml_writer->getXML();
381 }
382
383 public function updateCourse($sid, $course_id, $xml)
384 {
385 $this->initAuth($sid);
386 $this->initIlias();
387
388 if (!$this->__checkSession($sid)) {
389 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
390 }
391
392 if (!is_numeric($course_id)) {
393 return $this->__raiseError(
394 'No valid course id given. Please choose an existing reference id of an ILIAS course',
395 'Client'
396 );
397 }
398
399 global $DIC;
400
401 $rbacsystem = $DIC['rbacsystem'];
402
403 if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs') {
404 $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
405 if (ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs') {
406 return $this->__raiseError('Invalid course id. Object with id "' . $course_id . '" is not of type "course"', 'Client');
407 }
408 }
409
410 if (!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id, false)) {
411 return $this->__raiseError('Cannot create course instance!', 'Server');
412 }
413
414 if (!$rbacsystem->checkAccess('write', $course_id)) {
415 return $this->__raiseError('Check access failed. No permission to write course', 'Server');
416 }
417
418
419 // First delete old meta data
420 include_once 'Services/MetaData/classes/class.ilMD.php';
421
422 $md = new ilMD($tmp_course->getId(), 0, 'crs');
423 $md->deleteAll();
424
425 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
426 ilCourseParticipants::_deleteAllEntries($tmp_course->getId());
427
428
429 include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
430 ilCourseWaitingList::_deleteAll($tmp_course->getId());
431
432 include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
433
434 $xml_parser = new ilCourseXMLParser($tmp_course);
435 $xml_parser->setXMLContent($xml);
436
437 $xml_parser->startParsing();
438
439 $tmp_course->MDUpdateListener('General');
440
441 return true;
442 }
443
444 // PRIVATE
445
453 public function getCoursesForUser($sid, $parameters)
454 {
455 $this->initAuth($sid);
456 $this->initIlias();
457
458 if (!$this->__checkSession($sid)) {
459 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
460 }
461
462 global $DIC;
463
464 $rbacreview = $DIC['rbacreview'];
465 $ilObjDataCache = $DIC['ilObjDataCache'];
466 $tree = $DIC['tree'];
467
468 include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
469 $parser = new ilXMLResultSetParser($parameters);
470 try {
471 $parser->startParsing();
472 } catch (ilSaxParserException $exception) {
473 return $this->__raiseError($exception->getMessage(), "Client");
474 }
475 $xmlResultSet = $parser->getXMLResultSet();
476
477 if (!$xmlResultSet->hasColumn("user_id")) {
478 return $this->__raiseError("parameter user_id is missing", "Client");
479 }
480
481 if (!$xmlResultSet->hasColumn("status")) {
482 return $this->__raiseError("parameter status is missing", "Client");
483 }
484
485 $user_id = (int) $xmlResultSet->getValue(0, "user_id");
486 $status = (int) $xmlResultSet->getValue(0, "status");
487
488 $ref_ids = array();
489
490 // get roles
491 #var_dump($xmlResultSet);
492 #echo "uid:".$user_id;
493 #echo "status:".$status;
497 foreach ($rbacreview->assignedRoles($user_id) as $role_id) {
498 if ($role = ilObjectFactory::getInstanceByObjId($role_id, false)) {
499 #echo $role->getType();
500 if ($role->getType() != "role") {
501 continue;
502 }
503 if ($role->getParent() == ROLE_FOLDER_ID) {
504 continue;
505 }
506 $role_title = $role->getTitle();
507
508 if ($ref_id = ilUtil::__extractRefId($role_title)) {
509 if (!ilObject::_exists($ref_id, true) || ilObject::_isInTrash($ref_id)) {
510 continue;
511 }
512
513 #echo $role_title;
514 if (ilSoapCourseAdministration::MEMBER == ($status & ilSoapCourseAdministration::MEMBER) && strpos($role_title, "member") !== false) {
515 $ref_ids [] = $ref_id;
516 } elseif (ilSoapCourseAdministration::TUTOR == ($status & ilSoapCourseAdministration::TUTOR) && strpos($role_title, "tutor") !== false) {
517 $ref_ids [] = $ref_id;
518 } elseif (ilSoapCourseAdministration::ADMIN == ($status & ilSoapCourseAdministration::ADMIN) && strpos($role_title, "admin") !== false) {
519 $ref_ids [] = $ref_id;
520 } elseif (($status & ilSoapCourseAdministration::OWNER) == ilSoapCourseAdministration::OWNER && $ilObjDataCache->lookupOwner($ilObjDataCache->lookupObjId($ref_id)) == $user_id) {
521 $ref_ids [] = $ref_id;
522 }
523 }
524 }
525 }
526 }
528 $owned_objects = ilObjectFactory::getObjectsForOwner("crs", $user_id);
529 foreach ($owned_objects as $obj_id) {
530 $allrefs = ilObject::_getAllReferences($obj_id);
531 foreach ($allrefs as $r) {
532 if ($tree->isDeleted($r)) {
533 continue;
534 }
535 if ($tree->isInTree($r)) {
536 $refs[] = $r;
537 }
538 }
539 if (count($refs) > 0) {
540 $ref_ids[] = array_pop($refs);
541 }
542 }
543 }
544 $ref_ids = array_unique($ref_ids);
545
546
547
548 $ref_ids = array_unique($ref_ids);
549 #print_r($ref_ids);
550 include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
551 include_once 'Modules/Course/classes/class.ilObjCourse.php';
552 include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
553
554 $xmlResultSet = new ilXMLResultSet();
555 $xmlResultSet->addColumn("ref_id");
556 $xmlResultSet->addColumn("xml");
557 $xmlResultSet->addColumn("parent_ref_id");
558
559 global $DIC;
560
561 $ilUser = $DIC['ilUser'];
562 //#18004
563 // Enable to see own participations by reducing the needed permissions
564 $permission = $user_id == $ilUser->getId() ? 'read' : 'write';
565
566 foreach ($ref_ids as $course_id) {
567 $course_obj = $this->checkObjectAccess($course_id, "crs", $permission, true);
568 if ($course_obj instanceof ilObjCourse) {
569 $row = new ilXMLResultSetRow();
570 $row->setValue("ref_id", $course_id);
571 $xmlWriter = new ilCourseXMLWriter($course_obj);
572 $xmlWriter->setAttachUsers(false);
573 $xmlWriter->start();
574 $row->setValue("xml", $xmlWriter->getXML());
575 $row->setValue("parent_ref_id", $tree->getParentId($course_id));
576 $xmlResultSet->addRow($row);
577 }
578 }
579 $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
580 $xmlResultSetWriter->start();
581 return $xmlResultSetWriter->getXML();
582 }
583}
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 getObjectsForOwner($object_type, $owner_id)
returns all objects of an owner, filtered by type, objects are not deleted!
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
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 _deleteAll($a_obj_id)
delete all
XML Writer for XMLResultSet.
const ROLE_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: goto.php:24
$target_id
Definition: goto.php:51
$ilUser
Definition: imgupload.php:18
$xml
Definition: metadata.php:332
$type
$log
Definition: result.php:15