1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Export/classes/class.ilXmlImporter.php");
5
6/**
7* folder xml importer
8*
9* @author Stefan Meyer <meyer@leifos.com>
10*
11* @version $Id$
12*
13* @ingroup ModulesGroup
14*/
15class ilGroupImporter extends ilXmlImporter
16{
17    private $group = null;
18
19
20    public function init()
21    {
22    }
23
24    /**
25     * Import XML
26     *
27     * @param
28     * @return
29     */
30    public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
31    {
32        include_once './Modules/Group/classes/class.ilObjGroup.php';
33        if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
34            $refs = ilObject::_getAllReferences($new_id);
35            $this->group = ilObjectFactory::getInstanceByRefId(end($refs), false);
36        #$this->group = ilObjectFactory::getInstanceByObjId($new_id,false);
37        }
38        // Mapping for containers without subitems
39        elseif ($new_id = $a_mapping->getMapping('Services/Container', 'refs', 0)) {
40            $this->group = ilObjectFactory::getInstanceByRefId($new_id, false);
41        } elseif (!$this->group instanceof ilObjGroup) {
42            $this->group = new ilObjGroup();
43            $this->group->create(true);
44        }
45
46        include_once './Modules/Group/classes/class.ilGroupXMLParser.php';
47        #$GLOBALS['DIC']['ilLog']->write($a_xml);
48
49        try {
50            $parser = new ilGroupXMLParser($this->group, $a_xml, 0);
51            $parser->setMode(ilGroupXMLParser::$UPDATE);
52            $parser->startParsing();
53            $a_mapping->addMapping('Modules/Group', 'grp', $a_id, $this->group->getId());
54        } catch (ilSaxParserException $e) {
55            $GLOBALS['DIC']->logger()->grp()->warning('Parsing failed with message, "' . $e->getMessage() . '".');
56        } catch (ilWebLinkXMLParserException $e) {
57            $GLOBALS['DIC']->logger()->grp()->warning('Parsing failed with message, "' . $e->getMessage() . '".');
58        }
59    }
60}
61