• Main Page
  • Related Pages
  • 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                 $this->setFields(array('meta_version'));
00441 
00442                 if($this->options['version'])
00443                 {
00444                         $where = $this->__createLifecycleWhereCondition();
00445                         $locate = $this->__createLocateString();
00446                 }
00447                 else
00448                 {
00449                         $where = "WHERE 1 ";
00450                 }
00451                 $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
00452                 
00453                 if($this->options['status'])
00454                 {
00455                         $and .= (" AND lifecycle_status = '".$this->options['status']."'");
00456                 }
00457 
00458                 $query = "SELECT rbac_id,obj_id,obj_type ".
00459                         $locate.
00460                         "FROM il_meta_lifecycle ".
00461                         $where." ".$and.' ';
00462 
00463                 $res = $this->db->query($query);
00464                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00465                 {
00466                         $found = $this->__prepareFound($row);
00467                         if(!in_array(0,$found))
00468                         {
00469                                 $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
00470                         }
00471                 }
00472 
00473                 return $this->search_result;
00474         }
00475 
00476         function &__searchFormat()
00477         {
00478                 if(!$this->options['format'])
00479                 {
00480                         return false;
00481                 }
00482 
00483                 $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_format ".
00484                         "WHERE format LIKE('".ilUtil::prepareDBString($this->options['format'])."') ".
00485                         "AND obj_type ".$this->__getInStatement($this->getFilter());
00486                 
00487                 $res = $this->db->query($query);
00488                 #var_dump("<pre>",$query,"<pre>");
00489                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00490                 {
00491                         $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
00492                 }
00493                 return $this->search_result;
00494         }
00495 
00496 
00497         function __createRightsWhere()
00498         {
00499                 $counter = 0;
00500                 $where = 'WHERE ';
00501 
00502 
00503                 if($this->options['costs'])
00504                 {
00505                         $and = $counter++ ? 'AND ' : ' ';
00506                         $where .= ($and."costs = '".ilUtil::prepareDBString($this->options['costs'])."' ");
00507                 }
00508                 if($this->options['copyright'])
00509                 {
00510                         $and = $counter++ ? 'AND ' : ' ';
00511                         $where .= ($and."copyright_and_other_restrictions = '".ilUtil::prepareDBString($this->options['copyright'])."' ");
00512                 }
00513                 return $counter ? $where : '';
00514         }
00515         function __createClassificationWhere()
00516         {
00517                 $counter = 0;
00518                 $where = 'WHERE ';
00519 
00520 
00521                 if($this->options['purpose'])
00522                 {
00523                         $and = $counter++ ? 'AND ' : ' ';
00524                         $where .= ($and."purpose = '".ilUtil::prepareDBString($this->options['purpose'])."' ");
00525                 }
00526                 return $counter ? $where : '';
00527         }
00528         function __createEducationalWhere()
00529         {
00530                 $counter = 0;
00531                 $where = 'WHERE ';
00532 
00533 
00534                 if($this->options['int_type'])
00535                 {
00536                         $and = $counter++ ? 'AND ' : ' ';
00537                         $where .= ($and."interactivity_type = '".ilUtil::prepareDBString($this->options['int_type'])."' ");
00538                 }
00539                 if($this->options['lea_type'])
00540                 {
00541                         $and = $counter++ ? 'AND ' : ' ';
00542                         $where .= ($and."learning_resource_type = '".ilUtil::prepareDBString($this->options['lea_type'])."' ");
00543                 }
00544                 if($this->options['int_role'])
00545                 {
00546                         $and = $counter++ ? 'AND ' : ' ';
00547                         $where .= ($and."intended_end_user_role = '".ilUtil::prepareDBString($this->options['int_role'])."' ");
00548                 }
00549                 if($this->options['con'])
00550                 {
00551                         $and = $counter++ ? 'AND ' : ' ';
00552                         $where .= ($and."context = '".ilUtil::prepareDBString($this->options['con'])."' ");
00553                 }
00554                 if($this->options['int_level_1'] or $this->options['int_level_2'])
00555                 {
00556                         $and = $counter++ ? 'AND ' : ' ';
00557 
00558                         $fields = $this->__getDifference($this->options['int_level_1'],$this->options['int_level_2'],
00559                                                                                            array('VeryLow','Low','Medium','High','VeryHigh'));
00560 
00561                         $where .= ($and."interactivity_level ".$this->__getInStatement($fields));
00562                 }
00563                 if($this->options['sem_1'] or $this->options['sem_2'])
00564                 {
00565                         $and = $counter++ ? 'AND ' : ' ';
00566 
00567                         $fields = $this->__getDifference($this->options['sem_1'],$this->options['sem_2'],
00568                                                                                            array('VeryLow','Low','Medium','High','VeryHigh'));
00569 
00570                         $where .= ($and."semantic_density ".$this->__getInStatement($fields));
00571                 }
00572                 if($this->options['dif_1'] or $this->options['dif_2'])
00573                 {
00574                         $and = $counter++ ? 'AND ' : ' ';
00575 
00576                         $fields = $this->__getDifference($this->options['dif_1'],$this->options['dif_2'],
00577                                                                                          array('VeryEasy','Easy','Medium','Difficult','VeryDifficult'));
00578 
00579                         $where .= ($and."difficulty ".$this->__getInStatement($fields));
00580                 }
00581 
00582                 return $counter ? $where : '';
00583         }
00584         function __createRequirementWhere()
00585         {
00586                 $counter = 0;
00587                 $where = 'WHERE ';
00588 
00589 
00590                 if($this->options['os'])
00591                 {
00592                         $and = $counter++ ? 'AND ' : ' ';
00593                         $where .= ($and."operating_system_name = '".ilUtil::prepareDBString($this->options['os'])."' ");
00594                 }
00595                 if($this->options['browser'])
00596                 {
00597                         $and = $counter++ ? 'AND ' : ' ';
00598                         $where .= ($and."browser_name = '".ilUtil::prepareDBString($this->options['browser'])."' ");
00599                 }
00600                 return $counter ? $where : '';
00601         }
00602 
00603         function __getDifference($a_val1,$a_val2,$options)
00604         {
00605                 $a_val2 = $a_val2 ? $a_val2 : count($options);
00606                 // Call again if a > b
00607                 if($a_val1 > $a_val2)
00608                 {
00609                         return $this->__getDifference($a_val2,$a_val1,$options);
00610                 }
00611 
00612                 $counter = 0;
00613                 foreach($options as $option)
00614                 {
00615                         if($a_val1 > ++$counter)
00616                         {
00617                                 continue;
00618                         }
00619                         if($a_val2 < $counter)
00620                         {
00621                                 break;
00622                         }
00623                         $fields[] = $option;
00624                 }
00625                 return $fields ? $fields : array();
00626         }
00627 
00628         function __getInStatement($a_fields)
00629         {
00630                 if(!$a_fields)
00631                 {
00632                         return '';
00633                 }
00634                 $in = " IN ('";
00635                 $in .= implode("','",$a_fields);
00636                 $in .= "') ";
00637 
00638                 return $in;
00639         }
00640 
00641 }
00642 ?>

Generated on Fri Dec 13 2013 10:18:31 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1