• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/PersonalDesktop/classes/class.ilBookmarkFolder.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00033 class ilBookmarkFolder
00034 {
00040         var $tree;
00041 
00047         var $ilias;
00048 
00049         var $id;
00050         var $title;
00051         var $parent;
00052 
00058         function ilBookmarkFolder($a_bmf_id = 0, $a_tree_id = 0)
00059         {
00060                 global $ilias;
00061 
00062                 // Initiate variables
00063                 $this->ilias =& $ilias;
00064                 if ($a_tree_id == 0)
00065                 {
00066                         $a_tree_id = $_SESSION["AccountId"];
00067                 }
00068 
00069                 $this->tree = new ilTree($a_tree_id);
00070                 $this->tree->setTableNames('bookmark_tree','bookmark_data');
00071                 $this->id = $a_bmf_id;
00072 
00073                 if(!empty($this->id))
00074                 {
00075                         $this->read();
00076                 }
00077         }
00078 
00082         function read()
00083         {
00084                 global $ilias;
00085 
00086                 $q = "SELECT * FROM bookmark_data WHERE obj_id = ".$this->ilias->db->quote($this->getId());
00087                 $bmf_set = $this->ilias->db->query($q);
00088                 if ($bmf_set->numRows() == 0)
00089                 {
00090                         $message = "ilBookmarkFolder::read(): Bookmark Folder with id ".$this->getId()." not found!";
00091                         $ilias->raiseError($message,$ilias->error_obj->WARNING);
00092                 }
00093                 else
00094                 {
00095                         $bmf = $bmf_set->fetchRow(DB_FETCHMODE_ASSOC);
00096                         $this->setTitle($bmf["title"]);
00097                         $this->setParent($this->tree->getParentId($this->getId()));
00098                 }
00099         }
00100 
00104         function delete()
00105         {
00106                 $q = "DELETE FROM bookmark_data WHERE obj_id = ".$this->ilias->db->quote($this->getId());
00107                 $this->ilias->db->query($q);
00108         }
00109 
00113         function createNewBookmarkTree()
00114         {
00115                 global $ilDB;
00116 
00117                 /*
00118                 $q = "INSERT INTO bookmark_data (user_id, title, target, type) ".
00119                         "VALUES ('".$this->tree->getTreeId()."','dummy_folder','','bmf')";
00120                 $ilDB->query($q);*/
00121                 //$this->tree->addTree($this->tree->getTreeId(), $ilDB->getLastInsertId());
00122                 $this->tree->addTree($this->tree->getTreeId(), 1);
00123         }
00124 
00130         function create()
00131         {
00132                 $q = sprintf(
00133                                 "INSERT INTO bookmark_data (user_id, title, type) ".
00134                                 "VALUES (%s,%s,%s)",
00135                                 $this->ilias->db->quote($_SESSION["AccountId"]),
00136                                 $this->ilias->db->quote($this->getTitle()),
00137                                 $this->ilias->db->quote('bmf')
00138                         );
00139 
00140                 $this->ilias->db->query($q);
00141                 $this->setId($this->ilias->db->getLastInsertId());
00142                 $this->tree->insertNode($this->getId(), $this->getParent());
00143         }
00144         function update()
00145         {
00146                 $q = sprintf(
00147                                 "UPDATE bookmark_data SET title=%s ".
00148                                 "WHERE obj_id=%s",
00149                                 $this->ilias->db->quote($this->getTitle()),
00150                                 $this->ilias->db->quote($this->getId())
00151                         );
00152                 $this->ilias->db->query($q);
00153         }
00154 
00155 
00156         function getId()
00157         {
00158                 return $this->id;
00159         }
00160 
00161         function setId($a_id)
00162         {
00163                 $this->id = $a_id;
00164         }
00165 
00166         function getTitle()
00167         {
00168                 return $this->title;
00169         }
00170 
00171         function setTitle($a_title)
00172         {
00173                 $this->title = $a_title;
00174         }
00175 
00176         function getParent()
00177         {
00178                 return $this->parent;
00179         }
00180 
00181         function setParent($a_parent_id)
00182         {
00183                 $this->parent = $a_parent_id;
00184         }
00185 
00189         function _lookupTitle($a_bmf_id)
00190         {
00191                 global $ilDB;
00192 
00193                 $q = "SELECT * FROM bookmark_data WHERE obj_id = ".$ilDB->quote($a_bmf_id);
00194                 $bmf_set = $ilDB->query($q);
00195                 $bmf = $bmf_set->fetchRow(DB_FETCHMODE_ASSOC);
00196 
00197                 return $bmf["title"];
00198         }
00199 
00203         function getObjects($a_id)
00204         {
00205                 $a_tree_id = $_SESSION["AccountId"];
00206                 $tree = new ilTree($a_tree_id);
00207                 $tree->setTableNames('bookmark_tree','bookmark_data');
00208 
00209                 if(empty($a_id))
00210                 {
00211                         $a_id = $tree->getRootId();
00212                 }
00213 
00214                 $childs = $tree->getChilds($a_id, "title");
00215 
00216                 $objects = array();
00217                 $bookmarks = array();
00218 
00219                 foreach ($childs as $key => $child)
00220                 {
00221                         switch ($child["type"])
00222                         {
00223                                 case "bmf":
00224                                         $objects[] = $child;
00225                                         break;
00226 
00227                                 case "bm":
00228                                         $bookmarks[] = $child;
00229                                         break;
00230                         }
00231                 }
00232                 foreach ($bookmarks as $key => $bookmark)
00233                 {
00234                         $objects[] = $bookmark;
00235                 }
00236                 return $objects;
00237         }
00238         
00242         function _getNumberOfObjects()
00243         {
00244                 $a_tree_id = $_SESSION["AccountId"];
00245                 $tree = new ilTree($a_tree_id);
00246                 $tree->setTableNames('bookmark_tree','bookmark_data');
00247 
00248                 $root_node = $tree->getNodeData($tree->getRootId());
00249                 
00250                 if ($root_node["lft"] != "")
00251                 {
00252                         $bmf = $tree->getSubTree($root_node, false, "bmf");
00253                         $bm = $tree->getSubTree($root_node, false, "bm");
00254                 }
00255                 else
00256                 {
00257                         $bmf = array("dummy");
00258                         $bm = array();
00259                 }
00260                 
00261                 return array("folders" => (int) count($bmf) - 1, "bookmarks" => (int) count($bm));
00262         }
00263 
00264         
00268         function getObject($a_id)
00269         {
00270                 $a_tree_id = $_SESSION["AccountId"];
00271                 $tree = new ilTree($a_tree_id);
00272                 $tree->setTableNames('bookmark_tree','bookmark_data');
00273 
00274                 if(empty($a_id))
00275                 {
00276                         $a_id = $tree->getRootId();
00277                 }
00278 
00279                 $object = $tree->getNodeData($a_id);
00280                 return $object;
00281         }
00282 
00283         function isRootFolder($a_id)
00284         {
00285                 $a_tree_id = $_SESSION["AccountId"];
00286                 $tree = new ilTree($a_tree_id);
00287                 $tree->setTableNames('bookmark_tree','bookmark_data');
00288 
00289                 if ($a_id == $tree->getRootId())
00290                 {
00291                         return true;
00292                 }
00293                 else
00294                 {
00295                         return false;
00296                 }
00297         }
00298 
00299         function getRootFolder()
00300         {
00301                 $a_tree_id = $_SESSION["AccountId"];
00302                 $tree = new ilTree($a_tree_id);
00303                 $tree->setTableNames('bookmark_tree','bookmark_data');
00304 
00305                 return $tree->getRootId();
00306         }
00307 
00308         function _getParentId($a_id)
00309         {
00310                 $a_tree_id = $_SESSION["AccountId"];
00311                 $tree = new ilTree($a_tree_id);
00312                 $tree->setTableNames('bookmark_tree','bookmark_data');
00313                 return $tree->getParentId($a_id);
00314         }
00315 
00316 }
00317 ?>

Generated on Fri Dec 13 2013 17:57:00 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1