ILIAS  release_7 Revision v7.30-3-g800a261c036
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...
 
 canUseIcons (ilDidacticTemplateSetting $setting)
 
 parseActions (ilDidacticTemplateSetting $set, SimpleXMLElement $actions=null)
 Parse template action from xml. More...
 
 parseXmlErrors ()
 Parse xml errors from libxml_get_errors. More...
 

Protected Attributes

 $objDefinition
 

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 34 of file class.ilDidacticTemplateImport.php.

35 {
36 global $DIC;
37
38 $this->logger = $DIC->logger()->otpl();
39 $this->type = $a_type;
40 $this->objDefinition = $DIC['objDefinition'];
41 }
global $DIC
Definition: goto.php:24

References $DIC.

Member Function Documentation

◆ canUseIcons()

ilDidacticTemplateImport::canUseIcons ( ilDidacticTemplateSetting  $setting)
protected

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

165 : bool
166 {
167 foreach ($setting->getAssignments() as $assignment) {
168 if (!$this->objDefinition->isContainer($assignment)) {
169 return false;
170 }
171 }
172 return true;
173 }

References ilDidacticTemplateSetting\getAssignments().

Referenced by parseSettings().

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

◆ getInputFile()

ilDidacticTemplateImport::getInputFile ( )

Get inputfile.

Returns
<type>

Definition at line 56 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 65 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 73 of file class.ilDidacticTemplateImport.php.

74 {
75 libxml_use_internal_errors(true);
76
77 switch ($this->getInputType()) {
79
80 $root = simplexml_load_file($this->getInputFile());
81 if ($root == false) {
83 $this->parseXmlErrors()
84 );
85 }
86 break;
87 }
88
89 $settings = $this->parseSettings($root);
90 $this->parseActions($settings, $root->didacticTemplate->actions);
91
92 return $settings;
93 }
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.

References 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 181 of file class.ilDidacticTemplateImport.php.

182 {
183 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
184
185 if ($actions === null) {
186 return;
187 }
188
190 // Local role action
192 foreach ($actions->localRoleAction as $ele) {
193 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalRoleAction.php';
195 $act->setTemplateId($set->getId());
196
197 foreach ($ele->roleTemplate as $tpl) {
198 // extract role
199 foreach ($tpl->role as $roleDef) {
200 include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
201 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
202 $role_id = $rimporter->importSimpleXml($roleDef);
203 $act->setRoleTemplateId($role_id);
204 }
205 $act->save();
206 }
207 }
208
210 // Block role action
212 foreach ($actions->blockRoleAction as $ele) {
213 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateBlockRoleAction.php';
215 $act->setTemplateId($set->getId());
216
217 // Role filter
218 foreach ($ele->roleFilter as $rfi) {
219 switch ((string) $rfi->attributes()->source) {
220 case 'title':
222 break;
223
224 case 'objId':
226 break;
227
228 case 'parentRoles':
230 break;
231 }
232 foreach ($rfi->includePattern as $pat) {
233 // @TODO other subtypes
234 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
237 $pattern->setPattern((string) $pat->attributes()->preg);
238 $act->addFilterPattern($pattern);
239 }
240 foreach ($rfi->excludePattern as $pat) {
241 // @TODO other subtypes
242 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
245 $pattern->setPattern((string) $pat->attributes()->preg);
246 $act->addFilterPattern($pattern);
247 }
248 }
249
250 $act->save();
251 }
252
253
254
256 // Local policy action
258 foreach ($actions->localPolicyAction as $ele) {
259 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalPolicyAction.php';
261 $act->setTemplateId($set->getId());
262
263 // Role filter
264 foreach ($ele->roleFilter as $rfi) {
265 $this->logger->dump($rfi->attributes(), \ilLogLevel::DEBUG);
266 $this->logger->debug('Current filter source: ' . (string) $rfi->attributes()->source);
267
268 switch ((string) $rfi->attributes()->source) {
269 case 'title':
271 break;
272
273 case 'objId':
275 break;
276
277 case 'parentRoles':
279 break;
280
281 case 'localRoles':
283 break;
284 }
285 foreach ($rfi->includePattern as $pat) {
286 // @TODO other subtypes
287 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
290 $pattern->setPattern((string) $pat->attributes()->preg);
291 $act->addFilterPattern($pattern);
292 }
293 foreach ($rfi->excludePattern as $pat) {
294 // @TODO other subtypes
295 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
298 $pattern->setPattern((string) $pat->attributes()->preg);
299 $act->addFilterPattern($pattern);
300 }
301 }
302
303 // role template assignment
304 foreach ($ele->localPolicyTemplate as $lpo) {
305 switch ((string) $lpo->attributes()->type) {
306 case 'overwrite':
308 break;
309
310 case 'union':
312 break;
313
314 case 'intersect':
316 break;
317 }
318
319 // extract role
320 foreach ($lpo->role as $roleDef) {
321 try {
322 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
323 $role_id = $rimporter->importSimpleXml($roleDef);
324 $act->setRoleTemplateId($role_id);
325 } catch (ilRoleImporterException $e) {
326 // delete half-imported template
327 $set->delete();
328 throw new ilDidacticTemplateImportException($e->getMessage());
329 }
330 }
331 }
332
333 // Save action including all filter patterns
334 $act->save();
335 }
336 }
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.
const ROLE_FOLDER_ID
Definition: constants.php:32
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41

