ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
19
24 public function __construct($a_type)
25 {
26 $this->type = $a_type;
27 }
28
33 public function setInputFile($a_file)
34 {
35 $this->xmlfile = $a_file;
36 }
37
42 public function getInputFile()
43 {
44 return $this->xmlfile;
45 }
46
51 public function getInputType()
52 {
53 return $this->type;
54 }
55
59 public function import()
60 {
61 libxml_use_internal_errors(true);
62
63 switch($this->getInputType())
64 {
66
67 $root = simplexml_load_file($this->getInputFile());
68 if($root == FALSE)
69 {
71 $this->parseXmlErrors()
72 );
73 }
74 break;
75 }
76
77 $settings = $this->parseSettings($root);
78 $this->parseActions($settings,$root->didacticTemplate->actions);
79
80 }
81
87 protected function parseSettings(SimpleXMLElement $root)
88 {
89
90 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
91 $setting = new ilDidacticTemplateSetting();
92
93 foreach($root->didacticTemplate as $tpl)
94 {
95 switch((string) $tpl->attributes()->type)
96 {
97 case 'creation':
98 default:
100 break;
101 }
102 $setting->setTitle(trim((string) $tpl->title));
103 $setting->setDescription(trim((string) $tpl->description));
104
105 $info = '';
106 foreach((array) $tpl->info->p as $paragraph)
107 {
108 if(strlen($info))
109 {
110 $info .= "\n";
111 }
112 $info .= trim((string) $paragraph);
113 }
114 $setting->setInfo($info);
115
116 foreach($tpl->assignments->assignment as $element)
117 {
118 $setting->addAssignment(trim((string) $element));
119 }
120 }
121 $setting->save();
122 return $setting;
123 }
124
131 protected function parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions = NULL)
132 {
133 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
134
135 if($actions === NULL)
136 {
137 return void;
138 }
139
141 // Local role action
143 foreach($actions->localRoleAction as $ele)
144 {
145 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalRoleAction.php';
147 $act->setTemplateId($set->getId());
148
149 foreach($ele->roleTemplate as $tpl)
150 {
151 // extract role
152 foreach($tpl->role as $roleDef)
153 {
154 include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
155 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
156 $role_id = $rimporter->importSimpleXml($roleDef);
157 $act->setRoleTemplateId($role_id);
158 }
159 $act->save();
160 }
161 }
162
164 // Block role action
166 foreach($actions->blockRoleAction as $ele)
167 {
168 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateBlockRoleAction.php';
170 $act->setTemplateId($set->getId());
171
172 // Role filter
173 foreach($ele->roleFilter as $rfi)
174 {
175 $act->setFilterType((string) $rfi->attributes()->source);
176 foreach($rfi->includePattern as $pat)
177 {
178 // @TODO other subtypes
179 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
182 $pattern->setPattern((string) $pat->attributes()->preg);
183 $act->addFilterPattern($pattern);
184 }
185 foreach($rfi->excludePattern as $pat)
186 {
187 // @TODO other subtypes
188 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
191 $pattern->setPattern((string) $pat->attributes()->preg);
192 $act->addFilterPattern($pattern);
193 }
194 }
195
196 $act->save();
197 }
198
199
200
202 // Local policy action
204 foreach($actions->localPolicyAction as $ele)
205 {
206 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalPolicyAction.php';
208 $act->setTemplateId($set->getId());
209
210 // Role filter
211 foreach($ele->roleFilter as $rfi)
212 {
213 $act->setFilterType((string) $rfi->attributes()->source);
214 foreach($rfi->includePattern as $pat)
215 {
216 // @TODO other subtypes
217 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
220 $pattern->setPattern((string) $pat->attributes()->preg);
221 $act->addFilterPattern($pattern);
222 }
223 foreach($rfi->excludePattern as $pat)
224 {
225 // @TODO other subtypes
226 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
229 $pattern->setPattern((string) $pat->attributes()->preg);
230 $act->addFilterPattern($pattern);
231 }
232 }
233
234 // role template assignment
235 foreach($ele->localPolicyTemplate as $lpo)
236 {
238 switch((string) $lpo->attributes()->type)
239 {
240 case 'overwrite':
242 break;
243
244 case 'union':
246 break;
247
248 case 'intersect':
250 break;
251 }
252
253 // extract role
254 foreach($lpo->role as $roleDef)
255 {
256 include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
257 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
258 $role_id = $rimporter->importSimpleXml($roleDef);
259 $act->setRoleTemplateId($role_id);
260 }
261 }
262
263 // Save action including all filter patterns
264 $act->save();
265 }
266
267 }
268
274 protected function parseXmlErrors()
275 {
276 $errors = '';
277 foreach(libxml_get_errors() as $err)
278 {
279 $errors .= $err->code.'<br/>';
280 }
281 return $errors;
282 }
283
284
285}
286?>
global $tpl
Definition: ilias.php:8
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.
parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions=NULL)
Parse template action from xml.
parseSettings(SimpleXMLElement $root)
Parse settings.
Implementation of an include filter pattern for didactic template actions.
represents a creation of local roles action
Description of class.
$info
Definition: example_052.php:80
$errors