ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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...
 
 validateImportFile ()
 

Data Fields

const IMPORT_FILE = 1
 

Protected Member Functions

 parseSettings (SimpleXMLElement $root)
 Parse settings. More...
 
 canUseIcons (ilDidacticTemplateSetting $setting)
 
 parseLocalRoleAction (ilDidacticTemplateSetting $didactic_template_setting, SimpleXMLElement $local_role_action)
 
 parseBlockRoleAction (ilDidacticTemplateSetting $didactic_template_setting, SimpleXMLElement $block_role_action)
 
 parseLocalPolicyAction (ilDidacticTemplateSetting $didactic_template_setting, SimpleXMLElement $local_policy_action)
 
 parseActions (ilDidacticTemplateSetting $set, ?SimpleXMLElement $actions=null)
 Parse template action from xml. More...
 
 parseXmlErrors ()
 Parse xml errors from libxml_get_errors. More...
 

Protected Attributes

const XML_ELEMENT_NAME_LOCAL_ROLE_ACTION = 'localRoleAction'
 
const XML_ELEMENT_NAME_BLOCK_ROLE_ACIONE = 'blockRoleAction'
 
const XML_ELEMENT_NAME_LOCAL_POLICY_ACTION = 'localPolicyAction'
 
const SCHEMA_TYPE = 'otpl'
 
int $type = 0
 
string $xmlfile = ''
 
ilLogger $logger
 
ilObjectDefinition $objDefinition
 
ilSetting $settings
 

Detailed Description

Description of ilDidacticTemplateImport.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilDidacticTemplateImport::__construct ( int  $a_type)

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

46 {
47 global $DIC;
48 $this->logger = $DIC->logger()->otpl();
49 $this->type = $a_type;
50 $this->objDefinition = $DIC['objDefinition'];
51 $this->settings = $DIC->settings();
52 }
global $DIC
Definition: shib_login.php:26

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

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

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

59 : string
60 {
61 return $this->xmlfile;
62 }

References $xmlfile.

Referenced by import(), and validateImportFile().

+ Here is the caller graph for this function:

◆ getInputType()

ilDidacticTemplateImport::getInputType ( )

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

64 : int
65 {
66 return $this->type;
67 }

References $type.

Referenced by import(), and validateImportFile().

+ Here is the caller graph for this function:

◆ import()

ilDidacticTemplateImport::import ( int  $a_dtpl_id = 0)

Do import.

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

73 {
74 $root = null;
75 $use_internal_errors = libxml_use_internal_errors(true);
76 switch ($this->getInputType()) {
78 $root = simplexml_load_string(file_get_contents($this->getInputFile()));
79 break;
80 }
81 libxml_use_internal_errors($use_internal_errors);
82 if (!$root instanceof SimpleXMLElement) {
84 $this->parseXmlErrors()
85 );
86 }
87 $settings = $this->parseSettings($root);
88 $this->parseActions($settings, $root->didacticTemplate->actions);
89 return $settings;
90 }
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().

Referenced by ilDidacticTemplateSettingsGUI\importTemplate().

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

◆ parseActions()

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

Parse template action from xml.

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

309 : void
310 {
311 if ($actions === null) {
312 return;
313 }
314 foreach ($actions->children() as $action) {
315 if ($action->getName() === self::XML_ELEMENT_NAME_LOCAL_ROLE_ACTION) {
316 $this->parseLocalRoleAction($set, $action);
317 continue;
318 }
319 if ($action->getName() === self::XML_ELEMENT_NAME_BLOCK_ROLE_ACIONE) {
320 $this->parseBlockRoleAction($set, $action);
321 continue;
322 }
323 if ($action->getName() === self::XML_ELEMENT_NAME_LOCAL_POLICY_ACTION) {
324 $this->parseLocalPolicyAction($set, $action);
325 continue;
326 }
327 }
328 }
parseBlockRoleAction(ilDidacticTemplateSetting $didactic_template_setting, SimpleXMLElement $block_role_action)
parseLocalPolicyAction(ilDidacticTemplateSetting $didactic_template_setting, SimpleXMLElement $local_policy_action)
parseLocalRoleAction(ilDidacticTemplateSetting $didactic_template_setting, SimpleXMLElement $local_role_action)

Referenced by import().

+ Here is the caller graph for this function:

◆ parseBlockRoleAction()

ilDidacticTemplateImport::parseBlockRoleAction ( ilDidacticTemplateSetting  $didactic_template_setting,
SimpleXMLElement  $block_role_action 
)
protected

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

