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