ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
52  private $group_obj;
53 
57  private $lom_parsing_active = false;
58 
59 
63  protected $sax_controller = null;
64 
65 
69  protected $advanced_md_value_parser = null;
70 
71 
72  private $participants = null;
74  private $sort = null;
75 
76  public $group_data;
77 
78 
79  public $parent;
80  public $counter;
81 
82  public $mode;
83  public $grp;
84 
100  public function __construct(ilObjGroup $group, $a_xml, $a_parent_id)
101  {
102  define('EXPORT_VERSION', 2);
103 
104  parent::__construct(null);
105 
106  $this->sax_controller = new ilSaxController();
107 
108  $this->mode = ilGroupXMLParser::$CREATE;
109  $this->group_obj = $group;
110  $this->log = $GLOBALS['DIC']->logger()->grp();
111 
112  $this->setXMLContent($a_xml);
113 
114  // init md parsing
115  $this->setMDObject(
116  new ilMD(
117  $this->group_obj->getId(),
118  $this->group_obj->getId(),
119  $this->group_obj->getType()
120  )
121  );
122 
123  // SET MEMBER VARIABLES
124  $this->__pushParentId($a_parent_id);
125  }
126 
127  public function __pushParentId($a_id)
128  {
129  $this->parent[] = $a_id;
130  }
131  public function __popParentId()
132  {
133  array_pop($this->parent);
134 
135  return true;
136  }
137  public function __getParentId()
138  {
139  return $this->parent[count($this->parent) - 1];
140  }
141 
142 
149  public function setHandlers($a_xml_parser)
150  {
151  $this->sax_controller->setHandlers($a_xml_parser);
152  $this->sax_controller->setDefaultElementHandler($this);
153 
154  $this->advanced_md_value_parser = new ilAdvancedMDValueParser(
155  $this->group_obj->getId()
156  );
157 
158  $this->sax_controller->setElementHandler(
159  $this->advanced_md_value_parser,
160  'AdvancedMetaData'
161  );
162  }
163 
164 
168  public function startParsing()
169  {
170  parent::startParsing();
171 
172  if ($this->mode == ilGroupXMLParser::$CREATE) {
173  return is_object($this->group_obj) ? $this->group_obj->getRefId() : false;
174  } else {
175  return is_object($this->group_obj) ? $this->group_obj->update() : false;
176  }
177  }
178 
179 
183  public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
184  {
185  global $DIC;
186 
187  $ilErr = $DIC['ilErr'];
188 
189  if ($this->lom_parsing_active) {
190  parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
191  return;
192  }
193 
194  switch ($a_name) {
195  case "MetaData":
196  $this->lom_parsing_active = true;
197  parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
198  break;
199 
200 
201  // GROUP DATA
202  case "group":
203  $this->group_data["admin"] = array();
204  $this->group_data["member"] = array();
205 
206  $this->group_data["type"] = $a_attribs["type"];
207  $this->group_data["id"] = $a_attribs["id"];
208 
209  break;
210 
211  case 'title':
212  break;
213 
214  case "owner":
215  $this->group_data["owner"] = $a_attribs["id"];
216  break;
217 
218  case 'registration':
219  $this->group_data['registration_type'] = $a_attribs['type'];
220  $this->group_data['waiting_list_enabled'] = $a_attribs['waitingList'] == 'Yes' ? true : false;
221  break;
222 
223  case 'period':
224  $this->in_period = true;
225  break;
226 
227  case 'maxMembers':
228  $this->group_data['max_members_enabled'] = $a_attribs['enabled'] == 'Yes' ? true : false;
229  break;
230 
231  case "admin":
232  if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach") {
233  $this->group_data["admin"]["attach"][] = $a_attribs["id"];
234  } elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach") {
235  $this->group_data["admin"]["detach"][] = $a_attribs["id"];
236  }
237 
238  if (isset($a_attribs['notification']) and $a_attribs['notification'] == 'Yes') {
239  $this->group_data['notifications'][] = $a_attribs['id'];
240  }
241 
242  break;
243 
244  case "member":
245  if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach") {
246  $GLOBALS['DIC']->logger()->grp()->debug('New member with id ' . $a_attribs['id']);
247  $this->group_data["member"]["attach"][] = $a_attribs["id"];
248  } elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach") {
249  $GLOBALS['DIC']->logger()->grp()->debug('Deprecated member with id ' . $a_attribs['id']);
250  $this->group_data["member"]["detach"][] = $a_attribs["id"];
251  }
252 
253  break;
254 
255  case 'ContainerSetting':
256  $this->current_container_setting = $a_attribs['id'];
257  break;
258 
259  case 'Sort':
260 
261  if ($this->group_imported) {
262  $this->__initContainerSorting($a_attribs, $this->group_obj->getId());
263  } else {
264  $this->sort = $a_attribs;
265  }
266 
267  break;
268 
269  case 'WaitingListAutoFill':
270  case 'CancellationEnd':
271  case 'minMembers':
272  case 'mailMembersType':
273  break;
274  }
275  }
276 
277 
278  public function handlerEndTag($a_xml_parser, $a_name)
279  {
280  if ($this->lom_parsing_active) {
281  parent::handlerEndTag($a_xml_parser, $a_name);
282  }
283 
284  switch ($a_name) {
285  case 'MetaData':
286  $this->lom_parsing_active = false;
287  parent::handlerEndTag($a_xml_parser, $a_name);
288  break;
289 
290 
291  case "title":
292  $this->group_data["title"] = trim($this->cdata);
293  break;
294 
295  case "description":
296  $this->group_data["description"] = trim($this->cdata);
297  break;
298 
299  case 'information':
300  $this->group_data['information'] = trim($this->cdata);
301  break;
302 
303  case 'password':
304  $this->group_data['password'] = trim($this->cdata);
305  break;
306 
307  case 'maxMembers':
308  $this->group_data['max_members'] = trim($this->cdata);
309  break;
310 
311  case 'expiration':
312  $this->group_data['expiration_end'] = trim($this->cdata);
313  break;
314 
315  case 'start':
316  if ($this->in_period) {
317  $this->group_data['period_start'] = trim($this->cdata);
318  } else {
319  $this->group_data['expiration_start'] = trim($this->cdata);
320  }
321  break;
322 
323  case 'end':
324  if ($this->in_period) {
325  $this->group_data['period_end'] = trim($this->cdata);
326  } else {
327  $this->group_data['expiration_end'] = trim($this->cdata);
328  }
329  break;
330 
331  case 'period':
332  $this->in_period = false;
333  break;
334 
335  case "group":
336  // NOW SAVE THE NEW OBJECT (if it hasn't been imported)
337  $this->__save();
338  break;
339 
340  case 'ContainerSetting':
341  if ($this->current_container_setting) {
343  $this->group_obj->getId(),
345  $this->cdata
346  );
347  }
348  break;
349 
350  case 'WaitingListAutoFill':
351  $this->group_data['auto_wait'] = trim($this->cdata);
352  break;
353 
354  case 'CancellationEnd':
355  if ((int) $this->cdata) {
356  $this->group_data['cancel_end'] = new ilDate((int) $this->cdata, IL_CAL_UNIX);
357  }
358  break;
359 
360  case 'minMembers':
361  if ((int) $this->cdata) {
362  $this->group_data['min_members'] = (int) $this->cdata;
363  }
364  break;
365 
366  case 'showMembers':
367  if ((int) $this->cdata) {
368  $this->group_data['show_members'] = (int) $this->cdata;
369  }
370  break;
371 
372  case 'mailMembersType':
373  $this->group_data['mail_members_type'] = (int) $this->cdata;
374  break;
375 
376  }
377  $this->cdata = '';
378  }
379 
380 
384  public function handlerCharacterData($a_xml_parser, $a_data)
385  {
386  if ($this->lom_parsing_active) {
387  parent::handlerCharacterData($a_xml_parser, $a_data);
388  }
389 
390  $a_data = str_replace("<", "&lt;", $a_data);
391  $a_data = str_replace(">", "&gt;", $a_data);
392 
393  if (!empty($a_data)) {
394  $this->cdata .= $a_data;
395  }
396  }
397 
398  // PRIVATE
399  public function __save()
400  {
401  if ($this->group_imported) {
402  return true;
403  }
404 
405  $this->group_obj->setImportId($this->group_data["id"]);
406  $this->group_obj->setTitle($this->group_data["title"]);
407  $this->group_obj->setDescription($this->group_data["description"]);
408  $this->group_obj->setInformation((string) $this->group_data['information']);
409 
410  if (
411  $this->group_data['period_start'] &&
412  $this->group_data['period_end']) {
413  $this->group_obj->setStart(new ilDate($this->group_data['period_start'], IL_CAL_UNIX));
414  $this->group_obj->setEnd(new ilDate($this->group_data['period_end'], IL_CAL_UNIX));
415  }
416 
417  $ownerChanged = false;
418  if (isset($this->group_data["owner"])) {
419  $owner = $this->group_data["owner"];
420  if (!is_numeric($owner)) {
421  $owner = ilUtil::__extractId($owner, IL_INST_ID);
422  }
423  if (is_numeric($owner) && $owner > 0) {
424  $this->group_obj->setOwner($owner);
425  $ownerChanged = true;
426  }
427  }
428 
432  if ($this->mode == ilGroupXMLParser::$CREATE) {
433  $this->group_obj->createReference();
434  $this->group_obj->putInTree($this->__getParentId());
435  $this->group_obj->setPermissions($this->__getParentId());
436  if (
437  array_key_exists('type', $this->group_data) &&
438  $this->group_data['type'] == 'closed'
439  ) {
440  $this->group_obj->updateGroupType(GRP_TYPE_CLOSED);
441  }
442  } else {
443  if (
444  array_key_exists('type', $this->group_data) &&
445  $this->group_data['type'] == 'closed'
446  ) {
447  $this->group_obj->updateGroupType(GRP_TYPE_CLOSED);
448  } elseif (
449  array_key_exists('type', $this->group_data) &&
450  $this->group_data['type'] == 'open'
451  ) {
452  $this->group_obj->updateGroupType(GRP_TYPE_OPEN);
453  }
454  }
455  // SET GROUP SPECIFIC DATA
456  switch ($this->group_data['registration_type']) {
457  case 'direct':
458  case 'enabled':
459  $flag = GRP_REGISTRATION_DIRECT;
460  break;
461 
462  case 'disabled':
464  break;
465 
466  case 'confirmation':
467  $flag = GRP_REGISTRATION_REQUEST;
468  break;
469 
470  case 'password':
472  break;
473 
474  default:
475  $flag = GRP_REGISTRATION_DIRECT;
476  }
477  $this->group_obj->setRegistrationType($flag);
478 
479  $end = new ilDateTime(time(), IL_CAL_UNIX);
480  if ($this->group_data['expiration_end']) {
481  $end = new ilDateTime($this->group_data['expiration_end'], IL_CAL_UNIX);
482  }
483 
484  $start = clone $end;
485  if ($this->group_data['expiration_start']) {
486  $start = new ilDateTime($this->group_data['expiration_start'], IL_CAL_UNIX);
487  }
488 
489  $this->group_obj->setRegistrationStart($start);
490  $this->group_obj->setRegistrationEnd($end);
491  $this->group_obj->setPassword($this->group_data['password']);
492  $this->group_obj->enableUnlimitedRegistration(!isset($this->group_data['expiration_end']));
493  $this->group_obj->enableMembershipLimitation($this->group_data['max_members_enabled']);
494  $this->group_obj->setMaxMembers($this->group_data['max_members'] ? $this->group_data['max_members'] : 0);
495  $this->group_obj->enableWaitingList($this->group_data['waiting_list_enabled']);
496 
497  $this->group_obj->setWaitingListAutoFill($this->group_data['auto_wait']);
498  $this->group_obj->setCancellationEnd($this->group_data['cancel_end']);
499  $this->group_obj->setMinMembers($this->group_data['min_members']);
500  $this->group_obj->setShowMembers($this->group_data['show_members'] ? $this->group_data['show_members'] : 0);
501  $this->group_obj->setMailToMembersType((int) $this->group_data['mail_members_type']);
502  $this->group_obj->update();
503 
504  // ASSIGN ADMINS/MEMBERS
505  $this->__assignMembers();
506 
507  $this->__pushParentId($this->group_obj->getRefId());
508 
509  if ($this->sort) {
510  $this->__initContainerSorting($this->sort, $this->group_obj->getId());
511  }
512 
513  $this->group_imported = true;
514 
515  return true;
516  }
517 
518  public function __assignMembers()
519  {
520  global $DIC;
521 
522  $ilias = $DIC['ilias'];
523  $ilUser = $DIC['ilUser'];
524  $ilSetting = $DIC['ilSetting'];
525 
526  $this->participants = new ilGroupParticipants($this->group_obj->getId());
527  $this->participants->add($ilUser->getId(), IL_GRP_ADMIN);
528  $this->participants->updateNotification($ilUser->getId(), $ilSetting->get('mail_grp_admin_notification', true));
529 
530  // attach ADMINs
531  if (isset($this->group_data["admin"]["attach"]) && count($this->group_data["admin"]["attach"])) {
532  foreach ($this->group_data["admin"]["attach"] as $user) {
533  if ($id_data = $this->__parseId($user)) {
534  if ($id_data['local'] or $id_data['imported']) {
535  $this->participants->add($id_data['usr_id'], IL_GRP_ADMIN);
536  if (in_array($user, (array) $this->group_data['notifications'])) {
537  $this->participants->updateNotification($id_data['usr_id'], true);
538  }
539  }
540  }
541  }
542  }
543  // detach ADMINs
544  if (isset($this->group_data["admin"]["detach"]) && count($this->group_data["admin"]["detach"])) {
545  foreach ($this->group_data["admin"]["detach"] as $user) {
546  if ($id_data = $this->__parseId($user)) {
547  if ($id_data['local'] or $id_data['imported']) {
548  if ($this->participants->isAssigned($id_data['usr_id'])) {
549  $this->participants->delete($id_data['usr_id']);
550  }
551  }
552  }
553  }
554  }
555  // MEMBER
556  if (isset($this->group_data["member"]["attach"]) && count($this->group_data["member"]["attach"])) {
557  foreach ($this->group_data["member"]["attach"] as $user) {
558  if ($id_data = $this->__parseId($user)) {
559  if ($id_data['local'] or $id_data['imported']) {
560  $this->participants->add($id_data['usr_id'], IL_GRP_MEMBER);
561  }
562  }
563  }
564  }
565 
566  if (isset($this->group_data["member"]["detach"]) && count($this->group_data["member"]["detach"])) {
567  foreach ($this->group_data["member"]["detach"] as $user) {
568  if ($id_data = $this->__parseId($user)) {
569  if ($id_data['local'] or $id_data['imported']) {
570  if ($this->participants->isAssigned($id_data['usr_id'])) {
571  $this->participants->delete($id_data['usr_id']);
572  }
573  }
574  }
575  }
576  }
577  return true;
578  }
579 
580  public function __parseId($a_id)
581  {
582  global $DIC;
583 
584  $ilias = $DIC['ilias'];
585 
586  $fields = explode('_', $a_id);
587 
588  if (!is_array($fields) or
589  $fields[0] != 'il' or
590  !is_numeric($fields[1]) or
591  $fields[2] != 'usr' or
592  !is_numeric($fields[3])) {
593  return false;
594  }
595  if ($id = ilObjUser::_getImportedUserId($a_id)) {
596  return array('imported' => true,
597  'local' => false,
598  'usr_id' => $id);
599  }
600  if (($fields[1] == $ilias->getSetting('inst_id', 0)) and ($user = ilObjUser::_lookupName($fields[3]))) {
601  if (strlen($user['login'])) {
602  return array('imported' => false,
603  'local' => true,
604  'usr_id' => $fields[3]);
605  }
606  }
607  $GLOBALS['DIC']->logger()->grp()->warning('Parsing id failed: ' . $a_id);
608  return false;
609  }
610 
611 
612  public function setMode($mode)
613  {
614  $this->mode = $mode;
615  }
616 
617  public function __initContainerSorting($a_attribs, $a_group_id)
618  {
619  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
621  }
622 }
const GRP_TYPE_OPEN
static _lookupName($a_user_id)
lookup user name
const GRP_REGISTRATION_DEACTIVATED
global $DIC
Definition: saml.php:7
const IL_GRP_ADMIN
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
if(!array_key_exists('StateId', $_REQUEST)) $id
const IL_CAL_UNIX
const IL_GRP_MEMBER
const GRP_REGISTRATION_PASSWORD
const GRP_REGISTRATION_REQUEST
add($a_usr_id, $a_role)
Add user to role.
$ilErr
Definition: raiseError.php:18
static _getImportedUserId($i2_id)
startParsing()
start the parser
handlerEndTag($a_xml_parser, $a_name)
End element handler.
$start
Definition: bench.php:8
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
$user
Definition: migrateto20.php:57
__construct(ilObjGroup $group, $a_xml, $a_parent_id)
Constructor.
Interface definition for sax subset parsers.
Controller class for sax element handlers.
Group Import Parser.
global $ilSetting
Definition: privfeed.php:17
Class ilObjGroup.
static _writeContainerSetting($a_id, $a_keyword, $a_value)
setHandlers($a_xml_parser)
set event handlers
const GRP_REGISTRATION_DIRECT
setXMLContent($a_xml_content)
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.