ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAdvancedSearch.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
35 include_once 'Services/Search/classes/class.ilAbstractSearch.php';
36 
38 {
39  var $mode = '';
40 
41  /*
42  * instance of query parser
43  */
44  var $query_parser = null;
45 
46  var $db = null;
47 
54  function setMode($a_mode)
55  {
56  $this->mode = $a_mode;
57  }
58  function getMode()
59  {
60  return $this->mode;
61  }
62 
63  function setOptions(&$options)
64  {
65  $this->options =& $options;
66  }
67 
68  function &performSearch()
69  {
70  switch($this->getMode())
71  {
72  case 'requirement':
73  return $this->__searchRequirement();
74  break;
75 
76  case 'educational':
77  return $this->__searchEducational();
78  break;
79 
80  case 'typical_age_range':
81  return $this->__searchTypicalAgeRange();
82  break;
83 
84  case 'rights':
85  return $this->__searchRights();
86  break;
87 
88  case 'classification':
89  return $this->__searchClassification();
90  break;
91 
92  case 'taxon':
93  return $this->__searchTaxon();
94  break;
95 
96  case 'keyword':
97  return $this->__searchKeyword();
98  break;
99 
100  case 'format':
101  return $this->__searchFormat();
102  break;
103 
104  case 'lifecycle':
105  return $this->__searchLifecycle();
106  break;
107 
108  case 'contribute':
109  return $this->__searchContribute();
110  break;
111 
112  case 'entity':
113  return $this->__searchEntity();
114  break;
115 
116  case 'general':
117  return $this->__searchGeneral();
118  break;
119 
120  case 'keyword_all':
121  return $this->__searchKeyword(false);
122  break;
123 
124  case 'title_description':
125  return $this->__searchTitleDescription();
126  break;
127 
128  case 'language':
129  return $this->__searchLanguage();
130  break;
131 
132  default:
133  echo "ilMDSearch::performSearch() no mode given";
134  return false;
135  }
136  }
137 
139  {
140  $this->setFields(array('title','description'));
141 
142  $and = ("AND type ".$this->__getInStatement($this->getFilter()));
143  $where = $this->__createTitleDescriptionWhereCondition();
144  $locate = $this->__createLocateString();
145 
146  $query = "SELECT obj_id,type ".
147  $locate.
148  "FROM object_data ".
149  $where." ".$and.' '.
150  "ORDER BY obj_id DESC";
151 
152  $res = $this->db->query($query);
153  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
154  {
155  $this->search_result->addEntry($row->obj_id,$row->type,$this->__prepareFound($row));
156  }
157 
158  return $this->search_result;
159  }
160 
161  function &__searchGeneral()
162  {
163  global $ilDB;
164 
165  if(!$this->options['lom_coverage'] and !$this->options['lom_structure'])
166  {
167  return false;
168  }
169  if($this->options['lom_coverage'])
170  {
171  $this->setFields(array('coverage'));
172  $and = $this->__createCoverageAndCondition();
173  $locate = $this->__createLocateString();
174  }
175  if($this->options['lom_structure'])
176  {
177  $and .= ("AND general_structure = ".$ilDB->quote($this->options['lom_structure'] ,'text')." ");
178  }
179 
180  $query = "SELECT rbac_id,obj_type,obj_id ".
181  $locate." ".
182  "FROM il_meta_general ".
183  "WHERE obj_type ".$this->__getInStatement($this->getFilter())." ".
184  $and;
185 
186  $res = $this->db->query($query);
187  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
188  {
189  if($this->options['lom_coverage'])
190  {
191  $found = $this->__prepareFound($row);
192  if(!in_array(0,$found))
193  {
194  $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
195  }
196  }
197  else
198  {
199  $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
200  }
201  }
202 
203  return $this->search_result;
204  }
205 
206  function &__searchLanguage()
207  {
208  global $ilDB;
209 
210  if(!$this->options['lom_language'])
211  {
212  return false;
213  }
214 
215  $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_language ".
216  "WHERE language = ".$ilDB->quote($this->options['lom_language'] ,'text')." ".
217  "AND obj_type ".$this->__getInStatement($this->getFilter()).' '.
218  "AND parent_type = 'meta_general'";
219 
220  $res = $this->db->query($query);
221  #var_dump("<pre>",$query,"<pre>");
222  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
223  {
224  $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
225  }
226  return $this->search_result;
227  }
228 
229  function &__searchContribute()
230  {
231  global $ilDB;
232 
233  if(!$this->options['lom_role'])
234  {
235  return false;
236  }
237 
238  $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_contribute ".
239  "WHERE role = ".$ilDB->quote($this->options['lom_role'] ,'text')." ".
240  "AND obj_type ".$this->__getInStatement($this->getFilter());
241 
242  $res = $this->db->query($query);
243  #var_dump("<pre>",$query,"<pre>");
244  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
245  {
246  $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
247  }
248  return $this->search_result;
249  }
250 
251  function &__searchEntity()
252  {
253  $this->setFields(array('entity'));
254 
255  $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
256  $where = $this->__createEntityWhereCondition();
257  $locate = $this->__createLocateString();
258 
259  $query = "SELECT rbac_id,obj_id,obj_type ".
260  $locate.
261  "FROM il_meta_entity ".
262  $where." ".$and.' ';
263 
264  $res = $this->db->query($query);
265  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
266  {
267  $found = $this->__prepareFound($row);
268  if(!in_array(0,$found))
269  {
270  $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
271  }
272  }
273 
274  return $this->search_result;
275  }
276 
277 
278 
280  {
281  $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_requirement ";
282 
283  if(!strlen($where = $this->__createRequirementWhere()))
284  {
285  return false;
286  }
287  $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
288  $query = $query.$where.$and;
289  $res = $this->db->query($query);
290  #var_dump("<pre>",$query,"<pre>");
291  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
292  {
293  $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
294  }
295  return $this->search_result;
296  }
297 
299  {
300  $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_educational ";
301 
302  if(!strlen($where = $this->__createEducationalWhere()))
303  {
304  return false;
305  }
306  $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
307  $query = $query.$where.$and;
308  $res = $this->db->query($query);
309  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
310  {
311  $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
312  }
313  return $this->search_result;
314  }
315 
317  {
318  if(!$this->options['typ_age_1'] or !$this->options['typ_age_2'])
319  {
320  return false;
321  }
322 
323  $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_typical_age_range ".
324  "WHERE typical_age_range_min >= '".(int) $this->options['typ_age_1']."' ".
325  "AND typical_age_range_max <= '".(int) $this->options['typ_age_2']."'";
326 
327 
328  $res = $this->db->query($query);
329  #var_dump("<pre>",$query,"<pre>");
330  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
331  {
332  $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
333  }
334  return $this->search_result;
335  }
336 
337  function &__searchRights()
338  {
339  $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_rights ";
340 
341  if(!strlen($where = $this->__createRightsWhere()))
342  {
343  return false;
344  }
345  $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
346  $query = $query.$where.$and;
347  $res = $this->db->query($query);
348  #var_dump("<pre>",$query,"<pre>");
349  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
350  {
351  $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
352  }
353  return $this->search_result;
354  }
355 
357  {
358  $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_classification ";
359 
360  if(!strlen($where = $this->__createClassificationWhere()))
361  {
362  return false;
363  }
364  $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
365  $query = $query.$where.$and;
366  $res = $this->db->query($query);
367  #var_dump("<pre>",$query,"<pre>");
368  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
369  {
370  $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
371  }
372  return $this->search_result;
373  }
374 
375  function &__searchTaxon()
376  {
377  $this->setFields(array('taxon'));
378 
379  $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
380  $where = $this->__createTaxonWhereCondition();
381  $locate = $this->__createLocateString();
382 
383  $query = "SELECT rbac_id,obj_id,obj_type ".
384  $locate.
385  "FROM il_meta_taxon ".
386  $where." ".$and.' ';
387 
388  $res = $this->db->query($query);
389  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
390  {
391  $found = $this->__prepareFound($row);
392  if(!in_array(0,$found))
393  {
394  $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
395  }
396  }
397 
398  return $this->search_result;
399  }
400 
401  function &__searchKeyword($a_in_classification = false)
402  {
403  $this->setFields(array('keyword'));
404 
405  $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
406  if($a_in_classification)
407  {
408  $and .= " AND parent_type = 'meta_classification' ";
409  }
410  $where = $this->__createKeywordWhereCondition();
411  $locate = $this->__createLocateString();
412 
413  $query = "SELECT rbac_id,obj_id,obj_type ".
414  $locate.
415  "FROM il_meta_keyword ".
416  $where." ".$and.' ';
417 
418  $res = $this->db->query($query);
419  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
420  {
421  $found = $this->__prepareFound($row);
422  if(!in_array(0,$found) or !$a_in_classification)
423  {
424  $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
425  }
426  }
427 
428  return $this->search_result;
429  }
430  function &__searchLifecycle()
431  {
432  global $ilDB;
433 
434  $this->setFields(array('meta_version'));
435 
436  if($this->options['lom_version'])
437  {
438  $where = $this->__createLifecycleWhereCondition();
439  $locate = $this->__createLocateString();
440  }
441  else
442  {
443  $where = "WHERE 1 = 1 ";
444  }
445  $and = ("AND obj_type ".$this->__getInStatement($this->getFilter()));
446 
447  if($this->options['lom_status'])
448  {
449  $and .= (" AND lifecycle_status = ".$ilDB->quote($this->options['lom_status'] ,'text') ."");
450  }
451 
452  $query = "SELECT rbac_id,obj_id,obj_type ".
453  $locate.
454  "FROM il_meta_lifecycle ".
455  $where." ".$and.' ';
456 
457  $res = $this->db->query($query);
458  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
459  {
460  $found = $this->__prepareFound($row);
461  if(!in_array(0,$found))
462  {
463  $this->search_result->addEntry($row->rbac_id,$row->obj_type,$found,$row->obj_id);
464  }
465  }
466 
467  return $this->search_result;
468  }
469 
470  function &__searchFormat()
471  {
472  global $ilDB;
473 
474  if(!$this->options['lom_format'])
475  {
476  return false;
477  }
478 
479  $query = "SELECT rbac_id,obj_id,obj_type FROM il_meta_format ".
480  "WHERE format LIKE(".$ilDB->quote($this->options['lom_format']).") ".
481  "AND obj_type ".$this->__getInStatement($this->getFilter());
482 
483  $res = $this->db->query($query);
484  #var_dump("<pre>",$query,"<pre>");
485  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
486  {
487  $this->search_result->addEntry($row->rbac_id,$row->obj_type,array(),$row->obj_id);
488  }
489  return $this->search_result;
490  }
491 
492 
494  {
495  global $ilDB;
496 
497  $counter = 0;
498  $where = 'WHERE ';
499 
500 
501  if($this->options['lom_costs'])
502  {
503  $and = $counter++ ? 'AND ' : ' ';
504  $where .= ($and."costs = ".$ilDB->quote($this->options['lom_costs'] ,'text')." ");
505  }
506  if($this->options['lom_copyright'])
507  {
508  $and = $counter++ ? 'AND ' : ' ';
509  $where .= ($and."cpr_and_or = ".$ilDB->quote($this->options['lom_copyright'] ,'text')." ");
510  }
511  return $counter ? $where : '';
512  }
514  {
515  global $ilDB;
516 
517  $counter = 0;
518  $where = 'WHERE ';
519 
520 
521  if($this->options['lom_purpose'])
522  {
523  $and = $counter++ ? 'AND ' : ' ';
524  $where .= ($and."purpose = ".$ilDB->quote($this->options['lom_purpose'])." ");
525  }
526  return $counter ? $where : '';
527  }
529  {
530  global $ilDB;
531 
532  $counter = 0;
533  $where = 'WHERE ';
534 
535 
536  if($this->options['lom_interactivity'])
537  {
538  $and = $counter++ ? 'AND ' : ' ';
539  $where .= ($and."interactivity_type = ".$ilDB->quote($this->options['lom_interactivity'] ,'text')." ");
540  }
541  if($this->options['lom_resource'])
542  {
543  $and = $counter++ ? 'AND ' : ' ';
544  $where .= ($and."learning_resource_type = ".$ilDB->quote($this->options['lom_resource'] ,'text')." ");
545  }
546  if($this->options['lom_user_role'])
547  {
548  $and = $counter++ ? 'AND ' : ' ';
549  $where .= ($and."intended_end_user_role = ".$ilDB->quote($this->options['lom_user_role'] ,'text')." ");
550  }
551  if($this->options['lom_context'])
552  {
553  $and = $counter++ ? 'AND ' : ' ';
554  $where .= ($and."context = ".$ilDB->quote($this->options['lom_context'] ,'text')." ");
555  }
556  if($this->options['lom_level_start'] or $this->options['lom_level_end'])
557  {
558  $and = $counter++ ? 'AND ' : ' ';
559 
560  $fields = $this->__getDifference($this->options['lom_level_start'],$this->options['lom_level_end'],
561  array('VeryLow','Low','Medium','High','VeryHigh'));
562 
563  $where .= ($and."interactivity_level ".$this->__getInStatement($fields));
564  }
565  if($this->options['lom_density_start'] or $this->options['lom_density_end'])
566  {
567  $and = $counter++ ? 'AND ' : ' ';
568 
569  $fields = $this->__getDifference($this->options['lom_density_start'],$this->options['lom_density_end'],
570  array('VeryLow','Low','Medium','High','VeryHigh'));
571 
572  $where .= ($and."semantic_density ".$this->__getInStatement($fields));
573  }
574  if($this->options['lom_difficulty_start'] or $this->options['lom_difficulty_end'])
575  {
576  $and = $counter++ ? 'AND ' : ' ';
577 
578  $fields = $this->__getDifference($this->options['lom_difficulty_start'],$this->options['lom_difficulty_end'],
579  array('VeryEasy','Easy','Medium','Difficult','VeryDifficult'));
580 
581  $where .= ($and."difficulty ".$this->__getInStatement($fields));
582  }
583 
584  return $counter ? $where : '';
585  }
587  {
588  global $ilDB;
589 
590  $counter = 0;
591  $where = 'WHERE ';
592 
593 
594  if($this->options['lom_operating_system'])
595  {
596  $and = $counter++ ? 'AND ' : ' ';
597  $where .= ($and."operating_system_name = ".$ilDB->quote($this->options['lom_operating_system'])." ");
598  }
599  if($this->options['lom_browser'])
600  {
601  $and = $counter++ ? 'AND ' : ' ';
602  $where .= ($and."browser_name = ".$ilDB->quote($this->options['lom_browser'])." ");
603  }
604  return $counter ? $where : '';
605  }
606 
607  function __getDifference($a_val1,$a_val2,$options)
608  {
609  $a_val2 = $a_val2 ? $a_val2 : count($options);
610  // Call again if a > b
611  if($a_val1 > $a_val2)
612  {
613  return $this->__getDifference($a_val2,$a_val1,$options);
614  }
615 
616  $counter = 0;
617  foreach($options as $option)
618  {
619  if($a_val1 > ++$counter)
620  {
621  continue;
622  }
623  if($a_val2 < $counter)
624  {
625  break;
626  }
627  $fields[] = $option;
628  }
629  return $fields ? $fields : array();
630  }
631 
632  function __getInStatement($a_fields)
633  {
634  if(!$a_fields)
635  {
636  return '';
637  }
638  $in = " IN ('";
639  $in .= implode("','",$a_fields);
640  $in .= "') ";
641 
642  return $in;
643  }
644 
645 }
646 ?>
setMode($a_mode)
Define meta elements to search.
__createLocateString()
build locate string in case of AND search
setFields($a_fields)
Set fields to search.
getFilter()
get object type to search in
$counter
__getDifference($a_val1, $a_val2, $options)
if(!is_array($argv)) $options
& __searchKeyword($a_in_classification=false)
Create styles array
The data for the language used.
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
global $ilDB