ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilContentStyleSettings.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 {
27  protected ilDBInterface $db;
28  public array $styles = array();
29 
30  public function __construct()
31  {
32  global $DIC;
33 
34  $this->db = $DIC->database();
35  $this->read();
36  }
37 
41  public function addStyle(int $a_style_id): void
42  {
43  $this->styles[$a_style_id] =
44  array("id" => $a_style_id,
45  "title" => ilObject::_lookupTitle($a_style_id));
46  }
47 
51  public function removeStyle(int $a_id): void
52  {
53  unset($this->styles[$a_id]);
54  }
55 
56  public function update(): bool
57  {
58  $ilDB = $this->db;
59 
60  // save styles of style folder
61  // note: there are no different style folders in ILIAS, only the one in the settings
62  $q = "DELETE FROM style_folder_styles";
63  $ilDB->manipulate($q);
64  foreach ($this->styles as $style) {
65  $q = "INSERT INTO style_folder_styles (folder_id, style_id) VALUES" .
66  "(" . $ilDB->quote(0, "integer") . ", " .
67  $ilDB->quote((int) $style["id"], "integer") . ")";
68  $ilDB->manipulate($q);
69  }
70 
71  return true;
72  }
73 
74  public function read(): void
75  {
76  $ilDB = $this->db;
77 
78  // get styles of style folder
79  $q = "SELECT * FROM style_folder_styles JOIN style_data ON (style_id = style_data.id)";
80 
81  $style_set = $ilDB->query($q);
82  $this->styles = array();
83  while ($style_rec = $ilDB->fetchAssoc($style_set)) {
84  $this->styles[$style_rec["style_id"]] =
85  array("id" => $style_rec["style_id"],
86  "title" => ilObject::_lookupTitle((int) $style_rec["style_id"]),
87  "category" => $style_rec["category"]);
88  }
89 
90  $this->styles =
91  ilArrayUtil::sortArray($this->styles, "title", "asc", false, true);
92  }
93 
94  public function getStyles(): array
95  {
96  return $this->styles;
97  }
98 }
addStyle(int $a_style_id)
Add style to style folder.
global $DIC
Definition: feed.php:28
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
removeStyle(int $a_id)
remove Style from style list
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)