ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilBookmark.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
18 {
22  protected $db;
23 
27  protected $error;
28 
34  public $user_Id;
35 
41  public $tree;
42 
43  public $title;
44  public $description;
45  public $target;
46  public $id;
47  public $parent;
48 
54  public function __construct($a_bm_id = 0, $a_tree_id = 0)
55  {
56  global $DIC;
57 
58  $this->db = $DIC->database();
59  $this->error = $DIC["ilErr"];
60  // Initiate variables
61  if ($a_tree_id == 0) {
62  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
63  }
64 
65  $this->tree = new ilTree($a_tree_id);
66  $this->tree->setTableNames('bookmark_tree', 'bookmark_data');
67 
68  $this->id = $a_bm_id;
69 
70  if (!empty($this->id)) {
71  $this->read();
72  }
73  }
74 
75 
79  public function read()
80  {
81  $ilDB = $this->db;
83 
84  $q = "SELECT * FROM bookmark_data WHERE obj_id = " .
85  $ilDB->quote($this->getId(), "integer");
86  $bm_set = $ilDB->query($q);
87  if ($ilDB->numRows($bm_set) == 0) {
88  $message = "ilBookmark::read(): Bookmark with id " . $this->id . " not found!";
89  $ilErr->raiseError($message, $ilErr->WARNING);
90  } else {
91  $bm = $ilDB->fetchAssoc($bm_set);
92  $this->setTitle($bm["title"]);
93  $this->setDescription($bm["description"]);
94  $this->setTarget($bm["target"]);
95  $this->setParent($this->tree->getParentId($this->id));
96  }
97  }
98 
102  public function delete()
103  {
104  $ilDB = $this->db;
105 
106  if ($this->getId() != 1) {
107  $q = "DELETE FROM bookmark_data WHERE obj_id = " .
108  $ilDB->quote($this->getId(), "integer");
109  $ilDB->manipulate($q);
110  }
111  }
112 
113 
117  public function create()
118  {
119  $ilDB = $this->db;
120 
121  $this->setId($ilDB->nextId("bookmark_data"));
122  $q = sprintf(
123  "INSERT INTO bookmark_data (obj_id, user_id, title,description, target, type) " .
124  "VALUES (%s,%s,%s,%s,%s,%s)",
125  $ilDB->quote($this->getId(), "integer"),
126  $ilDB->quote($GLOBALS['DIC']['ilUser']->getId(), "integer"),
127  $ilDB->quote($this->getTitle(), "text"),
128  $ilDB->quote($this->getDescription(), "text"),
129  $ilDB->quote($this->getTarget(), "text"),
130  $ilDB->quote('bm', "text")
131  );
132 
133  $ilDB->manipulate($q);
134  $this->tree->insertNode($this->getId(), $this->getParent());
135  }
136 
140  public function update()
141  {
142  $ilDB = $this->db;
143 
144  $q = sprintf(
145  "UPDATE bookmark_data SET title=%s,description=%s,target=%s " .
146  "WHERE obj_id=%s",
147  $ilDB->quote($this->getTitle(), "text"),
148  $ilDB->quote($this->getDescription(), "text"),
149  $ilDB->quote($this->getTarget(), "text"),
150  $ilDB->quote($this->getId(), "integer")
151  );
152  $ilDB->manipulate($q);
153  }
154 
155 
156  /*
157  * set id
158  * @access public
159  * @param integer
160  */
161  public function setId($a_id)
162  {
163  $this->id = $a_id;
164  }
165 
166  public function getId()
167  {
168  return $this->id;
169  }
170 
176  public function setTitle($a_str)
177  {
178  $this->title = $a_str;
179  }
180 
181  public function getTitle()
182  {
183  return $this->title;
184  }
190  public function setDescription($a_str)
191  {
192  $this->description = $a_str;
193  }
194 
195  public function getDescription()
196  {
197  return $this->description;
198  }
199 
205  public function setTarget($a_target)
206  {
207  $this->target = $a_target;
208  }
209 
210 
211  public function getTarget()
212  {
213  return $this->target;
214  }
215 
216  public function setParent($a_parent_id)
217  {
218  $this->parent = $a_parent_id;
219  }
220 
221  public function getParent()
222  {
223  return $this->parent;
224  }
225 
230  public static function _getTypeOfId($a_id)
231  {
232  global $DIC;
233 
234  $ilDB = $DIC->database();
235 
236  $q = "SELECT * FROM bookmark_data WHERE obj_id = " .
237  $ilDB->quote($a_id, "integer");
238  $bm_set = $ilDB->query($q);
239  if ($ilDB->numRows($bm_set) == 0) {
240  return null;
241  } else {
242  $bm = $ilDB->fetchAssoc($bm_set);
243  return $bm["type"];
244  }
245  }
246 }
global $ilErr
Definition: raiseError.php:16
Class Bookmarks Bookmark management.
setTarget($a_target)
set target public
global $DIC
Definition: saml.php:7
read()
read bookmark folder data from db
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
setTitle($a_str)
set title public
update()
Update bookmark item.
catch(Exception $e) $message
setParent($a_parent_id)
create()
Create new bookmark item.
static _getTypeOfId($a_id)
get type of a given id
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
setDescription($a_str)
set description public
global $ilDB
__construct($a_bm_id=0, $a_tree_id=0)
Constructor public.