ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
StyleManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
28  protected \ilDBInterface $db;
29  protected \ILIAS\COPage\Dom\DomUtil $dom_util;
30 
31  public function __construct()
32  {
33  global $DIC;
34 
35  $this->dom_util = $DIC->copage()->internal()->domain()->domUtil();
36  $this->db = $DIC->database();
37  }
38 
42  public function saveStyleUsage(
43  \ilPageObject $page,
44  \DOMDocument $a_domdoc,
45  int $a_old_nr = 0
46  ): void {
47  $sname = "";
48  $stype = "";
49  $template = "";
50  // media aliases
51  $path = "//Paragraph | //Section | //MediaAlias | //FileItem" .
52  " | //Table | //TableData | //Tabs | //List";
53  $usages = array();
54  $nodes = $this->dom_util->path($a_domdoc, $path);
55  foreach ($nodes as $node) {
56  switch ($node->localName) {
57  case "Paragraph":
58  $sname = $node->getAttribute("Characteristic");
59  $stype = "text_block";
60  $template = 0;
61  break;
62 
63  case "Section":
64  $sname = $node->getAttribute("Characteristic");
65  $stype = "section";
66  $template = 0;
67  break;
68 
69  case "MediaAlias":
70  $sname = $node->getAttribute("Class");
71  $stype = "media_cont";
72  $template = 0;
73  break;
74 
75  case "FileItem":
76  $sname = $node->getAttribute("Class");
77  $stype = "flist_li";
78  $template = 0;
79  break;
80 
81  case "Table":
82  $sname = $node->getAttribute("Template");
83  if ($sname == "") {
84  $sname = $node->getAttribute("Class");
85  $stype = "table";
86  $template = 0;
87  } else {
88  $stype = "table";
89  $template = 1;
90  }
91  break;
92 
93  case "TableData":
94  $sname = $node->getAttribute("Class");
95  $stype = "table_cell";
96  $template = 0;
97  break;
98 
99  case "Tabs":
100  $sname = $node->getAttribute("Template");
101  if ($sname != "") {
102  if ($node->getAttribute("Type") == "HorizontalAccordion") {
103  $stype = "haccordion";
104  }
105  if ($node->getAttribute("Type") == "VerticalAccordion") {
106  $stype = "vaccordion";
107  }
108  }
109  $template = 1;
110  break;
111 
112  case "List":
113  $sname = $node->getAttribute("Class");
114  if ($node->getAttribute("Type") == "Ordered") {
115  $stype = "list_o";
116  } else {
117  $stype = "list_u";
118  }
119  $template = 0;
120  break;
121  }
122  if ($sname != "" && $stype != "") {
123  $usages[$sname . ":" . $stype . ":" . $template] = array("sname" => $sname,
124  "stype" => $stype,
125  "template" => $template
126  );
127  }
128  }
129 
130  $this->deleteStyleUsages($page, $a_old_nr);
131 
132  foreach ($usages as $u) {
133  $id = $this->db->nextId('page_style_usage');
134  $this->db->manipulate("INSERT INTO page_style_usage " .
135  "(id, page_id, page_type, page_lang, page_nr, template, stype, sname) VALUES (" .
136  $this->db->quote($id, "integer") . "," .
137  $this->db->quote($page->getId(), "integer") . "," .
138  $this->db->quote($page->getParentType(), "text") . "," .
139  $this->db->quote($page->getLanguage(), "text") . "," .
140  $this->db->quote($a_old_nr, "integer") . "," .
141  $this->db->quote($u["template"], "integer") . "," .
142  $this->db->quote($u["stype"], "text") . "," .
143  $this->db->quote(\ilStr::subStr($u["sname"], 0, 30), "text") .
144  ")");
145  }
146  }
147 
151  public function deleteStyleUsages(
152  \ilPageObject $page,
153  int $a_old_nr = 0
154  ): void {
155  $and_old_nr = "";
156  if ($a_old_nr !== 0) {
157  $and_old_nr = " AND page_nr = " . $this->db->quote($a_old_nr, "integer");
158  }
159 
160  $this->db->manipulate(
161  "DELETE FROM page_style_usage WHERE " .
162  " page_id = " . $this->db->quote($page->getId(), "integer") .
163  " AND page_type = " . $this->db->quote($page->getParentType(), "text") .
164  " AND page_lang = " . $this->db->quote($page->getLanguage(), "text") .
165  $and_old_nr
166  );
167  }
168 }
ILIAS COPage Dom DomUtil $dom_util
deleteStyleUsages(\ilPageObject $page, int $a_old_nr=0)
Delete style usages.
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:21
$path
Definition: ltiservices.php:29
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
global $DIC
Definition: shib_login.php:26
saveStyleUsage(\ilPageObject $page, \DOMDocument $a_domdoc, int $a_old_nr=0)
Save all style class/template usages.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23