ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
44  private $participants = null;
46  private $sort = null;
47 
50 
51  var $parent;
52  var $counter;
53 
54  var $mode;
55  var $grp;
56 
65  function ilGroupXMLParser($a_xml, $a_parent_id)
66  {
67  define('EXPORT_VERSION',2);
68 
69  parent::ilSaxParser(null);
70 
71  $this->mode = ilGroupXMLParser::$CREATE;
72  $this->grp = null;
73 
74  $this->setXMLContent($a_xml);
75 
76  // SET MEMBER VARIABLES
77  $this->__pushParentId($a_parent_id);
78 
79 
80  }
81 
82  function __pushParentId($a_id)
83  {
84  $this->parent[] = $a_id;
85  }
86  function __popParentId()
87  {
88  array_pop($this->parent);
89 
90  return true;
91  }
92  function __getParentId()
93  {
94  return $this->parent[count($this->parent) - 1];
95  }
96 
102  function setHandlers($a_xml_parser)
103  {
104  xml_set_object($a_xml_parser,$this);
105  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
106  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
107  }
108 
112  function startParsing()
113  {
114  parent::startParsing();
115 
116  if ($this->mode == ilGroupXMLParser::$CREATE)
117  {
118  return is_object($this->group_obj) ? $this->group_obj->getRefId() : false;
119  }
120  else
121  {
122  return is_object($this->group_obj) ? $this->group_obj->update() : false;
123  }
124  }
125 
126 
130  function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
131  {
132  global $ilErr;
133 
134  switch($a_name)
135  {
136  // GROUP DATA
137  case "group":
138  #if($a_attribs["exportVersion"] < EXPORT_VERSION)
139  #{
140  # $ilErr->raiseError("!!! This export Version isn't supported, update your ILIAS 2 installation"
141  # ,$ilErr->WARNING);
142  #}
143  // DEFAULT
144  $this->group_data["admin"] = array();
145  $this->group_data["member"] = array();
146 
147  $this->group_data["type"] = $a_attribs["type"];
148  $this->group_data["id"] = $a_attribs["id"];
149 
150  break;
151 
152  case 'title':
153  break;
154 
155  case "owner":
156  $this->group_data["owner"] = $a_attribs["id"];
157  break;
158 
159  case 'registration':
160  $this->group_data['registration_type'] = $a_attribs['type'];
161  $this->group_data['waiting_list_enabled'] = $a_attribs['waitingList'] == 'Yes' ? true : false;
162  break;
163 
164  case 'maxMembers':
165  $this->group_data['max_members_enabled'] = $a_attribs['enabled'] == 'Yes' ? true : false;
166  break;
167 
168  case "admin":
169  if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach")
170  {
171  $this->group_data["admin"]["attach"][] = $a_attribs["id"];
172  }
173  elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach")
174  {
175  $this->group_data["admin"]["detach"][] = $a_attribs["id"];
176  }
177 
178  if(isset($a_attribs['notification']) and $a_attribs['notification'] == 'Yes')
179  {
180  $this->group_data['notifications'][] = $a_attribs['id'];
181  }
182 
183  break;
184 
185  case "member":
186  if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach")
187  {
188  $GLOBALS['ilLog']->write(__METHOD__.': new member with id '.$a_attribs['id']);
189  $this->group_data["member"]["attach"][] = $a_attribs["id"];
190  } elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach")
191  {
192  $GLOBALS['ilLog']->write(__METHOD__.': deprecated member with id '.$a_attribs['id']);
193  $this->group_data["member"]["detach"][] = $a_attribs["id"];
194  }
195 
196  break;
197 
198  case "folder":
199  // NOW SAVE THE NEW OBJECT (if it hasn't been imported)
200  $this->__save();
201  break;
202 
203  case "file":
204  // NOW SAVE THE NEW OBJECT (if it hasn't been imported)
205  $this->__save();
206 
207  $this->file["fileName"] = $a_attribs["fileName"];
208  $this->file["id"] = $a_attribs["id"];
209 
210  // SAVE IT
211  $this->__saveFile();
212  break;
213 
214  case 'ContainerSetting':
215  $this->current_container_setting = $a_attribs['id'];
216  break;
217 
218  case 'Sort':
219 
220  if($this->group_imported)
221  {
222  $this->__initContainerSorting($a_attribs, $this->group_obj->getId());
223  }
224  else
225  {
226  $this->sort = $a_attribs;
227  }
228 
229  break;
230 
231  case 'WaitingListAutoFill':
232  case 'CancellationEnd':
233  case 'MinMembers':
234  break;
235  }
236  }
237 
238 
239  function handlerEndTag($a_xml_parser, $a_name)
240  {
241  switch($a_name)
242  {
243  case "title":
244  $this->group_data["title"] = trim($this->cdata);
245  break;
246 
247  case "description":
248  $this->group_data["description"] = trim($this->cdata);
249  break;
250 
251  case 'information':
252  $this->group_data['information'] = trim($this->cdata);
253  break;
254 
255  case 'password':
256  $this->group_data['password'] = trim($this->cdata);
257  break;
258 
259  case 'maxMembers':
260  $this->group_data['max_members'] = trim($this->cdata);
261  break;
262 
263  case 'expiration':
264  $this->group_data['expiration_end'] = trim($this->cdata);
265  break;
266 
267  case 'start':
268  $this->group_data['expiration_start'] = trim($this->cdata);
269  break;
270 
271  case 'end':
272  $this->group_data['expiration_end'] = trim($this->cdata);
273  break;
274 
275  case "folder":
276  $this->__popParentId();
277  break;
278 
279  case "folderTitle":
280  $this->folder = trim($this->cdata);
281  $this->__saveFolder();
282  break;
283 
284  case "group":
285  // NOW SAVE THE NEW OBJECT (if it hasn't been imported)
286  $this->__save();
287  break;
288 
289  case 'ContainerSetting':
290  if($this->current_container_setting)
291  {
292  // #17357
293  if(!($this->group_obj instanceof ilObjGroup))
294  {
295  $this->__initGroupObject();
296  }
298  $this->group_obj->getId(),
300  $this->cdata);
301  }
302  break;
303 
304  case 'WaitingListAutoFill':
305  $this->group_data['auto_wait'] = trim($this->cdata);
306  break;
307 
308  case 'CancellationEnd':
309  if((int)$this->cdata)
310  {
311  $this->group_data['cancel_end'] = new ilDate((int)$this->cdata, IL_CAL_UNIX);
312  }
313  break;
314 
315  case 'MinMembers':
316  if((int)$this->cdata)
317  {
318  $this->group_data['min_members'] = (int)$this->cdata;
319  }
320  break;
321  }
322  $this->cdata = '';
323  }
324 
325 
329  function handlerCharacterData($a_xml_parser, $a_data)
330  {
331  // i don't know why this is necessary, but
332  // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
333  // in character data, but we don't want that, because it's the
334  // way we mask user html in our content, so we convert back...
335  $a_data = str_replace("<","&lt;",$a_data);
336  $a_data = str_replace(">","&gt;",$a_data);
337 
338  if(!empty($a_data))
339  {
340  $this->cdata .= $a_data;
341  }
342  }
343 
344  // PRIVATE
345  function __save()
346  {
347  if($this->group_imported)
348  {
349  return true;
350  }
351 
352  $this->__initGroupObject();
353 
354  $this->group_obj->setImportId($this->group_data["id"]);
355  $this->group_obj->setTitle($this->group_data["title"]);
356  $this->group_obj->setDescription($this->group_data["description"]);
357 
358  $ownerChanged = false;
359  if (isset($this->group_data["owner"]))
360  {
361  $owner = $this->group_data["owner"];
362  if (!is_numeric($owner))
363  {
364  $owner = ilUtil::__extractId ($owner, IL_INST_ID);
365  }
366  if (is_numeric($owner) && $owner > 0)
367  {
368  $this->group_obj->setOwner($owner);
369  $ownerChanged = true;
370  }
371  }
372 
376  if ($this->mode == ilGroupXMLParser::$CREATE)
377  {
378  $this->group_obj->create();
379  $this->group_obj->createReference();
380  $this->group_obj->putInTree($this->__getParentId());
381  $this->group_obj->setPermissions($this->__getParentId());
382  $this->group_obj->initGroupStatus($this->group_data["type"] == "open" ? GRP_TYPE_PUBLIC : GRP_TYPE_CLOSED);
383  }
384  else
385  {
386  switch($this->group_data['type'])
387  {
388  case 'open':
389  $grp_status = GRP_TYPE_PUBLIC;
390  break;
391 
392  case 'closed':
393  $grp_status = GRP_TYPE_CLOSED;
394  break;
395 
396  }
397 
398  $this->group_obj->updateOwner();
399  if($this->group_obj->getGroupStatus() != $grp_status)
400  {
401  $this->group_obj->setGroupType($grp_status);
402  $this->group_obj->updateGroupType();
403  }
404  }
405 
406  // SET GROUP SPECIFIC DATA
407  switch($this->group_data['registration_type'])
408  {
409  case 'direct':
410  case 'enabled':
411  $flag = GRP_REGISTRATION_DIRECT;
412  break;
413 
414  case 'disabled':
416  break;
417 
418  case 'confirmation':
419  $flag = GRP_REGISTRATION_REQUEST;
420  break;
421 
422  case 'password':
424  break;
425 
426  default:
427  $flag = GRP_REGISTRATION_DIRECT;
428  }
429  $this->group_obj->setRegistrationType($flag);
430 
431  $end = new ilDateTime(time(),IL_CAL_UNIX);
432  if($this->group_data['expiration_end'])
433  {
434  $end = new ilDateTime($this->group_data['expiration_end'],IL_CAL_UNIX);
435  }
436 
437  $start = clone $end;
438  if($this->group_data['expiration_start'])
439  {
440  $start = new ilDateTime($this->group_data['expiration_start'],IL_CAL_UNIX);
441  }
442 
443  $this->group_obj->setRegistrationStart($start);
444  $this->group_obj->setRegistrationEnd($end);
445  $this->group_obj->setPassword($this->group_data['password']);
446  $this->group_obj->enableUnlimitedRegistration(!isset($this->group_data['expiration_end']));
447  $this->group_obj->enableMembershipLimitation($this->group_data['max_members_enabled']);
448  $this->group_obj->setMaxMembers($this->group_data['max_members'] ? $this->group_data['max_members'] : 0);
449  $this->group_obj->enableWaitingList($this->group_data['waiting_list_enabled']);
450 
451  $this->group_obj->setWaitingListAutoFill($this->group_data['auto_wait']);
452  $this->group_obj->setCancellationEnd($this->group_data['cancel_end']);
453  $this->group_obj->setMinMembers($this->group_data['min_members']);
454 
455  if ($this->mode == ilGroupXMLParser::$CREATE)
456  {
457  $this->group_obj->initGroupStatus($this->group_data["type"] == "open" ? 0 : 1);
458  }
459 
460  $this->group_obj->update();
461 
462  // ASSIGN ADMINS/MEMBERS
463  $this->__assignMembers();
464 
465  $this->__pushParentId($this->group_obj->getRefId());
466 
467  if($this->sort)
468  {
469  $this->__initContainerSorting($this->sort, $this->group_obj->getId());
470  }
471 
472  $this->group_imported = true;
473 
474  return true;
475  }
476 
477  function __saveFolder()
478  {
479  $this->__initFolderObject();
480 
481  $this->folder_obj->setTitle($this->folder);
482  $this->folder_obj->create();
483  $this->folder_obj->createReference();
484  $this->folder_obj->putInTree($this->__getParentId());
485 
486  $this->__pushParentId($this->folder_obj->getRefId());
487 
488  $this->__destroyFolderObject();
489 
490  return true;
491  }
492 
493  function __saveFile()
494  {
495  $this->__initFileObject();
496 
497  $this->file_obj->setType("file");
498  $this->file_obj->setTitle($this->file["fileName"]);
499  $this->file_obj->setFileName($this->file["fileName"]);
500  $this->file_obj->create();
501  $this->file_obj->createReference();
502  $this->file_obj->putInTree($this->__getParentId());
503  $this->file_obj->setPermissions($this->__getParentId());
504 
505  // COPY FILE
506  $this->file_obj->createDirectory();
507 
508  $this->__initImportFileObject();
509 
510  if($this->import_file_obj->findObjectFile($this->file["id"]))
511  {
512  $this->file_obj->copy($this->import_file_obj->getObjectFile(),$this->file["fileName"]);
513  }
514 
515  unset($this->file_obj);
516  unset($this->import_file_obj);
517 
518  return true;
519  }
520 
521  function __assignMembers()
522  {
523  global $ilias,$ilUser, $ilSetting;
524 
525  $this->participants = new ilGroupParticipants($this->group_obj->getId());
526  $this->participants->add($ilUser->getId(),IL_GRP_ADMIN);
527  $this->participants->updateNotification($ilUser->getId(),$ilSetting->get('mail_grp_admin_notification', true));
528 
529  // attach ADMINs
530  if (count($this->group_data["admin"]["attach"]))
531  {
532  foreach($this->group_data["admin"]["attach"] as $user)
533  {
534  if($id_data = $this->__parseId($user))
535  {
536  if($id_data['local'] or $id_data['imported'])
537  {
538  $this->participants->add($id_data['usr_id'],IL_GRP_ADMIN);
539  if(in_array($user,(array) $this->group_data['notifications']))
540  {
541  $this->participants->updateNotification($id_data['usr_id'],true);
542  }
543  }
544  }
545  }
546  }
547  // detach ADMINs
548  if (count($this->group_data["admin"]["detach"]))
549  {
550  foreach($this->group_data["admin"]["detach"] as $user)
551  {
552  if($id_data = $this->__parseId($user))
553  {
554  if($id_data['local'] or $id_data['imported'])
555  {
556  if($this->participants->isAssigned($id_data['usr_id']))
557  {
558  $this->participants->delete($id_data['usr_id']);
559  }
560  }
561  }
562  }
563  }
564  // MEMBER
565  if (count($this->group_data["member"]["attach"]))
566  {
567  foreach($this->group_data["member"]["attach"] as $user)
568  {
569  if($id_data = $this->__parseId($user))
570  {
571  if($id_data['local'] or $id_data['imported'])
572  {
573  $this->participants->add($id_data['usr_id'],IL_GRP_MEMBER);
574  }
575  }
576  }
577  }
578 
579  if (count($this->group_data["member"]["detach"]))
580  {
581  foreach($this->group_data["member"]["detach"] as $user)
582  {
583  if($id_data = $this->__parseId($user))
584  {
585  if($id_data['local'] or $id_data['imported'])
586  {
587  if($this->participants->isAssigned($id_data['usr_id']))
588  {
589  $this->participants->delete($id_data['usr_id']);
590  }
591  }
592  }
593  }
594  }
595  return true;
596  }
597 
598  function __initGroupObject()
599  {
600  include_once "./Modules/Group/classes/class.ilObjGroup.php";
601 
602  if ($this->mode == ilGroupXMLParser::$CREATE)
603  {
604  $this->group_obj =& new ilObjGroup();
605  } elseif ($this->mode == ilGroupXMLParser::$UPDATE) {
606  $this->group_obj = $this->grp;
607  }
608 
609  return true;
610  }
611 
613  {
614  include_once "./Modules/Folder/classes/class.ilObjFolder.php";
615 
616  $this->folder_obj =& new ilObjFolder();
617 
618  return true;
619  }
620 
622  {
623  include_once "./Modules/Group/classes/class.ilFileDataImportGroup.php";
624 
625  $this->import_file_obj =& new ilFileDataImportGroup();
626 
627  return true;
628  }
629 
630  function __initFileObject()
631  {
632  include_once "./Modules/File/classes/class.ilObjFile.php";
633 
634  $this->file_obj =& new ilObjFile();
635 
636  return true;
637  }
638 
640  {
641  unset($this->folder_obj);
642  }
643 
644  function __parseId($a_id)
645  {
646  global $ilias;
647 
648  $fields = explode('_',$a_id);
649 
650  if(!is_array($fields) or
651  $fields[0] != 'il' or
652  !is_numeric($fields[1]) or
653  $fields[2] != 'usr' or
654  !is_numeric($fields[3]))
655  {
656  return false;
657  }
658  if($id = ilObjUser::_getImportedUserId($a_id))
659  {
660  return array('imported' => true,
661  'local' => false,
662  'usr_id' => $id);
663  }
664  if(($fields[1] == $ilias->getSetting('inst_id',0)) and ($user = ilObjUser::_lookupName($fields[3])))
665  {
666  if(strlen($user['login']))
667  {
668  return array('imported' => false,
669  'local' => true,
670  'usr_id' => $fields[3]);
671  }
672  }
673  $GLOBALS['ilLog']->write(__METHOD__.' Parsing id failed: '.$a_id);
674  return false;
675  }
676 
677 
678  public function setMode($mode) {
679  $this->mode = $mode;
680  }
681 
682  public function setGroup(& $grp) {
683  $this->grp = $grp;
684  }
685 
686  function __initContainerSorting($a_attribs, $a_group_id)
687  {
688  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
690  }
691 }
692 ?>
static _lookupName($a_user_id)
lookup user name
Class ilObjFolder.
const GRP_REGISTRATION_DEACTIVATED
const IL_GRP_ADMIN
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
_writeContainerSetting($a_id, $a_keyword, $a_value)
const IL_CAL_UNIX
const IL_GRP_MEMBER
This class handles all operations on files for the exercise object.
const GRP_REGISTRATION_PASSWORD
add($a_usr_id, $a_role)
Add user to course.
const GRP_REGISTRATION_REQUEST
const GRP_TYPE_PUBLIC
_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
Class ilObjFile.
Date and time handling
__initContainerSorting($a_attribs, $a_group_id)
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
ilGroupXMLParser($a_xml, $a_parent_id)
Constructor.
global $ilUser
Definition: imgupload.php:15
Group Import Parser.
global $ilSetting
Definition: privfeed.php:40
Class ilObjGroup.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
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.