ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function __construct()
41  {
42  global $DIC;
43 
44  $this->db = $DIC->database();
45  parent::__construct();
46  $this->log = ilLoggerFactory::getLogger('styl');
47  $this->log->debug("constructed");
48  }
49 
50 
56  public function getSupportedVersions()
57  {
58  return array("5.1.0");
59  }
60 
67  public function getXmlNamespace($a_entity, $a_schema_version)
68  {
69  return "http://www.ilias.de/xml/Services/Style/" . $a_entity;
70  }
71 
79  protected function getTypes($a_entity, $a_version)
80  {
81  if ($a_entity == "sty") {
82  switch ($a_version) {
83  case "5.1.0":
84  return array(
85  "Id" => "integer",
86  "Title" => "text",
87  "Description" => "text",
88  "ImagesDir" => "directory"
89  );
90  }
91  }
92 
93  if ($a_entity == "object_style") {
94  switch ($a_version) {
95  case "5.1.0":
96  return array(
97  "ObjectId" => "integer"
98  );
99  }
100  }
101 
102  if ($a_entity == "sty_setting") {
103  switch ($a_version) {
104  case "5.1.0":
105  return array(
106  "StyleId" => "integer",
107  "Name" => "test",
108  "Value" => "text"
109  );
110  }
111  }
112 
113  if ($a_entity == "sty_char") {
114  switch ($a_version) {
115  case "5.1.0":
116  return array(
117  "StyleId" => "integer",
118  "Type" => "text",
119  "Characteristic" => "text",
120  "Hide" => "integer"
121  );
122  }
123  }
124 
125  if ($a_entity == "sty_parameter") {
126  switch ($a_version) {
127  case "5.1.0":
128  return array(
129  "StyleId" => "integer",
130  "Tag" => "text",
131  "Class" => "text",
132  "Parameter" => "text",
133  "Value" => "text",
134  "Type" => "text",
135  "MqId" => "integer",
136  "Custom" => "integer"
137  );
138  }
139  }
140 
141  if ($a_entity == "sty_color") {
142  switch ($a_version) {
143  case "5.1.0":
144  return array(
145  "StyleId" => "integer",
146  "ColorName" => "text",
147  "ColorCode" => "text"
148  );
149  }
150  }
151 
152  if ($a_entity == "sty_media_query") {
153  switch ($a_version) {
154  case "5.1.0":
155  return array(
156  "Id" => "integer",
157  "StyleId" => "integer",
158  "OrderNr" => "integer",
159  "MQuery" => "text"
160  );
161  }
162  }
163 
164  if ($a_entity == "sty_template") {
165  switch ($a_version) {
166  case "5.1.0":
167  return array(
168  "Id" => "integer",
169  "StyleId" => "integer",
170  "Name" => "text",
171  "Preview" => "text",
172  "TempType" => "text"
173  );
174  }
175  }
176 
177  if ($a_entity == "sty_template_class") {
178  switch ($a_version) {
179  case "5.1.0":
180  return array(
181  "TemplateId" => "integer",
182  "ClassType" => "text",
183  "Class" => "text"
184  );
185  }
186  }
187 
188  if ($a_entity == "sty_usage") {
189  switch ($a_version) {
190  case "5.1.0":
191  return array(
192  "ObjId" => "integer",
193  "StyleId" => "integer"
194  );
195  }
196  }
197  }
198 
205  public function getXmlRecord($a_entity, $a_version, $a_set)
206  {
207  if ($a_entity == "sty") {
208  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
209  $dir = ilObjStyleSheet::_getImagesDirectory($a_set["Id"]);
210  $a_set["ImagesDir"] = $dir;
211  }
212 
213  return $a_set;
214  }
215 
222  public function readData($a_entity, $a_version, $a_ids, $a_field = "")
223  {
224  $ilDB = $this->db;
225 
226  if (!is_array($a_ids)) {
227  $a_ids = array($a_ids);
228  }
229 
230  if ($a_entity == "object_style") {
231  switch ($a_version) {
232  case "5.1.0":
233  foreach ($a_ids as $id) {
234  $this->data[] = array("ObjectId" => $id);
235  }
236  break;
237  }
238  }
239 
240  if ($a_entity == "sty") {
241  switch ($a_version) {
242  case "5.1.0":
243  $this->getDirectDataFromQuery("SELECT o.title, o.description, o.obj_id id" .
244  " FROM object_data o " .
245  " WHERE " . $ilDB->in("o.obj_id", $a_ids, false, "integer"));
246  break;
247  }
248  }
249 
250  if ($a_entity == "sty_setting") {
251  switch ($a_version) {
252  case "5.1.0":
253  $this->getDirectDataFromQuery("SELECT style_id, name, value" .
254  " FROM style_setting " .
255  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
256  break;
257  }
258  }
259 
260  if ($a_entity == "sty_char") {
261  switch ($a_version) {
262  case "5.1.0":
263  $this->getDirectDataFromQuery("SELECT style_id, type, characteristic, hide" .
264  " FROM style_char " .
265  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
266  break;
267  }
268  }
269 
270  if ($a_entity == "sty_parameter") {
271  switch ($a_version) {
272  case "5.1.0":
273  $this->getDirectDataFromQuery("SELECT style_id, tag, class, parameter, value, type, mq_id, custom" .
274  " FROM style_parameter " .
275  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
276  break;
277  }
278  }
279 
280  if ($a_entity == "sty_color") {
281  switch ($a_version) {
282  case "5.1.0":
283  $this->getDirectDataFromQuery("SELECT style_id, color_name, color_code" .
284  " FROM style_color " .
285  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
286  break;
287  }
288  }
289 
290  if ($a_entity == "sty_media_query") {
291  switch ($a_version) {
292  case "5.1.0":
293  $this->getDirectDataFromQuery("SELECT id, style_id, order_nr, mquery m_query" .
294  " FROM sty_media_query " .
295  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
296  break;
297  }
298  }
299 
300  if ($a_entity == "sty_template") {
301  switch ($a_version) {
302  case "5.1.0":
303  $this->getDirectDataFromQuery("SELECT id, style_id, name, preview, temp_type" .
304  " FROM style_template " .
305  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
306  break;
307  }
308  }
309 
310  if ($a_entity == "sty_template_class") {
311  switch ($a_version) {
312  case "5.1.0":
313  $this->getDirectDataFromQuery("SELECT template_id, class_type, class" .
314  " FROM style_template_class " .
315  " WHERE " . $ilDB->in("template_id", $a_ids, false, "integer"));
316  break;
317  }
318  }
319 
320  if ($a_entity == "sty_usage") {
321  switch ($a_version) {
322  case "5.1.0":
323  $this->getDirectDataFromQuery("SELECT obj_id, style_id" .
324  " FROM style_usage " .
325  " WHERE " . $ilDB->in("style_id", $a_ids, false, "integer"));
326  break;
327  }
328  }
329  }
330 
334  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
335  {
336  $this->ds_log->debug("entity: " . $a_entity . ", rec: " . print_r($a_rec, true));
337  switch ($a_entity) {
338  case "object_style":
339  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
340  $this->ds_log->debug("object id: " . $a_rec["ObjectId"]);
341  $style_id = ilObjStyleSheet::lookupObjectStyle($a_rec["ObjectId"]);
342  $this->ds_log->debug("style id: " . $style_id);
343  //if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
344  if ($style_id > 0 && ilObject::_lookupType($style_id) == "sty") { // #0019337 always export style, if valid
345  return array(
346  "sty" => array("ids" => $style_id));
347  }
348  return array();
349  break;
350 
351  case "sty":
352  return array(
353  "sty_setting" => array("ids" => $a_rec["Id"]),
354  "sty_media_query" => array("ids" => $a_rec["Id"]),
355  "sty_char" => array("ids" => $a_rec["Id"]),
356  "sty_color" => array("ids" => $a_rec["Id"]),
357  "sty_parameter" => array("ids" => $a_rec["Id"]),
358  "sty_template" => array("ids" => $a_rec["Id"]),
359  "sty_usage" => array("ids" => $a_rec["Id"])
360  );
361 
362  case "sty_template":
363  return array(
364  "sty_template_class" => array("ids" => $a_rec["Id"])
365  );
366  }
367 
368  return false;
369  }
370 
371 
378  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
379  {
380  switch ($a_entity) {
381  case "sty":
382  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
383  $this->log->debug("Entity: " . $a_entity);
384  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
385  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
386  } else {
387  $newObj = new ilObjStyleSheet();
388  $newObj->create(0, true);
389  }
390 
391  $newObj->setTitle($a_rec["Title"]);
392  $newObj->setDescription($a_rec["Description"]);
393  $newObj->update(true);
394 
395  $this->current_obj = $newObj;
396  $a_mapping->addMapping("Services/Style", "sty", $a_rec["Id"], $newObj->getId());
397  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
398  $this->log->debug("Added mapping Services/Style sty " . $a_rec["Id"] . " > " . $newObj->getId());
399 
400  $dir = str_replace("..", "", $a_rec["ImagesDir"]);
401  if ($dir != "" && $this->getImportDirectory() != "") {
402  $source_dir = $this->getImportDirectory() . "/" . $dir;
403  $target_dir = $dir = ilObjStyleSheet::_getImagesDirectory($newObj->getId());
404  ilUtil::rCopy($source_dir, $target_dir);
405  }
406  break;
407 
408  case "sty_setting":
409  $this->current_obj->writeStyleSetting($a_rec["Name"], $a_rec["Value"]);
410  break;
411 
412  case "sty_char":
413  $this->current_obj->addCharacteristic($a_rec["Type"], $a_rec["Characteristic"], $a_rec["Hide"]);
414  break;
415 
416  case "sty_parameter":
417  $mq_id = (int) $a_mapping->getMapping("Services/Style", "media_query", $a_rec["MqId"]);
418  $this->current_obj->replaceStylePar($a_rec["Tag"], $a_rec["Class"], $a_rec["Parameter"], $a_rec["Value"], $a_rec["Type"], $mq_id, $a_rec["Custom"]);
419  break;
420 
421  case "sty_color":
422  $this->current_obj->addColor($a_rec["ColorName"], $a_rec["ColorCode"]);
423  break;
424 
425  case "sty_media_query":
426  $mq_id = $this->current_obj->addMediaQuery($a_rec["MQuery"], $a_rec["OrderNr"]);
427  $a_mapping->addMapping("Services/Style", "media_query", $a_rec["Id"], $mq_id);
428  break;
429 
430  case "sty_template":
431  $tid = $this->current_obj->addTemplate($a_rec["TempType"], $a_rec["Name"], array());
432  $a_mapping->addMapping("Services/Style", "template", $a_rec["Id"], $tid);
433  break;
434 
435  case "sty_template_class":
436  $tid = (int) $a_mapping->getMapping("Services/Style", "template", $a_rec["TemplateId"]);
437  $this->current_obj->addTemplateClass($tid, $a_rec["ClassType"], $a_rec["Class"]);
438  break;
439 
440  case "sty_usage":
441  $obj_id = (int) $a_mapping->getMapping("Services/Object", "obj", $a_rec["ObjId"]);
442  $style_id = (int) $a_mapping->getMapping("Services/Style", "sty", $a_rec["StyleId"]);
443  if ($obj_id > 0 && $style_id > 0) {
444  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
445  ilObjStyleSheet::writeStyleUsage($obj_id, $style_id);
446  }
447  break;
448  }
449  }
450 }
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
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.
global $DIC
Definition: saml.php:7
__construct()
constructor
if(!array_key_exists('StateId', $_REQUEST)) $id
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
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.
$this data['403_header']
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...