ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
19  protected $db;
20 
24  protected $error;
25 
31  public $tree;
32  public $id;
33  public $title;
34  public $parent;
35 
41  public function __construct($a_bmf_id = 0, $a_tree_id = 0)
42  {
43  global $DIC;
44 
45  $this->db = $DIC->database();
46  $this->error = $DIC["ilErr"];
47  // Initiate variables
48  if ($a_tree_id == 0) {
49  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
50  }
51 
52  $this->tree = new ilTree($a_tree_id);
53  $this->tree->setTableNames('bookmark_tree', 'bookmark_data');
54  $this->id = $a_bmf_id;
55 
56  if (!empty($this->id)) {
57  $this->read();
58  }
59  }
60 
64  public function read()
65  {
66  $ilDB = $this->db;
68 
69  $q = "SELECT * FROM bookmark_data WHERE obj_id = " .
70  $ilDB->quote($this->getId(), "integer");
71  $bmf_set = $ilDB->query($q);
72  if ($ilDB->numRows($bmf_set) == 0) {
73  $message = "ilBookmarkFolder::read(): Bookmark Folder with id " . $this->getId() . " not found!";
74  $ilErr->raiseError($message, $ilErr->WARNING);
75  } else {
76  $bmf = $ilDB->fetchAssoc($bmf_set);
77  $this->setTitle($bmf["title"]);
78  $this->setParent($this->tree->getParentId($this->getId()));
79  }
80  }
81 
85  public function delete()
86  {
87  $ilDB = $this->db;
88 
89  $q = "DELETE FROM bookmark_data WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
90  $ilDB->query($q);
91  }
92 
96  public function createNewBookmarkTree()
97  {
98  $ilDB = $this->db;
99 
100  /*
101  $q = "INSERT INTO bookmark_data (user_id, title, target, type) ".
102  "VALUES ('".$this->tree->getTreeId()."','dummy_folder','','bmf')";
103  $ilDB->query($q);*/
104  //$this->tree->addTree($this->tree->getTreeId(), $ilDB->getLastInsertId());
105  $this->tree->addTree($this->tree->getTreeId(), 1);
106  }
107 
113  public function create()
114  {
115  $ilDB = $this->db;
116 
117  $this->setId($ilDB->nextId("bookmark_data"));
118  $q = sprintf(
119  "INSERT INTO bookmark_data (obj_id, user_id, title, type) " .
120  "VALUES (%s,%s,%s,%s)",
121  $ilDB->quote($this->getId(), "integer"),
122  $ilDB->quote($GLOBALS['DIC']['ilUser']->getId(), "integer"),
123  $ilDB->quote($this->getTitle(), "text"),
124  $ilDB->quote('bmf', "text")
125  );
126 
127  $ilDB->manipulate($q);
128  $this->tree->insertNode($this->getId(), $this->getParent());
129  }
130 
134  public function update()
135  {
136  $ilDB = $this->db;
137 
138  $q = sprintf(
139  "UPDATE bookmark_data SET title=%s " .
140  "WHERE obj_id=%s",
141  $ilDB->quote($this->getTitle(), "text"),
142  $ilDB->quote($this->getId(), "integer")
143  );
144  $ilDB->manipulate($q);
145  }
146 
147 
148  public function getId()
149  {
150  return $this->id;
151  }
152 
153  public function setId($a_id)
154  {
155  $this->id = $a_id;
156  }
157 
158  public function getTitle()
159  {
160  return $this->title;
161  }
162 
163  public function setTitle($a_title)
164  {
165  $this->title = $a_title;
166  }
167 
168  public function getParent()
169  {
170  return $this->parent;
171  }
172 
173  public function setParent($a_parent_id)
174  {
175  $this->parent = $a_parent_id;
176  }
177 
181  public static function _lookupTitle($a_bmf_id)
182  {
183  global $DIC;
184 
185  $ilDB = $DIC->database();
186 
187  $q = "SELECT * FROM bookmark_data WHERE obj_id = " .
188  $ilDB->quote($a_bmf_id, "integer");
189  $bmf_set = $ilDB->query($q);
190  $bmf = $ilDB->fetchAssoc($bmf_set);
191 
192  return $bmf["title"];
193  }
194 
198  public static function getObjects($a_id)
199  {
200  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
201  $tree = new ilTree($a_tree_id);
202  $tree->setTableNames('bookmark_tree', 'bookmark_data');
203 
204  if (empty($a_id)) {
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  switch ($child["type"]) {
215  case "bmf":
216  $objects[] = $child;
217  break;
218 
219  case "bm":
220  $bookmarks[] = $child;
221  break;
222  }
223  }
224  foreach ($bookmarks as $key => $bookmark) {
225  $objects[] = $bookmark;
226  }
227  return $objects;
228  }
229 
233  public static function _getNumberOfObjects()
234  {
235  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
236  $tree = new ilTree($a_tree_id);
237  $tree->setTableNames('bookmark_tree', 'bookmark_data');
238 
239  $root_node = $tree->getNodeData($tree->getRootId());
240 
241  if ($root_node["lft"] != "") {
242  $bmf = $tree->getSubTree($root_node, false, "bmf");
243  $bm = $tree->getSubTree($root_node, false, "bm");
244  } else {
245  $bmf = array("dummy");
246  $bm = array();
247  }
248 
249  return array("folders" => (int) count($bmf) - 1, "bookmarks" => (int) count($bm));
250  }
251 
252 
256  public static function getObject($a_id)
257  {
258  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
259  $tree = new ilTree($a_tree_id);
260  $tree->setTableNames('bookmark_tree', 'bookmark_data');
261 
262  if (empty($a_id)) {
263  $a_id = $tree->getRootId();
264  }
265 
266  $object = $tree->getNodeData($a_id);
267  return $object;
268  }
269 
270  public static function isRootFolder($a_id)
271  {
272  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
273  $tree = new ilTree($a_tree_id);
274  $tree->setTableNames('bookmark_tree', 'bookmark_data');
275 
276  if ($a_id == $tree->getRootId()) {
277  return true;
278  } else {
279  return false;
280  }
281  }
282 
283  public function getRootFolder()
284  {
285  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
286  $tree = new ilTree($a_tree_id);
287  $tree->setTableNames('bookmark_tree', 'bookmark_data');
288 
289  return $tree->getRootId();
290  }
291 
292  public static function _getParentId($a_id)
293  {
294  $a_tree_id = $GLOBALS['DIC']['ilUser']->getId();
295  $tree = new ilTree($a_tree_id);
296  $tree->setTableNames('bookmark_tree', 'bookmark_data');
297  return $tree->getParentId($a_id);
298  }
299 }
global $ilErr
Definition: raiseError.php:16
static getObject($a_id)
static
global $DIC
Definition: saml.php:7
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
catch(Exception $e) $message
read()
read bookmark folder data from db
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
$key
Definition: croninfo.php:18