ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilContainerXmlParser Class Reference

XML parser for container structure. More...

+ Collaboration diagram for ilContainerXmlParser:

Public Member Functions

 __construct (ilImportMapping $mapping, $xml='')
 Constructor. More...
 
 getMapping ()
 Get ilImportMapping object. More...
 
 parse ($a_root_id)
 

Static Public Attributes

static $style_map = array()
 

Protected Member Functions

 initItem ($item, $a_parent_node)
 Init Item. More...
 
 parseTiming ($a_ref_id, $a_parent_id, $timing)
 Parse timing info. More...
 
 createObject ($ref_id, $obj_id, $type, $title, $parent_node)
 Create the objects. More...
 

Protected Attributes

 $settings
 
 $obj_definition
 
 $cont_log
 

Private Attributes

 $source = 0
 
 $mapping = null
 
 $xml = ''
 
 $sxml = null
 
 $root_id = 0
 

Detailed Description

XML parser for container structure.

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

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

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

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

44 {
45 global $DIC;
46
47 $this->settings = $DIC->settings();
48 $this->obj_definition = $DIC["objDefinition"];
49 $this->mapping = $mapping;
50 $this->xml = $xml;
51 $this->cont_log = ilLoggerFactory::getLogger('cont');
52 }
static getLogger($a_component_id)
Get component logger.
settings()
Definition: settings.php:2
$DIC
Definition: xapitoken.php:46

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

+ Here is the call graph for this function:

Member Function Documentation

◆ createObject()

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

Create the objects.

Parameters
object$ref_id
object$obj_id
object$type
object$title
object$parent_node
Returns
int | null

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

207 :? int
208 {
209 $objDefinition = $this->obj_definition;
210
211 // A mapping for this object already exists => create reference
212 $new_obj_id = $this->getMapping()->getMapping('Services/Container', 'objs', $obj_id);
213 if ($new_obj_id) {
214 include_once './Services/Object/classes/class.ilObjectFactory.php';
215 $obj = ilObjectFactory::getInstanceByObjId($new_obj_id, false);
216 if ($obj instanceof ilObject) {
217 $obj->createReference();
218 $obj->putInTree($parent_node);
219 $obj->setPermissions($parent_node);
220 $this->mapping->addMapping('Services/Container', 'refs', $ref_id, $obj->getRefId());
221 return $obj->getRefId();
222 }
223 }
224
225 if (!$objDefinition->isAllowedInRepository($type) || $objDefinition->isInactivePlugin($type)) {
226 $this->cont_log->notice('Cannot import object of type: ' . $type);
227 return null;
228 }
229
230 $class_name = "ilObj" . $objDefinition->getClassName($type);
231 $location = $objDefinition->getLocation($type);
232
233 include_once($location . "/class." . $class_name . ".php");
234 $new = new $class_name();
235 $new->setTitle($title);
236 $new->create(true);
237 $new->createReference();
238 $new->putInTree($parent_node);
239 $new->setPermissions($parent_node);
240
241 $this->mapping->addMapping('Services/Container', 'objs', $obj_id, $new->getId());
242 $this->mapping->addMapping('Services/Container', 'refs', $ref_id, $new->getRefId());
243
244 return $new->getRefId();
245 }
$location
Definition: buildRTE.php:44
getMapping()
Get ilImportMapping object.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObject Basic functions for all objects.
$type

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

Referenced by initItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMapping()

ilContainerXmlParser::getMapping ( )

Get ilImportMapping object.

Returns
ilImportMapping $map

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

60 {
61 return $this->mapping;
62 }

References $mapping.

Referenced by createObject(), and initItem().

+ Here is the caller graph for this function:

◆ initItem()

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

Init Item.

Parameters
object$item
object$a_parent_node
Returns

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

