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