ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
MapDBRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Help\Map;
22 
24 {
25  protected \ilDBInterface $db;
26 
27  public function __construct(
28  \ilDBInterface $db
29  ) {
30  $this->db = $db;
31  }
32 
33  public function saveScreenIdsForChapter(
34  int $a_chap,
35  array $a_ids
36  ): void {
37  $this->removeScreenIdsOfChapter($a_chap);
38  foreach ($a_ids as $id) {
39  $id = trim($id);
40  $id = explode("/", $id);
41  if ($id[0] != "") {
42  if (($id[1] ?? "") == "") {
43  $id[1] = "-";
44  }
45  $id2 = explode("#", ($id[2] ?? ""));
46  if (($id2[0] ?? "") == "") {
47  $id2[0] = "-";
48  }
49  if (($id2[1] ?? "") == "") {
50  $id2[1] = "-";
51  }
52  $this->db->replace(
53  "help_map",
54  array("chap" => array("integer", $a_chap),
55  "component" => array("text", $id[0]),
56  "screen_id" => array("text", $id[1]),
57  "screen_sub_id" => array("text", $id2[0]),
58  "perm" => array("text", $id2[1]),
59  "module_id" => array("integer", 0)
60  ),
61  array()
62  );
63  }
64  }
65  }
66 
67  public function saveMappingEntry(
68  int $a_chap,
69  string $a_comp,
70  string $a_screen_id,
71  string $a_screen_sub_id,
72  string $a_perm,
73  int $a_module_id = 0
74  ): void {
75  $this->db->replace(
76  "help_map",
77  array("chap" => array("integer", $a_chap),
78  "component" => array("text", $a_comp),
79  "screen_id" => array("text", $a_screen_id),
80  "screen_sub_id" => array("text", $a_screen_sub_id),
81  "perm" => array("text", $a_perm),
82  "module_id" => array("integer", $a_module_id)
83  ),
84  array()
85  );
86  }
87 
88  public function removeScreenIdsOfChapter(
89  int $a_chap,
90  int $a_module_id = 0
91  ): void {
92  $this->db->manipulate(
93  "DELETE FROM help_map WHERE " .
94  " chap = " . $this->db->quote($a_chap, "integer") .
95  " AND module_id = " . $this->db->quote($a_module_id, "integer")
96  );
97  }
98 
99  public function getScreenIdsOfChapter(
100  int $a_chap,
101  int $a_module_id = 0
102  ): array {
103  $set = $this->db->query(
104  "SELECT * FROM help_map " .
105  " WHERE chap = " . $this->db->quote($a_chap, "integer") .
106  " AND module_id = " . $this->db->quote($a_module_id, "integer") .
107  " ORDER BY component, screen_id, screen_sub_id"
108  );
109  $screen_ids = array();
110  while ($rec = $this->db->fetchAssoc($set)) {
111  if ($rec["screen_id"] == "-") {
112  $rec["screen_id"] = "";
113  }
114  if ($rec["screen_sub_id"] == "-") {
115  $rec["screen_sub_id"] = "";
116  }
117  $id = $rec["component"] . "/" . $rec["screen_id"] . "/" . $rec["screen_sub_id"];
118  if ($rec["perm"] != "" && $rec["perm"] != "-") {
119  $id .= "#" . $rec["perm"];
120  }
121  $screen_ids[] = $id;
122  }
123  return $screen_ids;
124  }
125 
126  public function getChaptersForScreenId(
127  string $a_screen_id,
128  array $module_ids
129  ): \Generator {
130  $sc_id = explode("/", $a_screen_id);
131  $chaps = array();
132  foreach ($module_ids as $module_id) {
133  if (($sc_id[0] ?? "") != "") {
134  if (($sc_id[1] ?? "") == "") {
135  $sc_id[1] = "-";
136  }
137  if (($sc_id[2] ?? "") == "") {
138  $sc_id[2] = "-";
139  }
140  $set = $this->db->query(
141  "SELECT chap, perm FROM help_map JOIN lm_tree" .
142  " ON (help_map.chap = lm_tree.child) " .
143  " WHERE (component = " . $this->db->quote($sc_id[0], "text") .
144  " OR component = " . $this->db->quote("*", "text") . ")" .
145  " AND screen_id = " . $this->db->quote($sc_id[1], "text") .
146  " AND screen_sub_id = " . $this->db->quote($sc_id[2], "text") .
147  " AND module_id = " . $this->db->quote($module_id, "integer") .
148  " ORDER BY lm_tree.lft"
149  );
150  while ($rec = $this->db->fetchAssoc($set)) {
151  yield $rec;
152  }
153  }
154  }
155  }
156 
157  public function deleteEntriesOfModule(
158  int $a_id
159  ): void {
160  $this->db->manipulate("DELETE FROM help_map WHERE " .
161  " module_id = " . $this->db->quote($a_id, "integer"));
162  }
163 
164 }
removeScreenIdsOfChapter(int $a_chap, int $a_module_id=0)
saveScreenIdsForChapter(int $a_chap, array $a_ids)
getChaptersForScreenId(string $a_screen_id, array $module_ids)
saveMappingEntry(int $a_chap, string $a_comp, string $a_screen_id, string $a_screen_sub_id, string $a_perm, int $a_module_id=0)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(\ilDBInterface $db)
getScreenIdsOfChapter(int $a_chap, int $a_module_id=0)