References Vendor\Package\$e, $tpl, ilLogLevel\DEBUG, ilDidacticTemplateSetting\delete(), ilDidacticTemplateAction\FILTER_LOCAL_ROLES, ilDidacticTemplateAction\FILTER_PARENT_ROLES, ilDidacticTemplateAction\FILTER_SOURCE_OBJ_ID, ilDidacticTemplateAction\FILTER_SOURCE_TITLE, ilDidacticTemplateSetting\getId(), ilDidacticTemplateFilterPattern\PATTERN_SUBTYPE_REGEX, ROLE_FOLDER_ID, 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 100 of file class.ilDidacticTemplateImport.php.

101 {
102 global $DIC;
103
104 $icon = '';
105
106 $ilSetting = $DIC['ilSetting'];
107 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
108 $setting = new ilDidacticTemplateSetting();
109
110 foreach ($root->didacticTemplate as $tpl) {
111 switch ((string) $tpl->attributes()->type) {
112 case 'creation':
113 default:
115 break;
116 }
117 $setting->setTitle(trim((string) $tpl->title));
118 $setting->setDescription(trim((string) $tpl->description));
119
120 $icon = (string) $tpl->icon;
121
122 $info = '';
123 foreach ((array) $tpl->info->p as $paragraph) {
124 if (strlen($info)) {
125 $info .= "\n";
126 }
127 $info .= trim((string) $paragraph);
128 }
129 $setting->setInfo($info);
130
131 if (isset($tpl->effectiveFrom) && (string) $tpl->effectiveFrom["nic_id"] == $ilSetting->get('inst_id')) {
132 $node = array();
133 foreach ($tpl->effectiveFrom->node as $element) {
134 $node[] = (int) $element;
135 }
136
137 $setting->setEffectiveFrom($node);
138 }
139
140 if (isset($tpl->exclusive)) {
141 $setting->setExclusive(true);
142 }
143
144 foreach ($tpl->assignments->assignment as $element) {
145 $setting->addAssignment(trim((string) $element));
146 }
147 }
148 $setting->save();
149
150 if (strlen($icon) && $this->canUseIcons($setting)) {
151 $setting->getIconHandler()->writeSvg($icon);
152 }
153
154 include_once("./Services/Multilingualism/classes/class.ilMultilingualism.php");
155 $trans = ilMultilingualism::getInstance($setting->getId(), "dtpl");
156
157 if (isset($root->didacticTemplate->translations)) {
158 $trans->fromXML($root->didacticTemplate->translations);
159 }
160 $trans->save();
161
162 return $setting;
163 }
canUseIcons(ilDidacticTemplateSetting $setting)
static getInstance($a_obj_id, $a_type)
Get instance.
global $ilSetting
Definition: privfeed.php:17

References $DIC, $ilSetting, $tpl, canUseIcons(), 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 343 of file class.ilDidacticTemplateImport.php.

344 {
345 $errors = '';
346 foreach (libxml_get_errors() as $err) {
347 $errors .= $err->code . '<br/>';
348 }
349 return $errors;
350 }
$errors
Definition: imgupload.php:49

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 47 of file class.ilDidacticTemplateImport.php.

48 {
49 $this->xmlfile = $a_file;
50 }

Field Documentation

◆ $logger

ilDidacticTemplateImport::$logger = null
private

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

◆ $objDefinition

ilDidacticTemplateImport::$objDefinition
protected

Definition at line 27 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: