ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBookmarkFolder.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
40  var $tree;
41 
47  var $ilias;
48 
49  var $id;
50  var $title;
51  var $parent;
52 
58  function ilBookmarkFolder($a_bmf_id = 0, $a_tree_id = 0)
59  {
60  global $ilias;
61 
62  // Initiate variables
63  $this->ilias =& $ilias;
64  if ($a_tree_id == 0)
65  {
66  $a_tree_id = $_SESSION["AccountId"];
67  }
68 
69  $this->tree = new ilTree($a_tree_id);
70  $this->tree->setTableNames('bookmark_tree','bookmark_data');
71  $this->id = $a_bmf_id;
72 
73  if(!empty($this->id))
74  {
75  $this->read();
76  }
77  }
78 
82  function read()
83  {
84  global $ilias;
85 
86  $q = "SELECT * FROM bookmark_data WHERE obj_id = ".$this->ilias->db->quote($this->getId());
87  $bmf_set = $this->ilias->db->query($q);
88  if ($bmf_set->numRows() == 0)
89  {
90  $message = "ilBookmarkFolder::read(): Bookmark Folder with id ".$this->getId()." not found!";
91  $ilias->raiseError($message,$ilias->error_obj->WARNING);
92  }
93  else
94  {
95  $bmf = $bmf_set->fetchRow(DB_FETCHMODE_ASSOC);
96  $this->setTitle($bmf["title"]);
97  $this->setParent($this->tree->getParentId($this->getId()));
98  }
99  }
100 
104  function delete()
105  {
106  $q = "DELETE FROM bookmark_data WHERE obj_id = ".$this->ilias->db->quote($this->getId());
107  $this->ilias->db->query($q);
108  }
109 
114  {
115  global $ilDB;
116 
117  /*
118  $q = "INSERT INTO bookmark_data (user_id, title, target, type) ".
119  "VALUES ('".$this->tree->getTreeId()."','dummy_folder','','bmf')";
120  $ilDB->query($q);*/
121  //$this->tree->addTree($this->tree->getTreeId(), $ilDB->getLastInsertId());
122  $this->tree->addTree($this->tree->getTreeId(), 1);
123  }
124 
130  function create()
131  {
132  $q = sprintf(
133  "INSERT INTO bookmark_data (user_id, title, type) ".
134  "VALUES (%s,%s,%s)",
135  $this->ilias->db->quote($_SESSION["AccountId"]),
136  $this->ilias->db->quote($this->getTitle()),
137  $this->ilias->db->quote('bmf')
138  );
139 
140  $this->ilias->db->query($q);
141  $this->setId($this->ilias->db->getLastInsertId());
142  $this->tree->insertNode($this->getId(), $this->getParent());
143  }
144  function update()
145  {
146  $q = sprintf(
147  "UPDATE bookmark_data SET title=%s ".
148  "WHERE obj_id=%s",
149  $this->ilias->db->quote($this->getTitle()),
150  $this->ilias->db->quote($this->getId())
151  );
152  $this->ilias->db->query($q);
153  }
154 
155 
156  function getId()
157  {
158  return $this->id;
159  }
160 
161  function setId($a_id)
162  {
163  $this->id = $a_id;
164  }
165 
166  function getTitle()
167  {
168  return $this->title;
169  }
170 
171  function setTitle($a_title)
172  {
173  $this->title = $a_title;
174  }
175 
176  function getParent()
177  {
178  return $this->parent;
179  }
180 
181  function setParent($a_parent_id)
182  {
183  $this->parent = $a_parent_id;
184  }
185 
189  function _lookupTitle($a_bmf_id)
190  {
191  global $ilDB;
192 
193  $q = "SELECT * FROM bookmark_data WHERE obj_id = ".$ilDB->quote($a_bmf_id);
194  $bmf_set = $ilDB->query($q);
195  $bmf = $bmf_set->fetchRow(DB_FETCHMODE_ASSOC);
196 
197  return $bmf["title"];
198  }
199 
203  function getObjects($a_id)
204  {
205  $a_tree_id = $_SESSION["AccountId"];
206  $tree = new ilTree($a_tree_id);
207  $tree->setTableNames('bookmark_tree','bookmark_data');
208 
209  if(empty($a_id))
210  {
211  $a_id = $tree->getRootId();
212  }
213 
214  $childs = $tree->getChilds($a_id, "title");
215 
216  $objects = array();
217  $bookmarks = array();
218 
219  foreach ($childs as $key => $child)
220  {
221  switch ($child["type"])
222  {
223  case "bmf":
224  $objects[] = $child;
225  break;
226 
227  case "bm":
228  $bookmarks[] = $child;
229  break;
230  }
231  }
232  foreach ($bookmarks as $key => $bookmark)
233  {
234  $objects[] = $bookmark;
235  }
236  return $objects;
237  }
238 
243  {
244  $a_tree_id = $_SESSION["AccountId"];
245  $tree = new ilTree($a_tree_id);
246  $tree->setTableNames('bookmark_tree','bookmark_data');
247 
248  $root_node = $tree->getNodeData($tree->getRootId());
249 
250  if ($root_node["lft"] != "")
251  {
252  $bmf = $tree->getSubTree($root_node, false, "bmf");
253  $bm = $tree->getSubTree($root_node, false, "bm");
254  }
255  else
256  {
257  $bmf = array("dummy");
258  $bm = array();
259  }
260 
261  return array("folders" => (int) count($bmf) - 1, "bookmarks" => (int) count($bm));
262  }
263 
264 
268  function getObject($a_id)
269  {
270  $a_tree_id = $_SESSION["AccountId"];
271  $tree = new ilTree($a_tree_id);
272  $tree->setTableNames('bookmark_tree','bookmark_data');
273 
274  if(empty($a_id))
275  {
276  $a_id = $tree->getRootId();
277  }
278 
279  $object = $tree->getNodeData($a_id);
280  return $object;
281  }
282 
283  function isRootFolder($a_id)
284  {
285  $a_tree_id = $_SESSION["AccountId"];
286  $tree = new ilTree($a_tree_id);
287  $tree->setTableNames('bookmark_tree','bookmark_data');
288 
289  if ($a_id == $tree->getRootId())
290  {
291  return true;
292  }
293  else
294  {
295  return false;
296  }
297  }
298 
299  function getRootFolder()
300  {
301  $a_tree_id = $_SESSION["AccountId"];
302  $tree = new ilTree($a_tree_id);
303  $tree->setTableNames('bookmark_tree','bookmark_data');
304 
305  return $tree->getRootId();
306  }
307 
308  function _getParentId($a_id)
309  {
310  $a_tree_id = $_SESSION["AccountId"];
311  $tree = new ilTree($a_tree_id);
312  $tree->setTableNames('bookmark_tree','bookmark_data');
313  return $tree->getParentId($a_id);
314  }
315 
316 }
317 ?>