ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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:93

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  {
65  case self::IMPORT_FILE:
66 
67  $root = simplexml_load_file($this->getInputFile());
68  if($root == FALSE)
69  {
71  $this->parseXmlErrors()
72  );
73  }
74  break;
75  }
76 
77  $settings = $this->parseSettings($root);
78  $this->parseActions($settings,$root->didacticTemplate->actions);
79 
80  return $settings;
81  }
parseXmlErrors()
Parse xml errors from libxml_get_errors.
parseSettings(SimpleXMLElement $root)
Parse settings.
Description of ilDidacticTemplateImportException.
parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions=NULL)
Parse template action from xml.
+ 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 158 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().

159  {
160  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
161 
162  if($actions === NULL)
163  {
164  return void;
165  }
166 
168  // Local role action
170  foreach($actions->localRoleAction as $ele)
171  {
172  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalRoleAction.php';
174  $act->setTemplateId($set->getId());
175 
176  foreach($ele->roleTemplate as $tpl)
177  {
178  // extract role
179  foreach($tpl->role as $roleDef)
180  {
181  include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
182  $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
183  $role_id = $rimporter->importSimpleXml($roleDef);
184  $act->setRoleTemplateId($role_id);
185  }
186  $act->save();
187  }
188  }
189 
191  // Block role action
193  foreach($actions->blockRoleAction as $ele)
194  {
195  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateBlockRoleAction.php';
197  $act->setTemplateId($set->getId());
198 
199  // Role filter
200  foreach($ele->roleFilter as $rfi)
201  {
202  $act->setFilterType((string) $rfi->attributes()->source);
203  foreach($rfi->includePattern as $pat)
204  {
205  // @TODO other subtypes
206  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
208  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
209  $pattern->setPattern((string) $pat->attributes()->preg);
210  $act->addFilterPattern($pattern);
211  }
212  foreach($rfi->excludePattern as $pat)
213  {
214  // @TODO other subtypes
215  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
217  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
218  $pattern->setPattern((string) $pat->attributes()->preg);
219  $act->addFilterPattern($pattern);
220  }
221  }
222 
223  $act->save();
224  }
225 
226 
227 
229  // Local policy action
231  foreach($actions->localPolicyAction as $ele)
232  {
233  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalPolicyAction.php';
235  $act->setTemplateId($set->getId());
236 
237  // Role filter
238  foreach($ele->roleFilter as $rfi)
239  {
240  $act->setFilterType((string) $rfi->attributes()->source);
241  foreach($rfi->includePattern as $pat)
242  {
243  // @TODO other subtypes
244  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
246  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
247  $pattern->setPattern((string) $pat->attributes()->preg);
248  $act->addFilterPattern($pattern);
249  }
250  foreach($rfi->excludePattern as $pat)
251  {
252  // @TODO other subtypes
253  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
255  $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
256  $pattern->setPattern((string) $pat->attributes()->preg);
257  $act->addFilterPattern($pattern);
258  }
259  }
260 
261  // role template assignment
262  foreach($ele->localPolicyTemplate as $lpo)
263  {
265  switch((string) $lpo->attributes()->type)
266  {
267  case 'overwrite':
269  break;
270 
271  case 'union':
273  break;
274 
275  case 'intersect':
277  break;
278  }
279 
280  // extract role
281  foreach($lpo->role as $roleDef)
282  {
283  include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
284  $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
285  $role_id = $rimporter->importSimpleXml($roleDef);
286  $act->setRoleTemplateId($role_id);
287  }
288  }
289 
290  // Save action including all filter patterns
291  $act->save();
292  }
293 
294  }
Description of ilDidacticTemplateBlockRoleAction.
global $tpl
Definition: ilias.php:8
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 88 of file class.ilDidacticTemplateImport.php.

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

Referenced by import().

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

References $errors.

Referenced by import().

302  {
303  $errors = '';
304  foreach(libxml_get_errors() as $err)
305  {
306  $errors .= $err->code.'<br/>';
307  }
308  return $errors;
309  }
$errors
+ 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: