ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilDidacticTemplateImport Class Reference

Description of ilDidacticTemplateImport. More...

+ Collaboration diagram for ilDidacticTemplateImport:

Public Member Functions

 __construct ($a_type)
 Constructor. More...
 
 setInputFile ($a_file)
 Set input file. More...
 
 getInputFile ()
 Get inputfile. More...
 
 getInputType ()
 Get input type. More...
 
 import ($a_dtpl_id=0)
 Do import. More...
 

Data Fields

const IMPORT_FILE = 1
 

Protected Member Functions

 parseSettings (SimpleXMLElement $root)
 Parse settings. More...
 
 parseActions (ilDidacticTemplateSetting $set, SimpleXMLElement $actions=null)
 Parse template action from xml. More...
 
 parseXmlErrors ()
 Parse xml errors from libxml_get_errors. More...
 

Private Attributes

 $type = 0
 
 $xmlfile = ''
 
 $logger = null
 

Detailed Description

Description of ilDidacticTemplateImport.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 12 of file class.ilDidacticTemplateImport.php.

Constructor & Destructor Documentation

◆ __construct()

ilDidacticTemplateImport::__construct (   $a_type)

Constructor.

Parameters
<type>$a_type

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

30 {
31 global $DIC;
32
33 $this->logger = $DIC->logger()->otpl();
34 $this->type = $a_type;
35 }
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92

References $a_type, and $DIC.

Member Function Documentation

◆ getInputFile()

ilDidacticTemplateImport::getInputFile ( )

Get inputfile.

Returns
<type>

Definition at line 50 of file class.ilDidacticTemplateImport.php.

References $xmlfile.

Referenced by import().

+ Here is the caller graph for this function:

◆ getInputType()

ilDidacticTemplateImport::getInputType ( )

Get input type.

Returns
string

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

References $type.

Referenced by import().

+ Here is the caller graph for this function:

◆ import()

ilDidacticTemplateImport::import (   $a_dtpl_id = 0)

Do import.

Definition at line 67 of file class.ilDidacticTemplateImport.php.

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 }
Description of ilDidacticTemplateImportException.
parseXmlErrors()
Parse xml errors from libxml_get_errors.
parseSettings(SimpleXMLElement $root)
Parse settings.
parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions=null)
Parse template action from xml.
$root
Definition: sabredav.php:45

References $root, getInputFile(), getInputType(), IMPORT_FILE, parseActions(), parseSettings(), and parseXmlErrors().

+ Here is the call graph for this function:

◆ parseActions()

ilDidacticTemplateImport::parseActions ( ilDidacticTemplateSetting  $set,
SimpleXMLElement  $actions = null 
)
protected

Parse template action from xml.

Parameters
ilDidacticTemplateSetting$set
SimpleXMLElement$root
Returns
void

Definition at line 157 of file class.ilDidacticTemplateImport.php.

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 }
$tpl
Definition: ilias.php:10
Description of ilDidacticTemplateBlockRoleAction.
Implementation of an include filter pattern for didactic template actions.
Implementation of an include filter pattern for didactic template actions.
represents a creation of local roles action
Description of class.

References $tpl, ilLogLevel\DEBUG, ilDidacticTemplateAction\FILTER_LOCAL_ROLES, ilDidacticTemplateAction\FILTER_PARENT_ROLES, ilDidacticTemplateAction\FILTER_SOURCE_OBJ_ID, ilDidacticTemplateAction\FILTER_SOURCE_TITLE, ilDidacticTemplateSetting\getId(), ilDidacticTemplateFilterPattern\PATTERN_SUBTYPE_REGEX, ilDidacticTemplateLocalPolicyAction\TPL_ACTION_INTERSECT, ilDidacticTemplateLocalPolicyAction\TPL_ACTION_OVERWRITE, and ilDidacticTemplateLocalPolicyAction\TPL_ACTION_UNION.

Referenced by import().

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

◆ parseSettings()

ilDidacticTemplateImport::parseSettings ( SimpleXMLElement  $root)
protected

Parse settings.

Parameters
SimpleXMLElement$el
Returns
ilDidacticTemplateSetting

Definition at line 94 of file class.ilDidacticTemplateImport.php.

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 }
static getInstance($a_obj_id, $a_type)
Get instance.
$info
Definition: index.php:5
global $ilSetting
Definition: privfeed.php:17

References $DIC, $ilSetting, $info, $root, $tpl, ilMultilingualism\getInstance(), and ilDidacticTemplateSetting\TYPE_CREATION.

Referenced by import().

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

◆ parseXmlErrors()

ilDidacticTemplateImport::parseXmlErrors ( )
protected

Parse xml errors from libxml_get_errors.

Returns
string

Definition at line 316 of file class.ilDidacticTemplateImport.php.

317 {
318 $errors = '';
319 foreach (libxml_get_errors() as $err) {
320 $errors .= $err->code . '<br/>';
321 }
322 return $errors;
323 }
$errors
Definition: index.php:6

References $errors.

Referenced by import().

+ Here is the caller graph for this function:

◆ setInputFile()

ilDidacticTemplateImport::setInputFile (   $a_file)

Set input file.

Parameters
string$a_file

Definition at line 41 of file class.ilDidacticTemplateImport.php.

42 {
43 $this->xmlfile = $a_file;
44 }

Field Documentation

◆ $logger

ilDidacticTemplateImport::$logger = null
private

Definition at line 22 of file class.ilDidacticTemplateImport.php.

◆ $type

ilDidacticTemplateImport::$type = 0
private

Definition at line 16 of file class.ilDidacticTemplateImport.php.

Referenced by getInputType().

◆ $xmlfile

ilDidacticTemplateImport::$xmlfile = ''
private

Definition at line 17 of file class.ilDidacticTemplateImport.php.

Referenced by getInputFile().

◆ IMPORT_FILE

const ilDidacticTemplateImport::IMPORT_FILE = 1

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