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

classes/class.ilSearchFolder.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 
00032 require_once "./classes/class.ilTree.php";
00033 
00034 
00035 class ilSearchFolder
00036 {
00037         // OBJECT VARIABLES
00038         var $s_tree;
00039         var $ilias;
00040 
00041         var $user_id;
00042         var $root_id;
00043         var $folder_id;
00044         var $parent_id;
00045         var $title;
00046 
00051         function ilSearchFolder($a_user_id,$a_folder_id = 0)
00052         {
00053                 global $ilias;
00054 
00055                 define("TABLE_SEARCH_TREE","search_tree");
00056                 define("TABLE_SEARCH_DATA","search_data");
00057 
00058                 $this->ilias =& $ilias;
00059 
00060                 $this->user_id = $a_user_id;
00061                 
00062                 $this->__readRootId();
00063 
00064                 // IF NO FOLDER ID IS GIVEN DEFAULT TO ROOT ID
00065                 $this->setFolderId($a_folder_id ? $a_folder_id : $this->getRootId());
00066 
00067                 $this->__initTreeObject();
00068 
00069                 if(!$this->__treeExists())
00070                 {
00071                         $this->__createNewTree();
00072                 }
00073                 $this->__init();
00074 
00075                 // CHECK USER TREE IF HAS BEEN CREATED
00076         }
00077 
00078         // SET/GET
00079         function getType()
00080         {
00081                 return "seaf";
00082         }
00083         
00084         function getRootId()
00085         {
00086                 return $this->root_id;
00087         }
00088         function setRootId($a_root_id)
00089         {
00090                 $this->root_id = $a_root_id;
00091         }
00092         function setFolderId($a_folder_id)
00093         {
00094                 $this->folder_id = $a_folder_id;
00095         }
00096         function getFolderId()
00097         {
00098                 return $this->folder_id;
00099         }
00100         function setUserId($a_user_id)
00101         {
00102                 $this->user_id = $a_user_id;
00103                 
00104         }
00105         function getUserId()
00106         {
00107                 return $this->user_id;
00108         }
00109         function setTitle($a_title)
00110         {
00111                 $this->title = $a_title;
00112         }
00113         function getTitle()
00114         {
00115                 return $this->title;
00116         }
00117 
00118         function getChilds()
00119         {
00120                 return $this->s_tree->getChilds($this->getFolderId(),"type","DESC");
00121         }
00122         function hasSubfolders()
00123         {
00124                 $childs = $this->getChilds();
00125 
00126                 return $childs[0]["type"] == "seaf" ? true : false;
00127         }
00128         function hasResults()
00129         {
00130                 $childs = $this->getChilds();
00131 
00132                 return $childs[count($childs)-1]["type"] == "sea" ? true : false;
00133         }
00134         function countFolders()
00135         {
00136                 $childs = $this->s_tree->getChilds($this->getRootId(),"type","DESC");
00137 
00138                 $counter = 0;
00139                 while(true)
00140                 {
00141                         if($childs[$counter]["type"] != "seaf")
00142                         {
00143                                 break;
00144                         }
00145                         ++$counter;
00146                 }
00147                 return $counter;
00148         }
00149 
00150         function getPath()
00151         {
00152                 return $this->s_tree->getPathFull($this->getFolderId(),$this->getRootId());
00153         }
00154 
00155         function setParentId($a_parent_id)
00156         {
00157                 $this->parent_id = $a_parent_id;
00158         }
00159         
00160         function getParentId()
00161         {
00162                 return $this->parent_id;
00163         }
00164 
00165         function delete($a_folder_id)
00166         {
00167                 $subtree = $this->s_tree->getSubTree($this->s_tree->getNodeData($a_folder_id));
00168                 
00169                 foreach($subtree as $node)
00170                 {
00171                         // DELETE DATA ENTRIES
00172                         $query = "DELETE FROM ".TABLE_SEARCH_DATA." ".
00173                                 "WHERE user_id = '".$this->getUserId()."' ".
00174                                 "AND obj_id = '".$node["obj_id"]."'";
00175 
00176                         $res = $this->ilias->db->query($query);
00177                 }
00178                 // FINALLY DELETE SUBTREE
00179                 $this->s_tree->deleteTree($this->s_tree->getNodeData($a_folder_id));
00180 
00181                 return true;
00182         }
00183         
00184         function assignResult(&$search_result)
00185         {
00186                 if(!$this->__treeExists())
00187                 {
00188                         $this->__createNewTree();
00189                 }
00190                 // CREATE RESULT
00191                 $query = "INSERT INTO ".TABLE_SEARCH_DATA ." ".
00192                         "SET user_id = '".$this->getUserId()."', ".
00193                         "title = '".$search_result->getTitle()."', ".
00194                         "target = '".$search_result->getTarget()."', ".
00195                         "type = 'sea'";
00196                 
00197                 $res = $this->ilias->db->query($query);
00198 
00199                 $this->s_tree->insertNode($this->ilias->db->getLastInsertId(),$this->getFolderId());
00200 
00201                 return true;
00202         }
00203 
00204         function updateTitle($a_title)
00205         {
00206                 $query = "UPDATE ".TABLE_SEARCH_DATA." ".
00207                         "SET title = '".addslashes($a_title)."' ".
00208                         "WHERE obj_id = '".$this->getFolderId()."' ".
00209                         "AND user_id = '".$this->getUserId()."'";
00210 
00211                 $res = $this->ilias->db->query($query);
00212 
00213                 return true;
00214         }
00215 
00216         function &create($a_title)
00217         {
00218                 // CREATE FOLDER
00219                 $query = "INSERT INTO ".TABLE_SEARCH_DATA ." ".
00220                         "SET user_id = '".$this->getUserId()."', ".
00221                         "title = '".addslashes($a_title)."', ".
00222                         "type = 'seaf'";
00223                 
00224                 $res = $this->ilias->db->query($query);
00225 
00226                 $this->s_tree->insertNode($this->ilias->db->getLastInsertId(),$this->getFolderId());
00227 
00228                 $new_obj =& new ilSearchFolder($this->getUserId(),$this->getFolderId());
00229                 $new_obj->setTitle($a_title);
00230 
00231                 return $new_obj;
00232         }
00233         function getTree()
00234         {
00235                 $tmp_folder_id = $this->getFolderId();
00236 
00237                 $this->setFolderId($this->getRootId());
00238                 
00239                 $tree_data = $this->getSubtree();
00240                 $this->setFolderId($tmp_folder_id);
00241 
00242                 return $tree_data;
00243         }
00244 
00245         function getSubtree()
00246         {
00247                 $subtree = $this->s_tree->getSubtree($this->s_tree->getNodeData($this->getFolderId()));
00248 
00249                 // FILTER FOLDERS
00250                 foreach($subtree as $node)
00251                 {
00252                         if($node["type"] == "seaf")
00253                         {
00254                                 $filtered[] = $node;
00255                         }
00256                 }
00257                 return count($filtered) ? $filtered : array();
00258         }
00259         // PRIVATE METHODS
00260         function __init()
00261         {
00262                 $query = "SELECT * FROM ".TABLE_SEARCH_TREE.", ".TABLE_SEARCH_DATA." ".
00263                         "WHERE child = obj_id ".
00264                         "AND child = '".$this->getFolderId()."' ".
00265                         "AND tree = '".$this->getUserId()."'";
00266 
00267                 $res = $this->ilias->db->query($query);
00268 
00269                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00270                 {
00271                         $this->setTitle($row->title);
00272                         $this->setParentId($row->parent);
00273                 }
00274         }
00275 
00276         function  __initTreeObject()
00277         {
00278                 $this->s_tree = new ilTree($this->getUserId(),$this->getRootId());
00279                 $this->s_tree->setTableNames(TABLE_SEARCH_TREE,TABLE_SEARCH_DATA);
00280 
00281                 return true;
00282         }
00283 
00284         function __treeExists()
00285         {
00286                 $query = "SELECT tree FROM ".TABLE_SEARCH_TREE." ".
00287                         "WHERE tree = ".$this->getUserId();
00288                 
00289                 $res = $this->ilias->db->query($query);
00290 
00291                 return $res->numRows() ? true : false;
00292         }
00293 
00294         function __createNewTree()
00295         {
00296                 // ADD ENTRY search_data
00297                 $query = "INSERT INTO ".TABLE_SEARCH_DATA." ".
00298                         "SET user_id = '".$this->getUserId()."', ".
00299                         "type = 'seaf'";
00300                 
00301                 $res = $this->ilias->db->query($query);
00302                 $root_id = $this->__getLastInsertId();
00303 
00304                 $this->s_tree->addTree($this->getUserId(),$root_id);
00305 
00306                 // SET MEMBER VARIABLES
00307                 $this->setFolderId($root_id);
00308                 $this->setRootId($root_id);
00309 
00310                 return true;
00311         }
00312 
00313         function __readRootId()
00314         {
00315                 $query = "SELECT child FROM ".TABLE_SEARCH_TREE." ".
00316                         "WHERE tree = '".$this->getUserId()."' ".
00317                         "AND parent = '0'";
00318 
00319                 $res = $this->ilias->db->query($query);
00320                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00321                 {
00322                         $this->setRootId($row->child);
00323                 }
00324                 return true;
00325         }
00326 
00327         function __getLastInsertId()
00328         {
00329                 return $this->ilias->db->getLastInsertId();
00330         }
00331 
00332 } // END class.Search
00333 ?>

Generated on Fri Dec 13 2013 09:06:35 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1