ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 = ''
 

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

References $a_type.

25  {
26  $this->type = $a_type;
27  }
$a_type
Definition: workflow.php:92

Member Function Documentation

◆ getInputFile()

ilDidacticTemplateImport::getInputFile ( )

Get inputfile.

Returns
<type>

Definition at line 42 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 51 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 59 of file class.ilDidacticTemplateImport.php.

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

60  {
61  libxml_use_internal_errors(true);
62 
63  switch ($this->getInputType()) {
64  case self::IMPORT_FILE:
65 
66  $root = simplexml_load_file($this->getInputFile());
67  if ($root == false) {
69  $this->parseXmlErrors()
70  );
71  }
72  break;
73  }
74 
75  $settings = $this->parseSettings($root);
76  $this->parseActions($settings, $root->didacticTemplate->actions);
77 
78  return $settings;
79  }
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.

Parameters
ilDidacticTemplateSetting$set
SimpleXMLElement$root
Returns
void

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

References $tpl, 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().

148  {
149  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
150 
151  if ($actions === null) {
152  return void;
153  }
154 
156  // Local role action
158  foreach ($actions->localRoleAction as $ele) {
159  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalRoleAction.php';
161  $act->setTemplateId($set->getId());
162 
163  foreach ($ele->roleTemplate as $tpl) {
164  // extract role
165  foreach ($tpl->role as $roleDef) {
166  include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
167  $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
168  $role_id = $rimporter->importSimpleXml($roleDef);
169  $act->setRoleTemplateId($role_id);
170  }
171  $act->save();
172  }
173  }
174 
176  // Block role action
178  foreach ($actions->blockRoleAction as $ele) {
179  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateBlockRoleAction.php';
181  $act->setTemplateId($set->getId());
182 
183  // Role filter
184  foreach ($ele->roleFilter as $rfi) {
185  $act->setFilterType((string) $rfi->attributes()->source);
186  foreach ($rfi->includePattern as $pat) {
187  // @TODO other subtypes
188  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
190  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
191  $pattern->setPattern((string) $pat->attributes()->preg);
192  $act->addFilterPattern($pattern);
193  }
194  foreach ($rfi->excludePattern as $pat) {
195  // @TODO other subtypes
196  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
198  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
199  $pattern->setPattern((string) $pat->attributes()->preg);
200  $act->addFilterPattern($pattern);
201  }
202  }
203 
204  $act->save();
205  }
206 
207 
208 
210  // Local policy action
212  foreach ($actions->localPolicyAction as $ele) {
213  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalPolicyAction.php';
215  $act->setTemplateId($set->getId());
216 
217  // Role filter
218  foreach ($ele->roleFilter as $rfi) {
219  $act->setFilterType((string) $rfi->attributes()->source);
220  foreach ($rfi->includePattern as $pat) {
221  // @TODO other subtypes
222  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
224  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
225  $pattern->setPattern((string) $pat->attributes()->preg);
226  $act->addFilterPattern($pattern);
227  }
228  foreach ($rfi->excludePattern as $pat) {
229  // @TODO other subtypes
230  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
232  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
233  $pattern->setPattern((string) $pat->attributes()->preg);
234  $act->addFilterPattern($pattern);
235  }
236  }
237 
238  // role template assignment
239  foreach ($ele->localPolicyTemplate as $lpo) {
241  switch ((string) $lpo->attributes()->type) {
242  case 'overwrite':
244  break;
245 
246  case 'union':
248  break;
249 
250  case 'intersect':
252  break;
253  }
254 
255  // extract role
256  foreach ($lpo->role as $roleDef) {
257  include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
258  $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
259  $role_id = $rimporter->importSimpleXml($roleDef);
260  $act->setRoleTemplateId($role_id);
261  }
262  }
263 
264  // Save action including all filter patterns
265  $act->save();
266  }
267  }
Description of ilDidacticTemplateBlockRoleAction.
$tpl
Definition: ilias.php:10
Implementation of an include filter pattern for didactic template actions.
represents a creation of local roles action
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:

◆ parseSettings()

ilDidacticTemplateImport::parseSettings ( SimpleXMLElement  $root)
protected

Parse settings.

Parameters
SimpleXMLElement$el
Returns
ilDidacticTemplateSetting

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

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

Referenced by import().

87  {
88  global $ilSetting;
89  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
90  $setting = new ilDidacticTemplateSetting();
91 
92  foreach ($root->didacticTemplate as $tpl) {
93  switch ((string) $tpl->attributes()->type) {
94  case 'creation':
95  default:
97  break;
98  }
99  $setting->setTitle(trim((string) $tpl->title));
100  $setting->setDescription(trim((string) $tpl->description));
101 
102  $info = '';
103  foreach ((array) $tpl->info->p as $paragraph) {
104  if (strlen($info)) {
105  $info .= "\n";
106  }
107  $info .= trim((string) $paragraph);
108  }
109  $setting->setInfo($info);
110 
111  if (isset($tpl->effectiveFrom) && (string) $tpl->effectiveFrom["nic_id"] == $ilSetting->get('inst_id')) {
112  $node = array();
113  foreach ($tpl->effectiveFrom->node as $element) {
114  $node[] = (int) $element;
115  }
116 
117  $setting->setEffectiveFrom($node);
118  }
119 
120  if (isset($tpl->exclusive)) {
121  $setting->setExclusive(true);
122  }
123 
124  foreach ($tpl->assignments->assignment as $element) {
125  $setting->addAssignment(trim((string) $element));
126  }
127  }
128  $setting->save();
129 
130  include_once("./Services/Multilingualism/classes/class.ilMultilingualism.php");
131  $trans = ilMultilingualism::getInstance($setting->getId(), "dtpl");
132 
133  if (isset($root->didacticTemplate->translations)) {
134  $trans->fromXML($root->didacticTemplate->translations);
135  }
136  $trans->save();
137 
138  return $setting;
139  }
static getInstance($a_obj_id, $a_type)
Get instance.
$tpl
Definition: ilias.php:10
Create styles array
The data for the language used.
global $ilSetting
Definition: privfeed.php:17
$info
Definition: index.php:5
+ 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 274 of file class.ilDidacticTemplateImport.php.

References $errors.

Referenced by import().

275  {
276  $errors = '';
277  foreach (libxml_get_errors() as $err) {
278  $errors .= $err->code . '<br/>';
279  }
280  return $errors;
281  }
$errors
Definition: index.php:6
+ Here is the caller graph for this function:

◆ setInputFile()

ilDidacticTemplateImport::setInputFile (   $a_file)

Set input file.

Parameters
string$a_file

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

34  {
35  $this->xmlfile = $a_file;
36  }

Field Documentation

◆ $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: