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