ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilBookmarkFolder.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
15{
21 var $tree;
22
28 var $ilias;
29
30 var $id;
31 var $title;
33
39 function ilBookmarkFolder($a_bmf_id = 0, $a_tree_id = 0)
40 {
41 global $ilias;
42
43 // Initiate variables
44 $this->ilias =& $ilias;
45 if ($a_tree_id == 0)
46 {
47 $a_tree_id = $_SESSION["AccountId"];
48 }
49
50 $this->tree = new ilTree($a_tree_id);
51 $this->tree->setTableNames('bookmark_tree','bookmark_data');
52 $this->id = $a_bmf_id;
53
54 if(!empty($this->id))
55 {
56 $this->read();
57 }
58 }
59
63 function read()
64 {
65 global $ilias, $ilDB;
66
67 $q = "SELECT * FROM bookmark_data WHERE obj_id = ".
68 $ilDB->quote($this->getId(), "integer");
69 $bmf_set = $ilDB->query($q);
70 if ($ilDB->numRows($bmf_set) == 0)
71 {
72 $message = "ilBookmarkFolder::read(): Bookmark Folder with id ".$this->getId()." not found!";
73 $ilias->raiseError($message,$ilias->error_obj->WARNING);
74 }
75 else
76 {
77 $bmf = $ilDB->fetchAssoc($bmf_set);
78 $this->setTitle($bmf["title"]);
79 $this->setParent($this->tree->getParentId($this->getId()));
80 }
81 }
82
86 function delete()
87 {
88 global $ilDB;
89
90 $q = "DELETE FROM bookmark_data WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
91 $ilDB->query($q);
92 }
93
98 {
99 global $ilDB;
100
101 /*
102 $q = "INSERT INTO bookmark_data (user_id, title, target, type) ".
103 "VALUES ('".$this->tree->getTreeId()."','dummy_folder','','bmf')";
104 $ilDB->query($q);*/
105 //$this->tree->addTree($this->tree->getTreeId(), $ilDB->getLastInsertId());
106 $this->tree->addTree($this->tree->getTreeId(), 1);
107 }
108
114 function create()
115 {
116 global $ilDB;
117
118 $this->setId($ilDB->nextId("bookmark_data"));
119 $q = sprintf(
120 "INSERT INTO bookmark_data (obj_id, user_id, title, type) ".
121 "VALUES (%s,%s,%s,%s)",
122 $ilDB->quote($this->getId(), "integer"),
123 $ilDB->quote($_SESSION["AccountId"], "integer"),
124 $ilDB->quote($this->getTitle(), "text"),
125 $ilDB->quote('bmf', "text")
126 );
127
128 $ilDB->manipulate($q);
129 $this->tree->insertNode($this->getId(), $this->getParent());
130 }
131
135 function update()
136 {
137 global $ilDB;
138
139 $q = sprintf(
140 "UPDATE bookmark_data SET title=%s ".
141 "WHERE obj_id=%s",
142 $ilDB->quote($this->getTitle(), "text"),
143 $ilDB->quote($this->getId(), "integer")
144 );
145 $ilDB->manipulate($q);
146 }
147
148
149 function getId()
150 {
151 return $this->id;
152 }
153
154 function setId($a_id)
155 {
156 $this->id = $a_id;
157 }
158
159 function getTitle()
160 {
161 return $this->title;
162 }
163
164 function setTitle($a_title)
165 {
166 $this->title = $a_title;
167 }
168
169 function getParent()
170 {
171 return $this->parent;
172 }
173
174 function setParent($a_parent_id)
175 {
176 $this->parent = $a_parent_id;
177 }
178
182 function _lookupTitle($a_bmf_id)
183 {
184 global $ilDB;
185
186 $q = "SELECT * FROM bookmark_data WHERE obj_id = ".
187 $ilDB->quote($a_bmf_id, "integer");
188 $bmf_set = $ilDB->query($q);
189 $bmf = $ilDB->fetchAssoc($bmf_set);
190
191 return $bmf["title"];
192 }
193
197 function getObjects($a_id)
198 {
199 $a_tree_id = $_SESSION["AccountId"];
200 $tree = new ilTree($a_tree_id);
201 $tree->setTableNames('bookmark_tree','bookmark_data');
202
203 if(empty($a_id))
204 {
205 $a_id = $tree->getRootId();
206 }
207
208 $childs = $tree->getChilds($a_id, "title");
209
210 $objects = array();
211 $bookmarks = array();
212
213 foreach ($childs as $key => $child)
214 {
215 switch ($child["type"])
216 {
217 case "bmf":
218 $objects[] = $child;
219 break;
220
221 case "bm":
222 $bookmarks[] = $child;
223 break;
224 }
225 }
226 foreach ($bookmarks as $key => $bookmark)
227 {
228 $objects[] = $bookmark;
229 }
230 return $objects;
231 }
232
237 {
238 $a_tree_id = $_SESSION["AccountId"];
239 $tree = new ilTree($a_tree_id);
240 $tree->setTableNames('bookmark_tree','bookmark_data');
241
242 $root_node = $tree->getNodeData($tree->getRootId());
243
244 if ($root_node["lft"] != "")
245 {
246 $bmf = $tree->getSubTree($root_node, false, "bmf");
247 $bm = $tree->getSubTree($root_node, false, "bm");
248 }
249 else
250 {
251 $bmf = array("dummy");
252 $bm = array();
253 }
254
255 return array("folders" => (int) count($bmf) - 1, "bookmarks" => (int) count($bm));
256 }
257
258
262 function getObject($a_id)
263 {
264 $a_tree_id = $_SESSION["AccountId"];
265 $tree = new ilTree($a_tree_id);
266 $tree->setTableNames('bookmark_tree','bookmark_data');
267
268 if(empty($a_id))
269 {
270 $a_id = $tree->getRootId();
271 }
272
273 $object = $tree->getNodeData($a_id);
274 return $object;
275 }
276
277 function isRootFolder($a_id)
278 {
279 $a_tree_id = $_SESSION["AccountId"];
280 $tree = new ilTree($a_tree_id);
281 $tree->setTableNames('bookmark_tree','bookmark_data');
282
283 if ($a_id == $tree->getRootId())
284 {
285 return true;
286 }
287 else
288 {
289 return false;
290 }
291 }
292
293 function getRootFolder()
294 {
295 $a_tree_id = $_SESSION["AccountId"];
296 $tree = new ilTree($a_tree_id);
297 $tree->setTableNames('bookmark_tree','bookmark_data');
298
299 return $tree->getRootId();
300 }
301
302 function _getParentId($a_id)
303 {
304 $a_tree_id = $_SESSION["AccountId"];
305 $tree = new ilTree($a_tree_id);
306 $tree->setTableNames('bookmark_tree','bookmark_data');
307 return $tree->getParentId($a_id);
308 }
309
310}
311?>
$_SESSION["AccountId"]
bookmark folder (note: this class handles personal bookmarks folders only)
_lookupTitle($a_bmf_id)
lookup bookmark folder title
create()
creates new bookmark folder in db
ilBookmarkFolder($a_bmf_id=0, $a_tree_id=0)
Constructor @access public.
read()
read bookmark folder data from db
createNewBookmarkTree()
create personal bookmark tree
_getNumberOfObjects()
Get number of folders and bookmarks for current user.
update()
Update bookmark folder item.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
redirection script todo: (a better solution should control the processing via a xml file)
global $ilDB