ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLMMenuEditor.php
Go to the documentation of this file.
1<?php
2
25{
26 protected string $target = "";
27 protected string $title = "";
28 protected int $entry_id = 0;
29 protected int $lm_id = 0;
30 protected ?int $link_ref_id;
31 protected string $link_type;
32 protected string $active = "n";
33 protected ilDBInterface $db;
34
35 public function __construct()
36 {
37 global $DIC;
38
39 $ilDB = $DIC->database();
40
41 $this->db = $ilDB;
42 $this->link_type = "extern";
43 $this->link_ref_id = null;
44 }
45
46 public function setObjId(int $a_obj_id): void
47 {
48 $this->lm_id = $a_obj_id;
49 }
50
51 public function getObjId(): int
52 {
53 return $this->lm_id;
54 }
55
56 public function setEntryId(int $a_id): void
57 {
58 $this->entry_id = $a_id;
59 }
60
61 public function getEntryId(): int
62 {
63 return $this->entry_id;
64 }
65
66 public function setLinkType(string $a_link_type): void
67 {
68 $this->link_type = $a_link_type;
69 }
70
71 public function getLinkType(): string
72 {
73 return $this->link_type;
74 }
75
76 public function setTitle(string $a_title): void
77 {
78 $this->title = $a_title;
79 }
80
81 public function getTitle(): string
82 {
83 return $this->title;
84 }
85
86 public function setTarget(string $a_target): void
87 {
88 $this->target = $a_target;
89 }
90
91 public function getTarget(): string
92 {
93 return $this->target;
94 }
95
96 public function setLinkRefId(int $a_link_ref_id): void
97 {
98 $this->link_ref_id = $a_link_ref_id;
99 }
100
101 public function getLinkRefId(): int
102 {
103 return $this->link_ref_id;
104 }
105
106 public function setActive(string $a_val): void
107 {
108 $this->active = $a_val;
109 }
110
111 public function getActive(): string
112 {
113 return $this->active;
114 }
115
116
117 public function create(): void
118 {
120
121 $id = $ilDB->nextId("lm_menu");
122 $q = "INSERT INTO lm_menu (id, lm_id,link_type,title,target,link_ref_id, active) " .
123 "VALUES " .
124 "(" .
125 $ilDB->quote($id, "integer") . "," .
126 $ilDB->quote($this->getObjId(), "integer") . "," .
127 $ilDB->quote($this->getLinkType(), "text") . "," .
128 $ilDB->quote($this->getTitle(), "text") . "," .
129 $ilDB->quote($this->getTarget(), "text") . "," .
130 $ilDB->quote($this->getLinkRefId(), "integer") . "," .
131 $ilDB->quote($this->getActive(), "text") .
132 ")";
133 $ilDB->manipulate($q);
134 $this->entry_id = $id;
135 }
136
137 public function getMenuEntries(
138 bool $a_only_active = false
139 ): array {
140 $ilDB = $this->db;
141
142 $and = "";
143
144 $entries = array();
145
146 if ($a_only_active === true) {
147 $and = " AND active = " . $ilDB->quote("y", "text");
148 }
149
150 $q = "SELECT * FROM lm_menu " .
151 "WHERE lm_id = " . $ilDB->quote($this->lm_id, "integer") .
152 $and;
153
154 $r = $ilDB->query($q);
155
156 while ($row = $ilDB->fetchObject($r)) {
157 $entries[] = array('id' => $row->id,
158 'title' => $row->title,
159 'link' => $row->target,
160 'type' => $row->link_type,
161 'ref_id' => $row->link_ref_id,
162 'active' => $row->active
163 );
164 }
165
166 return $entries;
167 }
168
169 public function delete(int $a_id): void
170 {
171 $ilDB = $this->db;
172
173 $q = "DELETE FROM lm_menu WHERE id = " .
174 $ilDB->quote($a_id, "integer");
175 $ilDB->manipulate($q);
176 }
177
178 public function update(): void
179 {
180 $ilDB = $this->db;
181
182 $q = "UPDATE lm_menu SET " .
183 " link_type = " . $ilDB->quote($this->getLinkType(), "text") . "," .
184 " title = " . $ilDB->quote($this->getTitle(), "text") . "," .
185 " target = " . $ilDB->quote($this->getTarget(), "text") . "," .
186 " link_ref_id = " . $ilDB->quote($this->getLinkRefId(), "integer") .
187 " WHERE id = " . $ilDB->quote($this->getEntryId(), "integer");
188 $ilDB->manipulate($q);
189 }
190
191 public function readEntry(int $a_id): void
192 {
193 $ilDB = $this->db;
194
195 if (!$a_id) {
196 return;
197 }
198
199 $q = "SELECT * FROM lm_menu WHERE id = " .
200 $ilDB->quote($a_id, "integer");
201 $r = $ilDB->query($q);
202
203 $row = $ilDB->fetchObject($r);
204
205 $this->setTitle($row->title);
206 $this->setTarget($row->target);
207 $this->setLinkType($row->link_type);
208 $this->setLinkRefId($row->link_ref_id);
209 $this->setEntryId($a_id);
210 $this->setActive($row->active);
211 }
212
216 public function updateActiveStatus(array $a_entries): void
217 {
218 $ilDB = $this->db;
219
220 // update active status
221 $q = "UPDATE lm_menu SET " .
222 "active = CASE " .
223 "WHEN " . $ilDB->in("id", $a_entries, false, "integer") . " " .
224 "THEN " . $ilDB->quote("y", "text") . " " .
225 "ELSE " . $ilDB->quote("n", "text") . " " .
226 "END " .
227 "WHERE lm_id = " . $ilDB->quote($this->lm_id, "integer");
228
229 $ilDB->manipulate($q);
230 }
231
232 public static function fixImportMenuItems(
233 int $new_lm_id,
234 array $ref_mapping
235 ): void {
236 global $DIC;
237
238 $db = $DIC->database();
239
240 $set = $db->queryF(
241 "SELECT * FROM lm_menu " .
242 " WHERE lm_id = %s ",
243 array("integer"),
244 array($new_lm_id)
245 );
246 while ($rec = $db->fetchAssoc($set)) {
247 // ... only check internal links
248 if ($rec["link_type"] == "intern") {
249 $link = explode("_", $rec["link_ref_id"]);
250 $ref_id = (int) $link[count($link) - 1];
251 $new_ref_id = $ref_mapping[$ref_id] ?? 0;
252 // if ref id has been imported, update it
253 if ($new_ref_id > 0) {
254 $new_target = str_replace((string) $ref_id, (string) $new_ref_id, $rec["target"]);
255 $db->update("lm_menu", array(
256 "link_ref_id" => array("integer", $new_ref_id),
257 "target" => array("text", $new_target)
258 ), array( // where
259 "id" => array("integer", $rec["id"])
260 ));
261 } else { // if not, delete the menu item
262 $db->manipulateF(
263 "DELETE FROM lm_menu WHERE " .
264 " id = %s",
265 array("integer"),
266 array($rec["id"])
267 );
268 }
269 }
270 }
271 }
272
273 public static function writeActive(
274 int $entry_id,
275 bool $active
276 ): void {
277 global $DIC;
278
279 $db = $DIC->database();
280
281 $db->update("lm_menu", array(
282 "active" => array("text", ($active ? "y" : "n"))
283 ), array( // where
284 "id" => array("", $entry_id)
285 ));
286 }
287}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setActive(string $a_val)
setObjId(int $a_obj_id)
getMenuEntries(bool $a_only_active=false)
setLinkType(string $a_link_type)
setTarget(string $a_target)
static fixImportMenuItems(int $new_lm_id, array $ref_mapping)
updateActiveStatus(array $a_entries)
update active status of all menu entries of lm
static writeActive(int $entry_id, bool $active)
setTitle(string $a_title)
setLinkRefId(int $a_link_ref_id)
Interface ilDBInterface.
update(string $table_name, array $values, array $where)
@description $where MUST contain existing columns only.
manipulateF(string $query, array $types, array $values)
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23