200 : void {
202 $act->setTemplateId($didactic_template_setting->getId());
203 // Role filter
204 foreach ($block_role_action->roleFilter as $rfi) {
205 switch ((string) $rfi->attributes()->source) {
206 case 'title':
208 break;
209
210 case 'objId':
212 break;
213 case 'parentRoles':
215 break;
216 }
217 foreach ($rfi->includePattern as $pat) {
218 // @TODO other subtypes
221 $pattern->setPattern((string) $pat->attributes()->preg);
222 $act->addFilterPattern($pattern);
223 }
224 foreach ($rfi->excludePattern as $pat) {
225 // @TODO other subtypes
228 $pattern->setPattern((string) $pat->attributes()->preg);
229 $act->addFilterPattern($pattern);
230 }
231 }
232 $act->save();
233 }
Description of ilDidacticTemplateBlockRoleAction.
Implementation of an include filter pattern for didactic template actions.
Implementation of an include filter pattern for didactic template actions.

References ilDidacticTemplateAction\FILTER_PARENT_ROLES, ilDidacticTemplateAction\FILTER_SOURCE_OBJ_ID, ilDidacticTemplateAction\FILTER_SOURCE_TITLE, and ilDidacticTemplateFilterPattern\PATTERN_SUBTYPE_REGEX.

◆ parseLocalPolicyAction()

ilDidacticTemplateImport::parseLocalPolicyAction ( ilDidacticTemplateSetting  $didactic_template_setting,
SimpleXMLElement  $local_policy_action 
)
protected

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

238 : void {
240 $act->setTemplateId($didactic_template_setting->getId());
241 // Role filter
242 foreach ($local_policy_action->roleFilter as $rfi) {
243 $this->logger->dump($rfi->attributes(), \ilLogLevel::DEBUG);
244 $this->logger->debug(
245 'Current filter source: ' . $rfi->attributes()->source
246 );
247 switch ((string) $rfi->attributes()->source) {
248 case 'title':
250 break;
251 case 'objId':
253 break;
254 case 'parentRoles':
256 break;
257 case 'localRoles':
259 break;
260 }
261 foreach ($rfi->includePattern as $pat) {
262 // @TODO other subtypes
265 $pattern->setPattern((string) $pat->attributes()->preg);
266 $act->addFilterPattern($pattern);
267 }
268 foreach ($rfi->excludePattern as $pat) {
269 // @TODO other subtypes
272 $pattern->setPattern((string) $pat->attributes()->preg);
273 $act->addFilterPattern($pattern);
274 }
275 }
276 // role template assignment
277 foreach ($local_policy_action->localPolicyTemplate as $lpo) {
278 switch ((string) $lpo->attributes()->type) {
279 case 'overwrite':
281 break;
282 case 'union':
284 break;
285 case 'intersect':
287 break;
288 }
289 // extract role
290 foreach ($lpo->role as $roleDef) {
291 try {
292 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
293 $role_id = $rimporter->importSimpleXml($roleDef);
294 $act->setRoleTemplateId($role_id);
295 } catch (ilRoleImporterException $e) {
296 // delete half-imported template
297 $didactic_template_setting->delete();
298 throw new ilDidacticTemplateImportException($e->getMessage());
299 }
300 }
301 }
302 // Save action including all filter patterns
303 $act->save();
304 }
Description of class.
const ROLE_FOLDER_ID
Definition: constants.php:34

References ilLogLevel\DEBUG, ilDidacticTemplateAction\FILTER_LOCAL_ROLES, ilDidacticTemplateAction\FILTER_PARENT_ROLES, ilDidacticTemplateAction\FILTER_SOURCE_OBJ_ID, ilDidacticTemplateAction\FILTER_SOURCE_TITLE, ILIAS\Repository\logger(), and ilDidacticTemplateFilterPattern\PATTERN_SUBTYPE_REGEX.

+ Here is the call graph for this function:

◆ parseLocalRoleAction()

ilDidacticTemplateImport::parseLocalRoleAction ( ilDidacticTemplateSetting  $didactic_template_setting,
SimpleXMLElement  $local_role_action 
)
protected

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

182 : void {
184 $act->setTemplateId($didactic_template_setting->getId());
185
186 foreach ($local_role_action->roleTemplate as $tpl) {
187 // extract role
188 foreach ($tpl->role as $roleDef) {
189 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
190 $role_id = $rimporter->importSimpleXml($roleDef);
191 $act->setRoleTemplateId($role_id);
192 }
193 $act->save();
194 }
195 }
represents a creation of local roles action

References ROLE_FOLDER_ID.

◆ parseSettings()

ilDidacticTemplateImport::parseSettings ( SimpleXMLElement  $root)
protected

Parse settings.

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