81 {
83
84 $title = (string) $item['Title'];
85 $ref_id = (string) $item['RefId'];
86 $obj_id = (string) $item['Id'];
87 $type = (string) $item['Type'];
88
89
90 $new_ref = $this->getMapping()->getMapping('Services/Container', 'refs', $ref_id);
91
92 if (
93 !$new_ref &&
94 ($obj_id == $this->root_id)
95 ) {
96 // if container without subitems a dummy container has already been created
97 // see ilImportContainer::createDummy()
98 $new_ref = $this->mapping->getMapping('Services/Container', 'refs', 0);
99
100 // see below and ilContainerImporter::finalProcessing()
101 $this->mapping->addMapping('Services/Container', 'objs', $obj_id, ilObject::_lookupObjId($new_ref));
102 }
103
104 if (!$new_ref) {
105 $new_ref = $this->createObject($ref_id, $obj_id, $type, $title, $a_parent_node);
106 }
107 if (!$new_ref) {
108 // e.g inactive plugin
109 return;
110 }
111
112 // Course item information
113 foreach ($item->Timing as $timing) {
114 $this->parseTiming($new_ref, $a_parent_node, $timing);
115 }
116
117 foreach ($item->Item as $subitem) {
118 $this->initItem($subitem, $new_ref);
119 }
120
121 $new_obj_id = $this->mapping->getMapping('Services/Container', 'objs', $obj_id);
122
123 // style
124 if ((int) $item['Style']) {
125 self::$style_map[(int) $item['Style']][] = $new_obj_id;
126 }
127
128 // pages
129 if ($ilSetting->get('enable_cat_page_edit', false)) {
130 if ($item['Page'] == "1") {
131 $this->mapping->addMapping('Services/COPage', 'pg', 'cont:' . $obj_id, 'cont:' . $new_obj_id);
132 $this->cont_log->debug("add pg cont mapping, old: " . $obj_id . ", new: " . $new_obj_id . ", Page: -" . $item['Page'] . "-");
133 }
134
135 if ($item['StartPage'] == "1") {
136 $this->mapping->addMapping('Services/COPage', 'pg', 'cstr:' . $obj_id, 'cstr:' . $new_obj_id);
137 }
138 }
139 }
initItem($item, $a_parent_node)
Init Item.
parseTiming($a_ref_id, $a_parent_id, $timing)
Parse timing info.
createObject($ref_id, $obj_id, $type, $title, $parent_node)
Create the objects.
static _lookupObjId($a_id)
global $ilSetting
Definition: privfeed.php:17

References $ilSetting, $settings, $type, ilObject\_lookupObjId(), createObject(), getMapping(), initItem(), and parseTiming().

Referenced by initItem(), and parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

ilContainerXmlParser::parse (   $a_root_id)

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

65 {
66 $this->sxml = simplexml_load_string($this->xml);
67 $this->root_id = $a_root_id;
68
69 foreach ($this->sxml->Item as $item) {
70 $this->initItem($item, $this->mapping->getTargetId());
71 }
72 }

References initItem().

+ Here is the call graph for this function:

◆ parseTiming()

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

Parse timing info.

Parameters
object$a_ref_id
object$a_parent_id
object$timing
Returns

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

149 {
150 $type = (string) $timing['Type'];
151 $visible = (string) $timing['Visible'];
152 $changeable = (string) $timing['Changeable'];
153
154 include_once './Services/Object/classes/class.ilObjectActivation.php';
155 $crs_item = new ilObjectActivation();
156 $crs_item->setTimingType($type);
157 $crs_item->toggleVisible((bool) $visible);
158 $crs_item->toggleChangeable((bool) $changeable);
159
160 foreach ($timing->children() as $sub) {
161 switch ((string) $sub->getName()) {
162 case 'Start':
163 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
164 $crs_item->setTimingStart($dt->get(IL_CAL_UNIX));
165 break;
166
167 case 'End':
168 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
169 $crs_item->setTimingEnd($dt->get(IL_CAL_UNIX));
170 break;
171
172 case 'SuggestionStart':
173 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
174 $crs_item->setSuggestionStart($dt->get(IL_CAL_UNIX));
175 break;
176
177 case 'SuggestionEnd':
178 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
179 $crs_item->setSuggestionEnd($dt->get(IL_CAL_UNIX));
180 break;
181
182 case 'EarliestStart':
183 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
184 $crs_item->setEarliestStart($dt->get(IL_CAL_UNIX));
185 break;
186
187 case 'LatestEnd':
188 break;
189 }
190 }
191
192
193 if ($crs_item->getTimingStart()) {
194 $crs_item->update($a_ref_id, $a_parent_id);
195 }
196 }
const IL_CAL_UNIX
const IL_CAL_DATETIME
@classDescription Date and time handling
Class ilObjectActivation.

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

Referenced by initItem().

+ Here is the caller graph for this function:

Field Documentation

◆ $cont_log

ilContainerXmlParser::$cont_log
protected

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

◆ $mapping

ilContainerXmlParser::$mapping = null
private

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

Referenced by __construct(), and getMapping().

◆ $obj_definition

ilContainerXmlParser::$obj_definition
protected

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

Referenced by createObject().

◆ $root_id

ilContainerXmlParser::$root_id = 0
private

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

◆ $settings

ilContainerXmlParser::$settings
protected

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

Referenced by initItem().

◆ $source

ilContainerXmlParser::$source = 0
private

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

◆ $style_map

ilContainerXmlParser::$style_map = array()
static

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

Referenced by ilContainerImporter\finalProcessing().

◆ $sxml

ilContainerXmlParser::$sxml = null
private

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

◆ $xml

ilContainerXmlParser::$xml = ''
private

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

Referenced by __construct().


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