ILIAS  eassessment Revision 61809
 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 
150 
151  function performSearch()
152  {
153  global $ilUser;
154 
155  $this->initSearchType(self::TYPE_LOM);
156 
157  if(!isset($_GET['page_number']) and $this->search_mode != 'in_results' )
158  {
159  unset($_SESSION['adv_max_page']);
160  $this->search_cache->deleteCachedEntries();
161  }
162 
163  if(isset($_POST['query']))
164  {
165  $this->search_cache->setQuery($_POST['query']);
166  }
167 
168 
169  include_once 'Services/Search/classes/class.ilSearchResult.php';
170  $res =& new ilSearchResult();
171 
172  if($res_con =& $this->__performContentSearch())
173  {
174  $this->__storeEntries($res,$res_con);
175  }
176  if($res_lan =& $this->__performLanguageSearch())
177  {
178  $this->__storeEntries($res,$res_lan);
179  }
180  if($res_gen =& $this->__performGeneralSearch())
181  {
182  $this->__storeEntries($res,$res_gen);
183  }
184  if($res_lif =& $this->__performLifecycleSearch())
185  {
186  $this->__storeEntries($res,$res_lif);
187  }
188  if($res_con =& $this->__performContributeSearch())
189  {
190  $this->__storeEntries($res,$res_con);
191  }
192  if($res_ent =& $this->__performEntitySearch())
193  {
194  $this->__storeEntries($res,$res_ent);
195  }
196  if($res_req =& $this->__performRequirementSearch())
197  {
198  $this->__storeEntries($res,$res_req);
199  }
200  if($res_for =& $this->__performFormatSearch())
201  {
202  $this->__storeEntries($res,$res_for);
203  }
204  if($res_edu =& $this->__performEducationalSearch())
205  {
206  $this->__storeEntries($res,$res_edu);
207  }
208  if($res_typ =& $this->__performTypicalAgeRangeSearch())
209  {
210  $this->__storeEntries($res,$res_typ);
211  }
212  if($res_rig =& $this->__performRightsSearch())
213  {
214  $this->__storeEntries($res,$res_rig);
215  }
216  if($res_cla =& $this->__performClassificationSearch())
217  {
218  $this->__storeEntries($res,$res_cla);
219  }
220  if($res_tax =& $this->__performTaxonSearch())
221  {
222  $this->__storeEntries($res,$res_tax);
223  }
224  if($res_key =& $this->__performKeywordSearch())
225  {
226  $this->__storeEntries($res,$res_key);
227  }
228  if($this->search_mode == 'in_results')
229  {
230  include_once 'Services/Search/classes/class.ilSearchResult.php';
231 
232  $old_result_obj = new ilSearchResult($ilUser->getId());
233  $old_result_obj->read(ADVANCED_MD_SEARCH);
234 
235  $res->diffEntriesFromResult($old_result_obj);
236  }
237 
238 
239  $res->filter($this->getRootNode(),true);
240  $res->save();
241  $this->showSearch();
242 
243  if(!count($res->getResults()))
244  {
245  ilUtil::sendInfo($this->lng->txt('search_no_match'));
246  }
247 
248  if($res->isLimitReached())
249  {
250  #$message = sprintf($this->lng->txt('search_limit_reached'),$this->settings->getMaxHits());
251  #ilUtil::sendInfo($message);
252  }
253 
254  $this->addPager($res,'adv_max_page');
255 
256  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
258  $presentation->setResults($res->getResultsForPresentation());
259  $presentation->setPreviousNext($this->prev_link, $this->next_link);
260 
261  if($presentation->render())
262  {
263  $this->tpl->setVariable('RESULTS',$presentation->getHTML(true));
264  }
265  return true;
266  }
267 
273  protected function initAdvancedMetaDataForm()
274  {
275  if(is_object($this->form))
276  {
277  return $this->form;
278  }
279 
280  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
281  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
282  $this->form = new ilPropertyFormGUI();
283  $this->form->setFormAction($this->ctrl->getFormAction($this,'performAdvMDSearch'));
284  $this->form->setTitle($this->lng->txt('adv_md_search_title'));
285  $this->form->addCommandButton('performAdvMDSearch',$this->lng->txt('search'));
286  #$this->form->setSubformMode('right');
287 
288  $content = new ilTextInputGUI($this->lng->txt('meta_title').'/'.
289  $this->lng->txt('meta_keyword').'/'.
290  $this->lng->txt('meta_description'),'title');
291  $content->setValue($this->options['title']);
292  $content->setSize(30);
293  $content->setMaxLength(255);
294 // $content->setSubformMode('right');
295  $group = new ilRadioGroupInputGUI('','title_ao');
296  $group->setValue($this->options['title_ao']);
297  $radio_option = new ilRadioOption($this->lng->txt("search_any_word"),0);
298  $group->addOption($radio_option);
299  $radio_option = new ilRadioOption($this->lng->txt("search_all_words"),1);
300  $group->addOption($radio_option);
301  $content->addSubItem($group);
302  $this->form->addItem($content);
303 
304  $type = new ilSelectInputGUI($this->lng->txt('type'),'type');
305  $options['adv_all'] = $this->lng->txt('search_any');
306  foreach(ilAdvancedMDRecord::_getActivatedObjTypes() as $obj_type)
307  {
308  $options[$obj_type] = $this->lng->txt('objs_'.$obj_type);
309  }
310  $type->setOptions($options);
311  $type->setValue($this->options['type']);
312  $this->form->addItem($type);
313 
314  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordGUI.php');
316  $record_gui->setPropertyForm($this->form);
317  $record_gui->setSearchValues($this->options);
318  $record_gui->parse();
319  }
320 
326  protected function performAdvMDSearch()
327  {
328  global $ilUser;
329 
330  $this->initSearchType(self::TYPE_ADV_MD);
331  if(!isset($_GET['page_number']) and $this->search_mode != 'in_results' )
332  {
333  unset($_SESSION['adv_max_page']);
334  $this->search_cache->delete();
335  }
336 
337  include_once 'Services/Search/classes/class.ilSearchResult.php';
338  $res =& new ilSearchResult();
339 
340  if($res_tit =& $this->__performTitleSearch())
341  {
342  $this->__storeEntries($res,$res_tit);
343  }
344  $this->searchAdvancedMD($res);
345 
346  if($this->search_mode == 'in_results')
347  {
348  include_once 'Services/Search/classes/class.ilSearchResult.php';
349 
350  $old_result_obj = new ilSearchResult($ilUser->getId());
351  $old_result_obj->read(ADVANCED_MD_SEARCH);
352 
353  $res->diffEntriesFromResult($old_result_obj);
354  }
355 
356 
357  $res->filter($this->getRootNode(),true);
358  $res->save();
359  $this->showAdvMDSearch();
360 
361  if(!count($res->getResults()))
362  {
363  ilUtil::sendInfo($this->lng->txt('search_no_match'));
364  }
365 
366  if($res->isLimitReached())
367  {
368  #$message = sprintf($this->lng->txt('search_limit_reached'),$this->settings->getMaxHits());
369  #ilUtil::sendInfo($message);
370  }
371 
372  $this->addPager($res,'adv_max_page');
373 
374  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
376  $presentation->setResults($res->getResultsForPresentation());
377  $presentation->setPreviousNext($this->prev_link, $this->next_link);
378 
379  if($presentation->render())
380  {
381  $this->tpl->setVariable('RESULTS',$presentation->getHTML(true));
382  }
383  return true;
384 
385  }
386 
387 
393  public function showAdvMDSearch()
394  {
395  if(isset($_SESSION['search_adv_md']))
396  {
397  $this->options = $_SESSION['search_adv_md'];
398  }
399  $this->setSubTabs();
400  $this->tabs_gui->setSubTabActive('search_adv_md');
401 
402  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.advanced_adv_search.html','Services/Search');
403 
404  $this->initAdvancedMetaDataForm();
405  $this->tpl->setVariable('SEARCH_FORM',$this->form->getHTML());
406  return true;
407  }
408 
412  protected function initFormSearch()
413  {
414  global $tree;
415 
416  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
417 
418  $this->form = new ilPropertyFormGUI();
419  $this->form->setFormAction($this->ctrl->getFormAction($this,'performSearch'));
420  $this->form->setTitle($this->lng->txt('search_advanced'));
421  $this->form->addCommandButton('performSearch',$this->lng->txt('search'));
422  $this->form->addCommandButton('reset',$this->lng->txt('reset'));
423 
424  foreach($this->fields->getActiveSections() as $definition)
425  {
426  if($definition['name'] != 'default')
427  {
428  $section = new ilFormSectionHeaderGUI();
429  $section->setTitle($definition['name']);
430  $this->form->addItem($section);
431  }
432 
433  foreach($definition['fields'] as $field_name)
434  {
435  if(is_object($element = $this->fields->getFormElement($this->search_cache->getQuery(),$field_name)))
436  {
437  $this->form->addItem($element);
438  }
439  }
440  }
441  return true;
442  }
443 
444 
445 
446  function showSearch()
447  {
448  global $ilLocator;
449 
450  $this->setSubTabs();
451  $this->tabs_gui->setSubTabActive('search_lom');
452 
453  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.advanced_search.html','Services/Search');
454 
455  $this->initFormSearch();
456  $this->tpl->setVariable('SEARCH_FORM',$this->form->getHTML());
457  return true;
458  }
459 
460  function prepareOutput()
461  {
462  global $ilTabs;
463 
465 
466 // $this->tpl->addBlockFile("TABS","tabs","tpl.tabs.html");
467 
468  $ilTabs->addTab("search", $this->lng->txt("search"),
469  $this->ctrl->getLinkTargetByClass('ilsearchgui'));
470  $ilTabs->addTab("adv_search", $this->lng->txt("search_advanced"),
471  $this->ctrl->getLinkTarget($this));
472  $ilTabs->activateTab("adv_search");
473 
474  /*$this->tpl->setCurrentBlock("tab");
475  $this->tpl->setVariable("TAB_TYPE","tabinactive");
476  $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTargetByClass('ilsearchgui'));
477  $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search"));
478  $this->tpl->parseCurrentBlock();
479 
480  $this->tpl->setCurrentBlock("tab");
481  $this->tpl->setVariable("TAB_TYPE","tabactive");
482  $this->tpl->setVariable("TAB_LINK",$this->ctrl->getLinkTarget($this));
483  $this->tpl->setVariable("TAB_TEXT",$this->lng->txt("search_advanced"));
484  $this->tpl->parseCurrentBlock();*/
485  }
486 
487  // PRIVATE
494  private function showSavedAdvMDResults()
495  {
496  global $ilUser;
497 
498  // Read old result sets
499  include_once 'Services/Search/classes/class.ilSearchResult.php';
500 
501  $this->initSearchType(self::TYPE_ADV_MD);
502  $result_obj = new ilSearchResult($ilUser->getId());
503  $result_obj->read(ADVANCED_MD_SEARCH);
504 
505  $this->showAdvMDSearch();
506 
507  // Show them
508  if(count($result_obj->getResults()))
509  {
510  $this->addPager($result_obj,'adv_max_page');
511 
512  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
514  $presentation->setResults($result_obj->getResultsForPresentation());
515  $presentation->setPreviousNext($this->prev_link, $this->next_link);
516 
517  if($presentation->render())
518  {
519  $this->tpl->setVariable('RESULTS',$presentation->getHTML(true));
520  }
521  }
522 
523  return true;
524  }
525 
526 
527  function showSavedResults()
528  {
529  global $ilUser;
530 
531  // Read old result sets
532  include_once 'Services/Search/classes/class.ilSearchResult.php';
533 
534  $this->initSearchType(self::TYPE_LOM);
535  $result_obj = new ilSearchResult($ilUser->getId());
536  $result_obj->read(ADVANCED_SEARCH);
537 
538  $this->showSearch();
539 
540  // Show them
541  if(count($result_obj->getResults()))
542  {
543  $this->addPager($result_obj,'adv_max_page');
544 
545  include_once './Services/Search/classes/class.ilSearchResultPresentation.php';
547  $presentation->setResults($result_obj->getResultsForPresentation());
548  $presentation->setPreviousNext($this->prev_link, $this->next_link);
549 
550  if($presentation->render())
551  {
552  $this->tpl->setVariable('RESULTS',$presentation->getHTML(true));
553  }
554  }
555 
556  return true;
557  }
558 
560  {
561  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
562  include_once 'Services/Search/classes/class.ilQueryParser.php';
563  include_once 'Services/Search/classes/class.ilSearchResult.php';
564 
565  if(!$this->options['lom_content'])
566  {
567  return false;
568  }
569 
570  $res =& new ilSearchResult();
571 
572  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_content']));
573  #$query_parser->setCombination($this->options['content_ao']);
574  $query_parser->setCombination(QP_COMBINATION_OR);
575  $query_parser->parse();
576 
577  if($this->options['type'] == 'all' or $this->options['type'] == 'lms')
578  {
579  // LM content search
580  $lm_search =& ilObjectSearchFactory::_getLMContentSearchInstance($query_parser);
581  $res_cont =& $lm_search->performSearch();
582  $res->mergeEntries($res_cont);
583  }
584  if($this->options['type'] == 'all' or $this->options['type'] == 'tst')
585  {
586  $tst_search =& ilObjectSearchFactory::_getTestSearchInstance($query_parser);
587  $res_tes =& $tst_search->performSearch();
588  $res->mergeEntries($res_tes);
589  }
590  if($this->options['type'] == 'all' or $this->options['type'] == 'mep')
591  {
592  $med_search =& ilObjectSearchFactory::_getMediaPoolSearchInstance($query_parser);
593  $res_med =& $med_search->performSearch();
594  $res->mergeEntries($res_med);
595  }
596  if($this->options['type'] == 'all' or $this->options['type'] == 'glo')
597  {
599  $res_glo =& $glo_search->performSearch();
600  $res->mergeEntries($res_glo);
601  }
602  if($this->options['type'] == 'all' or $this->options['type'] == 'webr')
603  {
604  $web_search =& ilObjectSearchFactory::_getWebresourceSearchInstance($query_parser);
605  $res_web =& $web_search->performSearch();
606  $res->mergeEntries($res_web);
607  }
608  if($tit_res = $this->__performTitleSearch())
609  {
610  $res->mergeEntries($tit_res);
611  }
612 
613  return $res;
614  }
615 
616 
618  {
619  if(!$this->options['lom_content'])
620  {
621  return false;
622  }
623 
624  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
625  include_once 'Services/Search/classes/class.ilQueryParser.php';
626 
627  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_content']));
628  #$query_parser->setCombination($this->options['title_ao']);
629  $query_parser->setCombination(QP_COMBINATION_OR);
630  $query_parser->parse();
631  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
632 
633  $meta_search->setFilter($this->filter);
634  $meta_search->setMode('title_description');
635  $meta_search->setOptions($this->options);
636  $res_tit =& $meta_search->performSearch();
637 
638  $meta_search->setMode('keyword_all');
639  $res_key =& $meta_search->performSearch();
640 
641  // merge them
642  $res_tit->mergeEntries($res_key);
643 
644 
645  return $res_tit;
646  }
647 
648 
649 
651  {
652  if(!$this->options['lom_coverage'] and !$this->options['lom_structure'])
653  {
654  return false;
655  }
656 
657  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
658  include_once 'Services/Search/classes/class.ilQueryParser.php';
659 
660  if($this->options['lom_coverage'])
661  {
662  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_coverage']));
663  #$query_parser->setCombination($this->options['coverage_ao']);
664  $query_parser->setCombination(QP_COMBINATION_OR);
665  $query_parser->parse();
666  }
667  else
668  {
669  $query_parser = new ilQueryParser('');
670  }
671  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
672  $meta_search->setFilter($this->filter);
673  $meta_search->setMode('general');
674  $meta_search->setOptions($this->options);
675  $res =& $meta_search->performSearch();
676 
677  return $res;
678  }
679 
681  {
682  // Return if 'any'
683  if(!$this->options['lom_status'] and !$this->options['lom_version'])
684  {
685  return false;
686  }
687  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
688  include_once 'Services/Search/classes/class.ilQueryParser.php';
689 
690  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_version']));
691  #$query_parser->setCombination($this->options['version_ao']);
692  $query_parser->setCombination(QP_COMBINATION_OR);
693  $query_parser->parse();
694 
695  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
696  $meta_search->setFilter($this->filter);
697  $meta_search->setMode('lifecycle');
698  $meta_search->setOptions($this->options);
699  $res =& $meta_search->performSearch();
700 
701  return $res;
702  }
704  {
705  if(!$this->options['lom_language'])
706  {
707  return false;
708  }
709  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
710  include_once 'Services/Search/classes/class.ilQueryParser.php';
711 
712 
714  $meta_search->setFilter($this->filter);
715  $meta_search->setMode('language');
716  $meta_search->setOptions($this->options);
717  $res =& $meta_search->performSearch();
718 
719  return $res;
720  }
722  {
723  if(!strlen($this->options['lom_role']))
724  {
725  return false;
726  }
727  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
728  include_once 'Services/Search/classes/class.ilQueryParser.php';
729 
730 
732  $meta_search->setFilter($this->filter);
733  $meta_search->setMode('contribute');
734  $meta_search->setOptions($this->options);
735  $res =& $meta_search->performSearch();
736 
737  return $res;
738  }
740  {
741  // Return if 'any'
742  if(!$this->options['lom_role_entry'])
743  {
744  return false;
745  }
746 
747  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
748  include_once 'Services/Search/classes/class.ilQueryParser.php';
749 
750  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_role_entry']));
751  #$query_parser->setCombination($this->options['entity_ao']);
752  $query_parser->setCombination(QP_COMBINATION_OR);
753  $query_parser->parse();
754 
755  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
756  $meta_search->setFilter($this->filter);
757  $meta_search->setMode('entity');
758  $meta_search->setOptions($this->options);
759  $res =& $meta_search->performSearch();
760 
761  return $res;
762  }
763 
764 
766  {
767  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
768  include_once 'Services/Search/classes/class.ilQueryParser.php';
769 
770 
772  $meta_search->setFilter($this->filter);
773  $meta_search->setMode('requirement');
774  $meta_search->setOptions($this->options);
775  $res =& $meta_search->performSearch();
776 
777  return $res;
778  }
780  {
781  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
782  include_once 'Services/Search/classes/class.ilQueryParser.php';
783 
784 
786  $meta_search->setFilter($this->filter);
787  $meta_search->setMode('format');
788  $meta_search->setOptions($this->options);
789  $res =& $meta_search->performSearch();
790 
791  return $res;
792  }
794  {
795  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
796  include_once 'Services/Search/classes/class.ilQueryParser.php';
797 
798 
800  $meta_search->setFilter($this->filter);
801  $meta_search->setMode('educational');
802  $meta_search->setOptions($this->options);
803  $res =& $meta_search->performSearch();
804 
805  return $res;
806  }
808  {
809  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
810  include_once 'Services/Search/classes/class.ilQueryParser.php';
811 
812 
814  $meta_search->setFilter($this->filter);
815  $meta_search->setMode('typical_age_range');
816  $meta_search->setOptions($this->options);
817  $res =& $meta_search->performSearch();
818 
819  return $res;
820  }
822  {
823  if(!$this->options['lom_copyright'] and !$this->options['lom_costs'])
824  {
825  return false;
826  }
827  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
828  include_once 'Services/Search/classes/class.ilQueryParser.php';
829 
830 
832  $meta_search->setFilter($this->filter);
833  $meta_search->setMode('rights');
834  $meta_search->setOptions($this->options);
835  $res =& $meta_search->performSearch();
836 
837  return $res;
838  }
839 
841  {
842  // Return if 'any'
843  if(!$this->options['lom_purpose'])
844  {
845  return false;
846  }
847  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
848  include_once 'Services/Search/classes/class.ilQueryParser.php';
849 
850 
852  $meta_search->setFilter($this->filter);
853  $meta_search->setMode('classification');
854  $meta_search->setOptions($this->options);
855  $res =& $meta_search->performSearch();
856 
857  return $res;
858  }
859 
861  {
862  // Return if 'any'
863  if(!$this->options['lom_taxon'])
864  {
865  return false;
866  }
867  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
868  include_once 'Services/Search/classes/class.ilQueryParser.php';
869 
870  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_taxon']));
871  $query_parser->setCombination(QP_COMBINATION_OR);
872  $query_parser->parse();
873 
874  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
875  $meta_search->setFilter($this->filter);
876  $meta_search->setMode('taxon');
877  $meta_search->setOptions($this->options);
878  $res =& $meta_search->performSearch();
879 
880  return $res;
881  }
882 
890  private function searchAdvancedMD($res)
891  {
892  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
893  foreach($_POST as $key => $value)
894  {
895  if(!is_numeric($key))
896  {
897  continue;
898  }
899  if(!$value)
900  {
901  continue;
902  }
903 
905  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
906  include_once 'Services/Search/classes/class.ilQueryParser.php';
907 
908  if($def->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_SELECT)
909  {
910  $value = (int) $value;
911  $options = $def->getFieldValues();
912  if(!isset($options[$value - 1]))
913  {
914  continue;
915  }
916  $value = $options[$value - 1];
917  }
918  if($def->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_DATE)
919  {
920  $start = $this->toUnixTime($_POST['date_start'][$key]['date']);
921  $end = $this->toUnixTime($_POST['date_end'][$key]['date']);
922 
923  }
924  if($def->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_DATETIME)
925  {
926  $start = $this->toUnixTime($_POST['date_start'][$key]['date'],$_POST['date_start'][$key]['time']);
927  $end = $this->toUnixTime($_POST['date_end'][$key]['date'],$_POST['date_end'][$key]['time']);
928  }
929 
930  $query_parser = new ilQueryParser(ilUtil::stripSlashes($value));
931  if($_POST['boolean'][$key] == 1)
932  {
933  $query_parser->setCombination('and');
934  }
935  else
936  {
937  $query_parser->setCombination('or');
938  }
939  $query_parser->parse();
940 
941  $adv_md_search = ilObjectSearchFactory::_getAdvancedMDSearchInstance($query_parser);
942  $adv_md_search->setDefinition($def);
943  $adv_md_search->setTimeRange($start,$end);
944  $adv_md_search->setFilter($this->filter);
945  $res_field = $adv_md_search->performSearch();
946  $this->__storeEntries($res,$res_field);
947 
948  }
949  return $res;
950  }
951 
953  {
954  // Return if 'any'
955  if(!$this->options['lom_keyword'])
956  {
957  return false;
958  }
959  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
960  include_once 'Services/Search/classes/class.ilQueryParser.php';
961 
962  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->options['lom_keyword']));
963  #$query_parser->setCombination($this->options['keyword_ao']);
964  $query_parser->setCombination(QP_COMBINATION_OR);
965  $query_parser->parse();
966 
967  $meta_search =& ilObjectSearchFactory::_getAdvancedSearchInstance($query_parser);
968  $meta_search->setFilter($this->filter);
969  $meta_search->setMode('keyword');
970  $meta_search->setOptions($this->options);
971  $res =& $meta_search->performSearch();
972 
973  return $res;
974  }
975 
976  function __setSearchOptions(&$post_vars)
977  {
978  if(isset($_POST['cmd']['performSearch']))
979  {
980  $this->options = $_SESSION['search_adv'] = $_POST['query'];
981  }
982  elseif(isset($_POST['cmd']['performAdvMDSearch']))
983  {
984  $this->options = $_SESSION['search_adv_md'] = $_POST;
985  }
986  else
987  {
988  $this->options = $_SESSION['search_adv'];
989  }
990 
991  $_POST['result'] = $_POST['id'];
992 
993  $this->filter = array();
994 
995  $this->options['type'] = 'all';
996  switch($this->options['type'])
997  {
998  case 'cat':
999  $this->filter[] = 'cat';
1000  break;
1001 
1002  case 'webr':
1003  $this->filter[] = 'webr';
1004  break;
1005 
1006  case 'lms':
1007  $this->filter[] = 'lm';
1008  $this->filter[] = 'dbk';
1009  $this->filter[] = 'pg';
1010  $this->filter[] = 'st';
1011  $this->filter[] = 'sahs';
1012  $this->filter[] = 'htlm';
1013  break;
1014 
1015  case 'glo':
1016  $this->filter[] = 'glo';
1017  break;
1018 
1019  case 'tst':
1020  $this->filter[] = 'tst';
1021  $this->filter[] = 'svy';
1022  $this->filter[] = 'qpl';
1023  $this->filter[] = 'spl';
1024  break;
1025 
1026  case 'mep':
1027  $this->filter[] = 'mep';
1028  break;
1029 
1030  case 'crs':
1031  $this->filter[] = 'crs';
1032  break;
1033 
1034  case 'file':
1035  $this->filter[] = 'file';
1036  break;
1037 
1038  case 'adv_all':
1039  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
1041  break;
1042 
1043  case 'all':
1044  default:
1045  $this->filter[] = 'webr';
1046  $this->filter[] = 'crs';
1047  $this->filter[] = 'mep';
1048  $this->filter[] = 'tst';
1049  $this->filter[] = 'svy';
1050  $this->filter[] = 'qpl';
1051  $this->filter[] = 'spl';
1052  $this->filter[] = 'glo';
1053  $this->filter[] = 'lm';
1054  $this->filter[] = 'dbk';
1055  $this->filter[] = 'pg';
1056  $this->filter[] = 'st';
1057  $this->filter[] = 'sahs';
1058  $this->filter[] = 'htlm';
1059  $this->filter[] = 'file';
1060  }
1061  return true;
1062  }
1063 
1065  {
1066  $options = array('all' => $this->lng->txt('search_any'),
1067  'crs' => $this->lng->txt('objs_crs'),
1068  'lms' => $this->lng->txt('learning_resources'),
1069  'glo' => $this->lng->txt('objs_glo'),
1070  'mep' => $this->lng->txt('objs_mep'),
1071  'tst' => $this->lng->txt('search_tst_svy'),
1072  'file'=> $this->lng->txt('objs_file'),
1073  'webr' => $this->lng->txt('objs_webr'));
1074 
1075 
1076  return ilUtil::formSelect($this->options['type'],'search_adv[type]',$options,false,true);
1077  }
1078 
1079 
1080  function __storeEntries($res,$new_res)
1081  {
1082  if($this->stored == false)
1083  {
1084  $res->mergeEntries($new_res);
1085  $this->stored = true;
1086 
1087  return true;
1088  }
1089  else
1090  {
1091  $res->intersectEntries($new_res);
1092  return true;
1093  }
1094  }
1095 
1102  private function initUserSearchCache()
1103  {
1104  global $ilUser;
1105 
1106  include_once('Services/Search/classes/class.ilUserSearchCache.php');
1107  $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
1108  $this->search_cache->switchSearchType(ilUserSearchCache::ADVANCED_SEARCH);
1109  if($_GET['page_number'])
1110  {
1111  $this->search_cache->setResultPageNumber((int) $_GET['page_number']);
1112  }
1113  if($_POST['cmd']['performSearch'])
1114  {
1115  $this->search_cache->setQuery(ilUtil::stripSlashes($_POST['query']['lomContent']));
1116  $this->search_cache->save();
1117  }
1118  }
1119 
1126  public function setSubTabs()
1127  {
1128  global $ilTabs;
1129 
1130  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1132  {
1133  return true;
1134  }
1135  $ilTabs->addSubTabTarget('search_lom',$this->ctrl->getLinkTarget($this,'showSavedResults'));
1136  #$ilTabs->addSubTabTarget('search_adv_md',$this->ctrl->getLinkTarget($this,'showSavedAdvMDResults'));
1137 
1138  }
1139 
1147  private function toUnixTime($date,$time = array())
1148  {
1149  return mktime($time['h'],$time['m'],0,$date['m'],$date['d'],$date['y']);
1150  }
1151 
1159  private function initSearchType($type)
1160  {
1161  if($type == self::TYPE_LOM)
1162  {
1163  $_SESSION['search_last_sub_section'] = self::TYPE_LOM;
1164  $this->search_cache->switchSearchType(ilUserSearchCache::ADVANCED_SEARCH);
1165  }
1166  else
1167  {
1168  $_SESSION['search_last_sub_section'] = self::TYPE_ADV_MD;
1169  $this->search_cache->switchSearchType(ilUserSearchCache::ADVANCED_MD_SEARCH);
1170  }
1171  }
1172 }
1173 ?>