ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSoapGroupAdministration.php
Go to the documentation of this file.
1<?php
25{
26 public const MEMBER = 1;
27 public const ADMIN = 2;
28 public const OWNER = 4;
29
33 public function addGroup(string $sid, int $target_id, string $grp_xml)
34 {
35 $this->initAuth($sid);
36 $this->initIlias();
37
38 if (!$this->checkSession($sid)) {
39 return $this->raiseError($this->getMessage(), $this->getMessageCode());
40 }
41
42 global $DIC;
43
44 $rbacsystem = $DIC['rbacsystem'];
45
46 if (!$rbacsystem->checkAccess('create', $target_id, 'grp')) {
47 return $this->raiseError('Check access failed. No permission to create groups', 'Server');
48 }
49
50 if (ilObject::_isInTrash($target_id)) {
51 return $this->raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
52 }
53
54 $newObj = new ilObjGroup();
55 $newObj->setTitle('dummy');
56 $newObj->setDescription("");
57 $newObj->create();
58
59 $xml_parser = new ilGroupXMLParser($newObj, $grp_xml, $target_id);
60 $xml_parser->startParsing();
61 $new_ref_id = $xml_parser->getObjectRefId();
62
63 return $new_ref_id ?: "0";
64 }
65
69 public function updateGroup(string $sid, int $ref_id, string $grp_xml)
70 {
71 $this->initAuth($sid);
72 $this->initIlias();
73
74 if (!$this->checkSession($sid)) {
75 return $this->raiseError($this->getMessage(), $this->getMessageCode());
76 }
77
78 global $DIC;
79
80 $rbacsystem = $DIC['rbacsystem'];
81
82 if (!$rbacsystem->checkAccess('write', $ref_id, 'grp')) {
83 return $this->raiseError('Check access failed. No permission to edit groups', 'Server');
84 }
85
87 if (!$grp = ilObjectFactory::getInstanceByRefId($ref_id, false)) {
88 return $this->raiseError('Cannot create group instance!', 'CLIENT_OBJECT_NOT_FOUND');
89 }
90
91 if (ilObject::_isInTrash($ref_id)) {
92 return $this->raiseError("Object with ID $ref_id has been deleted.", 'CLIENT_OBJECT_DELETED');
93 }
94
95 if (ilObjectFactory::getTypeByRefId($ref_id, false) !== "grp") {
96 return $this->raiseError('Reference id does not point to a group!', 'CLIENT_WRONG_TYPE');
97 }
98
99 $xml_parser = new ilGroupXMLParser($grp, $grp_xml, -1);
100 $xml_parser->setMode(ilGroupXMLParser::$UPDATE);
101 $xml_parser->startParsing();
102 $new_ref_id = $xml_parser->getObjectRefId();
103
104 return $new_ref_id ?: "0";
105 }
106
110 public function groupExists(string $sid, string $title)
111 {
112 $this->initAuth($sid);
113 $this->initIlias();
114
115 if (!$this->checkSession($sid)) {
116 return $this->raiseError($this->getMessage(), $this->getMessageCode());
117 }
118
119 if (!$title) {
120 return $this->raiseError(
121 'No title given. Please choose an title for the group in question.',
122 'Client'
123 );
124 }
125
126 return ilUtil::groupNameExists($title);
127 }
128
132 public function getGroup(string $sid, int $ref_id)
133 {
134 $this->initAuth($sid);
135 $this->initIlias();
136
137 if (!$this->checkSession($sid)) {
138 return $this->raiseError($this->getMessage(), $this->getMessageCode());
139 }
140
141 if (ilObject::_isInTrash($ref_id)) {
142 return $this->raiseError("Parent with ID $ref_id has been deleted.", 'CLIENT_OBJECT_DELETED');
143 }
144
146 if (!$grp_obj = ilObjectFactory::getInstanceByRefId($ref_id, false)) {
147 return $this->raiseError(
148 'No valid reference id given.',
149 'Client'
150 );
151 }
152
153 $xml_writer = new ilGroupXMLWriter($grp_obj);
154 $xml_writer->start();
155
156 return $xml_writer->getXML();
157 }
158
162 public function assignGroupMember(string $sid, int $group_id, int $user_id, string $type)
163 {
164 $this->initAuth($sid);
165 $this->initIlias();
166
167 if (!$this->checkSession($sid)) {
168 return $this->raiseError($this->getMessage(), $this->getMessageCode());
169 }
170
171 global $DIC;
172
173 $rbacsystem = $DIC['rbacsystem'];
174
175 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
176 $ref_ids = ilObject::_getAllReferences($group_id);
177 $group_id = end($ref_ids);
178 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
179 return $this->raiseError(
180 'Invalid group id. Object with id "' . $group_id . '" is not of type "group"',
181 'Client'
182 );
183 }
184 }
185
186 if (!$rbacsystem->checkAccess('manage_members', $group_id)) {
187 return $this->raiseError('Check access failed. No permission to write to group', 'Server');
188 }
189
190 if (ilObject::_lookupType($user_id) !== 'usr') {
191 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
192 }
193 if ($type !== 'Admin' &&
194 $type !== 'Member') {
195 return $this->raiseError(
196 'Invalid type ' . $type . ' given. Parameter "type" must be "Admin","Member"',
197 'Client'
198 );
199 }
200
202 if (!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id, false)) {
203 return $this->raiseError('Cannot create group instance!', 'Server');
204 }
205
207 if (!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id, false)) {
208 return $this->raiseError('Cannot create user instance!', 'Server');
209 }
210
211 $group_members = ilGroupParticipants::_getInstanceByObjId($tmp_group->getId());
212
213 switch ($type) {
214 case 'Admin':
215 $group_members->add($tmp_user->getId(), ilParticipants::IL_GRP_ADMIN);
216 break;
217
218 case 'Member':
219 $group_members->add($tmp_user->getId(), ilParticipants::IL_GRP_MEMBER);
220 break;
221 }
222 return true;
223 }
224
228 public function excludeGroupMember(string $sid, int $group_id, int $user_id)
229 {
230 $this->initAuth($sid);
231 $this->initIlias();
232
233 if (!$this->checkSession($sid)) {
234 return $this->raiseError($this->getMessage(), $this->getMessageCode());
235 }
236
237 global $DIC;
238
239 $rbacsystem = $DIC['rbacsystem'];
240
241 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
242 $ref_ids = ilObject::_getAllReferences($group_id);
243 $group_id = end($ref_ids);
244 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
245 return $this->raiseError(
246 'Invalid group id. Object with id "' . $group_id . '" is not of type "group"',
247 'Client'
248 );
249 }
250 }
251
252 if (ilObject::_lookupType($user_id) !== 'usr') {
253 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
254 }
255
257 if (!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id, false)) {
258 return $this->raiseError('Cannot create group instance!', 'Server');
259 }
260
261 if (!$rbacsystem->checkAccess('manage_members', $group_id)) {
262 return $this->raiseError('Check access failed. No permission to write to group', 'Server');
263 }
264
265 $tmp_group->leave($user_id);
266 return true;
267 }
268
272 public function isAssignedToGroup(string $sid, int $group_id, int $user_id)
273 {
274 $this->initAuth($sid);
275 $this->initIlias();
276
277 if (!$this->checkSession($sid)) {
278 return $this->raiseError($this->getMessage(), $this->getMessageCode());
279 }
280
281 global $DIC;
282
283 $rbacsystem = $DIC['rbacsystem'];
284
285 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
286 $ref_ids = ilObject::_getAllReferences($group_id);
287 $group_id = end($ref_ids);
288 if (ilObject::_lookupType(ilObject::_lookupObjId($group_id)) !== 'grp') {
289 return $this->raiseError(
290 'Invalid group id. Object with id "' . $group_id . '" is not of type "group"',
291 'Client'
292 );
293 }
294 }
295
296 if (ilObject::_lookupType($user_id) !== 'usr') {
297 return $this->raiseError('Invalid user id. User with id "' . $user_id . ' does not exist', 'Client');
298 }
299
301 if (!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id, false)) {
302 return $this->raiseError('Cannot create group instance!', 'Server');
303 }
304
305 if (!$rbacsystem->checkAccess('read', $group_id)) {
306 return $this->raiseError('Check access failed. No permission to read group data', 'Server');
307 }
308
310
311 if ($participants->isAdmin($user_id)) {
312 return 1;
313 }
314 if ($participants->isMember($user_id)) {
315 return 2;
316 }
317 return 0;
318 }
319
323 public function getGroupsForUser(string $sid, string $parameters)
324 {
325 $this->initAuth($sid);
326 $this->initIlias();
327
328 if (!$this->checkSession($sid)) {
329 return $this->raiseError($this->getMessage(), $this->getMessageCode());
330 }
331 global $DIC;
332
333 $rbacreview = $DIC['rbacreview'];
334 $ilObjDataCache = $DIC['ilObjDataCache'];
335 $tree = $DIC['tree'];
336
337 $parser = new ilXMLResultSetParser($parameters);
338 try {
339 $parser->startParsing();
340 } catch (ilSaxParserException $exception) {
341 return $this->raiseError($exception->getMessage(), "Client");
342 }
343 $xmlResultSet = $parser->getXMLResultSet();
344
345 if (!$xmlResultSet->hasColumn("user_id")) {
346 return $this->raiseError("parameter user_id is missing", "Client");
347 }
348
349 if (!$xmlResultSet->hasColumn("status")) {
350 return $this->raiseError("parameter status is missing", "Client");
351 }
352
353 $user_id = (int) $xmlResultSet->getValue(0, "user_id");
354 $status = (int) $xmlResultSet->getValue(0, "status");
355
356 $ref_ids = array();
357
360 foreach ($rbacreview->assignedRoles($user_id) as $role_id) {
361 if ($role = ilObjectFactory::getInstanceByObjId($role_id, false)) {
362 #echo $role->getType();
363 if ($role->getType() !== "role") {
364 continue;
365 }
366
367 if ($role->getParent() == ROLE_FOLDER_ID) {
368 continue;
369 }
370 $role_title = $role->getTitle();
371
372 if ($ref_id = ilUtil::__extractRefId($role_title)) {
374 continue;
375 }
376
377 #echo $role_title;
379 $role_title,
380 "member"
381 ) !== false) {
382 $ref_ids [] = $ref_id;
384 $role_title,
385 "admin"
386 ) !== false) {
387 $ref_ids [] = $ref_id;
388 }
389 }
390 }
391 }
392 }
393
395 $owned_objects = ilObjectFactory::getObjectsForOwner("grp", $user_id);
396 foreach ($owned_objects as $obj_id) {
397 $allrefs = ilObject::_getAllReferences($obj_id);
398 $refs = array();
399 foreach ($allrefs as $r) {
400 if ($tree->isDeleted($r)) {
401 continue;
402 }
403 if ($tree->isInTree($r)) {
404 $refs[] = $r;
405 }
406 }
407 if (count($refs) > 0) {
408 $ref_ids[] = array_pop($refs);
409 }
410 }
411 }
412 $ref_ids = array_unique($ref_ids);
413
414 $xmlResultSet = new ilXMLResultSet();
415 $xmlResultSet->addColumn("ref_id");
416 $xmlResultSet->addColumn("xml");
417 $xmlResultSet->addColumn("parent_ref_id");
418
419 foreach ($ref_ids as $group_id) {
420 $group_obj = $this->checkObjectAccess($group_id, ['grp'], "write", true);
421 if ($group_obj instanceof ilObjGroup) {
422 $row = new ilXMLResultSetRow();
423 $row->setValue("ref_id", $group_id);
424 $xmlWriter = new ilGroupXMLWriter($group_obj);
425 $xmlWriter->setAttachUsers(false);
426 $xmlWriter->start();
427 $row->setValue("xml", $xmlWriter->getXML());
428 $row->setValue("parent_ref_id", $tree->getParentId($group_id));
429 $xmlResultSet->addRow($row);
430 }
431 }
432 $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
433 $xmlResultSetWriter->start();
434 return $xmlResultSetWriter->getXML();
435 }
436}
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
Group Import Parser.
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26