ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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;
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 {
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 {
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 {
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 {
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}
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
Class Bookmarks Bookmark management.
setTarget($a_target)
set target @access public
read()
read bookmark folder data from db
__construct($a_bm_id=0, $a_tree_id=0)
Constructor @access public.
update()
Update bookmark item.
setParent($a_parent_id)
setTitle($a_str)
set title @access public
static _getTypeOfId($a_id)
get type of a given id
create()
Create new bookmark item.
setDescription($a_str)
set description @access public
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
catch(Exception $e) $message
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
$ilErr
Definition: raiseError.php:18
global $DIC
Definition: saml.php:7
global $ilDB