ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilDidacticTemplateImport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/DidacticTemplate/exceptions/class.ilDidacticTemplateImportException.php';
5
13{
14 const IMPORT_FILE = 1;
15
16 private $type = 0;
17 private $xmlfile = '';
18
22 private $logger = null;
23
24
29 public function __construct($a_type)
30 {
31 global $DIC;
32
33 $this->logger = $DIC->logger()->otpl();
34 $this->type = $a_type;
35 }
36
41 public function setInputFile($a_file)
42 {
43 $this->xmlfile = $a_file;
44 }
45
50 public function getInputFile()
51 {
52 return $this->xmlfile;
53 }
54
59 public function getInputType()
60 {
61 return $this->type;
62 }
63
67 public function import($a_dtpl_id = 0)
68 {
69 libxml_use_internal_errors(true);
70
71 switch ($this->getInputType()) {
73
74 $root = simplexml_load_file($this->getInputFile());
75 if ($root == false) {
77 $this->parseXmlErrors()
78 );
79 }
80 break;
81 }
82
83 $settings = $this->parseSettings($root);
84 $this->parseActions($settings, $root->didacticTemplate->actions);
85
86 return $settings;
87 }
88
94 protected function parseSettings(SimpleXMLElement $root)
95 {
96 global $DIC;
97
98 $ilSetting = $DIC['ilSetting'];
99 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
100 $setting = new ilDidacticTemplateSetting();
101
102 foreach ($root->didacticTemplate as $tpl) {
103 switch ((string) $tpl->attributes()->type) {
104 case 'creation':
105 default:
107 break;
108 }
109 $setting->setTitle(trim((string) $tpl->title));
110 $setting->setDescription(trim((string) $tpl->description));
111
112 $info = '';
113 foreach ((array) $tpl->info->p as $paragraph) {
114 if (strlen($info)) {
115 $info .= "\n";
116 }
117 $info .= trim((string) $paragraph);
118 }
119 $setting->setInfo($info);
120
121 if (isset($tpl->effectiveFrom) && (string) $tpl->effectiveFrom["nic_id"] == $ilSetting->get('inst_id')) {
122 $node = array();
123 foreach ($tpl->effectiveFrom->node as $element) {
124 $node[] = (int) $element;
125 }
126
127 $setting->setEffectiveFrom($node);
128 }
129
130 if (isset($tpl->exclusive)) {
131 $setting->setExclusive(true);
132 }
133
134 foreach ($tpl->assignments->assignment as $element) {
135 $setting->addAssignment(trim((string) $element));
136 }
137 }
138 $setting->save();
139
140 include_once("./Services/Multilingualism/classes/class.ilMultilingualism.php");
141 $trans = ilMultilingualism::getInstance($setting->getId(), "dtpl");
142
143 if (isset($root->didacticTemplate->translations)) {
144 $trans->fromXML($root->didacticTemplate->translations);
145 }
146 $trans->save();
147
148 return $setting;
149 }
150
157 protected function parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions = null)
158 {
159 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
160
161 if ($actions === null) {
162 return;
163 }
164
166 // Local role action
168 foreach ($actions->localRoleAction as $ele) {
169 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalRoleAction.php';
171 $act->setTemplateId($set->getId());
172
173 foreach ($ele->roleTemplate as $tpl) {
174 // extract role
175 foreach ($tpl->role as $roleDef) {
176 include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
177 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
178 $role_id = $rimporter->importSimpleXml($roleDef);
179 $act->setRoleTemplateId($role_id);
180 }
181 $act->save();
182 }
183 }
184
186 // Block role action
188 foreach ($actions->blockRoleAction as $ele) {
189 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateBlockRoleAction.php';
191 $act->setTemplateId($set->getId());
192
193 // Role filter
194 foreach ($ele->roleFilter as $rfi) {
195
196 switch ((string) $rfi->attributes()->source) {
197 case 'title':
199 break;
200
201 case 'objId':
203 break;
204
205 case 'parentRoles':
207 break;
208 }
209 foreach ($rfi->includePattern as $pat) {
210 // @TODO other subtypes
211 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
214 $pattern->setPattern((string) $pat->attributes()->preg);
215 $act->addFilterPattern($pattern);
216 }
217 foreach ($rfi->excludePattern as $pat) {
218 // @TODO other subtypes
219 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
222 $pattern->setPattern((string) $pat->attributes()->preg);
223 $act->addFilterPattern($pattern);
224 }
225 }
226
227 $act->save();
228 }
229
230
231
233 // Local policy action
235 foreach ($actions->localPolicyAction as $ele) {
236 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalPolicyAction.php';
238 $act->setTemplateId($set->getId());
239
240 // Role filter
241 foreach ($ele->roleFilter as $rfi) {
242
243 $this->logger->dump($rfi->attributes(), \ilLogLevel::DEBUG);
244 $this->logger->debug('Current filter source: ' . (string) $rfi->attributes()->source);
245
246 switch ((string) $rfi->attributes()->source) {
247 case 'title':
249 break;
250
251 case 'objId':
253 break;
254
255 case 'parentRoles':
257 break;
258
259 case 'localRoles':
261 break;
262 }
263 foreach ($rfi->includePattern as $pat) {
264 // @TODO other subtypes
265 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
268 $pattern->setPattern((string) $pat->attributes()->preg);
269 $act->addFilterPattern($pattern);
270 }
271 foreach ($rfi->excludePattern as $pat) {
272 // @TODO other subtypes
273 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
276 $pattern->setPattern((string) $pat->attributes()->preg);
277 $act->addFilterPattern($pattern);
278 }
279 }
280
281 // role template assignment
282 foreach ($ele->localPolicyTemplate as $lpo) {
283 switch ((string) $lpo->attributes()->type) {
284 case 'overwrite':
286 break;
287
288 case 'union':
290 break;
291
292 case 'intersect':
294 break;
295 }
296
297 // extract role
298 foreach ($lpo->role as $roleDef) {
299 include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
300 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
301 $role_id = $rimporter->importSimpleXml($roleDef);
302 $act->setRoleTemplateId($role_id);
303 }
304 }
305
306 // Save action including all filter patterns
307 $act->save();
308 }
309 }
310
316 protected function parseXmlErrors()
317 {
318 $errors = '';
319 foreach (libxml_get_errors() as $err) {
320 $errors .= $err->code . '<br/>';
321 }
322 return $errors;
323 }
324}
$tpl
Definition: ilias.php:10
An exception for terminatinating execution or to throw for unit testing.
Description of ilDidacticTemplateBlockRoleAction.
Implementation of an include filter pattern for didactic template actions.
Description of ilDidacticTemplateImportException.
Description of ilDidacticTemplateImport.
parseXmlErrors()
Parse xml errors from libxml_get_errors.
parseSettings(SimpleXMLElement $root)
Parse settings.
parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions=null)
Parse template action from xml.
Implementation of an include filter pattern for didactic template actions.
represents a creation of local roles action
static getInstance($a_obj_id, $a_type)
Get instance.
Description of class.
$errors
Definition: index.php:6
$info
Definition: index.php:5
global $ilSetting
Definition: privfeed.php:17
$root
Definition: sabredav.php:45
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92