ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
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  }
82 
88  protected function parseSettings(SimpleXMLElement $root)
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  }
151 
158  protected function parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions = NULL)
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  }
295 
301  protected function parseXmlErrors()
302  {
303  $errors = '';
304  foreach(libxml_get_errors() as $err)
305  {
306  $errors .= $err->code.'<br/>';
307  }
308  return $errors;
309  }
310 
311 
312 }
313 ?>
static getInstance($a_obj_id, $a_type)
Get instance.
Description of ilDidacticTemplateBlockRoleAction.
parseXmlErrors()
Parse xml errors from libxml_get_errors.
global $tpl
Definition: ilias.php:8
$a_type
Definition: workflow.php:93
parseSettings(SimpleXMLElement $root)
Parse settings.
$info
Definition: example_052.php:80
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
represents a creation of local roles action
parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions=NULL)
Parse template action from xml.
global $ilSetting
Definition: privfeed.php:17
Description of class.
Implementation of an include filter pattern for didactic template actions.