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