ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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.

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

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: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ canUseIcons()

ilDidacticTemplateImport::canUseIcons ( ilDidacticTemplateSetting  $setting)
protected

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

References ilDidacticTemplateSetting\getAssignments().

Referenced by parseSettings().

169  : bool
170  {
171  foreach ($setting->getAssignments() as $assignment) {
172  if (!$this->objDefinition->isContainer($assignment)) {
173  return false;
174  }
175  }
176 
177  return true;
178  }
+ 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.

References $xmlfile.

Referenced by import(), and validateImportFile().

59  : string
60  {
61  return $this->xmlfile;
62  }
+ Here is the caller graph for this function:

◆ getInputType()

ilDidacticTemplateImport::getInputType ( )

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

References $type.

Referenced by import(), and validateImportFile().

64  : int
65  {
66  return $this->type;
67  }
+ 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.

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

73  {
74  $root = null;
75  $use_internal_errors = libxml_use_internal_errors(true);
76  switch ($this->getInputType()) {
77  case self::IMPORT_FILE:
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  }
parseXmlErrors()
Parse xml errors from libxml_get_errors.
parseSettings(SimpleXMLElement $root)
Parse settings.
parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions=null)
Parse template action from xml.
Description of ilDidacticTemplateImportException.
+ 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 310 of file class.ilDidacticTemplateImport.php.

References parseBlockRoleAction(), parseLocalPolicyAction(), and parseLocalRoleAction().

Referenced by import().

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

◆ parseBlockRoleAction()

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

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

References ilDidacticTemplateAction\FILTER_PARENT_ROLES, ilDidacticTemplateAction\FILTER_SOURCE_OBJ_ID, ilDidacticTemplateAction\FILTER_SOURCE_TITLE, ilDidacticTemplateSetting\getId(), and ilDidacticTemplateFilterPattern\PATTERN_SUBTYPE_REGEX.

Referenced by parseActions().

201  : void {
203  $act->setTemplateId($didactic_template_setting->getId());
204  // Role filter
205  foreach ($block_role_action->roleFilter as $rfi) {
206  switch ((string) $rfi->attributes()->source) {
207  case 'title':
208  $act->setFilterType(\ilDidacticTemplateAction::FILTER_SOURCE_TITLE);
209  break;
210 
211  case 'objId':
213  break;
214  case 'parentRoles':
215  $act->setFilterType(\ilDidacticTemplateAction::FILTER_PARENT_ROLES);
216  break;
217  }
218  foreach ($rfi->includePattern as $pat) {
219  // @TODO other subtypes
221  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
222  $pattern->setPattern((string) $pat->attributes()->preg);
223  $act->addFilterPattern($pattern);
224  }
225  foreach ($rfi->excludePattern as $pat) {
226  // @TODO other subtypes
228  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
229  $pattern->setPattern((string) $pat->attributes()->preg);
230  $act->addFilterPattern($pattern);
231  }
232  }
233  $act->save();
234  }
Description of ilDidacticTemplateBlockRoleAction.
Implementation of an include filter pattern for didactic template actions.
Implementation of an include filter pattern for didactic template actions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseLocalPolicyAction()

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

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

References Vendor\Package\$e, 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 parseActions().

