ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
24require_once("./Services/Xml/classes/class.ilSaxParser.php");
25require_once('./Services/User/classes/class.ilObjUser.php');
26include_once('./Services/Calendar/classes/class.ilDateTime.php');
27include_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
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
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 $this->group_data['period_with_time'] = $a_attribs['withTime'];
226 break;
227
228 case 'maxMembers':
229 $this->group_data['max_members_enabled'] = $a_attribs['enabled'] == 'Yes' ? true : false;
230 break;
231
232 case "admin":
233 if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach") {
234 $this->group_data["admin"]["attach"][] = $a_attribs["id"];
235 } elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach") {
236 $this->group_data["admin"]["detach"][] = $a_attribs["id"];
237 }
238
239 if (isset($a_attribs['notification']) and $a_attribs['notification'] == 'Yes') {
240 $this->group_data['notifications'][] = $a_attribs['id'];
241 }
242
243 break;
244
245 case "member":
246 if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach") {
247 $GLOBALS['DIC']->logger()->grp()->debug('New member with id ' . $a_attribs['id']);
248 $this->group_data["member"]["attach"][] = $a_attribs["id"];
249 } elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach") {
250 $GLOBALS['DIC']->logger()->grp()->debug('Deprecated member with id ' . $a_attribs['id']);
251 $this->group_data["member"]["detach"][] = $a_attribs["id"];
252 }
253
254 break;
255
256 case 'ContainerSetting':
257 $this->current_container_setting = $a_attribs['id'];
258 break;
259
260 case 'Sort':
261
262 if ($this->group_imported) {
263 $this->__initContainerSorting($a_attribs, $this->group_obj->getId());
264 } else {
265 $this->sort = $a_attribs;
266 }
267
268 break;
269
270 case 'WaitingListAutoFill':
271 case 'CancellationEnd':
272 case 'minMembers':
273 case 'mailMembersType':
274 break;
275 }
276 }
277
278
279 public function handlerEndTag($a_xml_parser, $a_name)
280 {
281 if ($this->lom_parsing_active) {
282 parent::handlerEndTag($a_xml_parser, $a_name);
283 }
284
285 switch ($a_name) {
286 case 'MetaData':
287 $this->lom_parsing_active = false;
288 parent::handlerEndTag($a_xml_parser, $a_name);
289 break;
290
291
292 case "title":
293 $this->group_data["title"] = trim($this->cdata);
294 break;
295
296 case "description":
297 $this->group_data["description"] = trim($this->cdata);
298 break;
299
300 case 'information':
301 $this->group_data['information'] = trim($this->cdata);
302 break;
303
304 case 'password':
305 $this->group_data['password'] = trim($this->cdata);
306 break;
307
308 case 'maxMembers':
309 $this->group_data['max_members'] = trim($this->cdata);
310 break;
311
312 case 'expiration':
313 $this->group_data['expiration_end'] = trim($this->cdata);
314 break;
315
316 case 'start':
317 if ($this->in_period) {
318 $this->group_data['period_start'] = trim($this->cdata);
319 } else {
320 $this->group_data['expiration_start'] = trim($this->cdata);
321 }
322 break;
323
324 case 'end':
325 if ($this->in_period) {
326 $this->group_data['period_end'] = trim($this->cdata);
327 } else {
328 $this->group_data['expiration_end'] = trim($this->cdata);
329 }
330 break;
331
332 case 'period':
333 $this->in_period = false;
334 break;
335
336 case "group":
337 // NOW SAVE THE NEW OBJECT (if it hasn't been imported)
338 $this->__save();
339 break;
340
341 case 'ContainerSetting':
342 if ($this->current_container_setting) {
344 $this->group_obj->getId(),
345 $this->current_container_setting,
346 $this->cdata
347 );
348 }
349 break;
350
351 case 'WaitingListAutoFill':
352 $this->group_data['auto_wait'] = trim($this->cdata);
353 break;
354
355 case 'CancellationEnd':
356 if ((int) $this->cdata) {
357 $this->group_data['cancel_end'] = new ilDate((int) $this->cdata, IL_CAL_UNIX);
358 }
359 break;
360
361 case 'minMembers':
362 if ((int) $this->cdata) {
363 $this->group_data['min_members'] = (int) $this->cdata;
364 }
365 break;
366
367 case 'showMembers':
368 if ((int) $this->cdata) {
369 $this->group_data['show_members'] = (int) $this->cdata;
370 }
371 break;
372
373 case 'admissionNotification':
374 if ((int) $this->cdata) {
375 $this->group_data['auto_notification'] = (bool) $this->cdata;
376 }
377 break;
378
379 case 'mailMembersType':
380 $this->group_data['mail_members_type'] = (int) $this->cdata;
381 break;
382
383 }
384 $this->cdata = '';
385 }
386
387
391 public function handlerCharacterData($a_xml_parser, $a_data)
392 {
393 if ($this->lom_parsing_active) {
394 parent::handlerCharacterData($a_xml_parser, $a_data);
395 }
396
397 $a_data = str_replace("<", "&lt;", $a_data);
398 $a_data = str_replace(">", "&gt;", $a_data);
399
400 if (!empty($a_data)) {
401 $this->cdata .= $a_data;
402 }
403 }
404
405 // PRIVATE
406 public function __save()
407 {
408 if ($this->group_imported) {
409 return true;
410 }
411
412 $this->group_obj->setImportId($this->group_data["id"]);
413 $this->group_obj->setTitle($this->group_data["title"]);
414 $this->group_obj->setDescription($this->group_data["description"]);
415 $this->group_obj->setInformation((string) $this->group_data['information']);
416
417 if (
418 $this->group_data['period_start'] &&
419 $this->group_data['period_end']) {
420 try {
421 if ($this->group_data['period_with_time']) {
422 $this->group_obj->setPeriod(
423 new \ilDateTime($this->group_data['period_start'], IL_CAL_UNIX),
424 new \ilDateTime($this->group_data['period_end'], IL_CAL_UNIX)
425 );
426 } else {
427 $this->group_obj->setPeriod(
428 new \ilDateTime($this->group_data['period_start'], IL_CAL_UNIX),
429 new \ilDateTime($this->group_data['period_end'], IL_CAL_UNIX)
430 );
431 }
432 } catch (Exception $e) {
433 $this->log->warning('Ignoring invalid group period settings: ');
434 $this->log->warning('Period start: ' . $this->group_data['period_start']);
435 $this->log->warning('Period end: ' . $this->group_data['period_end']);
436 }
437 }
438
439 $ownerChanged = false;
440 if (isset($this->group_data["owner"])) {
441 $owner = $this->group_data["owner"];
442 if (!is_numeric($owner)) {
443 $owner = ilUtil::__extractId($owner, IL_INST_ID);
444 }
445 if (is_numeric($owner) && $owner > 0) {
446 $this->group_obj->setOwner($owner);
447 $ownerChanged = true;
448 }
449 }
450
454 if ($this->mode == ilGroupXMLParser::$CREATE) {
455 $this->group_obj->createReference();
456 $this->group_obj->putInTree($this->__getParentId());
457 $this->group_obj->setPermissions($this->__getParentId());
458 if (
459 array_key_exists('type', $this->group_data) &&
460 $this->group_data['type'] == 'closed'
461 ) {
462 $this->group_obj->updateGroupType(GRP_TYPE_CLOSED);
463 }
464 } else {
465 if (
466 array_key_exists('type', $this->group_data) &&
467 $this->group_data['type'] == 'closed'
468 ) {
469 $this->group_obj->updateGroupType(GRP_TYPE_CLOSED);
470 } elseif (
471 array_key_exists('type', $this->group_data) &&
472 $this->group_data['type'] == 'open'
473 ) {
474 $this->group_obj->updateGroupType(GRP_TYPE_OPEN);
475 }
476 }
477 // SET GROUP SPECIFIC DATA
478 switch ($this->group_data['registration_type']) {
479 case 'direct':
480 case 'enabled':
482 break;
483
484 case 'disabled':
486 break;
487
488 case 'confirmation':
490 break;
491
492 case 'password':
494 break;
495
496 default:
498 }
499 $this->group_obj->setRegistrationType($flag);
500
501
502 $registration_end = null;
503 if ($this->group_data['expiration_end']) {
504 $registration_end = new ilDateTime($this->group_data['expiration_end'], IL_CAL_UNIX);
505 }
506
507 $registration_start = null;
508 if ($this->group_data['expiration_start']) {
509 $registration_start = new ilDateTime($this->group_data['expiration_start'], IL_CAL_UNIX);
510 }
511 if (
512 $registration_start instanceof ilDateTime &&
513 $registration_end instanceof ilDateTime
514 ) {
515 $this->group_obj->enableUnlimitedRegistration(false);
516 $this->group_obj->setRegistrationStart($registration_start);
517 $this->group_obj->setRegistrationEnd($registration_end);
518
519 } else {
520 $this->group_obj->enableUnlimitedRegistration(true);
521 }
522 $this->group_obj->setPassword($this->group_data['password']);
523 $this->group_obj->enableMembershipLimitation($this->group_data['max_members_enabled']);
524 $this->group_obj->setMaxMembers($this->group_data['max_members'] ? $this->group_data['max_members'] : 0);
525 $this->group_obj->enableWaitingList($this->group_data['waiting_list_enabled']);
526
527 $this->group_obj->setWaitingListAutoFill($this->group_data['auto_wait']);
528 $this->group_obj->setCancellationEnd($this->group_data['cancel_end']);
529 $this->group_obj->setMinMembers($this->group_data['min_members']);
530 $this->group_obj->setShowMembers($this->group_data['show_members'] ? $this->group_data['show_members'] : 0);
531 $this->group_obj->setAutoNotification($this->group_data['auto_notification'] ? true : false);
532 $this->group_obj->setMailToMembersType((int) $this->group_data['mail_members_type']);
533 $this->group_obj->update();
534
535 // ASSIGN ADMINS/MEMBERS
536 $this->__assignMembers();
537
538 $this->__pushParentId($this->group_obj->getRefId());
539
540 if ($this->sort) {
541 $this->__initContainerSorting($this->sort, $this->group_obj->getId());
542 }
543
544 $this->group_imported = true;
545
546 return true;
547 }
548
549 public function __assignMembers()
550 {
551 global $DIC;
552
553 $ilias = $DIC['ilias'];
554 $ilUser = $DIC['ilUser'];
555 $ilSetting = $DIC['ilSetting'];
556
557 $this->participants = new ilGroupParticipants($this->group_obj->getId());
558 $this->participants->add($ilUser->getId(), IL_GRP_ADMIN);
559 $this->participants->updateNotification($ilUser->getId(), $ilSetting->get('mail_grp_admin_notification', true));
560
561 // attach ADMINs
562 if (isset($this->group_data["admin"]["attach"]) && count($this->group_data["admin"]["attach"])) {
563 foreach ($this->group_data["admin"]["attach"] as $user) {
564 if ($id_data = $this->__parseId($user)) {
565 if ($id_data['local'] or $id_data['imported']) {
566 $this->participants->add($id_data['usr_id'], IL_GRP_ADMIN);
567 if (in_array($user, (array) $this->group_data['notifications'])) {
568 $this->participants->updateNotification($id_data['usr_id'], true);
569 }
570 }
571 }
572 }
573 }
574 // detach ADMINs
575 if (isset($this->group_data["admin"]["detach"]) && count($this->group_data["admin"]["detach"])) {
576 foreach ($this->group_data["admin"]["detach"] as $user) {
577 if ($id_data = $this->__parseId($user)) {
578 if ($id_data['local'] or $id_data['imported']) {
579 if ($this->participants->isAssigned($id_data['usr_id'])) {
580 $this->participants->delete($id_data['usr_id']);
581 }
582 }
583 }
584 }
585 }
586 // MEMBER
587 if (isset($this->group_data["member"]["attach"]) && count($this->group_data["member"]["attach"])) {
588 foreach ($this->group_data["member"]["attach"] as $user) {
589 if ($id_data = $this->__parseId($user)) {
590 if ($id_data['local'] or $id_data['imported']) {
591 $this->participants->add($id_data['usr_id'], IL_GRP_MEMBER);
592 }
593 }
594 }
595 }
596
597 if (isset($this->group_data["member"]["detach"]) && count($this->group_data["member"]["detach"])) {
598 foreach ($this->group_data["member"]["detach"] as $user) {
599 if ($id_data = $this->__parseId($user)) {
600 if ($id_data['local'] or $id_data['imported']) {
601 if ($this->participants->isAssigned($id_data['usr_id'])) {
602 $this->participants->delete($id_data['usr_id']);
603 }
604 }
605 }
606 }
607 }
608 return true;
609 }
610
611 public function __parseId($a_id)
612 {
613 global $DIC;
614
615 $ilias = $DIC['ilias'];
616
617 $fields = explode('_', $a_id);
618
619 if (!is_array($fields) or
620 $fields[0] != 'il' or
621 !is_numeric($fields[1]) or
622 $fields[2] != 'usr' or
623 !is_numeric($fields[3])) {
624 return false;
625 }
626 if ($id = ilObjUser::_getImportedUserId($a_id)) {
627 return array('imported' => true,
628 'local' => false,
629 'usr_id' => $id);
630 }
631 if (($fields[1] == $ilias->getSetting('inst_id', 0)) and ($user = ilObjUser::_lookupName($fields[3]))) {
632 if (strlen($user['login'])) {
633 return array('imported' => false,
634 'local' => true,
635 'usr_id' => $fields[3]);
636 }
637 }
638 $GLOBALS['DIC']->logger()->grp()->warning('Parsing id failed: ' . $a_id);
639 return false;
640 }
641
642
643 public function setMode($mode)
644 {
645 $this->mode = $mode;
646 }
647
648 public function __initContainerSorting($a_attribs, $a_group_id)
649 {
650 include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
652 }
653}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const GRP_REGISTRATION_DIRECT
const GRP_REGISTRATION_PASSWORD
const GRP_TYPE_OPEN
const GRP_TYPE_CLOSED
const GRP_REGISTRATION_DEACTIVATED
const GRP_REGISTRATION_REQUEST
const IL_GRP_MEMBER
const IL_GRP_ADMIN
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
static _writeContainerSetting($a_id, $a_keyword, $a_value)
@classDescription Date and time handling
Class for single dates.
Group Import Parser.
setHandlers($a_xml_parser)
set event handlers
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
__initContainerSorting($a_attribs, $a_group_id)
startParsing()
start the parser
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
__construct(ilObjGroup $group, $a_xml, $a_parent_id)
Constructor.
Class ilObjGroup.
static _getImportedUserId($i2_id)
static _lookupName($a_user_id)
lookup user name
Controller class for sax element handlers.
setXMLContent($a_xml_content)
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
Interface definition for sax subset parsers.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:17
$ilErr
Definition: raiseError.php:18
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46