ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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;
32  var $parent;
33 
39  function __construct($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 = $GLOBALS['DIC']['ilUser']->getId();
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($GLOBALS['DIC']['ilUser']->getId(), "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  static 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  static function getObjects($a_id)
198  {
199  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
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 
236  static function _getNumberOfObjects()
237  {
238  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
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  static function getObject($a_id)
263  {
264  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
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  static function isRootFolder($a_id)
278  {
279  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
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 = $GLOBALS['DIC']['ilUser']->getId();
296  $tree = new ilTree($a_tree_id);
297  $tree->setTableNames('bookmark_tree','bookmark_data');
298 
299  return $tree->getRootId();
300  }
301 
302  static function _getParentId($a_id)
303  {
304  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
305  $tree = new ilTree($a_tree_id);
306  $tree->setTableNames('bookmark_tree','bookmark_data');
307  return $tree->getParentId($a_id);
308  }
309 
310 }
311 ?>
static getObject($a_id)
static
static _getNumberOfObjects()
Get number of folders and bookmarks for current user.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
__construct($a_bmf_id=0, $a_tree_id=0)
Constructor public.
static _lookupTitle($a_bmf_id)
lookup bookmark folder title
read()
read bookmark folder data from db
redirection script todo: (a better solution should control the processing via a xml file) ...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create styles array
The data for the language used.
bookmark folder (note: this class handles personal bookmarks folders only)
createNewBookmarkTree()
create personal bookmark tree
global $ilDB
static getObjects($a_id)
static
update()
Update bookmark folder item.
create()
creates new bookmark folder in db