ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilStyleDataSet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
28 {
32  protected $log;
33 
40  function __construct()
41  {
42  parent::__construct();
43  $this->log = ilLoggerFactory::getLogger('styl');
44  $this->log->debug("constructed");
45  }
46 
47 
53  public function getSupportedVersions()
54  {
55  return array("5.1.0");
56  }
57 
64  function getXmlNamespace($a_entity, $a_schema_version)
65  {
66  return "http://www.ilias.de/xml/Services/Style/".$a_entity;
67  }
68 
76  protected function getTypes($a_entity, $a_version)
77  {
78  if ($a_entity == "sty")
79  {
80  switch ($a_version)
81  {
82  case "5.1.0":
83  return array(
84  "Id" => "integer",
85  "Title" => "text",
86  "Description" => "text",
87  "ImagesDir" => "directory"
88  );
89  }
90  }
91 
92  if ($a_entity == "object_style")
93  {
94  switch ($a_version)
95  {
96  case "5.1.0":
97  return array(
98  "ObjectId" => "integer"
99  );
100  }
101  }
102 
103  if ($a_entity == "sty_setting")
104  {
105  switch ($a_version)
106  {
107  case "5.1.0":
108  return array(
109  "StyleId" => "integer",
110  "Name" => "test",
111  "Value" => "text"
112  );
113  }
114  }
115 
116  if ($a_entity == "sty_char")
117  {
118  switch ($a_version)
119  {
120  case "5.1.0":
121  return array(
122  "StyleId" => "integer",
123  "Type" => "text",
124  "Characteristic" => "text",
125  "Hide" => "integer"
126  );
127  }
128  }
129 
130  if ($a_entity == "sty_parameter")
131  {
132  switch ($a_version)
133  {
134  case "5.1.0":
135  return array(
136  "StyleId" => "integer",
137  "Tag" => "text",
138  "Class" => "text",
139  "Parameter" => "text",
140  "Value" => "text",
141  "Type" => "text",
142  "MqId" => "integer",
143  "Custom" => "integer"
144  );
145  }
146  }
147 
148  if ($a_entity == "sty_color")
149  {
150  switch ($a_version)
151  {
152  case "5.1.0":
153  return array(
154  "StyleId" => "integer",
155  "ColorName" => "text",
156  "ColorCode" => "text"
157  );
158  }
159  }
160 
161  if ($a_entity == "sty_media_query")
162  {
163  switch ($a_version)
164  {
165  case "5.1.0":
166  return array(
167  "Id" => "integer",
168  "StyleId" => "integer",
169  "OrderNr" => "integer",
170  "MQuery" => "text"
171  );
172  }
173  }
174 
175  if ($a_entity == "sty_template")
176  {
177  switch ($a_version)
178  {
179  case "5.1.0":
180  return array(
181  "Id" => "integer",
182  "StyleId" => "integer",
183  "Name" => "text",
184  "Preview" => "text",
185  "TempType" => "text"
186  );
187  }
188  }
189 
190  if ($a_entity == "sty_template_class")
191  {
192  switch ($a_version)
193  {
194  case "5.1.0":
195  return array(
196  "TemplateId" => "integer",
197  "ClassType" => "text",
198  "Class" => "text"
199  );
200  }
201  }
202 
203  if ($a_entity == "sty_usage")
204  {
205  switch ($a_version)
206  {
207  case "5.1.0":
208  return array(
209  "ObjId" => "integer",
210  "StyleId" => "integer"
211  );
212  }
213  }
214 
215  }
216 
223  function getXmlRecord($a_entity, $a_version, $a_set)
224  {
225  if ($a_entity == "sty")
226  {
227  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
228  $dir = ilObjStyleSheet::_getImagesDirectory($a_set["Id"]);
229  $a_set["ImagesDir"] = $dir;
230  }
231 
232  return $a_set;
233  }
234 
241  function readData($a_entity, $a_version, $a_ids, $a_field = "")
242  {
243  global $ilDB;
244 
245  if (!is_array($a_ids))
246  {
247  $a_ids = array($a_ids);
248  }
249 
250  if ($a_entity == "object_style")
251  {
252  switch ($a_version)
253  {
254  case "5.1.0":
255  foreach ($a_ids as $id)
256  {
257  $this->data[] = array("ObjectId" => $id);
258  }
259  break;
260  }
261  }
262 
263  if ($a_entity == "sty")
264  {
265  switch ($a_version)
266  {
267  case "5.1.0":
268  $this->getDirectDataFromQuery("SELECT o.title, o.description, o.obj_id id".
269  " FROM object_data o ".
270  " WHERE ".$ilDB->in("o.obj_id", $a_ids, false, "integer"));
271  break;
272  }
273  }
274 
275  if ($a_entity == "sty_setting")
276  {
277  switch ($a_version)
278  {
279  case "5.1.0":
280  $this->getDirectDataFromQuery("SELECT style_id, name, value".
281  " FROM style_setting ".
282  " WHERE ".$ilDB->in("style_id", $a_ids, false, "integer"));
283  break;
284  }
285  }
286 
287  if ($a_entity == "sty_char")
288  {
289  switch ($a_version)
290  {
291  case "5.1.0":
292  $this->getDirectDataFromQuery("SELECT style_id, type, characteristic, hide".
293  " FROM style_char ".
294  " WHERE ".$ilDB->in("style_id", $a_ids, false, "integer"));
295  break;
296  }
297  }
298 
299  if ($a_entity == "sty_parameter")
300  {
301  switch ($a_version)
302  {
303  case "5.1.0":
304  $this->getDirectDataFromQuery("SELECT style_id, tag, class, parameter, value, type, mq_id, custom".
305  " FROM style_parameter ".
306  " WHERE ".$ilDB->in("style_id", $a_ids, false, "integer"));
307  break;
308  }
309  }
310 
311  if ($a_entity == "sty_color")
312  {
313  switch ($a_version)
314  {
315  case "5.1.0":
316  $this->getDirectDataFromQuery("SELECT style_id, color_name, color_code".
317  " FROM style_color ".
318  " WHERE ".$ilDB->in("style_id", $a_ids, false, "integer"));
319  break;
320  }
321  }
322 
323  if ($a_entity == "sty_media_query")
324  {
325  switch ($a_version)
326  {
327  case "5.1.0":
328  $this->getDirectDataFromQuery("SELECT id, style_id, order_nr, mquery m_query".
329  " FROM sty_media_query ".
330  " WHERE ".$ilDB->in("style_id", $a_ids, false, "integer"));
331  break;
332  }
333  }
334 
335  if ($a_entity == "sty_template")
336  {
337  switch ($a_version)
338  {
339  case "5.1.0":
340  $this->getDirectDataFromQuery("SELECT id, style_id, name, preview, temp_type".
341  " FROM style_template ".
342  " WHERE ".$ilDB->in("style_id", $a_ids, false, "integer"));
343  break;
344  }
345  }
346 
347  if ($a_entity == "sty_template_class")
348  {
349  switch ($a_version)
350  {
351  case "5.1.0":
352  $this->getDirectDataFromQuery("SELECT template_id, class_type, class".
353  " FROM style_template_class ".
354  " WHERE ".$ilDB->in("template_id", $a_ids, false, "integer"));
355  break;
356  }
357  }
358 
359  if ($a_entity == "sty_usage")
360  {
361  switch ($a_version)
362  {
363  case "5.1.0":
364  $this->getDirectDataFromQuery("SELECT obj_id, style_id".
365  " FROM style_usage ".
366  " WHERE ".$ilDB->in("style_id", $a_ids, false, "integer"));
367  break;
368  }
369  }
370  }
371 
375  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
376  {
377  $this->ds_log->debug("entity: ".$a_entity.", rec: ".print_r($a_rec, true));
378  switch ($a_entity)
379  {
380  case "object_style":
381  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
382  $this->ds_log->debug("object id: ".$a_rec["ObjectId"]);
383  $style_id = ilObjStyleSheet::lookupObjectStyle($a_rec["ObjectId"]);
384  $this->ds_log->debug("style id: ".$style_id);
385  //if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
386  if ($style_id > 0 && ilObject::_lookupType($style_id) == "sty") // #0019337 always export style, if valid
387  {
388  return array (
389  "sty" => array("ids" => $style_id));
390  }
391  return array();
392  break;
393 
394  case "sty":
395  return array (
396  "sty_setting" => array("ids" => $a_rec["Id"]),
397  "sty_media_query" => array("ids" => $a_rec["Id"]),
398  "sty_char" => array("ids" => $a_rec["Id"]),
399  "sty_color" => array("ids" => $a_rec["Id"]),
400  "sty_parameter" => array("ids" => $a_rec["Id"]),
401  "sty_template" => array("ids" => $a_rec["Id"]),
402  "sty_usage" => array("ids" => $a_rec["Id"])
403  );
404 
405  case "sty_template":
406  return array (
407  "sty_template_class" => array("ids" => $a_rec["Id"])
408  );
409  }
410 
411  return false;
412  }
413 
414 
421  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
422  {
423  switch ($a_entity)
424  {
425  case "sty":
426  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
427  $this->log->debug("Entity: ".$a_entity);
428  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
429  {
430  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
431  }
432  else
433  {
434  $newObj = new ilObjStyleSheet();
435  $newObj->create(0, true);
436  }
437 
438  $newObj->setTitle($a_rec["Title"]);
439  $newObj->setDescription($a_rec["Description"]);
440  $newObj->update(true);
441 
442  $this->current_obj = $newObj;
443  $a_mapping->addMapping("Services/Style", "sty", $a_rec["Id"], $newObj->getId());
444  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
445  $this->log->debug("Added mapping Services/Style sty ".$a_rec["Id"]." > ".$newObj->getId());
446 
447  $dir = str_replace("..", "", $a_rec["ImagesDir"]);
448  if ($dir != "" && $this->getImportDirectory() != "")
449  {
450  $source_dir = $this->getImportDirectory()."/".$dir;
451  $target_dir = $dir = ilObjStyleSheet::_getImagesDirectory($newObj->getId());
452  ilUtil::rCopy($source_dir, $target_dir);
453  }
454  break;
455 
456  case "sty_setting":
457  $this->current_obj->writeStyleSetting($a_rec["Name"], $a_rec["Value"]);
458  break;
459 
460  case "sty_char":
461  $this->current_obj->addCharacteristic($a_rec["Type"], $a_rec["Characteristic"], $a_rec["Hide"]);
462  break;
463 
464  case "sty_parameter":
465  $mq_id = (int) $a_mapping->getMapping("Services/Style", "media_query", $a_rec["MqId"]);
466  $this->current_obj->replaceStylePar($a_rec["Tag"], $a_rec["Class"], $a_rec["Parameter"], $a_rec["Value"], $a_rec["Type"], $mq_id, $a_rec["Custom"]);
467  break;
468 
469  case "sty_color":
470  $this->current_obj->addColor($a_rec["ColorName"], $a_rec["ColorCode"]);
471  break;
472 
473  case "sty_media_query":
474  $mq_id = $this->current_obj->addMediaQuery($a_rec["MQuery"], $a_rec["OrderNr"]);
475  $a_mapping->addMapping("Services/Style", "media_query", $a_rec["Id"], $mq_id);
476  break;
477 
478  case "sty_template":
479  $tid = $this->current_obj->addTemplate($a_rec["TempType"], $a_rec["Name"], array());
480  $a_mapping->addMapping("Services/Style", "template", $a_rec["Id"], $tid);
481  break;
482 
483  case "sty_template_class":
484  $tid = (int) $a_mapping->getMapping("Services/Style", "template", $a_rec["TemplateId"]);
485  $this->current_obj->addTemplateClass($tid, $a_rec["ClassType"], $a_rec["Class"]);
486  break;
487 
488  case "sty_usage":
489  $obj_id = (int) $a_mapping->getMapping("Services/Object", "obj", $a_rec["ObjId"]);
490  $style_id = (int) $a_mapping->getMapping("Services/Style", "sty", $a_rec["StyleId"]);
491  if ($obj_id > 0 && $style_id > 0)
492  {
493  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
494  ilObjStyleSheet::writeStyleUsage($obj_id, $style_id);
495  }
496  break;
497  }
498  }
499 }
500 ?>
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
Add some data
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true, $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
__construct()
constructor
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getImportDirectory()
Get import directory.
static lookupObjectStyle($a_obj_id)
Lookup object style.
static writeStyleUsage($a_obj_id, $a_style_id)
Write style usage.
getSupportedVersions()
Get supported versions.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getImagesDirectory($a_style_id)
Get images directory.
Style Data set class.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record.
global $ilDB
Class ilObjStyleSheet.
static getLogger($a_component_id)
Get component logger.
getTypes($a_entity, $a_version)
Get field types for entity.
A dataset contains in data in a common structure that can be shared and transformed for different pur...