ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
42 
43  // Service methods
44  public function addGroup($sid, $target_id, $grp_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 or group',
56  'Client'
57  );
58  }
59 
60  global $DIC;
61 
62  $rbacsystem = $DIC['rbacsystem'];
63 
64  if (!$rbacsystem->checkAccess('create', $target_id, 'grp')) {
65  return $this->__raiseError('Check access failed. No permission to create groups', 'Server');
66  }
67 
69  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
70  }
71 
72 
73  $newObj = new ilObjGroup();
74  $newObj->setTitle('dummy');
75  $newObj->setDescription("");
76  $newObj->create(true); // true for upload
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($newObj, $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  public function updateGroup($sid, $ref_id, $grp_xml)
89  {
90  $this->initAuth($sid);
91  $this->initIlias();
92 
93 
94  if (!$this->__checkSession($sid)) {
95  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
96  }
97 
98 
99 
100  if (!is_numeric($ref_id)) {
101  return $this->__raiseError(
102  'No valid target id given. Please choose an existing reference id of an ILIAS category or group',
103  'Client'
104  );
105  }
106 
107  global $DIC;
108 
109  $rbacsystem = $DIC['rbacsystem'];
110 
111  if (!$rbacsystem->checkAccess('write', $ref_id, 'grp')) {
112  return $this->__raiseError('Check access failed. No permission to edit groups', 'Server');
113  }
114 
115  // Start import
116  include_once("./Modules/Group/classes/class.ilObjGroup.php");
117 
118  if (!$grp = ilObjectFactory::getInstanceByRefId($ref_id, false)) {
119  return $this->__raiseError('Cannot create group instance!', 'CLIENT_OBJECT_NOT_FOUND');
120  }
121 
122  if (ilObject::_isInTrash($ref_id)) {
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  return $this->__raiseError('Reference id does not point to a group!', 'CLIENT_WRONG_TYPE');
129  }
130 
131 
132  include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
133  $xml_parser = new ilGroupXMLParser($grp, $grp_xml, -1);
134  $xml_parser->setMode(ilGroupXMLParser::$UPDATE);
135  $new_ref_id = $xml_parser->startParsing();
136 
137  return $new_ref_id ? $new_ref_id : "0";
138  }
139 
140 
141  public function groupExists($sid, $title)
142  {
143  $this->initAuth($sid);
144  $this->initIlias();
145 
146  if (!$this->__checkSession($sid)) {
147  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
148  }
149 
150  if (!$title) {
151  return $this->__raiseError(
152  'No title given. Please choose an title for the group in question.',
153  'Client'
154  );
155  }
156 
158  }
159 
160  public function getGroup($sid, $ref_id)
161  {
162  $this->initAuth($sid);
163  $this->initIlias();
164 
165  if (!$this->__checkSession($sid)) {
166  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
167  }
168 
169  if (ilObject::_isInTrash($ref_id)) {
170  return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'CLIENT_OBJECT_DELETED');
171  }
172 
173 
174  if (!$grp_obj =&ilObjectFactory::getInstanceByRefId($ref_id, false)) {
175  return $this->__raiseError(
176  'No valid reference id given.',
177  'Client'
178  );
179  }
180 
181 
182  include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
183 
184  $xml_writer = new ilGroupXMLWriter($grp_obj);
185  $xml_writer->start();
186 
187  $xml = $xml_writer->getXML();
188 
189  return strlen($xml) ? $xml : '';
190  }
191 
192 
193  public function assignGroupMember($sid, $group_id, $user_id, $type)
194  {
195  $this->initAuth($sid);
196  $this->initIlias();
197 
198  if (!$this->__checkSession($sid)) {
199  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
200  }
201 
202  if (!is_numeric($group_id)) {
203  return $this->__raiseError(
204  'No valid group id given. Please choose an existing reference id of an ILIAS group',
205  'Client'
206  );
207  }
208 
209  global $DIC;
210 
211  $rbacsystem = $DIC['rbacsystem'];
212 
213  if (($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($group_id))) != 'grp') {
214  $group_id = end($ref_ids = ilObject::_getAllReferences($group_id));
215  if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) != 'grp') {
216  return $this->__raiseError('Invalid group id. Object with id "' . $group_id . '" is not of type "group"', 'Client');
217  }
218  }
219 
220  if (!$rbacsystem->checkAccess('manage_members', $group_id)) {
221  return $this->__raiseError('Check access failed. No permission to write to group', 'Server');
222  }
223 
224 
225  if (ilObject::_lookupType($user_id) != 'usr') {
226  return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
227  }
228  if ($type != 'Admin' and
229  $type != 'Member') {
230  return $this->__raiseError('Invalid type ' . $type . ' given. Parameter "type" must be "Admin","Member"', 'Client');
231  }
232 
233  if (!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id, false)) {
234  return $this->__raiseError('Cannot create group instance!', 'Server');
235  }
236 
237  if (!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id, false)) {
238  return $this->__raiseError('Cannot create user instance!', 'Server');
239  }
240 
241 
242  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
243  $group_members = ilGroupParticipants::_getInstanceByObjId($tmp_group->getId());
244 
245  switch ($type) {
246  case 'Admin':
247  $group_members->add($tmp_user->getId(), IL_GRP_ADMIN);
248  break;
249 
250  case 'Member':
251  $group_members->add($tmp_user->getId(), IL_GRP_MEMBER);
252  break;
253  }
254  return true;
255  }
256 
257  public function excludeGroupMember($sid, $group_id, $user_id)
258  {
259  $this->initAuth($sid);
260  $this->initIlias();
261 
262  if (!$this->__checkSession($sid)) {
263  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
264  }
265  if (!is_numeric($group_id)) {
266  return $this->__raiseError(
267  'No valid group id given. Please choose an existing reference id of an ILIAS group',
268  'Client'
269  );
270  }
271 
272  global $DIC;
273 
274  $rbacsystem = $DIC['rbacsystem'];
275 
276  if (($type = ilObject::_lookupType(ilObject::_lookupObjId($group_id))) != 'grp') {
277  $group_id = end($ref_ids = ilObject::_getAllReferences($group_id));
278  if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) != 'grp') {
279  return $this->__raiseError('Invalid group id. Object with id "' . $group_id . '" is not of type "group"', 'Client');
280  }
281  }
282 
283  if (ilObject::_lookupType($user_id) != 'usr') {
284  return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
285  }
286 
287  if (!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id, false)) {
288  return $this->__raiseError('Cannot create group instance!', 'Server');
289  }
290 
291  if (!$rbacsystem->checkAccess('manage_members', $group_id)) {
292  return $this->__raiseError('Check access failed. No permission to write to group', 'Server');
293  }
294 
295  $tmp_group->leave($user_id);
296  return true;
297  }
298 
299 
300  public function isAssignedToGroup($sid, $group_id, $user_id)
301  {
302  $this->initAuth($sid);
303  $this->initIlias();
304 
305  if (!$this->__checkSession($sid)) {
306  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
307  }
308  if (!is_numeric($group_id)) {
309  return $this->__raiseError(
310  'No valid group id given. Please choose an existing id of an ILIAS group',
311  'Client'
312  );
313  }
314  global $DIC;
315 
316  $rbacsystem = $DIC['rbacsystem'];
317 
318  if (($type = ilObject::_lookupType(ilObject::_lookupObjId($group_id))) != 'grp') {
319  $group_id = end($ref_ids = ilObject::_getAllReferences($group_id));
320  if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) != 'grp') {
321  return $this->__raiseError('Invalid group id. Object with id "' . $group_id . '" is not of type "group"', 'Client');
322  }
323  }
324 
325  if (ilObject::_lookupType($user_id) != 'usr') {
326  return $this->__raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
327  }
328 
329  if (!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id, false)) {
330  return $this->__raiseError('Cannot create group instance!', 'Server');
331  }
332 
333  if (!$rbacsystem->checkAccess('read', $group_id)) {
334  return $this->__raiseError('Check access failed. No permission to read group data', 'Server');
335  }
336 
337  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
339 
340  if ($participants->isAdmin($user_id)) {
341  return 1;
342  }
343  if ($participants->isMember($user_id)) {
344  return 2;
345  }
346  return 0;
347  }
348 
349  // PRIVATE
350 
358  public function getGroupsForUser($sid, $parameters)
359  {
360  $this->initAuth($sid);
361  $this->initIlias();
362 
363  if (!$this->__checkSession($sid)) {
364  return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
365  }
366  global $DIC;
367 
368  $rbacreview = $DIC['rbacreview'];
369  $ilObjDataCache = $DIC['ilObjDataCache'];
370  $tree = $DIC['tree'];
371 
372  include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
373  $parser = new ilXMLResultSetParser($parameters);
374  try {
375  $parser->startParsing();
376  } catch (ilSaxParserException $exception) {
377  return $this->__raiseError($exception->getMessage(), "Client");
378  }
379  $xmlResultSet = $parser->getXMLResultSet();
380 
381  if (!$xmlResultSet->hasColumn("user_id")) {
382  return $this->__raiseError("parameter user_id is missing", "Client");
383  }
384 
385  if (!$xmlResultSet->hasColumn("status")) {
386  return $this->__raiseError("parameter status is missing", "Client");
387  }
388 
389  $user_id = (int) $xmlResultSet->getValue(0, "user_id");
390  $status = (int) $xmlResultSet->getValue(0, "status");
391 
392  $ref_ids = array();
393 
394  // get roles
395  #var_dump($xmlResultSet);
396  #echo "uid:".$user_id;
397  #echo "status:".$status;
400  foreach ($rbacreview->assignedRoles($user_id) as $role_id) {
401  if ($role = ilObjectFactory::getInstanceByObjId($role_id, false)) {
402  #echo $role->getType();
403  if ($role->getType() != "role") {
404  continue;
405  }
406 
407  if ($role->getParent() == ROLE_FOLDER_ID) {
408  continue;
409  }
410  $role_title = $role->getTitle();
411 
412  if ($ref_id = ilUtil::__extractRefId($role_title)) {
413  if (!ilObject::_exists($ref_id, true) || ilObject::_isInTrash($ref_id)) {
414  continue;
415  }
416 
417  #echo $role_title;
418  if (ilSoapGroupAdministration::MEMBER == ($status & ilSoapGroupAdministration::MEMBER) && strpos($role_title, "member") !== false) {
419  $ref_ids [] = $ref_id;
420  } elseif (ilSoapGroupAdministration::ADMIN == ($status & ilSoapGroupAdministration::ADMIN) && strpos($role_title, "admin") !== false) {
421  $ref_ids [] = $ref_id;
422  }
423  }
424  }
425  }
426  }
427 
428  if (($status & ilSoapGroupAdministration::OWNER) == ilSoapGroupAdministration::OWNER) {
429  $owned_objects = ilObjectFactory::getObjectsForOwner("grp", $user_id);
430  foreach ($owned_objects as $obj_id) {
431  $allrefs = ilObject::_getAllReferences($obj_id);
432  $refs = array();
433  foreach ($allrefs as $r) {
434  if ($tree->isDeleted($r)) {
435  continue;
436  }
437  if ($tree->isInTree($r)) {
438  $refs[] = $r;
439  }
440  }
441  if (count($refs) > 0) {
442  $ref_ids[] = array_pop($refs);
443  }
444  }
445  }
446  $ref_ids = array_unique($ref_ids);
447 
448 
449  #print_r($ref_ids);
450  include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
451  include_once 'Modules/Group/classes/class.ilObjGroup.php';
452  include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
453 
454  $xmlResultSet = new ilXMLResultSet();
455  $xmlResultSet->addColumn("ref_id");
456  $xmlResultSet->addColumn("xml");
457  $xmlResultSet->addColumn("parent_ref_id");
458 
459  foreach ($ref_ids as $group_id) {
460  $group_obj = $this->checkObjectAccess($group_id, "grp", "write", true);
461  if ($group_obj instanceof ilObjGroup) {
462  $row = new ilXMLResultSetRow();
463  $row->setValue("ref_id", $group_id);
464  $xmlWriter = new ilGroupXMLWriter($group_obj);
465  $xmlWriter->setAttachUsers(false);
466  $xmlWriter->start();
467  $row->setValue("xml", $xmlWriter->getXML());
468  $row->setValue("parent_ref_id", $tree->getParentId($group_id));
469  $xmlResultSet->addRow($row);
470  }
471  }
472  $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
473  $xmlResultSetWriter->start();
474  return $xmlResultSetWriter->getXML();
475  }
476 }
excludeGroupMember($sid, $group_id, $user_id)
getGroupsForUser($sid, $parameters)
get groups which belong to a specific user, fullilling the status
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 ...
$type
global $DIC
Definition: saml.php:7
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
assignGroupMember($sid, $group_id, $user_id, $type)
const IL_GRP_ADMIN
static groupNameExists($a_group_name, $a_id=0)
checks if group name already exists.
static _isInTrash($a_ref_id)
checks wether object is in trash
$target_id
Definition: goto.php:49
SaxParserException thrown by ilSaxParser if property throwException is set.
const IL_GRP_MEMBER
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!
static __extractRefId($role_title)
extract ref id from role title, e.g.
$r
Definition: example_031.php:79
isAssignedToGroup($sid, $group_id, $user_id)
static _lookupObjId($a_id)
__raiseError($a_message, $a_code)
static getTypeByRefId($a_ref_id, $stop_on_error=true)
get object type by reference id
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _lookupType($a_id, $a_reference=false)
lookup object type
$row
$parser
Definition: BPMN2Parser.php:23
Group Import Parser.
XML writer class.
initAuth($sid)
Init authentication.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObjGroup.
addGroup($sid, $target_id, $grp_xml)