ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapGroupAdministration.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 ADMIN = 2;
39  const OWNER = 4;
40 
41 
43  {
45  }
46 
47 
48  // Service methods
49  function addGroup($sid,$target_id,$grp_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 or group',
62  'Client');
63  }
64 
65  global $rbacsystem;
66 
67  if(!$rbacsystem->checkAccess('create',$target_id,'grp'))
68  {
69  return $this->__raiseError('Check access failed. No permission to create groups','Server');
70  }
71 
73  {
74  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
75  }
76 
77 
78  // Start import
79  include_once("./Modules/Group/classes/class.ilObjGroup.php");
80  include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
81  $xml_parser = new ilGroupXMLParser($grp_xml,$target_id);
82  $new_ref_id = $xml_parser->startParsing();
83 
84  return $new_ref_id ? $new_ref_id : "0";
85  }
86 
87  // Service methods
88  function updateGroup($sid,$ref_id,$grp_xml)
89  {
90  $this->initAuth($sid);
91  $this->initIlias();
92 
93 
94  if(!$this->__checkSession($sid))
95  {
96  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
97  }
98 
99 
100 
101  if(!is_numeric($ref_id))
102  {
103  return $this->__raiseError('No valid target id given. Please choose an existing reference id of an ILIAS category or group',
104  'Client');
105  }
106 
107  global $rbacsystem;
108 
109  if(!$rbacsystem->checkAccess('write',$ref_id,'grp'))
110  {
111  return $this->__raiseError('Check access failed. No permission to edit groups','Server');
112  }
113 
114  // Start import
115  include_once("./Modules/Group/classes/class.ilObjGroup.php");
116 
117  if(!$grp = ilObjectFactory::getInstanceByRefId($ref_id, false))
118  {
119  return $this->__raiseError('Cannot create group instance!','CLIENT_OBJECT_NOT_FOUND');
120  }
121 
123  {
124  return $this->__raiseError("Object with ID $ref_id has been deleted.", 'CLIENT_OBJECT_DELETED');
125  }
126 
127 
128  if (ilObjectFactory::getTypeByRefId($ref_id, false) !="grp")
129  {
130  return $this->__raiseError('Reference id does not point to a group!','CLIENT_WRONG_TYPE');
131  }
132 
133 
134  include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
135  $xml_parser = new ilGroupXMLParser($grp_xml, -1);
136  $xml_parser->setMode(ilGroupXMLParser::$UPDATE);
137  $xml_parser->setGroup($grp);
138  $new_ref_id = $xml_parser->startParsing();
139 
140  return $new_ref_id ? $new_ref_id : "0";
141  }
142 
143 
144  function groupExists($sid,$title)
145  {
146  $this->initAuth($sid);
147  $this->initIlias();
148 
149  if(!$this->__checkSession($sid))
150  {
151  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
152  }
153 
154  if(!$title)
155  {
156  return $this->__raiseError('No title given. Please choose an title for the group in question.',
157  'Client');
158  }
159 
161  }
162 
163  function getGroup($sid,$ref_id)
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 
174  {
175  return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'CLIENT_OBJECT_DELETED');
176  }
177 
178 
179  if(!$grp_obj =& ilObjectFactory::getInstanceByRefId($ref_id,false))
180  {
181  return $this->__raiseError('No valid reference id given.',
182  'Client');
183  }
184 
185 
186  include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
187 
188  $xml_writer = new ilGroupXMLWriter($grp_obj);
189  $xml_writer->start();
190 
191  $xml = $xml_writer->getXML();
192 
193  return strlen($xml) ? $xml : '';
194  }
195 
196 
197  function assignGroupMember($sid,$group_id,$user_id,$type)
198  {
199  $this->initAuth($sid);
200  $this->initIlias();
201 
202  if(!$this->__checkSession($sid))
203  {
204  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
205  }
206 
207  if(!is_numeric($group_id))
208  {
209  return $this->__raiseError('No valid group id given. Please choose an existing reference id of an ILIAS group',
210  'Client');
211  }
212 
213  global $rbacsystem;
214 
215  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($group_id))) != 'grp')
216  {
217  $group_id = end($ref_ids = ilObject::_getAllReferences($group_id));
218  if(ilObject::_lookupType(ilObject::_lookupObjId($group_id)) != 'grp')
219  {
220  return $this->__raiseError('Invalid group id. Object with id "'. $group_id.'" is not of type "group"','Client');
221  }
222  }
223 
224  if(!$rbacsystem->checkAccess('write',$group_id))
225  {
226  return $this->__raiseError('Check access failed. No permission to write to group','Server');
227  }
228 
229 
230  if(ilObject::_lookupType($user_id) != 'usr')
231  {
232  return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
233  }
234  if($type != 'Admin' and
235  $type != 'Member')
236  {
237  return $this->__raiseError('Invalid type '.$type.' given. Parameter "type" must be "Admin","Member"','Client');
238  }
239 
240  if(!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id,false))
241  {
242  return $this->__raiseError('Cannot create group instance!','Server');
243  }
244 
245  if(!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id,false))
246  {
247  return $this->__raiseError('Cannot create user instance!','Server');
248  }
249 
250 
251  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
252  $group_members = ilGroupParticipants::_getInstanceByObjId($tmp_group->getId());
253 
254  switch($type)
255  {
256  case 'Admin':
257  $group_members->add($tmp_user->getId(),IL_GRP_ADMIN);
258  break;
259 
260  case 'Member':
261  $group_members->add($tmp_user->getId(),IL_GRP_MEMBER);
262  break;
263  }
264  return true;
265  }
266 
267  function excludeGroupMember($sid,$group_id,$user_id)
268  {
269  $this->initAuth($sid);
270  $this->initIlias();
271 
272  if(!$this->__checkSession($sid))
273  {
274  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
275  }
276  if(!is_numeric($group_id))
277  {
278  return $this->__raiseError('No valid group id given. Please choose an existing reference id of an ILIAS group',
279  'Client');
280  }
281 
282  global $rbacsystem;
283 
284  if(($type = ilObject::_lookupType(ilObject::_lookupObjId($group_id))) != 'grp')
285  {
286  $group_id = end($ref_ids = ilObject::_getAllReferences($group_id));
287  if(ilObject::_lookupType(ilObject::_lookupObjId($group_id)) != 'grp')
288  {
289  return $this->__raiseError('Invalid group id. Object with id "'. $group_id.'" is not of type "group"','Client');
290  }
291  }
292 
293  if(ilObject::_lookupType($user_id) != 'usr')
294  {
295  return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
296  }
297 
298  if(!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id,false))
299  {
300  return $this->__raiseError('Cannot create group instance!','Server');
301  }
302 
303  if(!$rbacsystem->checkAccess('write',$group_id))
304  {
305  return $this->__raiseError('Check access failed. No permission to write to group','Server');
306  }
307 
308  $tmp_group->leave($user_id);
309  return true;
310  }
311 
312 
313  function isAssignedToGroup($sid,$group_id,$user_id)
314  {
315  $this->initAuth($sid);
316  $this->initIlias();
317 
318  if(!$this->__checkSession($sid))
319  {
320  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
321  }
322  if(!is_numeric($group_id))
323  {
324  return $this->__raiseError('No valid group id given. Please choose an existing id of an ILIAS group',
325  'Client');
326  }
327  global $rbacsystem;
328 
329  if(($type = ilObject::_lookupType(ilObject::_lookupObjId($group_id))) != 'grp')
330  {
331  $group_id = end($ref_ids = ilObject::_getAllReferences($group_id));
332  if(ilObject::_lookupType(ilObject::_lookupObjId($group_id)) != 'grp')
333  {
334  return $this->__raiseError('Invalid group id. Object with id "'. $group_id.'" is not of type "group"','Client');
335  }
336  }
337 
338  if(ilObject::_lookupType($user_id) != 'usr')
339  {
340  return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
341  }
342 
343  if(!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id,false))
344  {
345  return $this->__raiseError('Cannot create group instance!','Server');
346  }
347 
348  if(!$rbacsystem->checkAccess('read',$group_id))
349  {
350  return $this->__raiseError('Check access failed. No permission to read group data','Server');
351  }
352 
353  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
355 
356  if($participants->isAdmin($user_id))
357  {
358  return 1;
359  }
360  if($participants->isMember($user_id))
361  {
362  return 2;
363  }
364  return 0;
365  }
366 
367  // PRIVATE
368 
376  function getGroupsForUser($sid, $parameters) {
377 
378  $this->initAuth($sid);
379  $this->initIlias();
380 
381  if(!$this->__checkSession($sid))
382  {
383  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
384  }
385  global $rbacreview, $ilObjDataCache, $tree;
386 
387  include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
388  $parser = new ilXMLResultSetParser($parameters);
389  try {
390  $parser->startParsing();
391  } catch (ilSaxParserException $exception) {
392  return $this->__raiseError($exception->getMessage(), "Client");
393  }
394  $xmlResultSet = $parser->getXMLResultSet();
395 
396  if (!$xmlResultSet->hasColumn ("user_id"))
397  return $this->__raiseError("parameter user_id is missing", "Client");
398 
399  if (!$xmlResultSet->hasColumn ("status"))
400  return $this->__raiseError("parameter status is missing", "Client");
401 
402  $user_id = (int) $xmlResultSet->getValue (0, "user_id");
403  $status = (int) $xmlResultSet->getValue (0, "status");
404 
405  $ref_ids = array();
406 
407  // get roles
408 #var_dump($xmlResultSet);
409 #echo "uid:".$user_id;
410 #echo "status:".$status;
413  foreach($rbacreview->assignedRoles($user_id) as $role_id)
414  {
415  if($role = ilObjectFactory::getInstanceByObjId($role_id,false))
416  {
417  #echo $role->getType();
418  if ($role->getType() != "role")
419  continue;
420 
421  if ($role->getParent() == ROLE_FOLDER_ID)
422  {
423  continue;
424  }
425  $role_title = $role->getTitle();
426 
427  if ($ref_id = ilUtil::__extractRefId($role_title))
428  {
430  continue;
431 
432  #echo $role_title;
433  if (ilSoapGroupAdministration::MEMBER == ($status & ilSoapGroupAdministration::MEMBER) && strpos($role_title, "member") !== false)
434  {
435  $ref_ids [] = $ref_id;
436  } elseif (ilSoapGroupAdministration::ADMIN == ($status & ilSoapGroupAdministration::ADMIN) && strpos($role_title, "admin") !== false)
437  {
438  $ref_ids [] = $ref_id;
439  }
440  }
441  }
442  }
443 
444  if (($status & ilSoapGroupAdministration::OWNER) == ilSoapGroupAdministration::OWNER)
445  {
446  $owned_objects = ilObjectFactory::getObjectsForOwner("grp", $user_id);
447  foreach ($owned_objects as $obj_id) {
448  $allrefs = ilObject::_getAllReferences($obj_id);
449  $refs = array();
450  foreach($allrefs as $r)
451  {
452  if($tree->isDeleted($r))
453  {
454  continue;
455  }
456  if ($tree->isInTree($r))
457  {
458  $refs[] = $r;
459  }
460  }
461  if (count($refs) > 0)
462  $ref_ids[] = array_pop($refs);
463  }
464  }
465  $ref_ids = array_unique($ref_ids);
466 
467 
468 #print_r($ref_ids);
469  include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
470  include_once 'Modules/Group/classes/class.ilObjGroup.php';
471  include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
472 
473  $xmlResultSet = new ilXMLResultSet();
474  $xmlResultSet->addColumn("ref_id");
475  $xmlResultSet->addColumn("xml");
476  $xmlResultSet->addColumn("parent_ref_id");
477 
478  foreach ($ref_ids as $group_id) {
479  $group_obj = $this->checkObjectAccess($group_id,"grp","write", true);
480  if ($group_obj instanceof ilObjGroup) {
481  $row = new ilXMLResultSetRow();
482  $row->setValue("ref_id", $group_id);
483  $xmlWriter = new ilGroupXMLWriter($group_obj);
484  $xmlWriter->setAttachUsers(false);
485  $xmlWriter->start();
486  $row->setValue("xml", $xmlWriter->getXML());
487  $row->setValue("parent_ref_id", $tree->getParentId($group_id));
488  $xmlResultSet->addRow($row);
489  }
490  }
491  $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
492  $xmlResultSetWriter->start();
493  return $xmlResultSetWriter->getXML();
494  }
495 }
496 ?>