ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilContainerXmlParser Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilContainerXmlParser:

Public Member Functions

 __construct (ilImportMapping $mapping, string $xml='')
 
 getMapping ()
 
 parse (string $a_root_id)
 

Static Public Attributes

static array $style_map = []
 

Protected Member Functions

 initItem (SimpleXMLElement $item, int $a_parent_node)
 
 parseTiming (int $a_ref_id, int $a_parent_id, SimpleXMLElement $timing)
 
 createObject (int $ref_id, int $obj_id, string $type, string $title, int $parent_node)
 

Protected Attributes

ilSetting $settings
 
ilObjectDefinition $obj_definition
 
ilLogger $cont_log
 

Private Attributes

int $source = 0
 
ilImportMapping $mapping = null
 
string $xml = ''
 
int $root_id = 0
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning XML parser for container structure

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 24 of file class.ilContainerXmlParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilContainerXmlParser::__construct ( ilImportMapping  $mapping,
string  $xml = '' 
)

Definition at line 35 of file class.ilContainerXmlParser.php.

References $DIC, $mapping, $xml, ilLoggerFactory\getLogger(), and ILIAS\Repository\settings().

38  {
39  global $DIC;
40 
41  $this->settings = $DIC->settings();
42  $this->obj_definition = $DIC["objDefinition"];
43  $this->mapping = $mapping;
44  $this->xml = $xml;
45  $this->cont_log = ilLoggerFactory::getLogger('cont');
46  }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ createObject()

ilContainerXmlParser::createObject ( int  $ref_id,
int  $obj_id,
string  $type,
string  $title,
int  $parent_node 
)
protected

Definition at line 174 of file class.ilContainerXmlParser.php.

References $location, $obj_definition, ilObjectFactory\getInstanceByObjId(), and getMapping().

Referenced by initItem().

180  : ?int {
181  $objDefinition = $this->obj_definition;
182 
183  // A mapping for this object already exists => create reference
184  $new_obj_id = $this->getMapping()->getMapping('Services/Container', 'objs', (string) $obj_id);
185  if ($new_obj_id) {
186  $obj = ilObjectFactory::getInstanceByObjId((int) $new_obj_id, false);
187  if ($obj instanceof ilObject) {
188  $obj->createReference();
189  $obj->putInTree($parent_node);
190  $obj->setPermissions($parent_node);
191  $this->mapping->addMapping('Services/Container', 'refs', (string) $ref_id, (string) $obj->getRefId());
192  return $obj->getRefId();
193  }
194  }
195 
196  if (!$objDefinition->isAllowedInRepository($type) || $objDefinition->isInactivePlugin($type)) {
197  $this->cont_log->notice('Cannot import object of type: ' . $type);
198  return null;
199  }
200 
201  $class_name = "ilObj" . $objDefinition->getClassName($type);
202  $location = $objDefinition->getLocation($type);
203 
204  include_once($location . "/class." . $class_name . ".php");
205  $new = new $class_name();
206  $new->setTitle($title);
207  $new->create(true);
208  $new->createReference();
209  $new->putInTree($parent_node);
210  $new->setPermissions($parent_node);
211 
212  $this->mapping->addMapping('Services/Container', 'objs', (string) $obj_id, (string) $new->getId());
213  $this->mapping->addMapping('Services/Object', 'obj', (string) $obj_id, (string) $new->getId());
214  $this->mapping->addMapping('Services/Container', 'refs', (string) $ref_id, (string) $new->getRefId());
215 
216  return $new->getRefId();
217  }
$type
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
$ref_id
Definition: ltiauth.php:67
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
ilObjectDefinition $obj_definition
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMapping()

ilContainerXmlParser::getMapping ( )

Definition at line 48 of file class.ilContainerXmlParser.php.

References $mapping.

Referenced by createObject(), and initItem().

