Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00034 class ilBookmarkFolder
00035 {
00041 var $tree;
00042
00048 var $ilias;
00049
00050 var $id;
00051 var $title;
00052 var $parent;
00053
00059 function ilBookmarkFolder($a_bmf_id = 0, $a_tree_id = 0)
00060 {
00061 global $ilias;
00062
00063
00064 $this->ilias =& $ilias;
00065 if ($a_tree_id == 0)
00066 {
00067 $a_tree_id = $_SESSION["AccountId"];
00068 }
00069
00070 $this->tree = new ilTree($a_tree_id);
00071 $this->tree->setTableNames('bookmark_tree','bookmark_data');
00072 $this->id = $a_bmf_id;
00073
00074 if(!empty($this->id))
00075 {
00076 $this->read();
00077 }
00078 }
00079
00083 function read()
00084 {
00085 global $ilias;
00086
00087 $q = "SELECT * FROM bookmark_data WHERE obj_id = ".$this->ilias->db->quote($this->getId());
00088 $bmf_set = $this->ilias->db->query($q);
00089 if ($bmf_set->numRows() == 0)
00090 {
00091 $message = "ilBookmarkFolder::read(): Bookmark Folder with id ".$this->getId()." not found!";
00092 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00093 }
00094 else
00095 {
00096 $bmf = $bmf_set->fetchRow(DB_FETCHMODE_ASSOC);
00097 $this->setTitle($bmf["title"]);
00098 $this->setParent($this->tree->getParentId($this->getId()));
00099 }
00100 }
00101
00105 function delete()
00106 {
00107 $q = "DELETE FROM bookmark_data WHERE obj_id = ".$this->ilias->db->quote($this->getId());
00108 $this->ilias->db->query($q);
00109 }
00110
00114 function createNewBookmarkTree()
00115 {
00116 global $ilDB;
00117
00118
00119
00120
00121
00122
00123 $this->tree->addTree($this->tree->getTreeId(), 1);
00124 }
00125
00131 function create()
00132 {
00133 $q = sprintf(
00134 "INSERT INTO bookmark_data (user_id, title, type) ".
00135 "VALUES (%s,%s,%s)",
00136 $this->ilias->db->quote($_SESSION["AccountId"]),
00137 $this->ilias->db->quote($this->getTitle()),
00138 $this->ilias->db->quote('bmf')
00139 );
00140
00141 $this->ilias->db->query($q);
00142 $this->setId($this->ilias->db->getLastInsertId());
00143 $this->tree->insertNode($this->getId(), $this->getParent());
00144 }
00145 function update()
00146 {
00147 $q = sprintf(
00148 "UPDATE bookmark_data SET title=%s ".
00149 "WHERE obj_id=%s",
00150 $this->ilias->db->quote($this->getTitle()),
00151 $this->ilias->db->quote($this->getId())
00152 );
00153 $this->ilias->db->query($q);
00154 }
00155
00156
00157 function getId()
00158 {
00159 return $this->id;
00160 }
00161
00162 function setId($a_id)
00163 {
00164 $this->id = $a_id;
00165 }
00166
00167 function getTitle()
00168 {
00169 return $this->title;
00170 }
00171
00172 function setTitle($a_title)
00173 {
00174 $this->title = $a_title;
00175 }
00176
00177 function getParent()
00178 {
00179 return $this->parent;
00180 }
00181
00182 function setParent($a_parent_id)
00183 {
00184 $this->parent = $a_parent_id;
00185 }
00186
00190 function _lookupTitle($a_bmf_id)
00191 {
00192 global $ilDB;
00193
00194 $q = "SELECT * FROM bookmark_data WHERE obj_id = ".$ilDB->quote($a_bmf_id);
00195 $bmf_set = $ilDB->query($q);
00196 $bmf = $bmf_set->fetchRow(DB_FETCHMODE_ASSOC);
00197
00198 return $bmf["title"];
00199 }
00200
00204 function getObjects($a_id)
00205 {
00206 $a_tree_id = $_SESSION["AccountId"];
00207 $tree = new ilTree($a_tree_id);
00208 $tree->setTableNames('bookmark_tree','bookmark_data');
00209
00210 if(empty($a_id))
00211 {
00212 $a_id = $tree->getRootId();
00213 }
00214
00215 $childs = $tree->getChilds($a_id, "title");
00216
00217 $objects = array();
00218 $bookmarks = array();
00219
00220 foreach ($childs as $key => $child)
00221 {
00222 switch ($child["type"])
00223 {
00224 case "bmf":
00225 $objects[] = $child;
00226 break;
00227
00228 case "bm":
00229 $bookmarks[] = $child;
00230 break;
00231 }
00232 }
00233 foreach ($bookmarks as $key => $bookmark)
00234 {
00235 $objects[] = $bookmark;
00236 }
00237 return $objects;
00238 }
00242 function getObject($a_id)
00243 {
00244 $a_tree_id = $_SESSION["AccountId"];
00245 $tree = new ilTree($a_tree_id);
00246 $tree->setTableNames('bookmark_tree','bookmark_data');
00247
00248 if(empty($a_id))
00249 {
00250 $a_id = $tree->getRootId();
00251 }
00252
00253 $object = $tree->getNodeData($a_id);
00254 return $object;
00255 }
00256
00257 function isRootFolder($a_id)
00258 {
00259 $a_tree_id = $_SESSION["AccountId"];
00260 $tree = new ilTree($a_tree_id);
00261 $tree->setTableNames('bookmark_tree','bookmark_data');
00262
00263 if ($a_id == $tree->getRootId())
00264 {
00265 return true;
00266 }
00267 else
00268 {
00269 return false;
00270 }
00271 }
00272
00273 function getRootFolder()
00274 {
00275 $a_tree_id = $_SESSION["AccountId"];
00276 $tree = new ilTree($a_tree_id);
00277 $tree->setTableNames('bookmark_tree','bookmark_data');
00278
00279 return $tree->getRootId();
00280 }
00281
00282 function _getParentId($a_id)
00283 {
00284 $a_tree_id = $_SESSION["AccountId"];
00285 $tree = new ilTree($a_tree_id);
00286 $tree->setTableNames('bookmark_tree','bookmark_data');
00287 return $tree->getParentId($a_id);
00288 }
00289
00290 }
00291 ?>