ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 function addGroup($sid,$target_id,$grp_xml)
45 {
46 $this->initAuth($sid);
47 $this->initIlias();
48
49 if(!$this->__checkSession($sid))
50 {
51 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
52 }
53
54 if(!is_numeric($target_id))
55 {
56 return $this->__raiseError('No valid target id given. Please choose an existing reference id of an ILIAS category or group',
57 'Client');
58 }
59
60 global $rbacsystem;
61
62 if(!$rbacsystem->checkAccess('create',$target_id,'grp'))
63 {
64 return $this->__raiseError('Check access failed. No permission to create groups','Server');
65 }
66
68 {
69 return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_TARGET_DELETED');
70 }
71
72
73 // Start import
74 include_once("./Modules/Group/classes/class.ilObjGroup.php");
75 include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
76 $xml_parser = new ilGroupXMLParser($grp_xml,$target_id);
77 $new_ref_id = $xml_parser->startParsing();
78
79 return $new_ref_id ? $new_ref_id : "0";
80 }
81
82 // Service methods
83 function updateGroup($sid,$ref_id,$grp_xml)
84 {
85 $this->initAuth($sid);
86 $this->initIlias();
87
88
89 if(!$this->__checkSession($sid))
90 {
91 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
92 }
93
94
95
96 if(!is_numeric($ref_id))
97 {
98 return $this->__raiseError('No valid target id given. Please choose an existing reference id of an ILIAS category or group',
99 'Client');
100 }
101
102 global $rbacsystem;
103
104 if(!$rbacsystem->checkAccess('write',$ref_id,'grp'))
105 {
106 return $this->__raiseError('Check access failed. No permission to edit groups','Server');
107 }
108
109 // Start import
110 include_once("./Modules/Group/classes/class.ilObjGroup.php");
111
113 {
114 return $this->__raiseError('Cannot create group instance!','CLIENT_OBJECT_NOT_FOUND');
115 }
116
118 {
119 return $this->__raiseError("Object with ID $ref_id has been deleted.", 'CLIENT_OBJECT_DELETED');
120 }
121
122
123 if (ilObjectFactory::getTypeByRefId($ref_id, false) !="grp")
124 {
125 return $this->__raiseError('Reference id does not point to a group!','CLIENT_WRONG_TYPE');
126 }
127
128
129 include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
130 $xml_parser = new ilGroupXMLParser($grp_xml, -1);
131 $xml_parser->setMode(ilGroupXMLParser::$UPDATE);
132 $xml_parser->setGroup($grp);
133 $new_ref_id = $xml_parser->startParsing();
134
135 return $new_ref_id ? $new_ref_id : "0";
136 }
137
138
139 function groupExists($sid,$title)
140 {
141 $this->initAuth($sid);
142 $this->initIlias();
143
144 if(!$this->__checkSession($sid))
145 {
146 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
147 }
148
149 if(!$title)
150 {
151 return $this->__raiseError('No title given. Please choose an title for the group in question.',
152 'Client');
153 }
154
156 }
157
158 function getGroup($sid,$ref_id)
159 {
160 $this->initAuth($sid);
161 $this->initIlias();
162
163 if(!$this->__checkSession($sid))
164 {
165 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
166 }
167
169 {
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 {
176 return $this->__raiseError('No valid reference id given.',
177 'Client');
178 }
179
180
181 include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
182
183 $xml_writer = new ilGroupXMLWriter($grp_obj);
184 $xml_writer->start();
185
186 $xml = $xml_writer->getXML();
187
188 return strlen($xml) ? $xml : '';
189 }
190
191
192 function assignGroupMember($sid,$group_id,$user_id,$type)
193 {
194 $this->initAuth($sid);
195 $this->initIlias();
196
197 if(!$this->__checkSession($sid))
198 {
199 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
200 }
201
202 if(!is_numeric($group_id))
203 {
204 return $this->__raiseError('No valid group id given. Please choose an existing reference id of an ILIAS group',
205 'Client');
206 }
207
208 global $rbacsystem;
209
210 if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($group_id))) != 'grp')
211 {
212 $group_id = end($ref_ids = ilObject::_getAllReferences($group_id));
213 if(ilObject::_lookupType(ilObject::_lookupObjId($group_id)) != 'grp')
214 {
215 return $this->__raiseError('Invalid group id. Object with id "'. $group_id.'" is not of type "group"','Client');
216 }
217 }
218
219 if(!$rbacsystem->checkAccess('write',$group_id))
220 {
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 {
227 return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
228 }
229 if($type != 'Admin' and
230 $type != 'Member')
231 {
232 return $this->__raiseError('Invalid type '.$type.' given. Parameter "type" must be "Admin","Member"','Client');
233 }
234
235 if(!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id,false))
236 {
237 return $this->__raiseError('Cannot create group instance!','Server');
238 }
239
240 if(!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id,false))
241 {
242 return $this->__raiseError('Cannot create user instance!','Server');
243 }
244
245
246 include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
247 $group_members = ilGroupParticipants::_getInstanceByObjId($tmp_group->getId());
248
249 switch($type)
250 {
251 case 'Admin':
252 $group_members->add($tmp_user->getId(),IL_GRP_ADMIN);
253 break;
254
255 case 'Member':
256 $group_members->add($tmp_user->getId(),IL_GRP_MEMBER);
257 break;
258 }
259 return true;
260 }
261
262 function excludeGroupMember($sid,$group_id,$user_id)
263 {
264 $this->initAuth($sid);
265 $this->initIlias();
266
267 if(!$this->__checkSession($sid))
268 {
269 return $this->__raiseError($this->__getMessage(),$this->__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 global $rbacsystem;
278
279 if(($type = ilObject::_lookupType(ilObject::_lookupObjId($group_id))) != 'grp')
280 {
281 $group_id = end($ref_ids = ilObject::_getAllReferences($group_id));
282 if(ilObject::_lookupType(ilObject::_lookupObjId($group_id)) != 'grp')
283 {
284 return $this->__raiseError('Invalid group id. Object with id "'. $group_id.'" is not of type "group"','Client');
285 }
286 }
287
288 if(ilObject::_lookupType($user_id) != 'usr')
289 {
290 return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
291 }
292
293 if(!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id,false))
294 {
295 return $this->__raiseError('Cannot create group instance!','Server');
296 }
297
298 if(!$rbacsystem->checkAccess('write',$group_id))
299 {
300 return $this->__raiseError('Check access failed. No permission to write to group','Server');
301 }
302
303 $tmp_group->leave($user_id);
304 return true;
305 }
306
307
308 function isAssignedToGroup($sid,$group_id,$user_id)
309 {
310 $this->initAuth($sid);
311 $this->initIlias();
312
313 if(!$this->__checkSession($sid))
314 {
315 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
316 }
317 if(!is_numeric($group_id))
318 {
319 return $this->__raiseError('No valid group id given. Please choose an existing id of an ILIAS group',
320 'Client');
321 }
322 global $rbacsystem;
323
324 if(($type = ilObject::_lookupType(ilObject::_lookupObjId($group_id))) != 'grp')
325 {
326 $group_id = end($ref_ids = ilObject::_getAllReferences($group_id));
327 if(ilObject::_lookupType(ilObject::_lookupObjId($group_id)) != 'grp')
328 {
329 return $this->__raiseError('Invalid group id. Object with id "'. $group_id.'" is not of type "group"','Client');
330 }
331 }
332
333 if(ilObject::_lookupType($user_id) != 'usr')
334 {
335 return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
336 }
337
338 if(!$tmp_group = ilObjectFactory::getInstanceByRefId($group_id,false))
339 {
340 return $this->__raiseError('Cannot create group instance!','Server');
341 }
342
343 if(!$rbacsystem->checkAccess('read',$group_id))
344 {
345 return $this->__raiseError('Check access failed. No permission to read group data','Server');
346 }
347
348 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
350
351 if($participants->isAdmin($user_id))
352 {
353 return 1;
354 }
355 if($participants->isMember($user_id))
356 {
357 return 2;
358 }
359 return 0;
360 }
361
362 // PRIVATE
363
371 function getGroupsForUser($sid, $parameters) {
372
373 $this->initAuth($sid);
374 $this->initIlias();
375
376 if(!$this->__checkSession($sid))
377 {
378 return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
379 }
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
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->isDeleted($r))
448 {
449 continue;
450 }
451 if ($tree->isInTree($r))
452 {
453 $refs[] = $r;
454 }
455 }
456 if (count($refs) > 0)
457 $ref_ids[] = array_pop($refs);
458 }
459 }
460 $ref_ids = array_unique($ref_ids);
461
462
463#print_r($ref_ids);
464 include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
465 include_once 'Modules/Group/classes/class.ilObjGroup.php';
466 include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
467
468 $xmlResultSet = new ilXMLResultSet();
469 $xmlResultSet->addColumn("ref_id");
470 $xmlResultSet->addColumn("xml");
471 $xmlResultSet->addColumn("parent_ref_id");
472
473 foreach ($ref_ids as $group_id) {
474 $group_obj = $this->checkObjectAccess($group_id,"grp","write", true);
475 if ($group_obj instanceof ilObjGroup) {
476 $row = new ilXMLResultSetRow();
477 $row->setValue("ref_id", $group_id);
478 $xmlWriter = new ilGroupXMLWriter($group_obj);
479 $xmlWriter->setAttachUsers(false);
480 $xmlWriter->start();
481 $row->setValue("xml", $xmlWriter->getXML());
482 $row->setValue("parent_ref_id", $tree->getParentId($group_id));
483 $xmlResultSet->addRow($row);
484 }
485 }
486 $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
487 $xmlResultSetWriter->start();
488 return $xmlResultSetWriter->getXML();
489 }
490}
491?>
$parser
Definition: BPMN2Parser.php:24
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:51
$ref_id
Definition: sahs_server.php:39