ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAdvancedSearchGUI.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 
39 include_once 'Services/Search/classes/class.ilSearchBaseGUI.php';
40 include_once 'Services/MetaData/classes/class.ilMDUtilSelect.php';
41 include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchFields.php';
42 
44 {
45  const TYPE_LOM = 1;
46  const TYPE_ADV_MD = 2;
47 
48  protected $last_section = 'adv_search';
49 
50  protected $fields = array();
51 
52 
53 
58  private $options = array();
59 
60  protected $tabs_gui;
61 
67  {
68  global $ilTabs;
69 
70  $this->tabs_gui = $ilTabs;
71 
73 
74  $this->lng->loadLanguageModule('meta');
76 
77  $this->__setSearchOptions($_POST);
78  }
79 
80  function getRootNode()
81  {
82  return ROOT_FOLDER_ID;
83  }
84 
85 
90  function &executeCommand()
91  {
92  global $rbacsystem;
93 
94  $next_class = $this->ctrl->getNextClass($this);
95  $cmd = $this->ctrl->getCmd();
96 
97  switch($next_class)
98  {
99 
100  case 'ilobjectcopygui':
101  $this->prepareOutput();
102 
103  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
104  $cp = new ilObjectCopyGUI($this);
105  $this->ctrl->forwardCommand($cp);
106  break;
107 
108  default:
109  $this->initUserSearchCache();
110  if(!$cmd)
111  {
112  switch($_SESSION['search_last_sub_section'])
113  {
114  case self::TYPE_ADV_MD:
115  $cmd = "showSavedAdvMDResults";
116  break;
117 
118  default:
119  $cmd = "showSavedResults";
120  break;
121  }
122  }
123 
124  $this->prepareOutput();
125  $this->handleCommand($cmd);
126  break;
127  }
128  return true;
129  }
130  function reset()
131  {
132  $this->initSearchType(self::TYPE_LOM);
133  $this->options = array();
134  $this->search_cache->setQuery(array());
135  $this->search_cache->save();
136  $this->showSearch();
137  }
138 
139  function searchInResults()
140  {
141  $this->initSearchType(self::TYPE_LOM);
142  $this->search_mode = 'in_results';
143  $this->search_cache->setResultPageNumber(1);
144  unset($_SESSION['adv_max_page']);
145  $this->performSearch();
146 
147  return true;
148  }
149 
153  protected function remoteSearch()
154  {
155  $this->search_cache->setRoot((int) $_POST['root_id']);
156  $this->search_cache->setResultPageNumber(1);
157  $this->search_cache->setQuery(array('lom_content' => ilUtil::stripSlashes($_POST['queryString'])));
158  $this->search_cache->save();
159 
160  $this->options = $this->search_cache->getQuery();
161  $this->options['type'] = 'all';
162 
163  $this->performSearch();
164  }
165 
166 
167 
168  function performSearch()
169  {
170  global $ilUser;
171 
172  $this->initSearchType(self::TYPE_LOM);
173 
174  if(!isset($_GET['page_number']) and $this->search_mode != 'in_results' )
175  {
176  unset($_SESSION['adv_max_page']);
177  $this->search_cache->deleteCachedEntries();
178  }
179 
180  if(isset($_POST['query']))
181  {
182  $this->search_cache->setQuery($_POST['query']);
183  }
184 
185 
186  include_once 'Services/Search/classes/class.ilSearchResult.php';
187  $res =& new ilSearchResult();
188 
189  if($res_con =& $this->__performContentSearch())
190  {
191  $this->__storeEntries($res,$res_con);
192  }
193  if($res_lan =& $this->__performLanguageSearch())
194  {
195  $this->__storeEntries($res,$res_lan);
196  }
197  if($res_gen =& $this->__performGeneralSearch())
198  {
199  $this->__storeEntries($res,$res_gen);
200  }
201  if($res_lif =& $this->__performLifecycleSearch())
202  {
203  $this->__storeEntries($res,$res_lif);
204  }
205  if($res_con =& $this->__performContributeSearch())
206  {
207  $this->__storeEntries($res,$res_con);
208  }
209  if($res_ent =& $this->__performEntitySearch())
210  {
211  $this->__storeEntries($res,$res_ent);
212  }
213  if($res_req =& $this->__performRequirementSearch())
214  {
215  $this->__storeEntries($res,$res_req);
216  }
217  if($res_for =& $this->__performFormatSearch())
218  {
219  $this->__storeEntries($res,$res_for);
220  }
221  if($res_edu =& $this->__performEducationalSearch())
222  {
223  $this->__storeEntries($res,$res_edu);
224  }
225  if($res_typ =& $this->__performTypicalAgeRangeSearch())
226  {
227  $this->__storeEntries($res,$res_typ);
228  }
229  if($res_rig =& $this->__performRightsSearch())
230  {
231  $this->__storeEntries($res,$res_rig);
232  }
233  if($res_cla =& $this->__performClassificationSearch())
234  {
235  $this->__storeEntries($res,$res_cla);
236  }
237  if($res_tax =& $this->__performTaxonSearch())
238  {
239  $this->__storeEntries($res,$res_tax);
240  }
241  if($res_key =& $this->__performKeywordSearch())
242  {
243  $this->__storeEntries($res,$res_key);
244  }
245  if($this->search_mode == 'in_results')
246  {
247  include_once 'Services/Search/classes/class.ilSearchResult.php';
248 
249  $old_result_obj = new ilSearchResult($ilUser->getId());
250  $old_result_obj->read(ADVANCED_MD_SEARCH);
251 
252  $res->diffEntriesFromResult($old_result_obj);
253  }
254 
255 
256  $res->filter($this->getRootNode(),true);
257  $res->save();
258  $this->showSearch();
259 
260  if(!count($res->getResults()))
261  {
262  ilUtil::sendInfo($this->lng->txt('search_no_match'));
263  }
264 
265  if($res->isLimitReached())
266  {
267  #$message = sprintf($this->lng->txt('search_limit_reached'),$this->settings->getMaxHits());
268  #ilUtil::sendInfo($message);
269  }
270 
271  $this->addPager($res,'adv_max_page');
272 
273  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
275  $presentation->setResults($res->getResultsForPresentation());
276  $presentation->setPreviousNext($this->prev_link, $this->next_link);
277 
278  if($presentation->render())
279  {
280  $this->tpl->setVariable('RESULTS',$presentation->getHTML(true));
281  }
282  return true;
283  }
284 
290  protected function initAdvancedMetaDataForm()
291  {
292  if(is_object($this->form))
293  {
294  return $this->form;
295  }
296 
297  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
298  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
299  $this->form = new ilPropertyFormGUI();
300  $this->form->setFormAction($this->ctrl->getFormAction($this,'performAdvMDSearch'));
301  $this->form->setTitle($this->lng->txt('adv_md_search_title'));
302  $this->form->addCommandButton('performAdvMDSearch',$this->lng->txt('search'));
303  #$this->form->setSubformMode('right');
304 
305  $content = new ilTextInputGUI($this->lng->txt('meta_title').'/'.
306  $this->lng->txt('meta_keyword').'/'.
307  $this->lng->txt('meta_description'),'title');
308  $content->setValue($this->options['title']);
309  $content->setSize(30);
310  $content->setMaxLength(255);
311 // $content->setSubformMode('right');
312  $group = new ilRadioGroupInputGUI('','title_ao');
313  $group->setValue($this->options['title_ao']);
314  $radio_option = new ilRadioOption($this->lng->txt("search_any_word"),0);
315  $group->addOption($radio_option);
316  $radio_option = new ilRadioOption($this->lng->txt("search_all_words"),1);
317  $group->addOption($radio_option);
318  $content->addSubItem($group);
319  $this->form->addItem($content);
320 
321  $type = new ilSelectInputGUI($this->lng->txt('type'),'type');
322  $options['adv_all'] = $this->lng->txt('search_any');
323  foreach(ilAdvancedMDRecord::_getActivatedObjTypes() as $obj_type)
324  {
325  $options[$obj_type] = $this->lng->txt('objs_'.$obj_type);
326  }
327  $type->setOptions($options);
328  $type->setValue($this->options['type']);
329  $this->form->addItem($type);
330 
331  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php');
333  $record_gui->setPropertyForm($this->form);
334  $record_gui->setSearchValues($this->options);
335  $record_gui->parse();
336  }
337 
343  protected function performAdvMDSearch()
344  {
345  global $ilUser;
346 
347  $this->initSearchType(self::TYPE_ADV_MD);
348  if(!isset($_GET['page_number']) and $this->search_mode != 'in_results' )
349  {
350  unset($_SESSION['adv_max_page']);
351  $this->search_cache->delete();
352  }
353 
354  include_once 'Services/Search/classes/class.ilSearchResult.php';
355  $res =& new ilSearchResult();
356 
357  if($res_tit =& $this->__performTitleSearch())
358  {
359  $this->__storeEntries($res,$res_tit);
360  }
361  $this->searchAdvancedMD($res);
362 
363  if($this->search_mode == 'in_results')
364  {
365  include_once 'Services/Search/classes/class.ilSearchResult.php';
366 
367  $old_result_obj = new ilSearchResult($ilUser->getId());
368  $old_result_obj->read(ADVANCED_MD_SEARCH);
369 
370  $res->diffEntriesFromResult($old_result_obj);
371  }
372 
373 
374  $res->filter($this->getRootNode(),true);
375  $res->save();
376  $this->showAdvMDSearch();
377 
378  if(!count($res->getResults()))
379  {
380  ilUtil::sendInfo($this->lng->txt('search_no_match'));
381  }
382 
383  if($res->isLimitReached())
384  {
385  #$message = sprintf($this->lng->txt('search_limit_reached'),$this->settings->getMaxHits());
386  #ilUtil::sendInfo($message);
387  }
388 
389  $this->addPager($res,'adv_max_page');
390 
391  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
393  $presentation->setResults($res->getResultsForPresentation());
394  $presentation->setPreviousNext($this->prev_link, $this->next_link);
395 
396  if($presentation->render())
397  {
398  $this->tpl->setVariable('RESULTS',$presentation->getHTML(true));
399  }
400  return true;
401 
402  }
403 
404 
410  public function showAdvMDSearch()
411  {
412  if(isset($_SESSION['search_adv_md']))
413  {
414  $this->options = $_SESSION['search_adv_md'];
415  }
416  $this->setSubTabs();
417  $this->tabs_gui->setSubTabActive('search_adv_md');
418 
419  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.advanced_adv_search.html','Services/Search');
420 
421  $this->initAdvancedMetaDataForm();
422  $this->tpl->setVariable('SEARCH_FORM',$this->form->getHTML());
423  return true;
424  }
425 
429  protected function initFormSearch()
430  {
431  global $tree;
432 
433  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
434 
435  $this->form = new ilPropertyFormGUI();
436  $this->form->setFormAction($this->ctrl->getFormAction($this,'performSearch'));
437  $this->form->setTitle($this->lng->txt('search_advanced'));
438  $this->form->addCommandButton('performSearch',$this->lng->txt('search'));
439  $this->form->addCommandButton('reset',$this->lng->txt('reset'));
440 
441  foreach($this->fields->getActiveSections() as $definition)
442  {
443  if($definition['name'] != 'default')
444  {
446  $section->setTitle($definition['name']);
447  $this->form->addItem($section);
448  }
449 
450  foreach($definition['fields'] as $field_name)
451  {
452  if(is_object($element = $this->fields->getFormElement($this->search_cache->getQuery(),$field_name)))
453  {
454  $this->form->addItem($element);
455  }
456  }
457  }
458  return true;
459  }
460 
461 
462 
463  function showSearch()
464  {
465  global $ilLocator;
466 
467  $this->setSubTabs();
468  $this->tabs_gui->setSubTabActive('search_lom');
469 
470  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.advanced_search.html','Services/Search');
471 
472  $this->initFormSearch();
473  $this->tpl->setVariable('SEARCH_FORM',$this->form->getHTML());
474  return true;
475  }
476 
477  function prepareOutput()
478  {
479  global $ilTabs;
480 
482 
483 // $this->tpl->addBlockFile("TABS","tabs","tpl.tabs.html");
484 
485  $ilTabs->addTab("search", $this->lng->txt("search"),
486  $this->ctrl->getLinkTargetByClass('ilsearchgui'));
487  $ilTabs->addTab("adv_search", $this->lng->txt("search_advanced"),
488  $this->ctrl->getLinkTarget($this));
489  $ilTabs->activateTab("adv_search");
490 
491  /*$this->tpl->setCurrentBlock("tab");
492  $this->tpl->setVariable("TAB_TYPE","tabinactive");
493  $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('ilsearchgui'));
494  $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search"));
495  $this->tpl->parseCurrentBlock();
496 
497  $this->tpl->setCurrentBlock("tab");
498  $this->tpl->setVariable("TAB_TYPE","tabactive");
499  $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTarget($this));
500  $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_advanced"));
501  $this->tpl->parseCurrentBlock();*/
502  }
503 
504  // PRIVATE
511  private function showSavedAdvMDResults()
512  {
513  global $ilUser;
514 
515  // Read old result sets
516  include_once 'Services/Search/classes/class.ilSearchResult.php';
517 
518  $this->initSearchType(self::TYPE_ADV_MD);
519  $result_obj = new ilSearchResult($ilUser->getId());
520  $result_obj->read(ADVANCED_MD_SEARCH);
521 
522  $this->showAdvMDSearch();
523 
524  // Show them
525  if(count($result_obj->getResults()))
526  {
527  $this->addPager($result_obj,'adv_max_page');
528 
529  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
531  $presentation->setResults($result_obj->getResultsForPresentation());
532  $presentation->setPreviousNext($this->prev_link, $this->next_link);
533 
534  if($presentation->render())
535  {
536  $this->tpl->setVariable('RESULTS',$presentation->getHTML(true));
537  }
538  }
539 
540  return true;
541  }
542 
543 
544  function showSavedResults()
545  {
546  global $ilUser;
547 
548  // Read old result sets
549  include_once 'Services/Search/classes/class.ilSearchResult.php';
550 
551  $this->initSearchType(self::TYPE_LOM);
552  $result_obj = new ilSearchResult($ilUser->getId());
553  $result_obj->read(ADVANCED_SEARCH);
554 
555  $this->showSearch();
556 
557  // Show them
558  if(count($result_obj->getResults()))
559  {
560  $this->addPager($result_obj,'adv_max_page');
561 
562  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
564  $presentation->setResults($result_obj->getResultsForPresentation());
565  $presentation->setPreviousNext($this->prev_link, $this->next_link);
566 
567  if($presentation->render())
568  {
569  $this->tpl->setVariable('RESULTS',$presentation->getHTML(true));
570  }
571  }
572 
573  return true;
574  }
575 
577  {
578  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
579  include_once 'Services/Search/classes/class.ilQueryParser.php';
580  include_once 'Services/Search/classes/class.ilSearchResult.php';
581 
582  if(!$this->options['lom_content'])
583  {
584  return false;
585  }
586 
587  $res =& new ilSearchResult();
588 
589  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_content']));
590  #$query_parser->setCombination($this->options['content_ao']);
591  $query_parser->setCombination(QP_COMBINATION_OR);
592  $query_parser->parse();
593 
594  if($this->options['type'] == 'all' or $this->options['type'] == 'lms')
595  {
596  // LM content search
597  $lm_search =& ilObjectSearchFactory::_getLMContentSearchInstance($query_parser);
598  $res_cont =& $lm_search->performSearch();
599  $res->mergeEntries($res_cont);
600  }
601  if($this->options['type'] == 'all' or $this->options['type'] == 'tst')
602  {
603  $tst_search =& ilObjectSearchFactory::_getTestSearchInstance($query_parser);
604  $res_tes =& $tst_search->performSearch();
605  $res->mergeEntries($res_tes);
606  }
607  if($this->options['type'] == 'all' or $this->options['type'] == 'mep')
608  {
609  $med_search =& ilObjectSearchFactory::_getMediaPoolSearchInstance($query_parser);
610  $res_med =& $med_search->performSearch();
611  $res->mergeEntries($res_med);
612  }
613  if($this->options['type'] == 'all' or $this->options['type'] == 'glo')
614  {
616  $res_glo =& $glo_search->performSearch();
617  $res->mergeEntries($res_glo);
618  }
619  if($this->options['type'] == 'all' or $this->options['type'] == 'webr')
620  {
621  $web_search =& ilObjectSearchFactory::_getWebresourceSearchInstance($query_parser);
622  $res_web =& $web_search->performSearch();
623  $res->mergeEntries($res_web);
624  }
625  if($tit_res = $this->__performTitleSearch())
626  {
627  $res->mergeEntries($tit_res);
628  }
629 
630  return $res;
631  }
632 
633 
635  {
636  if(!$this->options['lom_content'])
637  {
638  return false;
639  }
640 
641  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
642  include_once 'Services/Search/classes/class.ilQueryParser.php';
643 
644  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_content']));
645  #$query_parser->setCombination($this->options['title_ao']);
646  $query_parser->setCombination(QP_COMBINATION_OR);
647  $query_parser->parse();
648  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
649 
650  $meta_search->setFilter($this->filter);
651  $meta_search->setMode('title_description');
652  $meta_search->setOptions($this->options);
653  $res_tit =& $meta_search->performSearch();
654 
655  $meta_search->setMode('keyword_all');
656  $res_key =& $meta_search->performSearch();
657 
658  // merge them
659  $res_tit->mergeEntries($res_key);
660 
661 
662  return $res_tit;
663  }
664 
665 
666 
668  {
669  if(!$this->options['lom_coverage'] and !$this->options['lom_structure'])
670  {
671  return false;
672  }
673 
674  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
675  include_once 'Services/Search/classes/class.ilQueryParser.php';
676 
677  if($this->options['lom_coverage'])
678  {
679  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_coverage']));
680  #$query_parser->setCombination($this->options['coverage_ao']);
681  $query_parser->setCombination(QP_COMBINATION_OR);
682  $query_parser->parse();
683  }
684  else
685  {
686  $query_parser = new ilQueryParser('');
687  }
688  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
689  $meta_search->setFilter($this->filter);
690  $meta_search->setMode('general');
691  $meta_search->setOptions($this->options);
692  $res =& $meta_search->performSearch();
693 
694  return $res;
695  }
696 
698  {
699  // Return if 'any'
700  if(!$this->options['lom_status'] and !$this->options['lom_version'])
701  {
702  return false;
703  }
704  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
705  include_once 'Services/Search/classes/class.ilQueryParser.php';
706 
707  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_version']));
708  #$query_parser->setCombination($this->options['version_ao']);
709  $query_parser->setCombination(QP_COMBINATION_OR);
710  $query_parser->parse();
711 
712  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
713  $meta_search->setFilter($this->filter);
714  $meta_search->setMode('lifecycle');
715  $meta_search->setOptions($this->options);
716  $res =& $meta_search->performSearch();
717 
718  return $res;
719  }
721  {
722  if(!$this->options['lom_language'])
723  {
724  return false;
725  }
726  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
727  include_once 'Services/Search/classes/class.ilQueryParser.php';
728 
729 
731  $meta_search->setFilter($this->filter);
732  $meta_search->setMode('language');
733  $meta_search->setOptions($this->options);
734  $res =& $meta_search->performSearch();
735 
736  return $res;
737  }
739  {
740  if(!strlen($this->options['lom_role']))
741  {
742  return false;
743  }
744  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
745  include_once 'Services/Search/classes/class.ilQueryParser.php';
746 
747 
749  $meta_search->setFilter($this->filter);
750  $meta_search->setMode('contribute');
751  $meta_search->setOptions($this->options);
752  $res =& $meta_search->performSearch();
753 
754  return $res;
755  }
757  {
758  // Return if 'any'
759  if(!$this->options['lom_role_entry'])
760  {
761  return false;
762  }
763 
764  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
765  include_once 'Services/Search/classes/class.ilQueryParser.php';
766 
767  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_role_entry']));
768  #$query_parser->setCombination($this->options['entity_ao']);
769  $query_parser->setCombination(QP_COMBINATION_OR);
770  $query_parser->parse();
771 
772  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
773  $meta_search->setFilter($this->filter);
774  $meta_search->setMode('entity');
775  $meta_search->setOptions($this->options);
776  $res =& $meta_search->performSearch();
777 
778  return $res;
779  }
780 
781 
783  {
784  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
785  include_once 'Services/Search/classes/class.ilQueryParser.php';
786 
787 
789  $meta_search->setFilter($this->filter);
790  $meta_search->setMode('requirement');
791  $meta_search->setOptions($this->options);
792  $res =& $meta_search->performSearch();
793 
794  return $res;
795  }
797  {
798  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
799  include_once 'Services/Search/classes/class.ilQueryParser.php';
800 
801 
803  $meta_search->setFilter($this->filter);
804  $meta_search->setMode('format');
805  $meta_search->setOptions($this->options);
806  $res =& $meta_search->performSearch();
807 
808  return $res;
809  }
811  {
812  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
813  include_once 'Services/Search/classes/class.ilQueryParser.php';
814 
815 
817  $meta_search->setFilter($this->filter);
818  $meta_search->setMode('educational');
819  $meta_search->setOptions($this->options);
820  $res =& $meta_search->performSearch();
821 
822  return $res;
823  }
825  {
826  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
827  include_once 'Services/Search/classes/class.ilQueryParser.php';
828 
829 
831  $meta_search->setFilter($this->filter);
832  $meta_search->setMode('typical_age_range');
833  $meta_search->setOptions($this->options);
834  $res =& $meta_search->performSearch();
835 
836  return $res;
837  }
839  {
840  if(!$this->options['lom_copyright'] and !$this->options['lom_costs'])
841  {
842  return false;
843  }
844  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
845  include_once 'Services/Search/classes/class.ilQueryParser.php';
846 
847 
849  $meta_search->setFilter($this->filter);
850  $meta_search->setMode('rights');
851  $meta_search->setOptions($this->options);
852  $res =& $meta_search->performSearch();
853 
854  return $res;
855  }
856 
858  {
859  // Return if 'any'
860  if(!$this->options['lom_purpose'])
861  {
862  return false;
863  }
864  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
865  include_once 'Services/Search/classes/class.ilQueryParser.php';
866 
867 
869  $meta_search->setFilter($this->filter);
870  $meta_search->setMode('classification');
871  $meta_search->setOptions($this->options);
872  $res =& $meta_search->performSearch();
873 
874  return $res;
875  }
876 
878  {
879  // Return if 'any'
880  if(!$this->options['lom_taxon'])
881  {
882  return false;
883  }
884  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
885  include_once 'Services/Search/classes/class.ilQueryParser.php';
886 
887  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_taxon']));
888  $query_parser->setCombination(QP_COMBINATION_OR);
889  $query_parser->parse();
890 
891  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
892  $meta_search->setFilter($this->filter);
893  $meta_search->setMode('taxon');
894  $meta_search->setOptions($this->options);
895  $res =& $meta_search->performSearch();
896 
897  return $res;
898  }
899 
907  private function searchAdvancedMD($res)
908  {
909  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
910  foreach($_POST as $key => $value)
911  {
912  if(!is_numeric($key))
913  {
914  continue;
915  }
916  if(!$value)
917  {
918  continue;
919  }
920 
922  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
923  include_once 'Services/Search/classes/class.ilQueryParser.php';
924 
925  if($def->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_SELECT)
926  {
927  $value = (int) $value;
928  $options = $def->getFieldValues();
929  if(!isset($options[$value - 1]))
930  {
931  continue;
932  }
933  $value = $options[$value - 1];
934  }
935  if($def->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_DATE)
936  {
937  $start = $this->toUnixTime($_POST['date_start'][$key]['date']);
938  $end = $this->toUnixTime($_POST['date_end'][$key]['date']);
939 
940  }
941  if($def->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_DATETIME)
942  {
943  $start = $this->toUnixTime($_POST['date_start'][$key]['date'],$_POST['date_start'][$key]['time']);
944  $end = $this->toUnixTime($_POST['date_end'][$key]['date'],$_POST['date_end'][$key]['time']);
945  }
946 
947  $query_parser = new ilQueryParser(ilUtil::stripSlashes($value));
948  if($_POST['boolean'][$key] == 1)
949  {
950  $query_parser->setCombination('and');
951  }
952  else
953  {
954  $query_parser->setCombination('or');
955  }
956  $query_parser->parse();
957 
958  $adv_md_search = ilObjectSearchFactory::_getAdvancedMDSearchInstance($query_parser);
959  $adv_md_search->setDefinition($def);
960  $adv_md_search->setTimeRange($start,$end);
961  $adv_md_search->setFilter($this->filter);
962  $res_field = $adv_md_search->performSearch();
963  $this->__storeEntries($res,$res_field);
964 
965  }
966  return $res;
967  }
968 
970  {
971  // Return if 'any'
972  if(!$this->options['lom_keyword'])
973  {
974  return false;
975  }
976  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
977  include_once 'Services/Search/classes/class.ilQueryParser.php';
978 
979  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_keyword']));
980  #$query_parser->setCombination($this->options['keyword_ao']);
981  $query_parser->setCombination(QP_COMBINATION_OR);
982  $query_parser->parse();
983 
984  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
985  $meta_search->setFilter($this->filter);
986  $meta_search->setMode('keyword');
987  $meta_search->setOptions($this->options);
988  $res =& $meta_search->performSearch();
989 
990  return $res;
991  }
992 
993  function __setSearchOptions(&$post_vars)
994  {
995  if(isset($_POST['cmd']['performSearch']))
996  {
997  $this->options = $_SESSION['search_adv'] = $_POST['query'];
998  }
999  elseif(isset($_POST['cmd']['performAdvMDSearch']))
1000  {
1001  $this->options = $_SESSION['search_adv_md'] = $_POST;
1002  }
1003  else
1004  {
1005  $this->options = $_SESSION['search_adv'];
1006  }
1007 
1008  $_POST['result'] = $_POST['id'];
1009 
1010  $this->filter = array();
1011 
1012  $this->options['type'] = 'all';
1013  switch($this->options['type'])
1014  {
1015  case 'cat':
1016  $this->filter[] = 'cat';
1017  break;
1018 
1019  case 'webr':
1020  $this->filter[] = 'webr';
1021  break;
1022 
1023  case 'lms':
1024  $this->filter[] = 'lm';
1025  $this->filter[] = 'dbk';
1026  $this->filter[] = 'pg';
1027  $this->filter[] = 'st';
1028  $this->filter[] = 'sahs';
1029  $this->filter[] = 'htlm';
1030  break;
1031 
1032  case 'glo':
1033  $this->filter[] = 'glo';
1034  break;
1035 
1036  case 'tst':
1037  $this->filter[] = 'tst';
1038  $this->filter[] = 'svy';
1039  $this->filter[] = 'qpl';
1040  $this->filter[] = 'spl';
1041  break;
1042 
1043  case 'mep':
1044  $this->filter[] = 'mep';
1045  break;
1046 
1047  case 'crs':
1048  $this->filter[] = 'crs';
1049  break;
1050 
1051  case 'file':
1052  $this->filter[] = 'file';
1053  break;
1054 
1055  case 'adv_all':
1056  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
1058  break;
1059 
1060  case 'all':
1061  default:
1062  $this->filter[] = 'webr';
1063  $this->filter[] = 'crs';
1064  $this->filter[] = 'mep';
1065  $this->filter[] = 'tst';
1066  $this->filter[] = 'svy';
1067  $this->filter[] = 'qpl';
1068  $this->filter[] = 'spl';
1069  $this->filter[] = 'glo';
1070  $this->filter[] = 'lm';
1071  $this->filter[] = 'dbk';
1072  $this->filter[] = 'pg';
1073  $this->filter[] = 'st';
1074  $this->filter[] = 'sahs';
1075  $this->filter[] = 'htlm';
1076  $this->filter[] = 'file';
1077  }
1078  return true;
1079  }
1080 
1082  {
1083  $options = array('all' => $this->lng->txt('search_any'),
1084  'crs' => $this->lng->txt('objs_crs'),
1085  'lms' => $this->lng->txt('learning_resources'),
1086  'glo' => $this->lng->txt('objs_glo'),
1087  'mep' => $this->lng->txt('objs_mep'),
1088  'tst' => $this->lng->txt('search_tst_svy'),
1089  'file'=> $this->lng->txt('objs_file'),
1090  'webr' => $this->lng->txt('objs_webr'));
1091 
1092 
1093  return ilUtil::formSelect($this->options['type'],'search_adv[type]',$options,false,true);
1094  }
1095 
1096 
1097  function __storeEntries($res,$new_res)
1098  {
1099  if($this->stored == false)
1100  {
1101  $res->mergeEntries($new_res);
1102  $this->stored = true;
1103 
1104  return true;
1105  }
1106  else
1107  {
1108  $res->intersectEntries($new_res);
1109  return true;
1110  }
1111  }
1112 
1119  private function initUserSearchCache()
1120  {
1121  global $ilUser;
1122 
1123  include_once('Services/Search/classes/class.ilUserSearchCache.php');
1124  $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
1125  $this->search_cache->switchSearchType(ilUserSearchCache::ADVANCED_SEARCH);
1126  if($_GET['page_number'])
1127  {
1128  $this->search_cache->setResultPageNumber((int) $_GET['page_number']);
1129  }
1130  if($_POST['cmd']['performSearch'])
1131  {
1132  $this->search_cache->setQuery(ilUtil::stripSlashes($_POST['query']['lomContent']));
1133  $this->search_cache->save();
1134  }
1135  }
1136 
1143  public function setSubTabs()
1144  {
1145  global $ilTabs;
1146 
1147  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1149  {
1150  return true;
1151  }
1152  $ilTabs->addSubTabTarget('search_lom',$this->ctrl->getLinkTarget($this,'showSavedResults'));
1153  #$ilTabs->addSubTabTarget('search_adv_md',$this->ctrl->getLinkTarget($this,'showSavedAdvMDResults'));
1154 
1155  }
1156 
1164  private function toUnixTime($date,$time = array())
1165  {
1166  return mktime($time['h'],$time['m'],0,$date['m'],$date['d'],$date['y']);
1167  }
1168 
1176  private function initSearchType($type)
1177  {
1178  if($type == self::TYPE_LOM)
1179  {
1180  $_SESSION['search_last_sub_section'] = self::TYPE_LOM;
1181  $this->search_cache->switchSearchType(ilUserSearchCache::ADVANCED_SEARCH);
1182  }
1183  else
1184  {
1185  $_SESSION['search_last_sub_section'] = self::TYPE_ADV_MD;
1186  $this->search_cache->switchSearchType(ilUserSearchCache::ADVANCED_MD_SEARCH);
1187  }
1188  }
1189 }
1190 ?>