ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilDidacticTemplateImport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/DidacticTemplate/exceptions/class.ilDidacticTemplateImportException.php';
5 
13 {
14  const IMPORT_FILE = 1;
15 
16  private $type = 0;
17  private $xmlfile = '';
18 
19 
24  public function __construct($a_type)
25  {
26  $this->type = $a_type;
27  }
28 
33  public function setInputFile($a_file)
34  {
35  $this->xmlfile = $a_file;
36  }
37 
42  public function getInputFile()
43  {
44  return $this->xmlfile;
45  }
46 
51  public function getInputType()
52  {
53  return $this->type;
54  }
55 
59  public function import($a_dtpl_id = 0)
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  }
80 
86  protected function parseSettings(SimpleXMLElement $root)
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  }
140 
147  protected function parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions = null)
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  }
268 
274  protected function parseXmlErrors()
275  {
276  $errors = '';
277  foreach (libxml_get_errors() as $err) {
278  $errors .= $err->code . '<br/>';
279  }
280  return $errors;
281  }
282 }
static getInstance($a_obj_id, $a_type)
Get instance.
Description of ilDidacticTemplateBlockRoleAction.
$tpl
Definition: ilias.php:10
parseXmlErrors()
Parse xml errors from libxml_get_errors.
$a_type
Definition: workflow.php:92
parseSettings(SimpleXMLElement $root)
Parse settings.
parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions=null)
Parse template action from xml.
Implementation of an include filter pattern for didactic template actions.
Description of ilDidacticTemplateImportException.
Description of ilDidacticTemplateImport.
Create styles array
The data for the language used.
$errors
Definition: index.php:6
represents a creation of local roles action
global $ilSetting
Definition: privfeed.php:17
$info
Definition: index.php:5
Description of class.
Implementation of an include filter pattern for didactic template actions.