ILIAS  release_8 Revision v8.24
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
24include_once './webservice/soap/classes/class.ilSoapAdministration.php';
25
33{
34 public const MEMBER = 1;
35 public const ADMIN = 2;
36 public const OWNER = 4;
37
41 public function addGroup(string $sid, int $target_id, string $grp_xml)
42 {
43 $this->initAuth($sid);
44 $this->initIlias();
45
46 if (!$this->checkSession($sid)) {
47 return $this->raiseError($this->getMessage(), $this->getMessageCode());
48 }
49
50 global $DIC;
51
52 $rbacsystem = $DIC['rbacsystem'];
53
54 if (!$rbacsystem->checkAccess('create', $target_id, 'grp')) {
55 return $this->raiseError('Check access failed. No permission to create groups', 'Server');
56 }
57
58 if (ilObject::_isInTrash($target_id)) {
59 return $this->raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
60 }
61
62 $newObj = new ilObjGroup();
63 $newObj->setTitle('dummy');
64 $newObj->setDescription("");
65 $newObj->create();
66
67 include_once("./Modules/Group/classes/class.ilObjGroup.php");
68 include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
69 $xml_parser = new ilGroupXMLParser($newObj, $grp_xml, $target_id);
70 $xml_parser->startParsing();
71 $new_ref_id = $xml_parser->getObjectRefId();
72
73 return $new_ref_id ?: "0";
74 }
75
79 public function updateGroup(string $sid, int $ref_id, string $grp_xml)
80 {
81 $this->initAuth($sid);
82 $this->initIlias();
83
84 if (!$this->checkSession($sid)) {
85 return $this->raiseError($this->getMessage(), $this->getMessageCode());
86 }
87
88 global $DIC;
89
90 $rbacsystem = $DIC['rbacsystem'];
91
92 if (!$rbacsystem->checkAccess('write', $ref_id, 'grp')) {
93 return $this->raiseError('Check access failed. No permission to edit groups', 'Server');
94 }
95
96 include_once("./Modules/Group/classes/class.ilObjGroup.php");
97
99 if (!$grp = ilObjectFactory::getInstanceByRefId($ref_id, false)) {
100 return $this->raiseError('Cannot create group instance!', 'CLIENT_OBJECT_NOT_FOUND');
101 }
102
103 if (ilObject::_isInTrash($ref_id)) {
104 return $this->raiseError("Object with ID $ref_id has been deleted.", 'CLIENT_OBJECT_DELETED');
105 }
106
107 if (ilObjectFactory::getTypeByRefId($ref_id, false) !== "grp") {
108 return $this->raiseError('Reference id does not point to a group!', 'CLIENT_WRONG_TYPE');
109 }
110
111 include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
112 $xml_parser = new ilGroupXMLParser($grp, $grp_xml, -1);
113 $xml_parser->setMode(ilGroupXMLParser::$UPDATE);
114 $xml_parser->startParsing();
115 $new_ref_id = $xml_parser->getObjectRefId();
116
117 return $new_ref_id ?: "0";
118 }
119
123 public function groupExists(string $sid, string $title)
124 {
125 $this->initAuth($sid);
126 $this->initIlias();
127
128 if (!$this->checkSession($sid)) {
129 return $this->raiseError($this->getMessage(), $this->getMessageCode());
130 }
131
132 if (!$title) {
133 return $this->raiseError(
134 'No title given. Please choose an title for the group in question.',
135 'Client'
136 );
137 }
138
139 return ilUtil::groupNameExists($title);
140 }
141
145 public function getGroup(string $sid, int $ref_id)
146 {
147 $this->initAuth($sid);
148 $this->initIlias();
149
150 if (!$this->checkSession($sid)) {
151 return $this->raiseError($this->getMessage(), $this->getMessageCode());
152 }
153
154 if (ilObject::_isInTrash($ref_id)) {
155 return $this->raiseError("Parent with ID $ref_id has been deleted.", 'CLIENT_OBJECT_DELETED');
156 }
157
159 if (!$grp_obj = ilObjectFactory::getInstanceByRefId($ref_id, false)) {
160 return $this->raiseError(
161 'No valid reference id given.',
162 'Client'
163 );
164 }
165
166 include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
167 $xml_writer = new ilGroupXMLWriter($grp_obj);
168 $xml_writer->start();
169
170 return $xml_writer->getXML();
171 }
172
176 public function assignGroupMember(string $sid, int $group_id, int $user_id, string $type)
177 {
178 $this->initAuth($sid);
179 $this->initIlias();
180
181 if (!$this->checkSession($sid)) {
182 return $this->raiseError($this->getMessage(), $this->getMessageCode());
183 }
184
185 global $DIC;
186
187 $rbacsystem = $DIC['rbacsystem'];
188
189 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
190 $ref_ids = ilObject::_getAllReferences($group_id);
191 $group_id = end($ref_ids);
192 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
193 return $this->raiseError(
194 'Invalid group id. Object with id "' . $group_id . '" is not of type "group"',
195 'Client'
196 );
197 }
198 }
199
200 if (!$rbacsystem->checkAccess('manage_members', $group_id)) {
201 return $this->raiseError('Check access failed. No permission to write to group', 'Server');
202 }
203
204 if (ilObject::_lookupType($user_id) !== 'usr') {
205 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
206 }
207 if ($type !== 'Admin' &&
208 $type !== 'Member') {
209 return $this->raiseError(
210 'Invalid type ' . $type . ' given. Parameter "type" must be "Admin","Member"',
211 'Client'
212 );
213 }
214
216 if (!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id, false)) {
217 return $this->raiseError('Cannot create group instance!', 'Server');
218 }
219
221 if (!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id, false)) {
222 return $this->raiseError('Cannot create user instance!', 'Server');
223 }
224
225 include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
226 $group_members = ilGroupParticipants::_getInstanceByObjId($tmp_group->getId());
227
228 switch ($type) {
229 case 'Admin':
230 $group_members->add($tmp_user->getId(), ilParticipants::IL_GRP_ADMIN);
231 break;
232
233 case 'Member':
234 $group_members->add($tmp_user->getId(), ilParticipants::IL_GRP_MEMBER);
235 break;
236 }
237 return true;
238 }
239
243 public function excludeGroupMember(string $sid, int $group_id, int $user_id)
244 {
245 $this->initAuth($sid);
246 $this->initIlias();
247
248 if (!$this->checkSession($sid)) {
249 return $this->raiseError($this->getMessage(), $this->getMessageCode());
250 }
251
252 global $DIC;
253
254 $rbacsystem = $DIC['rbacsystem'];
255
256 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
257 $ref_ids = ilObject::_getAllReferences($group_id);
258 $group_id = end($ref_ids);
259 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
260 return $this->raiseError(
261 'Invalid group id. Object with id "' . $group_id . '" is not of type "group"',
262 'Client'
263 );
264 }
265 }
266
267 if (ilObject::_lookupType($user_id) !== 'usr') {
268 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
269 }
270
272 if (!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id, false)) {
273 return $this->raiseError('Cannot create group instance!', 'Server');
274 }
275
276 if (!$rbacsystem->checkAccess('manage_members', $group_id)) {
277 return $this->raiseError('Check access failed. No permission to write to group', 'Server');
278 }
279
280 $tmp_group->leave($user_id);
281 return true;
282 }
283
287 public function isAssignedToGroup(string $sid, int $group_id, int $user_id)
288 {
289 $this->initAuth($sid);
290 $this->initIlias();
291
292 if (!$this->checkSession($sid)) {
293 return $this->raiseError($this->getMessage(), $this->getMessageCode());
294 }
295
296 global $DIC;
297
298 $rbacsystem = $DIC['rbacsystem'];
299
300 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
301 $ref_ids = ilObject::_getAllReferences($group_id);
302 $group_id = end($ref_ids);
303 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
304 return $this->raiseError(
305 'Invalid group id. Object with id "' . $group_id . '" is not of type "group"',
306 'Client'
307 );
308 }
309 }
310
311 if (ilObject::_lookupType($user_id) !== 'usr') {
312 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
313 }
314
316 if (!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id, false)) {
317 return $this->raiseError('Cannot create group instance!', 'Server');
318 }
319
320 if (!$rbacsystem->checkAccess('read', $group_id)) {
321 return $this->raiseError('Check access failed. No permission to read group data', 'Server');
322 }
323
324 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
326
327 if ($participants->isAdmin($user_id)) {
328 return 1;
329 }
330 if ($participants->isMember($user_id)) {
331 return 2;
332 }
333 return 0;
334 }
335
339 public function getGroupsForUser(string $sid, string $parameters)
340 {
341 $this->initAuth($sid);
342 $this->initIlias();
343
344 if (!$this->checkSession($sid)) {
345 return $this->raiseError($this->getMessage(), $this->getMessageCode());
346 }
347 global $DIC;
348
349 $rbacreview = $DIC['rbacreview'];
350 $ilObjDataCache = $DIC['ilObjDataCache'];
351 $tree = $DIC['tree'];
352
353 include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
354 $parser = new ilXMLResultSetParser($parameters);
355 try {
356 $parser->startParsing();
357 } catch (ilSaxParserException $exception) {
358 return $this->raiseError($exception->getMessage(), "Client");
359 }
360 $xmlResultSet = $parser->getXMLResultSet();
361
362 if (!$xmlResultSet->hasColumn("user_id")) {
363 return $this->raiseError("parameter user_id is missing", "Client");
364 }
365
366 if (!$xmlResultSet->hasColumn("status")) {
367 return $this->raiseError("parameter status is missing", "Client");
368 }
369
370 $user_id = (int) $xmlResultSet->getValue(0, "user_id");
371 $status = (int) $xmlResultSet->getValue(0, "status");
372
373 $ref_ids = array();
374
377 foreach ($rbacreview->assignedRoles($user_id) as $role_id) {
378 if ($role = ilObjectFactory::getInstanceByObjId($role_id, false)) {
379 #echo $role->getType();
380 if ($role->getType() !== "role") {
381 continue;
382 }
383
384 if ($role->getParent() == ROLE_FOLDER_ID) {
385 continue;
386 }
387 $role_title = $role->getTitle();
388
389 if ($ref_id = ilUtil::__extractRefId($role_title)) {
391 continue;
392 }
393
394 #echo $role_title;
396 $role_title,
397 "member"
398 ) !== false) {
399 $ref_ids [] = $ref_id;
401 $role_title,
402 "admin"
403 ) !== false) {
404 $ref_ids [] = $ref_id;
405 }
406 }
407 }
408 }
409 }
410
412 $owned_objects = ilObjectFactory::getObjectsForOwner("grp", $user_id);
413 foreach ($owned_objects as $obj_id) {
414 $allrefs = ilObject::_getAllReferences($obj_id);
415 $refs = array();
416 foreach ($allrefs as $r) {
417 if ($tree->isDeleted($r)) {
418 continue;
419 }
420 if ($tree->isInTree($r)) {
421 $refs[] = $r;
422 }
423 }
424 if (count($refs) > 0) {
425 $ref_ids[] = array_pop($refs);
426 }
427 }
428 }
429 $ref_ids = array_unique($ref_ids);
430
431 include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
432 include_once 'Modules/Group/classes/class.ilObjGroup.php';
433 include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
434
435 $xmlResultSet = new ilXMLResultSet();
436 $xmlResultSet->addColumn("ref_id");
437 $xmlResultSet->addColumn("xml");
438 $xmlResultSet->addColumn("parent_ref_id");
439
440 foreach ($ref_ids as $group_id) {
441 $group_obj = $this->checkObjectAccess($group_id, ['grp'], "write", true);
442 if ($group_obj instanceof ilObjGroup) {
443 $row = new ilXMLResultSetRow();
444 $row->setValue("ref_id", $group_id);
445 $xmlWriter = new ilGroupXMLWriter($group_obj);
446 $xmlWriter->setAttachUsers(false);
447 $xmlWriter->start();
448 $row->setValue("xml", $xmlWriter->getXML());
449 $row->setValue("parent_ref_id", $tree->getParentId($group_id));
450 $xmlResultSet->addRow($row);
451 }
452 }
453 $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
454 $xmlResultSetWriter->start();
455 return $xmlResultSetWriter->getXML();
456 }
457}
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
Group Import Parser.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjGroup.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getTypeByRefId(int $ref_id, bool $stop_on_error=true)
get object type by reference id
static getObjectsForOwner(string $object_type, int $owner_id)
returns all objects of an owner, filtered by type, objects are not deleted!
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _isInTrash(int $ref_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupObjId(int $ref_id)
SaxParserException thrown by ilSaxParser if property throwException is set.
soap server Base class for all SOAP registered methods.
raiseError(string $a_message, $a_code)
checkObjectAccess(int $ref_id, array $expected_type, string $permission, bool $returnObject=false)
check access for ref id: expected type, permission, return object instance if returnobject is true
groupExists(string $sid, string $title)
getGroupsForUser(string $sid, string $parameters)
addGroup(string $sid, int $target_id, string $grp_xml)
static groupNameExists(string $a_group_name, ?int $a_id=null)
checks if group name already exists.
static __extractRefId(string $role_title)
extract ref id from role title, e.g.
Row Class for XMLResultSet.
XML Writer for XMLResultSet.
const ROLE_FOLDER_ID
Definition: constants.php:34
global $DIC
Definition: feed.php:28
$target_id
Definition: goto.php:52
$ref_id
Definition: ltiauth.php:67
$type