ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 ilLMMenuEditor()
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  return true;
120  }
121 
122  function getMenuEntries($a_only_active = false)
123  {
124  global $ilDB;
125 
126  $entries = array();
127 
128  if ($a_only_active === true)
129  {
130  $and = " AND active = ".$ilDB->quote("y", "text");
131  }
132 
133  $q = "SELECT * FROM lm_menu ".
134  "WHERE lm_id = ".$ilDB->quote($this->lm_id, "integer").
135  $and;
136 
137  $r = $ilDB->query($q);
138 
139  while($row = $ilDB->fetchObject($r))
140  {
141  $entries[] = array('id' => $row->id,
142  'title' => $row->title,
143  'link' => $row->target,
144  'type' => $row->link_type,
145  'ref_id' => $row->link_ref_id,
146  'active' => $row->active
147  );
148  }
149 
150  return $entries;
151  }
152 
157  function delete($a_id)
158  {
159  global $ilDB;
160 
161  if (!$a_id)
162  {
163  return false;
164  }
165 
166  $q = "DELETE FROM lm_menu WHERE id = ".
167  $ilDB->quote($a_id, "integer");
168  $ilDB->manipulate($q);
169 
170  return true;
171  }
172 
177  function update()
178  {
179  global $ilDB;
180 
181  $q = "UPDATE lm_menu SET ".
182  " link_type = ".$ilDB->quote($this->getLinkType(), "text").",".
183  " title = ".$ilDB->quote($this->getTitle(), "text").",".
184  " target = ".$ilDB->quote($this->getTarget(), "text").",".
185  " link_ref_id = ".$ilDB->quote((int) $this->getLinkRefId(), "integer").
186  " WHERE id = ".$ilDB->quote($this->getEntryId(), "integer");
187  $r = $ilDB->manipulate($q);
188 
189  return true;
190  }
191 
192  function readEntry($a_id)
193  {
194  global $ilDB;
195 
196  if (!$a_id)
197  {
198  return false;
199  }
200 
201  $q = "SELECT * FROM lm_menu WHERE id = ".
202  $ilDB->quote($a_id, "integer");
203  $r = $ilDB->query($q);
204 
205  $row = $ilDB->fetchObject($r);
206 
207  $this->setTitle($row->title);
208  $this->setTarget($row->target);
209  $this->setLinkType($row->link_type);
210  $this->setLinkRefId($row->link_ref_id);
211  $this->setEntryid($a_id);
212  }
213 
219  function updateActiveStatus($a_entries)
220  {
221  global $ilDB;
222 
223  if (!is_array($a_entries))
224  {
225  $q = "UPDATE lm_menu SET active = ".$ilDB->quote("n", "text").
226  " WHERE lm_id = ".$ilDB->quote($this->lm_id, "integer");
227  }
228 
229  // update active status
230  $q = "UPDATE lm_menu SET " .
231  "active = CASE " .
232  "WHEN ".$ilDB->in("id", $a_entries, false, "integer")." ".
233  "THEN ".$ilDB->quote("y", "text")." ".
234  "ELSE ".$ilDB->quote("n", "text")." ".
235  "END " .
236  "WHERE lm_id = ".$ilDB->quote($this->lm_id, "integer");
237 
238  $ilDB->manipulate($q);
239  }
240 
241 }
242 ?>