239  : void {
241  $act->setTemplateId($didactic_template_setting->getId());
242  // Role filter
243  foreach ($local_policy_action->roleFilter as $rfi) {
244  $this->logger->dump($rfi->attributes(), \ilLogLevel::DEBUG);
245  $this->logger->debug(
246  'Current filter source: ' . $rfi->attributes()->source
247  );
248  switch ((string) $rfi->attributes()->source) {
249  case 'title':
250  $act->setFilterType(\ilDidacticTemplateAction::FILTER_SOURCE_TITLE);
251  break;
252  case 'objId':
254  break;
255  case 'parentRoles':
256  $act->setFilterType(\ilDidacticTemplateAction::FILTER_PARENT_ROLES);
257  break;
258  case 'localRoles':
259  $act->setFilterType(\ilDidacticTemplateAction::FILTER_LOCAL_ROLES);
260  break;
261  }
262  foreach ($rfi->includePattern as $pat) {
263  // @TODO other subtypes
265  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
266  $pattern->setPattern((string) $pat->attributes()->preg);
267  $act->addFilterPattern($pattern);
268  }
269  foreach ($rfi->excludePattern as $pat) {
270  // @TODO other subtypes
272  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
273  $pattern->setPattern((string) $pat->attributes()->preg);
274  $act->addFilterPattern($pattern);
275  }
276  }
277  // role template assignment
278  foreach ($local_policy_action->localPolicyTemplate as $lpo) {
279  switch ((string) $lpo->attributes()->type) {
280  case 'overwrite':
282  break;
283  case 'union':
285  break;
286  case 'intersect':
288  break;
289  }
290  // extract role
291  foreach ($lpo->role as $roleDef) {
292  try {
293  $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
294  $role_id = $rimporter->importSimpleXml($roleDef);
295  $act->setRoleTemplateId($role_id);
296  } catch (ilRoleImporterException $e) {
297  // delete half-imported template
298  $didactic_template_setting->delete();
299  throw new ilDidacticTemplateImportException($e->getMessage());
300  }
301  }
302  }
303  // Save action including all filter patterns
304  $act->save();
305  }
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.
Description of ilDidacticTemplateImportException.
const ROLE_FOLDER_ID
Definition: constants.php:34
Description of class.
Implementation of an include filter pattern for didactic template actions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseLocalRoleAction()

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

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

References ilDidacticTemplateSetting\getId(), and ROLE_FOLDER_ID.

Referenced by parseActions().

183  : void {
185  $act->setTemplateId($didactic_template_setting->getId());
186 
187  foreach ($local_role_action->roleTemplate as $tpl) {
188  // extract role
189  foreach ($tpl->role as $roleDef) {
190  $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
191  $role_id = $rimporter->importSimpleXml($roleDef);
192  $act->setRoleTemplateId($role_id);
193  }
194  $act->save();
195  }
196  }
const ROLE_FOLDER_ID
Definition: constants.php:34
represents a creation of local roles action
Description of class.
+ 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 113 of file class.ilDidacticTemplateImport.php.

References canUseIcons(), ilMultilingualism\getInstance(), ILIAS\Repository\int(), and ilDidacticTemplateSetting\TYPE_CREATION.

Referenced by import().

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

Referenced by import().

334  : string
335  {
336  $errors = '';
337  foreach (libxml_get_errors() as $err) {
338  $errors .= $err->code . '<br/>';
339  }
340  return $errors;
341  }
+ Here is the caller graph for this function:

◆ setInputFile()

ilDidacticTemplateImport::setInputFile ( string  $a_file)

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

Referenced by ilDidacticTemplateSettingsGUI\checkInput().

54  : void
55  {
56  $this->xmlfile = $a_file;
57  }
+ Here is the caller graph for this function:

◆ validateImportFile()

ilDidacticTemplateImport::validateImportFile ( )

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

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

Referenced by ilDidacticTemplateSettingsGUI\checkInput().

93  {
94  $status = new ilImportStatusFactory();
95  if ($this->getInputType() !== self::IMPORT_FILE) {
96  return $status->collection()->withAddedStatus($status->handler()
97  ->withType(ImportStatus\StatusType::FAILED)
98  ->withContent($status->content()->builder()->string()
99  ->withString("Invalid import status, import status 'IMPORT_FILE' expected.")));
100  }
101  $schema = new ilXMLSchemaFactory();
102  $import = new ilImportHandlerFactory();
103  $xml_spl_info = new SplFileInfo($this->getInputFile());
104  $xsd_spl_info = $schema->getLatest(self::SCHEMA_TYPE);
105  $xml_file_handler = $import->file()->xml()->withFileInfo($xml_spl_info);
106  $xsd_file_handler = $import->file()->xsd()->withFileInfo($xsd_spl_info);
107  return $import->file()->validation()->handler()->validateXMLFile($xml_file_handler, $xsd_file_handler);
108  }
+ Here is the call graph for this function:
+ Here is the caller 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: