ILIAS  release_8 Revision v8.24
ilDidacticTemplateImport Class Reference

Description of ilDidacticTemplateImport. More...

+ Collaboration diagram for ilDidacticTemplateImport:

Public Member Functions

 __construct (int $a_type)
 
 setInputFile (string $a_file)
 
 getInputFile ()
 
 getInputType ()
 
 import (int $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

ilObjectDefinition $objDefinition
 
ilSetting $settings
 

Private Attributes

int $type = 0
 
string $xmlfile = ''
 
ilLogger $logger
 

Detailed Description

Description of ilDidacticTemplateImport.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilDidacticTemplateImport::__construct ( int  $a_type)

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

23 {
24 global $DIC;
25
26 $this->logger = $DIC->logger()->otpl();
27 $this->type = $a_type;
28 $this->objDefinition = $DIC['objDefinition'];
29 $this->settings = $DIC->settings();
30 }
global $DIC
Definition: feed.php:28

References $DIC, ILIAS\Repository\logger(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ canUseIcons()

ilDidacticTemplateImport::canUseIcons ( ilDidacticTemplateSetting  $setting)
protected

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

129 : bool
130 {
131 foreach ($setting->getAssignments() as $assignment) {
132 if (!$this->objDefinition->isContainer($assignment)) {
133 return false;
134 }
135 }
136
137 return true;
138 }

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 ( )

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

37 : string
38 {
39 return $this->xmlfile;
40 }

References $xmlfile.

Referenced by import().

+ Here is the caller graph for this function:

◆ getInputType()

ilDidacticTemplateImport::getInputType ( )

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

42 : int
43 {
44 return $this->type;
45 }

References $type.

Referenced by import().

+ Here is the caller graph for this function:

◆ import()

ilDidacticTemplateImport::import ( int  $a_dtpl_id = 0)

Do import.

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

51 {
52 $root = null;
53 $use_internal_errors = libxml_use_internal_errors(true);
54 switch ($this->getInputType()) {
56 $root = simplexml_load_string(file_get_contents($this->getInputFile()));
57 break;
58 }
59 libxml_use_internal_errors($use_internal_errors);
60 if (!$root instanceof SimpleXMLElement) {
62 $this->parseXmlErrors()
63 );
64 }
65 $settings = $this->parseSettings($root);
66 $this->parseActions($settings, $root->didacticTemplate->actions);
67 return $settings;
68 }
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 $settings, 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.

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

143 : void
144 {
145 if ($actions === null) {
146 return;
147 }
149 // Local role action
151 foreach ($actions->localRoleAction as $ele) {
153 $act->setTemplateId($set->getId());
154
155 foreach ($ele->roleTemplate as $tpl) {
156 // extract role
157 foreach ($tpl->role as $roleDef) {
158 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
159 $role_id = $rimporter->importSimpleXml($roleDef);
160 $act->setRoleTemplateId($role_id);
161 }
162 $act->save();
163 }
164 }
165
167 // Block role action
169 foreach ($actions->blockRoleAction as $ele) {
171 $act->setTemplateId($set->getId());
172
173 // Role filter
174 foreach ($ele->roleFilter as $rfi) {
175 switch ((string) $rfi->attributes()->source) {
176 case 'title':
178 break;
179
180 case 'objId':
182 break;
183
184 case 'parentRoles':
186 break;
187 }
188 foreach ($rfi->includePattern as $pat) {
189 // @TODO other subtypes
190
193 $pattern->setPattern((string) $pat->attributes()->preg);
194 $act->addFilterPattern($pattern);
195 }
196 foreach ($rfi->excludePattern as $pat) {
197 // @TODO other subtypes
198
201 $pattern->setPattern((string) $pat->attributes()->preg);
202 $act->addFilterPattern($pattern);
203 }
204 }
205
206 $act->save();
207 }
208
210 // Local policy action
212 foreach ($actions->localPolicyAction as $ele) {
214 $act->setTemplateId($set->getId());
215
216 // Role filter
217 foreach ($ele->roleFilter as $rfi) {
218 $this->logger->dump($rfi->attributes(), \ilLogLevel::DEBUG);
219 $this->logger->debug(
220 'Current filter source: ' . $rfi->attributes()->source
221 );
222
223 switch ((string) $rfi->attributes()->source) {
224 case 'title':
226 break;
227
228 case 'objId':
230 break;
231
232 case 'parentRoles':
234 break;
235
236 case 'localRoles':
238 break;
239 }
240 foreach ($rfi->includePattern as $pat) {
241 // @TODO other subtypes
242
245 $pattern->setPattern((string) $pat->attributes()->preg);
246 $act->addFilterPattern($pattern);
247 }
248 foreach ($rfi->excludePattern as $pat) {
249 // @TODO other subtypes
250
253 $pattern->setPattern((string) $pat->attributes()->preg);
254 $act->addFilterPattern($pattern);
255 }
256 }
257
258 // role template assignment
259 foreach ($ele->localPolicyTemplate as $lpo) {
260 switch ((string) $lpo->attributes()->type) {
261 case 'overwrite':
263 break;
264
265 case 'union':
267 break;
268
269 case 'intersect':
271 break;
272 }
273
274 // extract role
275 foreach ($lpo->role as $roleDef) {
276 try {
277 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
278 $role_id = $rimporter->importSimpleXml($roleDef);
279 $act->setRoleTemplateId($role_id);
280 } catch (ilRoleImporterException $e) {
281 // delete half-imported template
282 $set->delete();
283 throw new ilDidacticTemplateImportException($e->getMessage());
284 }
285 }
286 }
287
288 // Save action including all filter patterns
289 $act->save();
290 }
291 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Description of class.
const ROLE_FOLDER_ID
Definition: constants.php:34
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(), ILIAS\Repository\logger(), 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.

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

74 {
75 $icon = '';
76 $setting = new ilDidacticTemplateSetting();
77 foreach ($root->didacticTemplate as $tpl) {
78 switch ((string) $tpl->attributes()->type) {
79 case 'creation':
80 default:
82 break;
83 }
84 $setting->setTitle(trim((string) $tpl->title));
85 $setting->setDescription(trim((string) $tpl->description));
86
87 $icon = (string) $tpl->icon;
88
89 $info = '';
90 foreach ((array) $tpl->info->p as $paragraph) {
91 if ($info !== '') {
92 $info .= "\n";
93 }
94 $info .= trim((string) $paragraph);
95 }
96 $setting->setInfo($info);
97
98 if (isset($tpl->effectiveFrom) && (string) $tpl->effectiveFrom["nic_id"] == $this->settings->get('inst_id')) {
99 $node = array();
100 foreach ($tpl->effectiveFrom->node as $element) {
101 $node[] = (int) $element;
102 }
103
104 $setting->setEffectiveFrom($node);
105 }
106
107 if (isset($tpl->exclusive)) {
108 $setting->setExclusive(true);
109 }
110
111 foreach ($tpl->assignments->assignment as $element) {
112 $setting->addAssignment(trim((string) $element));
113 }
114 }
115 $setting->save();
116
117 if ($icon !== '' && $this->canUseIcons($setting)) {
118 $setting->getIconHandler()->writeSvg($icon);
119 }
120 $trans = ilMultilingualism::getInstance($setting->getId(), "dtpl");
121 if (isset($root->didacticTemplate->translations)) {
122 $trans->fromXML($root->didacticTemplate->translations);
123 }
124 $trans->save();
125
126 return $setting;
127 }
canUseIcons(ilDidacticTemplateSetting $setting)
static getInstance(int $a_obj_id, string $a_type)

References $tpl, canUseIcons(), ilMultilingualism\getInstance(), ILIAS\Repository\int(), 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.

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

296 : string
297 {
298 $errors = '';
299 foreach (libxml_get_errors() as $err) {
300 $errors .= $err->code . '<br/>';
301 }
302 return $errors;
303 }
$errors
Definition: imgupload.php:65

References $errors.

Referenced by import().

+ Here is the caller graph for this function:

◆ setInputFile()

ilDidacticTemplateImport::setInputFile ( string  $a_file)

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

32 : void
33 {
34 $this->xmlfile = $a_file;
35 }

Field Documentation

◆ $logger

ilLogger ilDidacticTemplateImport::$logger
private

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

◆ $objDefinition

ilObjectDefinition ilDidacticTemplateImport::$objDefinition
protected

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

◆ $settings

ilSetting ilDidacticTemplateImport::$settings
protected

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

Referenced by import().

◆ $type

int ilDidacticTemplateImport::$type = 0
private

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

Referenced by getInputType().

◆ $xmlfile

string ilDidacticTemplateImport::$xmlfile = ''
private

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