ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBookmark.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
34 {
40  var $user_Id;
41 
47  var $ilias;
48  var $tree;
49 
50  var $title;
52  var $target;
53  var $id;
54  var $parent;
55 
61  function ilBookmark($a_bm_id = 0, $a_tree_id = 0)
62  {
63  global $ilias;
64 
65  // Initiate variables
66  $this->ilias =& $ilias;
67  if ($a_tree_id == 0)
68  {
69  $a_tree_id = $_SESSION["AccountId"];
70  }
71 
72  $this->tree = new ilTree($a_tree_id);
73  $this->tree->setTableNames('bookmark_tree','bookmark_data');
74 
75  $this->id = $a_bm_id;
76 
77  if(!empty($this->id))
78  {
79  $this->read();
80  }
81 
82  }
83 
84 
88  function read()
89  {
90  global $ilias;
91 
92  $q = "SELECT * FROM bookmark_data WHERE obj_id = ".$this->ilias->db->quote($this->getId());
93  $bm_set = $this->ilias->db->query($q);
94  if ($bm_set->numRows() == 0)
95  {
96  $message = "ilBookmark::read(): Bookmark with id ".$this->id." not found!";
97  $ilias->raiseError($message,$ilias->error_obj->WARNING);
98  }
99  else
100  {
101  $bm = $bm_set->fetchRow(DB_FETCHMODE_ASSOC);
102  $this->setTitle($bm["title"]);
103  $this->setDescription($bm["description"]);
104  $this->setTarget($bm["target"]);
105  $this->setParent($this->tree->getParentId($this->id));
106  }
107  }
108 
112  function delete()
113  {
114  $q = "DELETE FROM bookmark_data WHERE obj_id = ".$this->ilias->db->quote($this->getId());
115  $this->ilias->db->query($q);
116  }
117 
118 
119  function create()
120  {
121  $q = sprintf(
122  "INSERT INTO bookmark_data (user_id, title,description, target, type) ".
123  "VALUES (%s,%s,%s,%s,%s)",
124  $this->ilias->db->quote($_SESSION["AccountId"]),
125  $this->ilias->db->quote($this->getTitle()),
126  $this->ilias->db->quote($this->getDescription()),
127  $this->ilias->db->quote($this->getTarget()),
128  $this->ilias->db->quote('bm')
129  );
130 
131  $this->ilias->db->query($q);
132  $this->setId($this->ilias->db->getLastInsertId());
133  $this->tree->insertNode($this->getId(), $this->getParent());
134  }
135 
136  function update()
137  {
138  $q = sprintf(
139  "UPDATE bookmark_data SET title=%s,description=%s,target=%s ".
140  "WHERE obj_id=%s",
141  $this->ilias->db->quote($this->getTitle()),
142  $this->ilias->db->quote($this->getDescription()),
143  $this->ilias->db->quote($this->getTarget()),
144  $this->ilias->db->quote($this->getId())
145  );
146  $this->ilias->db->query($q);
147  }
148 
149 
150  /*
151  * set id
152  * @access public
153  * @param integer
154  */
155  function setId($a_id)
156  {
157  $this->id = $a_id;
158  }
159 
160  function getId()
161  {
162  return $this->id;
163  }
164 
170  function setTitle($a_str)
171  {
172  $this->title = $a_str;
173  }
174 
175  function getTitle()
176  {
177  return $this->title;
178  }
184  function setDescription($a_str)
185  {
186  $this->description = $a_str;
187  }
188 
189  function getDescription()
190  {
191  return $this->description;
192  }
193 
199  function setTarget($a_target)
200  {
201  $this->target = $a_target;
202  }
203 
204 
205  function getTarget()
206  {
207  return $this->target;
208  }
209 
210  function setParent($a_parent_id)
211  {
212  $this->parent = $a_parent_id;
213  }
214 
215  function getParent()
216  {
217  return $this->parent;
218  }
219 }
220 ?>