113 {
114 $icon = '';
115 $setting = new ilDidacticTemplateSetting();
116 foreach ($root->didacticTemplate as $tpl) {
117 switch ((string) $tpl->attributes()->type) {
118 case 'creation':
119 default:
121 break;
122 }
123 $setting->setTitle(trim((string) $tpl->title));
124 $setting->setDescription(trim((string) $tpl->description));
125
126 $icon = (string) $tpl->icon;
127
128 $info = '';
129 foreach ((array) $tpl->info->p as $paragraph) {
130 if ($info !== '') {
131 $info .= "\n";
132 }
133 $info .= trim((string) $paragraph);
134 }
135 $setting->setInfo($info);
136
137 if (isset($tpl->effectiveFrom) && (string) $tpl->effectiveFrom["nic_id"] == $this->settings->get('inst_id')) {
138 $node = array();
139 foreach ($tpl->effectiveFrom->node as $element) {
140 $node[] = (int) $element;
141 }
142
143 $setting->setEffectiveFrom($node);
144 }
145
146 if (isset($tpl->exclusive)) {
147 $setting->setExclusive(true);
148 }
149
150 foreach ($tpl->assignments->assignment as $element) {
151 $setting->addAssignment(trim((string) $element));
152 }
153 }
154 $setting->save();
155
156 if ($icon !== '' && $this->canUseIcons($setting)) {
157 $setting->getIconHandler()->writeSvg($icon);
158 }
159 $trans = ilMultilingualism::getInstance($setting->getId(), "dtpl");
160 if (isset($root->didacticTemplate->translations)) {
161 $trans->fromXML($root->didacticTemplate->translations);
162 }
163 $trans->save();
164
165 return $setting;
166 }
canUseIcons(ilDidacticTemplateSetting $setting)
static getInstance(int $a_obj_id, string $a_type)
$info
Definition: entry_point.php:21

References $info, 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 333 of file class.ilDidacticTemplateImport.php.

333 : string
334 {
335 $errors = '';
336 foreach (libxml_get_errors() as $err) {
337 $errors .= $err->code . '<br/>';
338 }
339 return $errors;
340 }

Referenced by import().

+ Here is the caller graph for this function:

◆ setInputFile()

ilDidacticTemplateImport::setInputFile ( string  $a_file)

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

54 : void
55 {
56 $this->xmlfile = $a_file;
57 }

◆ validateImportFile()

ilDidacticTemplateImport::validateImportFile ( )

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

92 : ilImportStatusCollectionInterface
93 {
94 $status = new ilImportStatusFactory();
95 if ($this->getInputType() !== self::IMPORT_FILE) {
96 return $status->collection()->withAddedStatus($status->handler()
97 ->withType(StatusType::FAILED)
98 ->withContent($status->content()->builder()->string()
99 ->withString("Invalid import status, import status 'IMPORT_FILE' expected.")));
100 }
101 $import = new ilImportHandlerFactory();
102 $xml_spl_info = new SplFileInfo($this->getInputFile());
103 $xsd_schema_info = $import->schemaFolder()->handler()->getLatest(self::SCHEMA_TYPE);
104 $xml_file_handler = $import->file()->xml()->handler()->withFileInfo($xml_spl_info);
105 $xsd_file_handler = $import->file()->xsd()->handler()->withFileInfo($xsd_schema_info->getFile());
106 return $import->validation()->handler()->validateXMLFile($xml_file_handler, $xsd_file_handler);
107 }

References ILIAS\Export\ImportStatus\FAILED, getInputFile(), and getInputType().

+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilLogger ilDidacticTemplateImport::$logger
protected

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

◆ $objDefinition

ilObjectDefinition ilDidacticTemplateImport::$objDefinition
protected

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

◆ $settings

ilSetting ilDidacticTemplateImport::$settings
protected

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

Referenced by import().

◆ $type

int ilDidacticTemplateImport::$type = 0
protected

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

Referenced by getInputType().

◆ $xmlfile

string ilDidacticTemplateImport::$xmlfile = ''
protected

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

Referenced by getInputFile().

◆ IMPORT_FILE

const ilDidacticTemplateImport::IMPORT_FILE = 1

◆ SCHEMA_TYPE

const ilDidacticTemplateImport::SCHEMA_TYPE = 'otpl'
protected

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

◆ XML_ELEMENT_NAME_BLOCK_ROLE_ACIONE

const ilDidacticTemplateImport::XML_ELEMENT_NAME_BLOCK_ROLE_ACIONE = 'blockRoleAction'
protected

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

◆ XML_ELEMENT_NAME_LOCAL_POLICY_ACTION

const ilDidacticTemplateImport::XML_ELEMENT_NAME_LOCAL_POLICY_ACTION = 'localPolicyAction'
protected

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

◆ XML_ELEMENT_NAME_LOCAL_ROLE_ACTION

const ilDidacticTemplateImport::XML_ELEMENT_NAME_LOCAL_ROLE_ACTION = 'localRoleAction'
protected

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


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