ILIAS  Release_4_4_x_branch Revision 61816
 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, $ilHelp;
480 
482 
483  $ilHelp->setScreenIdComponent("src");
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 
492  // PRIVATE
499  private function showSavedAdvMDResults()
500  {
501  global $ilUser;
502 
503  // Read old result sets
504  include_once 'Services/Search/classes/class.ilSearchResult.php';
505 
506  $this->initSearchType(self::TYPE_ADV_MD);
507  $result_obj = new ilSearchResult($ilUser->getId());
508  $result_obj->read(ADVANCED_MD_SEARCH);
509 
510  $this->showAdvMDSearch();
511 
512  // Show them
513  if(count($result_obj->getResults()))
514  {
515  $this->addPager($result_obj,'adv_max_page');
516 
517  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
519  $presentation->setResults($result_obj->getResultsForPresentation());
520  $presentation->setPreviousNext($this->prev_link, $this->next_link);
521 
522  if($presentation->render())
523  {
524  $this->tpl->setVariable('RESULTS',$presentation->getHTML(true));
525  }
526  }
527 
528  return true;
529  }
530 
531 
532  function showSavedResults()
533  {
534  global $ilUser;
535 
536  // Read old result sets
537  include_once 'Services/Search/classes/class.ilSearchResult.php';
538 
539  $this->initSearchType(self::TYPE_LOM);
540  $result_obj = new ilSearchResult($ilUser->getId());
541  $result_obj->read(ADVANCED_SEARCH);
542 
543  $this->showSearch();
544 
545  // Show them
546  if(count($result_obj->getResults()))
547  {
548  $this->addPager($result_obj,'adv_max_page');
549 
550  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
552  $presentation->setResults($result_obj->getResultsForPresentation());
553  $presentation->setPreviousNext($this->prev_link, $this->next_link);
554 
555  if($presentation->render())
556  {
557  $this->tpl->setVariable('RESULTS',$presentation->getHTML(true));
558  }
559  }
560 
561  return true;
562  }
563 
565  {
566  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
567  include_once 'Services/Search/classes/class.ilQueryParser.php';
568  include_once 'Services/Search/classes/class.ilSearchResult.php';
569 
570  if(!$this->options['lom_content'])
571  {
572  return false;
573  }
574 
575  $res =& new ilSearchResult();
576 
577  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_content']));
578  #$query_parser->setCombination($this->options['content_ao']);
579  $query_parser->setCombination(QP_COMBINATION_OR);
580  $query_parser->parse();
581 
582  if($this->options['type'] == 'all' or $this->options['type'] == 'lms')
583  {
584  // LM content search
585  $lm_search =& ilObjectSearchFactory::_getLMContentSearchInstance($query_parser);
586  $res_cont =& $lm_search->performSearch();
587  $res->mergeEntries($res_cont);
588  }
589  if($this->options['type'] == 'all' or $this->options['type'] == 'tst')
590  {
591  $tst_search =& ilObjectSearchFactory::_getTestSearchInstance($query_parser);
592  $res_tes =& $tst_search->performSearch();
593  $res->mergeEntries($res_tes);
594  }
595  if($this->options['type'] == 'all' or $this->options['type'] == 'mep')
596  {
597  $med_search =& ilObjectSearchFactory::_getMediaPoolSearchInstance($query_parser);
598  $res_med =& $med_search->performSearch();
599  $res->mergeEntries($res_med);
600  }
601  if($this->options['type'] == 'all' or $this->options['type'] == 'glo')
602  {
604  $res_glo =& $glo_search->performSearch();
605  $res->mergeEntries($res_glo);
606  }
607  if($this->options['type'] == 'all' or $this->options['type'] == 'webr')
608  {
609  $web_search =& ilObjectSearchFactory::_getWebresourceSearchInstance($query_parser);
610  $res_web =& $web_search->performSearch();
611  $res->mergeEntries($res_web);
612  }
613  if($tit_res = $this->__performTitleSearch())
614  {
615  $res->mergeEntries($tit_res);
616  }
617 
618  return $res;
619  }
620 
621 
623  {
624  if(!$this->options['lom_content'])
625  {
626  return false;
627  }
628 
629  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
630  include_once 'Services/Search/classes/class.ilQueryParser.php';
631 
632  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_content']));
633  #$query_parser->setCombination($this->options['title_ao']);
634  $query_parser->setCombination(QP_COMBINATION_OR);
635  $query_parser->parse();
636  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
637 
638  $meta_search->setFilter($this->filter);
639  $meta_search->setMode('title_description');
640  $meta_search->setOptions($this->options);
641  $res_tit =& $meta_search->performSearch();
642 
643  $meta_search->setMode('keyword_all');
644  $res_key =& $meta_search->performSearch();
645 
646  // merge them
647  $res_tit->mergeEntries($res_key);
648 
649 
650  return $res_tit;
651  }
652 
653 
654 
656  {
657  if(!$this->options['lom_coverage'] and !$this->options['lom_structure'])
658  {
659  return false;
660  }
661 
662  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
663  include_once 'Services/Search/classes/class.ilQueryParser.php';
664 
665  if($this->options['lom_coverage'])
666  {
667  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_coverage']));
668  #$query_parser->setCombination($this->options['coverage_ao']);
669  $query_parser->setCombination(QP_COMBINATION_OR);
670  $query_parser->parse();
671  }
672  else
673  {
674  $query_parser = new ilQueryParser('');
675  }
676  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
677  $meta_search->setFilter($this->filter);
678  $meta_search->setMode('general');
679  $meta_search->setOptions($this->options);
680  $res =& $meta_search->performSearch();
681 
682  return $res;
683  }
684 
686  {
687  // Return if 'any'
688  if(!$this->options['lom_status'] and !$this->options['lom_version'])
689  {
690  return false;
691  }
692  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
693  include_once 'Services/Search/classes/class.ilQueryParser.php';
694 
695  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_version']));
696  #$query_parser->setCombination($this->options['version_ao']);
697  $query_parser->setCombination(QP_COMBINATION_OR);
698  $query_parser->parse();
699 
700  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
701  $meta_search->setFilter($this->filter);
702  $meta_search->setMode('lifecycle');
703  $meta_search->setOptions($this->options);
704  $res =& $meta_search->performSearch();
705 
706  return $res;
707  }
709  {
710  if(!$this->options['lom_language'])
711  {
712  return false;
713  }
714  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
715  include_once 'Services/Search/classes/class.ilQueryParser.php';
716 
717 
719  $meta_search->setFilter($this->filter);
720  $meta_search->setMode('language');
721  $meta_search->setOptions($this->options);
722  $res =& $meta_search->performSearch();
723 
724  return $res;
725  }
727  {
728  if(!strlen($this->options['lom_role']))
729  {
730  return false;
731  }
732  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
733  include_once 'Services/Search/classes/class.ilQueryParser.php';
734 
735 
737  $meta_search->setFilter($this->filter);
738  $meta_search->setMode('contribute');
739  $meta_search->setOptions($this->options);
740  $res =& $meta_search->performSearch();
741 
742  return $res;
743  }
745  {
746  // Return if 'any'
747  if(!$this->options['lom_role_entry'])
748  {
749  return false;
750  }
751 
752  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
753  include_once 'Services/Search/classes/class.ilQueryParser.php';
754 
755  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_role_entry']));
756  #$query_parser->setCombination($this->options['entity_ao']);
757  $query_parser->setCombination(QP_COMBINATION_OR);
758  $query_parser->parse();
759 
760  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
761  $meta_search->setFilter($this->filter);
762  $meta_search->setMode('entity');
763  $meta_search->setOptions($this->options);
764  $res =& $meta_search->performSearch();
765 
766  return $res;
767  }
768 
769 
771  {
772  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
773  include_once 'Services/Search/classes/class.ilQueryParser.php';
774 
775 
777  $meta_search->setFilter($this->filter);
778  $meta_search->setMode('requirement');
779  $meta_search->setOptions($this->options);
780  $res =& $meta_search->performSearch();
781 
782  return $res;
783  }
785  {
786  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
787  include_once 'Services/Search/classes/class.ilQueryParser.php';
788 
789 
791  $meta_search->setFilter($this->filter);
792  $meta_search->setMode('format');
793  $meta_search->setOptions($this->options);
794  $res =& $meta_search->performSearch();
795 
796  return $res;
797  }
799  {
800  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
801  include_once 'Services/Search/classes/class.ilQueryParser.php';
802 
803 
805  $meta_search->setFilter($this->filter);
806  $meta_search->setMode('educational');
807  $meta_search->setOptions($this->options);
808  $res =& $meta_search->performSearch();
809 
810  return $res;
811  }
813  {
814  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
815  include_once 'Services/Search/classes/class.ilQueryParser.php';
816 
817 
819  $meta_search->setFilter($this->filter);
820  $meta_search->setMode('typical_age_range');
821  $meta_search->setOptions($this->options);
822  $res =& $meta_search->performSearch();
823 
824  return $res;
825  }
827  {
828  if(!$this->options['lom_copyright'] and !$this->options['lom_costs'])
829  {
830  return false;
831  }
832  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
833  include_once 'Services/Search/classes/class.ilQueryParser.php';
834 
835 
837  $meta_search->setFilter($this->filter);
838  $meta_search->setMode('rights');
839  $meta_search->setOptions($this->options);
840  $res =& $meta_search->performSearch();
841 
842  return $res;
843  }
844 
846  {
847  // Return if 'any'
848  if(!$this->options['lom_purpose'])
849  {
850  return false;
851  }
852  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
853  include_once 'Services/Search/classes/class.ilQueryParser.php';
854 
855 
857  $meta_search->setFilter($this->filter);
858  $meta_search->setMode('classification');
859  $meta_search->setOptions($this->options);
860  $res =& $meta_search->performSearch();
861 
862  return $res;
863  }
864 
866  {
867  // Return if 'any'
868  if(!$this->options['lom_taxon'])
869  {
870  return false;
871  }
872  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
873  include_once 'Services/Search/classes/class.ilQueryParser.php';
874 
875  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_taxon']));
876  $query_parser->setCombination(QP_COMBINATION_OR);
877  $query_parser->parse();
878 
879  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
880  $meta_search->setFilter($this->filter);
881  $meta_search->setMode('taxon');
882  $meta_search->setOptions($this->options);
883  $res =& $meta_search->performSearch();
884 
885  return $res;
886  }
887 
895  private function searchAdvancedMD($res)
896  {
897  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
898  foreach($_POST as $key => $value)
899  {
900  if(!is_numeric($key))
901  {
902  continue;
903  }
904  if(!$value)
905  {
906  continue;
907  }
908 
910  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
911  include_once 'Services/Search/classes/class.ilQueryParser.php';
912 
913  if($def->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_SELECT)
914  {
915  $value = (int) $value;
916  $options = $def->getFieldValues();
917  if(!isset($options[$value - 1]))
918  {
919  continue;
920  }
921  $value = $options[$value - 1];
922  }
923  if($def->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_DATE)
924  {
925  $start = $this->toUnixTime($_POST['date_start'][$key]['date']);
926  $end = $this->toUnixTime($_POST['date_end'][$key]['date']);
927 
928  }
929  if($def->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_DATETIME)
930  {
931  $start = $this->toUnixTime($_POST['date_start'][$key]['date'],$_POST['date_start'][$key]['time']);
932  $end = $this->toUnixTime($_POST['date_end'][$key]['date'],$_POST['date_end'][$key]['time']);
933  }
934 
935  $query_parser = new ilQueryParser(ilUtil::stripSlashes($value));
936  if($_POST['boolean'][$key] == 1)
937  {
938  $query_parser->setCombination('and');
939  }
940  else
941  {
942  $query_parser->setCombination('or');
943  }
944  $query_parser->parse();
945 
946  $adv_md_search = ilObjectSearchFactory::_getAdvancedMDSearchInstance($query_parser);
947  $adv_md_search->setDefinition($def);
948  $adv_md_search->setTimeRange($start,$end);
949  $adv_md_search->setFilter($this->filter);
950  $res_field = $adv_md_search->performSearch();
951  $this->__storeEntries($res,$res_field);
952 
953  }
954  return $res;
955  }
956 
958  {
959  // Return if 'any'
960  if(!$this->options['lom_keyword'])
961  {
962  return false;
963  }
964  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
965  include_once 'Services/Search/classes/class.ilQueryParser.php';
966 
967  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_keyword']));
968  #$query_parser->setCombination($this->options['keyword_ao']);
969  $query_parser->setCombination(QP_COMBINATION_OR);
970  $query_parser->parse();
971 
972  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
973  $meta_search->setFilter($this->filter);
974  $meta_search->setMode('keyword');
975  $meta_search->setOptions($this->options);
976  $res =& $meta_search->performSearch();
977 
978  return $res;
979  }
980 
981  function __setSearchOptions(&$post_vars)
982  {
983  if(isset($_POST['cmd']['performSearch']))
984  {
985  $this->options = $_SESSION['search_adv'] = $_POST['query'];
986  }
987  elseif(isset($_POST['cmd']['performAdvMDSearch']))
988  {
989  $this->options = $_SESSION['search_adv_md'] = $_POST;
990  }
991  else
992  {
993  $this->options = $_SESSION['search_adv'];
994  }
995 
996  $_POST['result'] = $_POST['id'];
997 
998  $this->filter = array();
999 
1000  $this->options['type'] = 'all';
1001  switch($this->options['type'])
1002  {
1003  case 'cat':
1004  $this->filter[] = 'cat';
1005  break;
1006 
1007  case 'webr':
1008  $this->filter[] = 'webr';
1009  break;
1010 
1011  case 'lms':
1012  $this->filter[] = 'lm';
1013  $this->filter[] = 'dbk';
1014  $this->filter[] = 'pg';
1015  $this->filter[] = 'st';
1016  $this->filter[] = 'sahs';
1017  $this->filter[] = 'htlm';
1018  break;
1019 
1020  case 'glo':
1021  $this->filter[] = 'glo';
1022  break;
1023 
1024  case 'tst':
1025  $this->filter[] = 'tst';
1026  $this->filter[] = 'svy';
1027  $this->filter[] = 'qpl';
1028  $this->filter[] = 'spl';
1029  break;
1030 
1031  case 'mep':
1032  $this->filter[] = 'mep';
1033  break;
1034 
1035  case 'crs':
1036  $this->filter[] = 'crs';
1037  break;
1038 
1039  case 'file':
1040  $this->filter[] = 'file';
1041  break;
1042 
1043  case 'adv_all':
1044  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
1046  break;
1047 
1048  case 'all':
1049  default:
1050  $this->filter[] = 'webr';
1051  $this->filter[] = 'crs';
1052  $this->filter[] = 'mep';
1053  $this->filter[] = 'tst';
1054  $this->filter[] = 'svy';
1055  $this->filter[] = 'qpl';
1056  $this->filter[] = 'spl';
1057  $this->filter[] = 'glo';
1058  $this->filter[] = 'lm';
1059  $this->filter[] = 'dbk';
1060  $this->filter[] = 'pg';
1061  $this->filter[] = 'st';
1062  $this->filter[] = 'sahs';
1063  $this->filter[] = 'htlm';
1064  $this->filter[] = 'file';
1065  }
1066  return true;
1067  }
1068 
1070  {
1071  $options = array('all' => $this->lng->txt('search_any'),
1072  'crs' => $this->lng->txt('objs_crs'),
1073  'lms' => $this->lng->txt('learning_resources'),
1074  'glo' => $this->lng->txt('objs_glo'),
1075  'mep' => $this->lng->txt('objs_mep'),
1076  'tst' => $this->lng->txt('search_tst_svy'),
1077  'file'=> $this->lng->txt('objs_file'),
1078  'webr' => $this->lng->txt('objs_webr'));
1079 
1080 
1081  return ilUtil::formSelect($this->options['type'],'search_adv[type]',$options,false,true);
1082  }
1083 
1084 
1085  function __storeEntries($res,$new_res)
1086  {
1087  if($this->stored == false)
1088  {
1089  $res->mergeEntries($new_res);
1090  $this->stored = true;
1091 
1092  return true;
1093  }
1094  else
1095  {
1096  $res->intersectEntries($new_res);
1097  return true;
1098  }
1099  }
1100 
1107  private function initUserSearchCache()
1108  {
1109  global $ilUser;
1110 
1111  include_once('Services/Search/classes/class.ilUserSearchCache.php');
1112  $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
1113  $this->search_cache->switchSearchType(ilUserSearchCache::ADVANCED_SEARCH);
1114  if($_GET['page_number'])
1115  {
1116  $this->search_cache->setResultPageNumber((int) $_GET['page_number']);
1117  }
1118  if($_POST['cmd']['performSearch'])
1119  {
1120  $this->search_cache->setQuery(ilUtil::stripSlashes($_POST['query']['lomContent']));
1121  $this->search_cache->save();
1122  }
1123  }
1124 
1131  public function setSubTabs()
1132  {
1133  global $ilTabs;
1134 
1135  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1137  {
1138  return true;
1139  }
1140  $ilTabs->addSubTabTarget('search_lom',$this->ctrl->getLinkTarget($this,'showSavedResults'));
1141  #$ilTabs->addSubTabTarget('search_adv_md',$this->ctrl->getLinkTarget($this,'showSavedAdvMDResults'));
1142 
1143  }
1144 
1152  private function toUnixTime($date,$time = array())
1153  {
1154  return mktime($time['h'],$time['m'],0,$date['m'],$date['d'],$date['y']);
1155  }
1156 
1164  private function initSearchType($type)
1165  {
1166  if($type == self::TYPE_LOM)
1167  {
1168  $_SESSION['search_last_sub_section'] = self::TYPE_LOM;
1169  $this->search_cache->switchSearchType(ilUserSearchCache::ADVANCED_SEARCH);
1170  }
1171  else
1172  {
1173  $_SESSION['search_last_sub_section'] = self::TYPE_ADV_MD;
1174  $this->search_cache->switchSearchType(ilUserSearchCache::ADVANCED_MD_SEARCH);
1175  }
1176  }
1177 }
1178 ?>