ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
53  public $group_data;
54  public $group_obj;
55 
56  public $parent;
57  public $counter;
58 
59  public $mode;
60  public $grp;
61 
70  public 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  public function __pushParentId($a_id)
88  {
89  $this->parent[] = $a_id;
90  }
91  public function __popParentId()
92  {
93  array_pop($this->parent);
94 
95  return true;
96  }
97  public function __getParentId()
98  {
99  return $this->parent[count($this->parent) - 1];
100  }
101 
107  public function setHandlers($a_xml_parser)
108  {
109  xml_set_object($a_xml_parser, $this);
110  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
111  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
112  }
113 
117  public function startParsing()
118  {
119  parent::startParsing();
120 
121  if ($this->mode == ilGroupXMLParser::$CREATE) {
122  return is_object($this->group_obj) ? $this->group_obj->getRefId() : false;
123  } else {
124  return is_object($this->group_obj) ? $this->group_obj->update() : false;
125  }
126  }
127 
128 
132  public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
133  {
134  global $ilErr;
135 
136  switch ($a_name) {
137  // GROUP DATA
138  case "group":
139  $this->group_data["admin"] = array();
140  $this->group_data["member"] = array();
141 
142  $this->group_data["type"] = $a_attribs["type"];
143  $this->group_data["id"] = $a_attribs["id"];
144 
145  break;
146 
147  case 'title':
148  break;
149 
150  case "owner":
151  $this->group_data["owner"] = $a_attribs["id"];
152  break;
153 
154  case 'registration':
155  $this->group_data['registration_type'] = $a_attribs['type'];
156  $this->group_data['waiting_list_enabled'] = $a_attribs['waitingList'] == 'Yes' ? true : false;
157  break;
158 
159  case 'period':
160  $this->in_period = true;
161  break;
162 
163  case 'maxMembers':
164  $this->group_data['max_members_enabled'] = $a_attribs['enabled'] == 'Yes' ? true : false;
165  break;
166 
167  case "admin":
168  if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach") {
169  $this->group_data["admin"]["attach"][] = $a_attribs["id"];
170  } elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach") {
171  $this->group_data["admin"]["detach"][] = $a_attribs["id"];
172  }
173 
174  if (isset($a_attribs['notification']) and $a_attribs['notification'] == 'Yes') {
175  $this->group_data['notifications'][] = $a_attribs['id'];
176  }
177 
178  break;
179 
180  case "member":
181  if (!isset($a_attribs['action']) || $a_attribs['action'] == "Attach") {
182  $GLOBALS['DIC']->logger()->grp()->debug('New member with id ' . $a_attribs['id']);
183  $this->group_data["member"]["attach"][] = $a_attribs["id"];
184  } elseif (isset($a_attribs['action']) || $a_attribs['action'] == "Detach") {
185  $GLOBALS['DIC']->logger()->grp()->debug('Deprecated member with id ' . $a_attribs['id']);
186  $this->group_data["member"]["detach"][] = $a_attribs["id"];
187  }
188 
189  break;
190 
191  case 'ContainerSetting':
192  $this->current_container_setting = $a_attribs['id'];
193  break;
194 
195  case 'Sort':
196 
197  if ($this->group_imported) {
198  $this->__initContainerSorting($a_attribs, $this->group_obj->getId());
199  } else {
200  $this->sort = $a_attribs;
201  }
202 
203  break;
204 
205  case 'WaitingListAutoFill':
206  case 'CancellationEnd':
207  case 'minMembers':
208  case 'showMembers':
209  case 'mailMembersType':
210  break;
211  }
212  }
213 
214 
215  public function handlerEndTag($a_xml_parser, $a_name)
216  {
217  switch ($a_name) {
218  case "title":
219  $this->group_data["title"] = trim($this->cdata);
220  break;
221 
222  case "description":
223  $this->group_data["description"] = trim($this->cdata);
224  break;
225 
226  case 'information':
227  $this->group_data['information'] = trim($this->cdata);
228  break;
229 
230  case 'password':
231  $this->group_data['password'] = trim($this->cdata);
232  break;
233 
234  case 'maxMembers':
235  $this->group_data['max_members'] = trim($this->cdata);
236  break;
237 
238  case 'expiration':
239  $this->group_data['expiration_end'] = trim($this->cdata);
240  break;
241 
242  case 'start':
243  if ($this->in_period) {
244  $this->group_data['period_start'] = trim($this->cdata);
245  } else {
246  $this->group_data['expiration_start'] = trim($this->cdata);
247  }
248  break;
249 
250  case 'end':
251  if ($this->in_period) {
252  $this->group_data['period_end'] = trim($this->cdata);
253  } else {
254  $this->group_data['expiration_end'] = trim($this->cdata);
255  }
256  break;
257 
258  case 'period':
259  $this->in_period = false;
260  break;
261 
262  case "group":
263  // NOW SAVE THE NEW OBJECT (if it hasn't been imported)
264  $this->__save();
265  break;
266 
267  case 'ContainerSetting':
268  if ($this->current_container_setting) {
269  // #17357
270  if (!($this->group_obj instanceof ilObjGroup)) {
271  $this->__initGroupObject();
272  }
274  $this->group_obj->getId(),
276  $this->cdata
277  );
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  $this->group_data['cancel_end'] = new ilDate((int) $this->cdata, IL_CAL_UNIX);
288  }
289  break;
290 
291  case 'minMembers':
292  if ((int) $this->cdata) {
293  $this->group_data['min_members'] = (int) $this->cdata;
294  }
295  break;
296 
297  case 'showMembers':
298  if ((int) $this->cdata) {
299  $this->group_data['show_members'] = (int) $this->cdata;
300  }
301  break;
302 
303  case 'mailMembersType':
304  $this->group_data['mail_members_type'] = (int) $this->cdata;
305  break;
306 
307  }
308  $this->cdata = '';
309  }
310 
311 
315  public function handlerCharacterData($a_xml_parser, $a_data)
316  {
317  // i don't know why this is necessary, but
318  // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
319  // in character data, but we don't want that, because it's the
320  // way we mask user html in our content, so we convert back...
321  $a_data = str_replace("<", "&lt;", $a_data);
322  $a_data = str_replace(">", "&gt;", $a_data);
323 
324  if (!empty($a_data)) {
325  $this->cdata .= $a_data;
326  }
327  }
328 
329  // PRIVATE
330  public function __save()
331  {
332  if ($this->group_imported) {
333  return true;
334  }
335 
336  $this->__initGroupObject();
337 
338  $this->group_obj->setImportId($this->group_data["id"]);
339  $this->group_obj->setTitle($this->group_data["title"]);
340  $this->group_obj->setDescription($this->group_data["description"]);
341  $this->group_obj->setInformation((string) $this->group_data['information']);
342 
343  if (
344  $this->group_data['period_start'] &&
345  $this->group_data['period_end']) {
346  $this->group_obj->setStart(new ilDate($this->group_data['period_start'], IL_CAL_UNIX));
347  $this->group_obj->setEnd(new ilDate($this->group_data['period_end'], IL_CAL_UNIX));
348  }
349 
350  $ownerChanged = false;
351  if (isset($this->group_data["owner"])) {
352  $owner = $this->group_data["owner"];
353  if (!is_numeric($owner)) {
354  $owner = ilUtil::__extractId($owner, IL_INST_ID);
355  }
356  if (is_numeric($owner) && $owner > 0) {
357  $this->group_obj->setOwner($owner);
358  $ownerChanged = true;
359  }
360  }
361 
365  if ($this->mode == ilGroupXMLParser::$CREATE) {
366  $this->group_obj->create();
367  $this->group_obj->createReference();
368  $this->group_obj->putInTree($this->__getParentId());
369  $this->group_obj->setPermissions($this->__getParentId());
370  if (
371  array_key_exists('type', $this->group_data) &&
372  $this->group_data['type'] == 'closed'
373  ) {
374  $this->group_obj->updateGroupType(GRP_TYPE_CLOSED);
375  }
376  } else {
377  if (
378  array_key_exists('type', $this->group_data) &&
379  $this->group_data['type'] == 'closed'
380  ) {
381  $this->group_obj->updateGroupType(GRP_TYPE_CLOSED);
382  } elseif (
383  array_key_exists('type', $this->group_data) &&
384  $this->group_data['type'] == 'open'
385  ) {
386  $this->group_obj->updateGroupType(GRP_TYPE_OPEN);
387  }
388  }
389  // SET GROUP SPECIFIC DATA
390  switch ($this->group_data['registration_type']) {
391  case 'direct':
392  case 'enabled':
393  $flag = GRP_REGISTRATION_DIRECT;
394  break;
395 
396  case 'disabled':
398  break;
399 
400  case 'confirmation':
401  $flag = GRP_REGISTRATION_REQUEST;
402  break;
403 
404  case 'password':
406  break;
407 
408  default:
409  $flag = GRP_REGISTRATION_DIRECT;
410  }
411  $this->group_obj->setRegistrationType($flag);
412 
413  $end = new ilDateTime(time(), IL_CAL_UNIX);
414  if ($this->group_data['expiration_end']) {
415  $end = new ilDateTime($this->group_data['expiration_end'], IL_CAL_UNIX);
416  }
417 
418  $start = clone $end;
419  if ($this->group_data['expiration_start']) {
420  $start = new ilDateTime($this->group_data['expiration_start'], IL_CAL_UNIX);
421  }
422 
423  $this->group_obj->setRegistrationStart($start);
424  $this->group_obj->setRegistrationEnd($end);
425  $this->group_obj->setPassword($this->group_data['password']);
426  $this->group_obj->enableUnlimitedRegistration(!isset($this->group_data['expiration_end']));
427  $this->group_obj->enableMembershipLimitation($this->group_data['max_members_enabled']);
428  $this->group_obj->setMaxMembers($this->group_data['max_members'] ? $this->group_data['max_members'] : 0);
429  $this->group_obj->enableWaitingList($this->group_data['waiting_list_enabled']);
430 
431  $this->group_obj->setWaitingListAutoFill($this->group_data['auto_wait']);
432  $this->group_obj->setCancellationEnd($this->group_data['cancel_end']);
433  $this->group_obj->setMinMembers($this->group_data['min_members']);
434  $this->group_obj->setShowMembers($this->group_data['show_members'] ? $this->group_data['show_members'] : 0);
435  $this->group_obj->setMailToMembersType((int) $this->group_data['mail_members_type']);
436  $this->group_obj->update();
437 
438  // ASSIGN ADMINS/MEMBERS
439  $this->__assignMembers();
440 
441  $this->__pushParentId($this->group_obj->getRefId());
442 
443  if ($this->sort) {
444  $this->__initContainerSorting($this->sort, $this->group_obj->getId());
445  }
446 
447  $this->group_imported = true;
448 
449  return true;
450  }
451 
452  public function __assignMembers()
453  {
454  global $ilias,$ilUser, $ilSetting;
455 
456  $this->participants = new ilGroupParticipants($this->group_obj->getId());
457  $this->participants->add($ilUser->getId(), IL_GRP_ADMIN);
458  $this->participants->updateNotification($ilUser->getId(), $ilSetting->get('mail_grp_admin_notification', true));
459 
460  // attach ADMINs
461  if (isset($this->group_data["admin"]["attach"]) && count($this->group_data["admin"]["attach"])) {
462  foreach ($this->group_data["admin"]["attach"] as $user) {
463  if ($id_data = $this->__parseId($user)) {
464  if ($id_data['local'] or $id_data['imported']) {
465  $this->participants->add($id_data['usr_id'], IL_GRP_ADMIN);
466  if (in_array($user, (array) $this->group_data['notifications'])) {
467  $this->participants->updateNotification($id_data['usr_id'], true);
468  }
469  }
470  }
471  }
472  }
473  // detach ADMINs
474  if (isset($this->group_data["admin"]["detach"]) && count($this->group_data["admin"]["detach"])) {
475  foreach ($this->group_data["admin"]["detach"] as $user) {
476  if ($id_data = $this->__parseId($user)) {
477  if ($id_data['local'] or $id_data['imported']) {
478  if ($this->participants->isAssigned($id_data['usr_id'])) {
479  $this->participants->delete($id_data['usr_id']);
480  }
481  }
482  }
483  }
484  }
485  // MEMBER
486  if (isset($this->group_data["member"]["attach"]) && count($this->group_data["member"]["attach"])) {
487  foreach ($this->group_data["member"]["attach"] as $user) {
488  if ($id_data = $this->__parseId($user)) {
489  if ($id_data['local'] or $id_data['imported']) {
490  $this->participants->add($id_data['usr_id'], IL_GRP_MEMBER);
491  }
492  }
493  }
494  }
495 
496  if (isset($this->group_data["member"]["detach"]) && count($this->group_data["member"]["detach"])) {
497  foreach ($this->group_data["member"]["detach"] as $user) {
498  if ($id_data = $this->__parseId($user)) {
499  if ($id_data['local'] or $id_data['imported']) {
500  if ($this->participants->isAssigned($id_data['usr_id'])) {
501  $this->participants->delete($id_data['usr_id']);
502  }
503  }
504  }
505  }
506  }
507  return true;
508  }
509 
510  public function __initGroupObject()
511  {
512  include_once "./Modules/Group/classes/class.ilObjGroup.php";
513 
514  if ($this->mode == ilGroupXMLParser::$CREATE) {
515  $this->group_obj = new ilObjGroup();
516  } elseif ($this->mode == ilGroupXMLParser::$UPDATE) {
517  $this->group_obj = $this->grp;
518  }
519 
520  return true;
521  }
522 
523  public function __parseId($a_id)
524  {
525  global $ilias;
526 
527  $fields = explode('_', $a_id);
528 
529  if (!is_array($fields) or
530  $fields[0] != 'il' or
531  !is_numeric($fields[1]) or
532  $fields[2] != 'usr' or
533  !is_numeric($fields[3])) {
534  return false;
535  }
536  if ($id = ilObjUser::_getImportedUserId($a_id)) {
537  return array('imported' => true,
538  'local' => false,
539  'usr_id' => $id);
540  }
541  if (($fields[1] == $ilias->getSetting('inst_id', 0)) and ($user = ilObjUser::_lookupName($fields[3]))) {
542  if (strlen($user['login'])) {
543  return array('imported' => false,
544  'local' => true,
545  'usr_id' => $fields[3]);
546  }
547  }
548  $GLOBALS['DIC']->logger()->grp()->warning('Parsing id failed: ' . $a_id);
549  return false;
550  }
551 
552 
553  public function setMode($mode)
554  {
555  $this->mode = $mode;
556  }
557 
558  public function setGroup(&$grp)
559  {
560  $this->grp = $grp;
561  }
562 
563  public function __initContainerSorting($a_attribs, $a_group_id)
564  {
565  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
567  }
568 }
const GRP_TYPE_OPEN
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
$end
Definition: saml1-acs.php:18
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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.
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.