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

Services/Search/classes/class.ilAdvancedSearch.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 
00035 include_once 'Services/Search/classes/class.ilAbstractSearch.php';
00036 
00037 class ilAdvancedSearch extends ilAbstractSearch
00038 {
00039         var $mode = '';
00040 
00041         /*
00042          * instance of query parser
00043          */
00044         var $query_parser = null;
00045 
00046         var $db = null;
00047 
00052         function ilAdvancedSearch(&$qp_obj)
00053         {
00054                 parent::ilAbstractSearch($qp_obj);
00055         }
00056 
00063         function setMode($a_mode)
00064         {
00065                 $this->mode = $a_mode;
00066         }
00067         function getMode()
00068         {
00069                 return $this->mode;
00070         }
00071 
00072         function setOptions(&$options)
00073         {
00074                 $this->options =& $options;
00075         }
00076 
00077         function &performSearch()
00078         {
00079                 switch($this->getMode())
00080                 {
00081                         case 'requirement':
00082                                 return $this->__searchRequirement();
00083                                 break;
00084 
00085                         case 'educational':
00086                                 return $this->__searchEducational();
00087                                 break;
00088 
00089                         case 'typical_age_range':
00090                                 return $this->__searchTypicalAgeRange();
00091                                 break;
00092 
00093                         case 'rights':
00094                                 return $this->__searchRights();
00095                                 break;
00096 
00097                         case 'classification':
00098                                 return $this->__searchClassification();
00099                                 break;
00100 
00101                         case 'taxon':
00102                                 return $this->__searchTaxon();
00103                                 break;
00104 
00105                         case 'keyword':
00106                                 return $this->__searchKeyword(true);
00107                                 break;
00108 
00109                         case 'format':
00110                                 return $this->__searchFormat();
00111                                 break;
00112 
00113                         case 'lifecycle':
00114                                 return $this->__searchLifecycle();
00115                                 break;
00116 
00117                         case 'contribute':
00118                                 return $this->__searchContribute();
00119                                 break;
00120 
00121                         case 'entity':
00122                                 return $this->__searchEntity();
00123                                 break;
00124 
00125                         case 'general':
00126                                 return $this->__searchGeneral();
00127                                 break;
00128 
00129                         case 'keyword_all':
00130                                 return $this->__searchKeyword(false);
00131                                 break;
00132 
00133                         case 'title_description':
00134                                 return $this->__searchTitleDescription();
00135                                 break;
00136 
00137                         case 'language':
00138                                 return $this->__searchLanguage();
00139                                 break;
00140 
00141                         default:
00142                                 echo "ilMDSearch::performSearch() no mode given";
00143                                 return false;
00144                 }
00145         }
00146 
00147         function &__searchTitleDescription()
00148         {
00149                 if(!$this->options['title'])
00150                 {
00151                         return false;
00152                 }
00153                 $this->setFields(array('title','description'));
00154 
00155                 $and = ("AND type ".$this->__getInStatement($this->getFilter()));
00156                 $where = $this->__createTitleDescriptionWhereCondition();
00157                 $locate = $this->__createLocateString();
00158 
00159                 $query = "SELECT obj_id,type ".
00160                         $locate.
00161                         "FROM object_data ".
00162                         $where." ".$and.' '.
00163                         "ORDER BY obj_id DESC";
00164 
00165                 $res = $this->db->query($query);
00166                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00167                 {
00168                         $this->search_result->addEntry($row->obj_id,$row->type,$this->__prepareFound($row));
00169                 }
00170 
00171                 return $this->search_result;
00172         }
00173 
00174         function &__searchGeneral()
00175         {
00176                 if(!$this->options['coverage'] and !$this->options['structure'])
00177                 {
00178                         return false;
00179                 }
00180                 if($this->options['coverage'])
00181                 {
00182                         $this->setFields(array('coverage'));
00183                         $and = $this->__createCoverageAndCondition();
00184                         $locate = $this->__createLocateString();
00185                 }
00186                 if($this->options['structure'])
00187                 {
00188                         $and .= ("AND general_structure = '".ilUtil::prepareDBString($this->options['structure'])."' ");
00189                 }
00190                         
00191                 $query = "SELECT rbac_id,obj_type,obj_id ".
00192                         $locate." ".
00193                         "FROM il_meta_general ".
00194                         "WHERE obj_type ".$this->__getInStatement($this->getFilter())." ".
00195                         $and;
00196 
00197                 $res = $this->db->query($query);
00198                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00199                 {
00200                         if($this->options['coverage'])
00201                         {
00202                                 $found = $this->__prepareFound($row);
00203                                 if(!in_array(0,$found))
00204                                 {
00205                                         $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
00206                                 }
00207                         }
00208                         else
00209                         {
00210                                 $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
00211                         }
00212                 }
00213 
00214                 return $this->search_result;
00215         }
00216 
00217         function &__searchLanguage()
00218         {
00219                 if(!$this->options['language'])
00220                 {
00221                         return false;
00222                 }
00223 
00224                 $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_language ".
00225                         "WHERE language = '".ilUtil::prepareDBString($this->options['language'])."' ".
00226                         "AND obj_type ".$this->__getInStatement($this->getFilter()).' '.
00227                         "AND parent_type = 'meta_general'";
00228 
00229                 $res = $this->db->query($query);
00230                 #var_dump("<pre>",$query,"<pre>");
00231                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00232                 {
00233                         $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
00234                 }
00235                 return $this->search_result;
00236         }
00237 
00238         function &__searchContribute()
00239         {
00240                 if(!$this->options['role'])
00241                 {
00242                         return false;
00243                 }
00244 
00245                 $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_contribute ".
00246                         "WHERE role = '".ilUtil::prepareDBString($this->options['role'])."' ".
00247                         "AND obj_type ".$this->__getInStatement($this->getFilter());
00248 
00249                 $res = $this->db->query($query);
00250                 #var_dump("<pre>",$query,"<pre>");
00251                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00252                 {
00253                         $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
00254                 }
00255                 return $this->search_result;
00256         }
00257 
00258         function &__searchEntity()
00259         {
00260                 $this->setFields(array('entity'));
00261 
00262                 $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
00263                 $where = $this->__createEntityWhereCondition();
00264                 $locate = $this->__createLocateString();
00265 
00266                 $query = "SELECT rbac_id,obj_id,obj_type ".
00267                         $locate.
00268                         "FROM il_meta_entity ".
00269                         $where." ".$and.' ';
00270 
00271                 $res = $this->db->query($query);
00272                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00273                 {
00274                         $found = $this->__prepareFound($row);
00275                         if(!in_array(0,$found))
00276                         {
00277                                 $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
00278                         }
00279                 }
00280 
00281                 return $this->search_result;
00282         }
00283 
00284 
00285 
00286         function &__searchRequirement()
00287         {
00288                 $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_requirement ";
00289 
00290                 if(!strlen($where = $this->__createRequirementWhere()))
00291                 {
00292                         return false;
00293                 }
00294                 $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
00295                 $query = $query.$where.$and;
00296                 $res = $this->db->query($query);
00297                 #var_dump("<pre>",$query,"<pre>");
00298                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00299                 {
00300                         $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
00301                 }
00302                 return $this->search_result;
00303         }
00304 
00305         function &__searchEducational()
00306         {
00307                 $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_educational ";
00308 
00309                 if(!strlen($where = $this->__createEducationalWhere()))
00310                 {
00311                         return false;
00312                 }
00313                 $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
00314                 $query = $query.$where.$and;
00315                 $res = $this->db->query($query);
00316                 #var_dump("<pre>",$query,"<pre>");
00317                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00318                 {
00319                         $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
00320                 }
00321                 return $this->search_result;
00322         }
00323 
00324         function &__searchTypicalAgeRange()
00325         {
00326                 if(!$this->options['typ_age_1'] or !$this->options['typ_age_2'])
00327                 {
00328                         return false;
00329                 }
00330 
00331                 $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_typical_age_range ".
00332                         "WHERE typical_age_range_min >= '".(int) $this->options['typ_age_1']."' ".
00333                         "AND typical_age_range_max <= '".(int) $this->options['typ_age_2']."'";
00334 
00335 
00336                 $res = $this->db->query($query);
00337                 #var_dump("<pre>",$query,"<pre>");
00338                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00339                 {
00340                         $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
00341                 }
00342                 return $this->search_result;
00343         }
00344 
00345         function &__searchRights()
00346         {
00347                 $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_rights ";
00348 
00349                 if(!strlen($where = $this->__createRightsWhere()))
00350                 {
00351                         return false;
00352                 }
00353                 $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
00354                 $query = $query.$where.$and;
00355                 $res = $this->db->query($query);
00356                 #var_dump("<pre>",$query,"<pre>");
00357                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00358                 {
00359                         $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
00360                 }
00361                 return $this->search_result;
00362         }
00363 
00364         function &__searchClassification()
00365         {
00366                 $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_classification ";
00367 
00368                 if(!strlen($where = $this->__createClassificationWhere()))
00369                 {
00370                         return false;
00371                 }
00372                 $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
00373                 $query = $query.$where.$and;
00374                 $res = $this->db->query($query);
00375                 #var_dump("<pre>",$query,"<pre>");
00376                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00377                 {
00378                         $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
00379                 }
00380                 return $this->search_result;
00381         }
00382 
00383         function &__searchTaxon()
00384         {
00385                 $this->setFields(array('taxon'));
00386 
00387                 $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
00388                 $where = $this->__createTaxonWhereCondition();
00389                 $locate = $this->__createLocateString();
00390 
00391                 $query = "SELECT rbac_id,obj_id,obj_type ".
00392                         $locate.
00393                         "FROM il_meta_taxon ".
00394                         $where." ".$and.' ';
00395 
00396                 $res = $this->db->query($query);
00397                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00398                 {
00399                         $found = $this->__prepareFound($row);
00400                         if(!in_array(0,$found))
00401                         {
00402                                 $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
00403                         }
00404                 }
00405 
00406                 return $this->search_result;
00407         }
00408 
00409         function &__searchKeyword($a_in_classification = false)
00410         {
00411                 $this->setFields(array('keyword'));
00412 
00413                 $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
00414                 if($a_in_classification)
00415                 {
00416                         $and .= " AND parent_type = 'meta_classification' ";
00417                 }
00418                 $where = $this->__createKeywordWhereCondition();
00419                 $locate = $this->__createLocateString();
00420 
00421                 $query = "SELECT rbac_id,obj_id,obj_type ".
00422                         $locate.
00423                         "FROM il_meta_keyword ".
00424                         $where." ".$and.' ';
00425 
00426                 $res = $this->db->query($query);
00427                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00428                 {
00429                         $found = $this->__prepareFound($row);
00430                         if(!in_array(0,$found) or !$a_in_classification)
00431                         {
00432                                 $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
00433                         }
00434                 }
00435 
00436                 return $this->search_result;
00437         }
00438         function &__searchLifecycle()
00439         {
00440                 global $ilDB;
00441 
00442                 $this->setFields(array('meta_version'));
00443 
00444                 if($this->options['version'])
00445                 {
00446                         $where = $this->__createLifecycleWhereCondition();
00447                         $locate = $this->__createLocateString();
00448                 }
00449                 else
00450                 {
00451                         $where = "WHERE 1 ";
00452                 }
00453                 $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
00454                 
00455                 if($this->options['status'])
00456                 {
00457                         $and .= (" AND lifecycle_status = ".$ilDB->quote($this->options['status'])." ");
00458                 }
00459 
00460                 $query = "SELECT rbac_id,obj_id,obj_type ".
00461                         $locate.
00462                         "FROM il_meta_lifecycle ".
00463                         $where." ".$and.' ';
00464 
00465                 $res = $this->db->query($query);
00466                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00467                 {
00468                         $found = $this->__prepareFound($row);
00469                         if(!in_array(0,$found))
00470                         {
00471                                 $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
00472                         }
00473                 }
00474 
00475                 return $this->search_result;
00476         }
00477 
00478         function &__searchFormat()
00479         {
00480                 if(!$this->options['format'])
00481                 {
00482                         return false;
00483                 }
00484 
00485                 $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_format ".
00486                         "WHERE format LIKE('".ilUtil::prepareDBString($this->options['format'])."') ".
00487                         "AND obj_type ".$this->__getInStatement($this->getFilter());
00488                 
00489                 $res = $this->db->query($query);
00490                 #var_dump("<pre>",$query,"<pre>");
00491                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00492                 {
00493                         $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
00494                 }
00495                 return $this->search_result;
00496         }
00497 
00498 
00499         function __createRightsWhere()
00500         {
00501                 $counter = 0;
00502                 $where = 'WHERE ';
00503 
00504 
00505                 if($this->options['costs'])
00506                 {
00507                         $and = $counter++ ? 'AND ' : ' ';
00508                         $where .= ($and."costs = '".ilUtil::prepareDBString($this->options['costs'])."' ");
00509                 }
00510                 if($this->options['copyright'])
00511                 {
00512                         $and = $counter++ ? 'AND ' : ' ';
00513                         $where .= ($and."copyright_and_other_restrictions = '".ilUtil::prepareDBString($this->options['copyright'])."' ");
00514                 }
00515                 return $counter ? $where : '';
00516         }
00517         function __createClassificationWhere()
00518         {
00519                 $counter = 0;
00520                 $where = 'WHERE ';
00521 
00522 
00523                 if($this->options['purpose'])
00524                 {
00525                         $and = $counter++ ? 'AND ' : ' ';
00526                         $where .= ($and."purpose = '".ilUtil::prepareDBString($this->options['purpose'])."' ");
00527                 }
00528                 return $counter ? $where : '';
00529         }
00530         function __createEducationalWhere()
00531         {
00532                 $counter = 0;
00533                 $where = 'WHERE ';
00534 
00535 
00536                 if($this->options['int_type'])
00537                 {
00538                         $and = $counter++ ? 'AND ' : ' ';
00539                         $where .= ($and."interactivity_type = '".ilUtil::prepareDBString($this->options['int_type'])."' ");
00540                 }
00541                 if($this->options['lea_type'])
00542                 {
00543                         $and = $counter++ ? 'AND ' : ' ';
00544                         $where .= ($and."learning_resource_type = '".ilUtil::prepareDBString($this->options['lea_type'])."' ");
00545                 }
00546                 if($this->options['int_role'])
00547                 {
00548                         $and = $counter++ ? 'AND ' : ' ';
00549                         $where .= ($and."intended_end_user_role = '".ilUtil::prepareDBString($this->options['int_role'])."' ");
00550                 }
00551                 if($this->options['con'])
00552                 {
00553                         $and = $counter++ ? 'AND ' : ' ';
00554                         $where .= ($and."context = '".ilUtil::prepareDBString($this->options['con'])."' ");
00555                 }
00556                 if($this->options['int_level_1'] or $this->options['int_level_2'])
00557                 {
00558                         $and = $counter++ ? 'AND ' : ' ';
00559 
00560                         $fields = $this->__getDifference($this->options['int_level_1'],$this->options['int_level_2'],
00561                                                                                            array('VeryLow','Low','Medium','High','VeryHigh'));
00562 
00563                         $where .= ($and."interactivity_level ".$this->__getInStatement($fields));
00564                 }
00565                 if($this->options['sem_1'] or $this->options['sem_2'])
00566                 {
00567                         $and = $counter++ ? 'AND ' : ' ';
00568 
00569                         $fields = $this->__getDifference($this->options['sem_1'],$this->options['sem_2'],
00570                                                                                            array('VeryLow','Low','Medium','High','VeryHigh'));
00571 
00572                         $where .= ($and."semantic_density ".$this->__getInStatement($fields));
00573                 }
00574                 if($this->options['dif_1'] or $this->options['dif_2'])
00575                 {
00576                         $and = $counter++ ? 'AND ' : ' ';
00577 
00578                         $fields = $this->__getDifference($this->options['dif_1'],$this->options['dif_2'],
00579                                                                                          array('VeryEasy','Easy','Medium','Difficult','VeryDifficult'));
00580 
00581                         $where .= ($and."difficulty ".$this->__getInStatement($fields));
00582                 }
00583 
00584                 return $counter ? $where : '';
00585         }
00586         function __createRequirementWhere()
00587         {
00588                 $counter = 0;
00589                 $where = 'WHERE ';
00590 
00591 
00592                 if($this->options['os'])
00593                 {
00594                         $and = $counter++ ? 'AND ' : ' ';
00595                         $where .= ($and."operating_system_name = '".ilUtil::prepareDBString($this->options['os'])."' ");
00596                 }
00597                 if($this->options['browser'])
00598                 {
00599                         $and = $counter++ ? 'AND ' : ' ';
00600                         $where .= ($and."browser_name = '".ilUtil::prepareDBString($this->options['browser'])."' ");
00601                 }
00602                 return $counter ? $where : '';
00603         }
00604 
00605         function __getDifference($a_val1,$a_val2,$options)
00606         {
00607                 $a_val2 = $a_val2 ? $a_val2 : count($options);
00608                 // Call again if a > b
00609                 if($a_val1 > $a_val2)
00610                 {
00611                         return $this->__getDifference($a_val2,$a_val1,$options);
00612                 }
00613 
00614                 $counter = 0;
00615                 foreach($options as $option)
00616                 {
00617                         if($a_val1 > ++$counter)
00618                         {
00619                                 continue;
00620                         }
00621                         if($a_val2 < $counter)
00622                         {
00623                                 break;
00624                         }
00625                         $fields[] = $option;
00626                 }
00627                 return $fields ? $fields : array();
00628         }
00629 
00630         function __getInStatement($a_fields)
00631         {
00632                 if(!$a_fields)
00633                 {
00634                         return '';
00635                 }
00636                 $in = " IN ('";
00637                 $in .= implode("','",$a_fields);
00638                 $in .= "') ";
00639 
00640                 return $in;
00641         }
00642 
00643 }
00644 ?>

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