49  {
50  return $this->mapping;
51  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ initItem()

ilContainerXmlParser::initItem ( SimpleXMLElement  $item,
int  $a_parent_node 
)
protected

Definition at line 62 of file class.ilContainerXmlParser.php.

References $ilSetting, $ref_id, $settings, $type, ilObject\_lookupObjId(), createObject(), getMapping(), ILIAS\Repository\int(), and parseTiming().

Referenced by parse().

65  : void {
67 
68  $title = (string) $item['Title'];
69  $ref_id = (string) $item['RefId'];
70  $obj_id = (string) $item['Id'];
71  $type = (string) $item['Type'];
72 
73 
74  $new_ref = $this->getMapping()->getMapping('Services/Container', 'refs', $ref_id);
75 
76  if (
77  !$new_ref &&
78  ($obj_id == $this->root_id)
79  ) {
80  // if container without subitems a dummy container has already been created
81  // see ilImportContainer::createDummy()
82  $new_ref = $this->mapping->getMapping('Services/Container', 'refs', '0');
83 
84  // see below and ilContainerImporter::finalProcessing()
85  $this->mapping->addMapping('Services/Container', 'objs', $obj_id, (string) ilObject::_lookupObjId((int) $new_ref));
86  $this->mapping->addMapping('Services/Object', 'obj', $obj_id, (string) ilObject::_lookupObjId((int) $new_ref));
87  }
88 
89  if (!$new_ref) {
90  $new_ref = $this->createObject((int) $ref_id, (int) $obj_id, $type, $title, $a_parent_node);
91  }
92  if (!$new_ref) {
93  // e.g inactive plugin
94  return;
95  }
96 
97  // Course item information
98  foreach ($item->Timing as $timing) {
99  $this->parseTiming($new_ref, $a_parent_node, $timing);
100  }
101 
102  foreach ($item->Item as $subitem) {
103  $this->initItem($subitem, $new_ref);
104  }
105 
106  $new_obj_id = $this->mapping->getMapping('Services/Container', 'objs', $obj_id);
107 
108  // style
109  if ((int) $item['Style']) {
110  self::$style_map[(int) $item['Style']][] = $new_obj_id;
111  }
112 
113  // pages
114  if ($ilSetting->get('enable_cat_page_edit', '0')) {
115  if ($item['Page'] == "1") {
116  $this->mapping->addMapping('Services/COPage', 'pg', 'cont:' . $obj_id, 'cont:' . $new_obj_id);
117  $this->cont_log->debug("add pg cont mapping, old: " . $obj_id . ", new: " . $new_obj_id . ", Page: -" . $item['Page'] . "-");
118  }
119 
120  if ($item['StartPage'] == "1") {
121  $this->mapping->addMapping('Services/COPage', 'pg', 'cstr:' . $obj_id, 'cstr:' . $new_obj_id);
122  }
123  }
124  }
initItem(SimpleXMLElement $item, int $a_parent_node)
parseTiming(int $a_ref_id, int $a_parent_id, SimpleXMLElement $timing)
createObject(int $ref_id, int $obj_id, string $type, string $title, int $parent_node)
$type
static _lookupObjId(int $ref_id)
$ref_id
Definition: ltiauth.php:67
global $ilSetting
Definition: privfeed.php:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

ilContainerXmlParser::parse ( string  $a_root_id)

Definition at line 53 of file class.ilContainerXmlParser.php.

References initItem(), and ILIAS\Repository\int().

53  : void
54  {
55  $sxml = simplexml_load_string($this->xml);
56  $this->root_id = (int) $a_root_id;
57  foreach ($sxml->Item as $item) {
58  $this->initItem($item, $this->mapping->getTargetId());
59  }
60  }
initItem(SimpleXMLElement $item, int $a_parent_node)
+ Here is the call graph for this function:

◆ parseTiming()

ilContainerXmlParser::parseTiming ( int  $a_ref_id,
int  $a_parent_id,
SimpleXMLElement  $timing 
)
protected

Definition at line 127 of file class.ilContainerXmlParser.php.

References $type, IL_CAL_DATETIME, IL_CAL_UNIX, and ilTimeZone\UTC.

Referenced by initItem().

131  : void {
132  $type = (string) $timing['Type'];
133  $visible = (string) $timing['Visible'];
134  $changeable = (string) $timing['Changeable'];
135 
136  $crs_item = new ilObjectActivation();
137  $crs_item->setTimingType((int) $type);
138  $crs_item->toggleVisible((bool) $visible);
139  $crs_item->toggleChangeable((bool) $changeable);
140 
141  foreach ($timing->children() as $sub) {
142  switch ($sub->getName()) {
143  case 'Start':
144  $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
145  $crs_item->setTimingStart($dt->get(IL_CAL_UNIX));
146  break;
147 
148  case 'End':
149  $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
150  $crs_item->setTimingEnd($dt->get(IL_CAL_UNIX));
151  break;
152 
153  case 'SuggestionStart':
154  $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
155  $crs_item->setSuggestionStart($dt->get(IL_CAL_UNIX));
156  break;
157 
158  case 'SuggestionEnd':
159  $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
160  $crs_item->setSuggestionEnd($dt->get(IL_CAL_UNIX));
161  break;
162 
163  case 'LatestEnd':
164  break;
165  }
166  }
167 
168 
169  if ($crs_item->getTimingStart()) {
170  $crs_item->update($a_ref_id, $a_parent_id);
171  }
172  }
const IL_CAL_DATETIME
$type
const IL_CAL_UNIX
Class ilObjectActivation.
+ Here is the caller graph for this function:

Field Documentation

◆ $cont_log

ilLogger ilContainerXmlParser::$cont_log
protected

Definition at line 28 of file class.ilContainerXmlParser.php.

◆ $mapping

ilImportMapping ilContainerXmlParser::$mapping = null
private

Definition at line 30 of file class.ilContainerXmlParser.php.

Referenced by __construct(), and getMapping().

◆ $obj_definition

ilObjectDefinition ilContainerXmlParser::$obj_definition
protected

Definition at line 27 of file class.ilContainerXmlParser.php.

Referenced by createObject().

◆ $root_id

int ilContainerXmlParser::$root_id = 0
private

Definition at line 32 of file class.ilContainerXmlParser.php.

◆ $settings

ilSetting ilContainerXmlParser::$settings
protected

Definition at line 26 of file class.ilContainerXmlParser.php.

Referenced by initItem().

◆ $source

int ilContainerXmlParser::$source = 0
private

Definition at line 29 of file class.ilContainerXmlParser.php.

◆ $style_map

array ilContainerXmlParser::$style_map = []
static

Definition at line 33 of file class.ilContainerXmlParser.php.

Referenced by ilContainerImporter\finalProcessing().

◆ $xml

string ilContainerXmlParser::$xml = ''
private

Definition at line 31 of file class.ilContainerXmlParser.php.

Referenced by __construct().


The documentation for this class was generated from the following file: