ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilGroupXMLParser.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 require_once("./Services/Xml/classes/class.ilSaxParser.php");
25 require_once('./Services/User/classes/class.ilObjUser.php');
26 include_once('./Services/Calendar/classes/class.ilDateTime.php');
27 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
28 
29 
40 {
41  public static $CREATE = 1;
42  public static $UPDATE = 2;
43 
47  protected $log;
48 
49  private $participants = null;
51  private $sort = null;
52 
55 
56  var $parent;
57  var $counter;
58 
59  var $mode;
60  var $grp;
61 
70  function __construct($a_xml, $a_parent_id)
71  {
72  define('EXPORT_VERSION',2);
73 
74  parent::__construct(null);
75 
76  $this->mode = ilGroupXMLParser::$CREATE;
77  $this->grp = null;
78 
79  $this->log = $GLOBALS['DIC']->logger()->grp();
80 
81  $this->setXMLContent($a_xml);
82 
83  // SET MEMBER VARIABLES
84  $this->__pushParentId($a_parent_id);
85 
86 
87  }
88 
89  function __pushParentId($a_id)
90  {
91  $this->parent[] = $a_id;
92  }
93  function __popParentId()
94  {
95  array_pop($this->parent);
96 
97  return true;
98  }
99  function __getParentId()
100  {
101  return $this->parent[count($this->parent) - 1];
102  }
103 
109  function setHandlers($a_xml_parser)
110  {
111  xml_set_object($a_xml_parser,$this);
112  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
113  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
114  }
115 
119  function startParsing()
120  {
121  parent::startParsing();
122 
123  if ($this->mode == ilGroupXMLParser::$CREATE)
124  {
125  return is_object($this->group_obj) ? $this->group_obj->getRefId() : false;
126  }
127  else
128  {
129  return is_object($this->group_obj) ? $this->group_obj->update() : false;
130  }
131  }
132 
133 
137  function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
138  {
139  global $ilErr;
140 
141  switch($a_name)
142  {
143  // GROUP DATA
144  case "group":
145  $this->group_data["admin"] = array();
146  $this->group_data["member"] = array();
147 
148  $this->group_data["type"] = $a_attribs["type"];
149  $this->group_data["id"] = $a_attribs["id"];
150 
151  break;
152 
153  case 'title':
154  break;
155 
156  case "owner":
157  $this->group_data["owner"] = $a_attribs["id"];
158  break;
159 
160  case 'registration':
161  $this->group_data['registration_type'] = $a_attribs['type'];
162  $this->group_data['waiting_list_enabled'] = $a_attribs['waitingList'] == 'Yes' ? true : false;
163  break;
164 
165  case 'maxMembers':
166  $this->group_data['max_members_enabled'] = $a_attribs['enabled'] == 'Yes' ? true : false;
167  break;
168 
169  case "admin":
170  if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach")
171  {
172  $this->group_data["admin"]["attach"][] = $a_attribs["id"];
173  }
174  elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach")
175  {
176  $this->group_data["admin"]["detach"][] = $a_attribs["id"];
177  }
178 
179  if(isset($a_attribs['notification']) and $a_attribs['notification'] == 'Yes')
180  {
181  $this->group_data['notifications'][] = $a_attribs['id'];
182  }
183 
184  break;
185 
186  case "member":
187  if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach")
188  {
189  $GLOBALS['ilLog']->write(__METHOD__.': new member with id '.$a_attribs['id']);
190  $this->group_data["member"]["attach"][] = $a_attribs["id"];
191  } elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach")
192  {
193  $GLOBALS['ilLog']->write(__METHOD__.': deprecated member with id '.$a_attribs['id']);
194  $this->group_data["member"]["detach"][] = $a_attribs["id"];
195  }
196 
197  break;
198 
199  case 'ContainerSetting':
200  $this->current_container_setting = $a_attribs['id'];
201  break;
202 
203  case 'Sort':
204 
205  if($this->group_imported)
206  {
207  $this->__initContainerSorting($a_attribs, $this->group_obj->getId());
208  }
209  else
210  {
211  $this->sort = $a_attribs;
212  }
213 
214  break;
215 
216  case 'WaitingListAutoFill':
217  case 'CancellationEnd':
218  case 'minMembers':
219  case 'mailMembersType':
220  break;
221  }
222  }
223 
224 
225  function handlerEndTag($a_xml_parser, $a_name)
226  {
227  switch($a_name)
228  {
229  case "title":
230  $this->group_data["title"] = trim($this->cdata);
231  break;
232 
233  case "description":
234  $this->group_data["description"] = trim($this->cdata);
235  break;
236 
237  case 'information':
238  $this->group_data['information'] = trim($this->cdata);
239  break;
240 
241  case 'password':
242  $this->group_data['password'] = trim($this->cdata);
243  break;
244 
245  case 'maxMembers':
246  $this->group_data['max_members'] = trim($this->cdata);
247  break;
248 
249  case 'expiration':
250  $this->group_data['expiration_end'] = trim($this->cdata);
251  break;
252 
253  case 'start':
254  $this->group_data['expiration_start'] = trim($this->cdata);
255  break;
256 
257  case 'end':
258  $this->group_data['expiration_end'] = trim($this->cdata);
259  break;
260 
261  case "group":
262  // NOW SAVE THE NEW OBJECT (if it hasn't been imported)
263  $this->__save();
264  break;
265 
266  case 'ContainerSetting':
267  if($this->current_container_setting)
268  {
269  // #17357
270  if(!($this->group_obj instanceof ilObjGroup))
271  {
272  $this->__initGroupObject();
273  }
275  $this->group_obj->getId(),
277  $this->cdata);
278  }
279  break;
280 
281  case 'WaitingListAutoFill':
282  $this->group_data['auto_wait'] = trim($this->cdata);
283  break;
284 
285  case 'CancellationEnd':
286  if((int)$this->cdata)
287  {
288  $this->group_data['cancel_end'] = new ilDate((int)$this->cdata, IL_CAL_UNIX);
289  }
290  break;
291 
292  case 'minMembers':
293  if((int)$this->cdata)
294  {
295  $this->group_data['min_members'] = (int)$this->cdata;
296  }
297  break;
298 
299  case 'mailMembersType':
300  $this->group_data['mail_members_type'] = (int) $this->cdata;
301  break;
302 
303  }
304  $this->cdata = '';
305  }
306 
307 
311  function handlerCharacterData($a_xml_parser, $a_data)
312  {
313  // i don't know why this is necessary, but
314  // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
315  // in character data, but we don't want that, because it's the
316  // way we mask user html in our content, so we convert back...
317  $a_data = str_replace("<","&lt;",$a_data);
318  $a_data = str_replace(">","&gt;",$a_data);
319 
320  if(!empty($a_data))
321  {
322  $this->cdata .= $a_data;
323  }
324  }
325 
326  // PRIVATE
327  function __save()
328  {
329  if($this->group_imported)
330  {
331  return true;
332  }
333 
334  $this->__initGroupObject();
335 
336  $this->group_obj->setImportId($this->group_data["id"]);
337  $this->group_obj->setTitle($this->group_data["title"]);
338  $this->group_obj->setDescription($this->group_data["description"]);
339  $this->group_obj->setInformation((string) $this->group_data['information']);
340 
341  $ownerChanged = false;
342  if (isset($this->group_data["owner"]))
343  {
344  $owner = $this->group_data["owner"];
345  if (!is_numeric($owner))
346  {
347  $owner = ilUtil::__extractId ($owner, IL_INST_ID);
348  }
349  if (is_numeric($owner) && $owner > 0)
350  {
351  $this->group_obj->setOwner($owner);
352  $ownerChanged = true;
353  }
354  }
355 
359  if ($this->mode == ilGroupXMLParser::$CREATE)
360  {
361  $this->group_obj->create();
362  $this->group_obj->createReference();
363  $this->group_obj->putInTree($this->__getParentId());
364  $this->group_obj->setPermissions($this->__getParentId());
365  $this->group_obj->initGroupStatus($this->group_data["type"] == "open" ? GRP_TYPE_PUBLIC : GRP_TYPE_CLOSED);
366  }
367  else
368  {
369  switch($this->group_data['type'])
370  {
371  case 'open':
372  $grp_status = GRP_TYPE_PUBLIC;
373  break;
374 
375  case 'closed':
376  $grp_status = GRP_TYPE_CLOSED;
377  break;
378 
379  }
380 
381  $this->group_obj->updateOwner();
382  if($this->group_obj->getGroupStatus() != $grp_status)
383  {
384  $this->group_obj->setGroupType($grp_status);
385  $this->group_obj->updateGroupType();
386  }
387  }
388 
389  // SET GROUP SPECIFIC DATA
390  switch($this->group_data['registration_type'])
391  {
392  case 'direct':
393  case 'enabled':
394  $flag = GRP_REGISTRATION_DIRECT;
395  break;
396 
397  case 'disabled':
399  break;
400 
401  case 'confirmation':
402  $flag = GRP_REGISTRATION_REQUEST;
403  break;
404 
405  case 'password':
407  break;
408 
409  default:
410  $flag = GRP_REGISTRATION_DIRECT;
411  }
412  $this->group_obj->setRegistrationType($flag);
413 
414  $end = new ilDateTime(time(),IL_CAL_UNIX);
415  if($this->group_data['expiration_end'])
416  {
417  $end = new ilDateTime($this->group_data['expiration_end'],IL_CAL_UNIX);
418  }
419 
420  $start = clone $end;
421  if($this->group_data['expiration_start'])
422  {
423  $start = new ilDateTime($this->group_data['expiration_start'],IL_CAL_UNIX);
424  }
425 
426  $this->group_obj->setRegistrationStart($start);
427  $this->group_obj->setRegistrationEnd($end);
428  $this->group_obj->setPassword($this->group_data['password']);
429  $this->group_obj->enableUnlimitedRegistration(!isset($this->group_data['expiration_end']));
430  $this->group_obj->enableMembershipLimitation($this->group_data['max_members_enabled']);
431  $this->group_obj->setMaxMembers($this->group_data['max_members'] ? $this->group_data['max_members'] : 0);
432  $this->group_obj->enableWaitingList($this->group_data['waiting_list_enabled']);
433 
434  $this->group_obj->setWaitingListAutoFill($this->group_data['auto_wait']);
435  $this->group_obj->setCancellationEnd($this->group_data['cancel_end']);
436  $this->group_obj->setMinMembers($this->group_data['min_members']);
437 
438  $this->group_obj->setMailToMembersType((int) $this->group_data['mail_members_type']);
439 
440  if ($this->mode == ilGroupXMLParser::$CREATE)
441  {
442  $this->group_obj->initGroupStatus($this->group_data["type"] == "open" ? 0 : 1);
443  }
444 
445  $this->group_obj->update();
446 
447  // ASSIGN ADMINS/MEMBERS
448  $this->__assignMembers();
449 
450  $this->__pushParentId($this->group_obj->getRefId());
451 
452  if($this->sort)
453  {
454  $this->__initContainerSorting($this->sort, $this->group_obj->getId());
455  }
456 
457  $this->group_imported = true;
458 
459  return true;
460  }
461 
462  function __assignMembers()
463  {
464  global $ilias,$ilUser, $ilSetting;
465 
466  $this->participants = new ilGroupParticipants($this->group_obj->getId());
467  $this->participants->add($ilUser->getId(),IL_GRP_ADMIN);
468  $this->participants->updateNotification($ilUser->getId(),$ilSetting->get('mail_grp_admin_notification', true));
469 
470  // attach ADMINs
471  if (count($this->group_data["admin"]["attach"]))
472  {
473  foreach($this->group_data["admin"]["attach"] as $user)
474  {
475  if($id_data = $this->__parseId($user))
476  {
477  if($id_data['local'] or $id_data['imported'])
478  {
479  $this->participants->add($id_data['usr_id'],IL_GRP_ADMIN);
480  if(in_array($user,(array) $this->group_data['notifications']))
481  {
482  $this->participants->updateNotification($id_data['usr_id'],true);
483  }
484  }
485  }
486  }
487  }
488  // detach ADMINs
489  if (count($this->group_data["admin"]["detach"]))
490  {
491  foreach($this->group_data["admin"]["detach"] as $user)
492  {
493  if($id_data = $this->__parseId($user))
494  {
495  if($id_data['local'] or $id_data['imported'])
496  {
497  if($this->participants->isAssigned($id_data['usr_id']))
498  {
499  $this->participants->delete($id_data['usr_id']);
500  }
501  }
502  }
503  }
504  }
505  // MEMBER
506  if (count($this->group_data["member"]["attach"]))
507  {
508  foreach($this->group_data["member"]["attach"] as $user)
509  {
510  if($id_data = $this->__parseId($user))
511  {
512  if($id_data['local'] or $id_data['imported'])
513  {
514  $this->participants->add($id_data['usr_id'],IL_GRP_MEMBER);
515  }
516  }
517  }
518  }
519 
520  if (count($this->group_data["member"]["detach"]))
521  {
522  foreach($this->group_data["member"]["detach"] as $user)
523  {
524  if($id_data = $this->__parseId($user))
525  {
526  if($id_data['local'] or $id_data['imported'])
527  {
528  if($this->participants->isAssigned($id_data['usr_id']))
529  {
530  $this->participants->delete($id_data['usr_id']);
531  }
532  }
533  }
534  }
535  }
536  return true;
537  }
538 
539  function __initGroupObject()
540  {
541  include_once "./Modules/Group/classes/class.ilObjGroup.php";
542 
543  if ($this->mode == ilGroupXMLParser::$CREATE)
544  {
545  $this->group_obj = new ilObjGroup();
546  } elseif ($this->mode == ilGroupXMLParser::$UPDATE) {
547  $this->group_obj = $this->grp;
548  }
549 
550  return true;
551  }
552 
553  function __parseId($a_id)
554  {
555  global $ilias;
556 
557  $fields = explode('_',$a_id);
558 
559  if(!is_array($fields) or
560  $fields[0] != 'il' or
561  !is_numeric($fields[1]) or
562  $fields[2] != 'usr' or
563  !is_numeric($fields[3]))
564  {
565  return false;
566  }
567  if($id = ilObjUser::_getImportedUserId($a_id))
568  {
569  return array('imported' => true,
570  'local' => false,
571  'usr_id' => $id);
572  }
573  if(($fields[1] == $ilias->getSetting('inst_id',0)) and ($user = ilObjUser::_lookupName($fields[3])))
574  {
575  if(strlen($user['login']))
576  {
577  return array('imported' => false,
578  'local' => true,
579  'usr_id' => $fields[3]);
580  }
581  }
582  $GLOBALS['ilLog']->write(__METHOD__.' Parsing id failed: '.$a_id);
583  return false;
584  }
585 
586 
587  public function setMode($mode) {
588  $this->mode = $mode;
589  }
590 
591  public function setGroup(& $grp) {
592  $this->grp = $grp;
593  }
594 
595  function __initContainerSorting($a_attribs, $a_group_id)
596  {
597  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
599  }
600 }
601 ?>
static _lookupName($a_user_id)
lookup user name
global $ilErr
Definition: raiseError.php:16
const GRP_REGISTRATION_DEACTIVATED
const IL_GRP_ADMIN
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const IL_CAL_UNIX
const IL_GRP_MEMBER
const GRP_REGISTRATION_PASSWORD
add($a_usr_id, $a_role)
Add user to course.
const GRP_REGISTRATION_REQUEST
const GRP_TYPE_PUBLIC
static _getImportedUserId($i2_id)
startParsing()
start the parser
handlerEndTag($a_xml_parser, $a_name)
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
Class for single dates.
const GRP_TYPE_CLOSED
Date and time handling
__initContainerSorting($a_attribs, $a_group_id)
$ilUser
Definition: imgupload.php:18
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
Create styles array
The data for the language used.
Group Import Parser.
global $ilSetting
Definition: privfeed.php:17
Class ilObjGroup.
static _writeContainerSetting($a_id, $a_keyword, $a_value)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class private
const GRP_REGISTRATION_DIRECT
setXMLContent($a_xml_content)
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
__construct($a_xml, $a_parent_id)
Constructor.