ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLMMenuEditor.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
33{
34 function __construct()
35 {
36 global $ilDB;
37
38 $this->db = $ilDB;
39 $this->link_type = "extern";
40 $this->link_ref_id = null;
41 }
42
43 function setObjId($a_obj_id)
44 {
45 $this->lm_id = $a_obj_id;
46 }
47
48 function getObjId()
49 {
50 return $this->lm_id;
51 }
52
53 function setEntryId($a_id)
54 {
55 $this->entry_id = $a_id;
56 }
57
58 function getEntryId()
59 {
60 return $this->entry_id;
61 }
62
63 function setLinkType($a_link_type)
64 {
65 $this->link_type = $a_link_type;
66 }
67
68 function getLinkType()
69 {
70 return $this->link_type;
71 }
72
73 function setTitle($a_title)
74 {
75 $this->title = $a_title;
76 }
77
78 function getTitle()
79 {
80 return $this->title;
81 }
82
83 function setTarget($a_target)
84 {
85 $this->target = $a_target;
86 }
87
88 function getTarget()
89 {
90 return $this->target;
91 }
92
93 function setLinkRefId($a_link_ref_id)
94 {
95 $this->link_ref_id = $a_link_ref_id;
96 }
97
98 function getLinkRefId()
99 {
100 return $this->link_ref_id;
101 }
102
103 function create()
104 {
105 global $ilDB;
106
107 $id = $ilDB->nextId("lm_menu");
108 $q = "INSERT INTO lm_menu (id, lm_id,link_type,title,target,link_ref_id) ".
109 "VALUES ".
110 "(".
111 $ilDB->quote($id, "integer").",".
112 $ilDB->quote((int) $this->getObjId(), "integer").",".
113 $ilDB->quote($this->getLinkType(), "text").",".
114 $ilDB->quote($this->getTitle(), "text").",".
115 $ilDB->quote($this->getTarget(), "text").",".
116 $ilDB->quote((int) $this->getLinkRefId(), "integer").")";
117 $r = $ilDB->manipulate($q);
118
119 $this->entry_id = $id;
120
121 return true;
122 }
123
124 function getMenuEntries($a_only_active = false)
125 {
126 global $ilDB;
127
128 $entries = array();
129
130 if ($a_only_active === true)
131 {
132 $and = " AND active = ".$ilDB->quote("y", "text");
133 }
134
135 $q = "SELECT * FROM lm_menu ".
136 "WHERE lm_id = ".$ilDB->quote($this->lm_id, "integer").
137 $and;
138
139 $r = $ilDB->query($q);
140
141 while($row = $ilDB->fetchObject($r))
142 {
143 $entries[] = array('id' => $row->id,
144 'title' => $row->title,
145 'link' => $row->target,
146 'type' => $row->link_type,
147 'ref_id' => $row->link_ref_id,
148 'active' => $row->active
149 );
150 }
151
152 return $entries;
153 }
154
159 function delete($a_id)
160 {
161 global $ilDB;
162
163 if (!$a_id)
164 {
165 return false;
166 }
167
168 $q = "DELETE FROM lm_menu WHERE id = ".
169 $ilDB->quote($a_id, "integer");
170 $ilDB->manipulate($q);
171
172 return true;
173 }
174
179 function update()
180 {
181 global $ilDB;
182
183 $q = "UPDATE lm_menu SET ".
184 " link_type = ".$ilDB->quote($this->getLinkType(), "text").",".
185 " title = ".$ilDB->quote($this->getTitle(), "text").",".
186 " target = ".$ilDB->quote($this->getTarget(), "text").",".
187 " link_ref_id = ".$ilDB->quote((int) $this->getLinkRefId(), "integer").
188 " WHERE id = ".$ilDB->quote($this->getEntryId(), "integer");
189 $r = $ilDB->manipulate($q);
190
191 return true;
192 }
193
194 function readEntry($a_id)
195 {
196 global $ilDB;
197
198 if (!$a_id)
199 {
200 return false;
201 }
202
203 $q = "SELECT * FROM lm_menu WHERE id = ".
204 $ilDB->quote($a_id, "integer");
205 $r = $ilDB->query($q);
206
207 $row = $ilDB->fetchObject($r);
208
209 $this->setTitle($row->title);
210 $this->setTarget($row->target);
211 $this->setLinkType($row->link_type);
212 $this->setLinkRefId($row->link_ref_id);
213 $this->setEntryid($a_id);
214 }
215
221 function updateActiveStatus($a_entries)
222 {
223 global $ilDB;
224
225 if (!is_array($a_entries))
226 {
227 $q = "UPDATE lm_menu SET active = ".$ilDB->quote("n", "text").
228 " WHERE lm_id = ".$ilDB->quote($this->lm_id, "integer");
229 }
230
231 // update active status
232 $q = "UPDATE lm_menu SET " .
233 "active = CASE " .
234 "WHEN ".$ilDB->in("id", $a_entries, false, "integer")." ".
235 "THEN ".$ilDB->quote("y", "text")." ".
236 "ELSE ".$ilDB->quote("n", "text")." ".
237 "END " .
238 "WHERE lm_id = ".$ilDB->quote($this->lm_id, "integer");
239
240 $ilDB->manipulate($q);
241 }
242
249 static public function writeActive($entry_id, $active)
250 {
251 global $DIC;
252
253 $db = $DIC->database();
254
255 $db->update("lm_menu", array(
256 "active" => array("text", ($active ? "y" : "n"))
257 ), array( // where
258 "id" => array("", $entry_id)
259 ));
260
261
262 }
263
264}
265?>
An exception for terminatinating execution or to throw for unit testing.
class for editing lm menu
updateActiveStatus($a_entries)
update active status of all menu entries of lm
setLinkType($a_link_type)
getMenuEntries($a_only_active=false)
static writeActive($entry_id, $active)
Write status for entry id.
update()
update menu entry
setLinkRefId($a_link_ref_id)
$r
Definition: example_031.php:79
global $ilDB
global $DIC