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

Services/Tracking/classes/class.ilLPFilter.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 
00037 include_once './Services/Tracking/classes/class.ilLPObjSettings.php';
00038 
00039 
00040 class ilLPFilter
00041 {
00042         var $permission = 'edit_learning_progress';
00043         var $limit = 0;
00044         var $limit_reached = false;
00045 
00046         var $anonymized_check = false;
00047 
00048         // Default values for filter
00049         var $root_node = ROOT_FOLDER_ID;
00050         var $filter_type = 'lm';
00051         var $hidden = array();
00052 
00053         var $usr_id = null;
00054         var $db = null;
00055 
00056         function ilLPFilter($a_usr_id)
00057         {
00058                 global $ilDB,$ilias;
00059 
00060                 $this->usr_id = $a_usr_id;
00061                 $this->db =& $ilDB;
00062                 $this->__read();
00063 
00064                 // Limit of filtered objects is search max hits
00065                 $this->limit = $ilias->getSetting('search_max_hits',50);
00066         }
00067 
00068         function getLimit()
00069         {
00070                 return $this->limit;
00071         }
00072 
00073         function limitReached()
00074         {
00075                 return $this->limit_reached;
00076         }
00077 
00078         function setRequiredPermission($a_permission)
00079         {
00080                 $this->permission = $a_permission;
00081         }
00082         function getRequiredPermission()
00083         {
00084                 return $this->permission;
00085         }
00086         
00087         function getUserId()
00088         {
00089                 return $this->usr_id;
00090         }
00091         
00092         function getFilterType()
00093         {
00094                 return $this->filter_type ? $this->filter_type : 'lm';
00095         }
00096         function setFilterType($a_type)
00097         {
00098                 return $this->filter_type = $a_type;
00099         }
00100 
00101         function getRootNode()
00102         {
00103                 return $this->root_node ? $this->root_node : ROOT_FOLDER_ID;
00104         }
00105         function setRootNode($a_root)
00106         {
00107                 $this->root_node = $a_root;
00108         }
00109 
00110         function getQueryString()
00111         {
00112                 return $this->query_string;
00113         }
00114         function setQueryString($a_query)
00115         {
00116                 $this->query_string = $a_query;
00117         }
00118 
00119         function getHidden()
00120         {
00121                 return $this->hidden ? $this->hidden : array();
00122         }
00123         function isHidden($a_obj_id)
00124         {
00125                 return in_array($a_obj_id,$this->hidden);
00126         }
00127         function setHidden($a_hidden)
00128         {
00129                 $this->hidden = $a_hidden;
00130         }
00131         function addHidden($a_hide)
00132         {
00133                 if(!in_array($a_hide,$this->hidden))
00134                 {
00135                         $this->hidden[] = $a_hide;
00136                         return true;
00137                 }
00138                 return false;
00139         }
00140 
00141         function removeHidden($a_show)
00142         {
00143                 foreach($this->hidden as $obj_id)
00144                 {
00145                         if($obj_id != $a_show)
00146                         {
00147                                 $tmp[] = $obj_id;
00148                         }
00149                 }
00150                 $this->hidden = $tmp ? $tmp : array();
00151         }
00152 
00153         function toggleAnonymizedCheck($a_status)
00154         {
00155                 $this->anonymized_check = $a_status;
00156         }
00157         function checkItemAnonymized()
00158         {
00159                 return $this->anonymized_check;
00160         }
00161 
00162         function update()
00163         {
00164                 $query = "UPDATE ut_lp_filter ".
00165                         "SET filter_type = '".$this->getFilterType()."', ".
00166                         "root_node = '".$this->getRootNode()."', ".
00167                         "hidden = '".addslashes(serialize($this->getHidden()))."', ".
00168                         "query_string = '".addslashes($this->getQueryString())."' ".
00169                         "WHERE usr_id = '".$this->getUserId()."'";
00170 
00171                 $res = $this->db->query($query);
00172                 return true;
00173         }
00174 
00175         function getObjects()
00176         {
00177                 return $this->__searchObjects();
00178 
00179 
00180                 // All is done by search class
00181                 /*
00182                 if(strlen($this->getQueryString()))
00183                 {
00184                         return $this->__searchObjects();
00185                 }
00186                 else
00187                 {
00188                         return $this->__getAllObjects();
00189                 }
00190                 */
00191         }
00192 
00193 
00194         // Static
00195         function _delete($a_usr_id)
00196         {
00197                 global $ilDB;
00198 
00199                 $query = "DELETE FROM ut_lp_filter ".
00200                         "WHERE usr_id = '".$a_usr_id."'";
00201                 $ilDB->query($query);
00202 
00203                 return true;
00204         }
00205                 
00206         // Private
00207         function __add()
00208         {
00209                 $query = "INSERT INTO ut_lp_filter ".
00210                         "SET usr_id = '".$this->getUserId()."', ".
00211                         "filter_type = '".$this->getFilterType()."', ".
00212                         "root_node = '".$this->getRootNode()."', ".
00213                         "hidden = '".addslashes(serialize($this->getHidden()))."', ".
00214                         "query_string = '".addslashes($this->getQueryString())."'";
00215 
00216                 $this->db->query($query);
00217 
00218                 return true;
00219         }
00220 
00221 
00222         function __read()
00223         {
00224                 $query = "SELECT * FROM ut_lp_filter ".
00225                         "WHERE usr_id = '".$this->getUserId()."'";
00226 
00227                 $res = $this->db->query($query);
00228 
00229                 if(!$res->numRows())
00230                 {
00231                         $this->__add();
00232                 }
00233 
00234                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00235                 {
00236                         $this->filter_type = $row->filter_type;
00237                         $this->root_node = $row->root_node;
00238                         $this->hidden = unserialize(ilUtil::stripSlashes($row->hidden));
00239                         $this->query_string = $row->query_string;
00240                 }
00241         }
00242 
00243         // Function is disabled everything shouild be done by search class
00244         function __getAllObjects()
00245         {
00246                 global $tree,$ilObjDataCache;
00247 
00248                 $objects = array();
00249                 foreach(ilUtil::_getObjectsByOperations($this->prepareType(),
00250                                                                                                 $this->getRequiredPermission(),
00251                                                                                                 $this->getUserId(),
00252                                                                                                 $this->getLimit()) as $ref_id)
00253                 {
00254                         $obj_id = $ilObjDataCache->lookupObjId($ref_id);
00255                         if($this->isHidden($obj_id))
00256                         {
00257                                 continue;
00258                         }
00259                         if(ilLPObjSettings::_lookupMode($obj_id) == LP_MODE_DEACTIVATED)
00260                         {
00261                                 continue;
00262                         }
00263 
00264                         if($tree->isGrandChild($this->getRootNode(),$ref_id))
00265                         {
00266                                 $objects[$obj_id]['ref_ids'][] = $ref_id;
00267                                 $objects[$obj_id]['title'] = $ilObjDataCache->lookupTitle($obj_id);
00268                                 $objects[$obj_id]['description'] = $ilObjDataCache->lookupDescription($obj_id);
00269                         }
00270                 }
00271                 return $objects ? $objects : array();
00272         }
00273 
00274 
00275         function __searchObjects()
00276         {
00277                 global $ilObjDataCache;
00278 
00279                 include_once './Services/Search/classes/class.ilQueryParser.php';
00280 
00281                 $query_parser =& new ilQueryParser($this->getQueryString());
00282                 $query_parser->setMinWordLength(0);
00283                 $query_parser->setCombination(QP_COMBINATION_OR);
00284                 $query_parser->parse();
00285                 if(!$query_parser->validate())
00286                 {
00287                         echo $query_parser->getMessage();
00288                 }
00289 
00290 
00291                 // only like search since fulltext does not support search with less than 3 characters
00292                 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
00293                 $object_search =& new ilLikeObjectSearch($query_parser);
00294 
00295                 #include_once './Services/Search/classes/class.ilObjectSearchFactory.php';
00296                 #$object_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
00297 
00298 
00299                 $object_search->setFilter($this->prepareType());
00300                 $res =& $object_search->performSearch();
00301                 $res->setRequiredPermission($this->getRequiredPermission());
00302 
00303                 // Add callback functions to receive only search_max_hits valid results
00304                 $res->addObserver($this,'searchFilterListener');
00305                 $res->filter($this->getRootNode(),false);
00306                 foreach($res->getResults() as $obj_data)
00307                 {
00308                         $objects[$obj_data['obj_id']]['ref_ids'][] = $obj_data['ref_id'];
00309                         $objects[$obj_data['obj_id']]['title'] = $ilObjDataCache->lookupTitle($obj_data['obj_id']);
00310                         $objects[$obj_data['obj_id']]['description'] = $ilObjDataCache->lookupDescription($obj_data['obj_id']);
00311                 }
00312 
00313                 // Check if search max hits is reached
00314                 $this->limit_reached = $res->isLimitReached();
00315 
00316                 return $objects ? $objects : array();
00317         }
00318 
00319         function prepareType()
00320         {
00321                 switch($this->getFilterType())
00322                 {
00323                         case 'lm':
00324                                 return array('lm','sahs','htlm');
00325 
00326                         default:
00327                                 return array($this->getFilterType());
00328                 }
00329         }
00330 
00336         function searchFilterListener($a_ref_id,$a_data)
00337         {
00338                 if($this->checkItemAnonymized())
00339                 {
00340                         switch($a_data['type'])
00341                         {
00342                                 case 'tst':
00343                                         include_once 'assessment/classes/class.ilObjTest.php';
00344                                         if(ilObjTest::_lookupTestType($a_data['obj_id']) == TYPE_SELF_ASSESSMENT)
00345                                         {
00346                                                 return false;
00347                                         }
00348                         }
00349                 }
00350                 if($this->isHidden($a_data['obj_id']))
00351                 {
00352                         return false;
00353                 }
00354                 if(ilLPObjSettings::_lookupMode($a_data['obj_id']) == LP_MODE_DEACTIVATED)
00355                 {
00356                         return false;
00357                 }
00358                 return true;
00359         }
00360                 
00361 }       
00362 ?>

Generated on Fri Dec 13 2013 13:52:12 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1