ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Payment/classes/class.ilShopBaseGUI.php';
5 include_once 'Services/Payment/classes/class.ilPaymentSettings.php';
6 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
7 include_once './Services/Payment/classes/class.ilShopRepositoryExplorer.php';
8 
17 class ilShopGUI extends ilShopBaseGUI
18 {
19  const SHOP_PAGE_EDITOR_PAGE_ID = 99999999;
20 
21  private $sort_type_topics = '';
22  private $sort_direction_topics = '';
23  private $sort_field = '';
24  private $sort_direction = '';
25  private $string = '';
26  private $type = '';
27  private $topic_id = 0;
28 
29 // private $form = null;
30  public $genSet = null;
31 
32  public $cur_ref_id = null;
33 
34  public function __construct($_post = '')
35  {
37 
38  global $ilCtrl;
39 
40  $this->cur_ref_id = (int)$_GET['ref_id'];
41  $this->cmd = $ilCtrl->getCmd();
42 
43  // set filter settings
44  $this->setType($_SESSION['shop_content']['type']);
45  $this->setString($_SESSION['shop_content']['text']);
46  $this->setTopicId($_POST['filter_topic_id']);
47 
48  // set sorting
49  $this->setSortingTypeTopics($_SESSION['shop_content']['order_topics_sorting_type']);
50  $this->setSortingDirectionTopics($_SESSION['shop_content']['shop_topics_sorting_direction']);
51 # $this->setSortField($_SESSION['shop_content']['shop_order_field']);
52  $this->setSortField($_POST['order_field']);
53  $this->setSortDirection($_SESSION['shop_content']['shop_order_direction']);
54 
55  $this->genSet = ilPaymentSettings::_getInstance();
56  }
57 
58  function executeCommand()
59  {
60  global $ilUser;
61 
62  // Check for incomplete profile
63  if($ilUser->getProfileIncomplete())
64  {
65  ilUtil::redirect('ilias.php?baseClass=ilPersonalDesktopGUI');
66  }
67 
68  // check whether password of user have to be changed
69  // due to first login or password of user is expired
70  if($ilUser->isPasswordChangeDemanded() || $ilUser->isPasswordExpired())
71  {
72  ilUtil::redirect('ilias.php?baseClass=ilPersonalDesktopGUI');
73  }
74 
75  $next_class = $this->ctrl->getNextClass($this);
76 
77  switch($next_class)
78  {
79  case 'ilpageobjectgui':
80  $this->prepareOutput();
81 
82  $ret = $this->forwardToPageObject();
83  if($ret != '')
84  {
85  $this->tpl->setContent($ret);
86  }
87  break;
88 
89  default:
90  switch($this->cmd)
91  {
92  case 'firstpage':
93  $this->clearFilter();
94 
95  if(!$this->genSet->get('show_general_filter')
96  && !$this->genSet->get('show_topics_filter')
97  && !$this->genSet->get('show_shop_explorer')
98  )
99  {
100  $cmd = 'performSearch';
101  }
102  else
103  {
104 
106  {
107  $cmd = 'showSpecialContent';
108  }
109  else
110  {
111  $cmd = 'performSearch';
112  }
113  }
114  break;
115  case 'resetFilter':
116  $cmd = 'resetFilter';
117  break;
118  case 'setFilter':
119  $cmd = 'setFilter';
120  break;
121  default:
122  $cmd = 'performSearch';
123  break;
124  }
125 
126  if($this->cmd != 'firstpage' && (isset($_GET['ref_id']) || $this->cmd == 'showTree')) #&& $_GET['ref_id'] != ROOT_FOLDER_ID )
127  {
128  $obj_type = ilObject::_lookupType(ilObject::_lookupObjId($this->cur_ref_id));
129  $container = array("root", "cat", 'catr', "grp", "icrs", "crs", 'crsr', 'rcrs');
130 
131  if(in_array($obj_type, $container))
132  {
133  $cmd = 'showContainerContent';
134  }
135  else
136  {
137  $cmd = 'performSearch';
138  }
139  }
140 
141  $this->prepareOutput();
142  $this->$cmd();
143 
144  break;
145  }
146 
147  return true;
148  }
149 
150  public function clearFilter()
151  {
152  $this->setString('');
153  $this->setType('');
154  $this->setTopicId(0);
155 
156  #return $this->performSearch();
157  }
158 
159  public function getPageHTML()
160  {
161  // page object
162  include_once 'Services/COPage/classes/class.ilPageObject.php';
163  include_once 'Services/COPage/classes/class.ilPageObjectGUI.php';
164 
165  // if page does not exist, return nothing
166  if(!ilPageObject::_exists('shop', self::SHOP_PAGE_EDITOR_PAGE_ID))
167  {
168  return '';
169  }
170 
171  include_once 'Services/Style/classes/class.ilObjStyleSheet.php';
172  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
173 
174  // get page object
175  $page_gui = new ilPageObjectGUI('shop', self::SHOP_PAGE_EDITOR_PAGE_ID);
176  $page_gui->setIntLinkHelpDefault('StructureObject', self::SHOP_PAGE_EDITOR_PAGE_ID);
177  $page_gui->setLinkXML('');
178  $page_gui->setFileDownloadLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'downloadFile'));
179  $page_gui->setFullscreenLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'displayMediaFullscreen'));
180  $page_gui->setSourcecodeDownloadScript($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'download_paragraph'));
181  $page_gui->setPresentationTitle('');
182  $page_gui->setTemplateOutput(false);
183  $page_gui->setHeader('');
184  $page_gui->setEnabledRepositoryObjects(false);
185  $page_gui->setEnabledFileLists(true);
186  $page_gui->setEnabledPCTabs(true);
187  $page_gui->setEnabledMaps(true);
188 
189  return $page_gui->showPage();
190  }
191 
192  public function forwardToPageObject()
193  {
194  global $lng, $ilTabs;
195 
196  $ilTabs->clearTargets();
197  $ilTabs->setBackTarget($lng->txt('back'), $this->ctrl->getLinkTarget($this), '_top');
198 
199  // page object
200  include_once 'Services/COPage/classes/class.ilPageObject.php';
201  include_once 'Services/COPage/classes/class.ilPageObjectGUI.php';
202 
203  $lng->loadLanguageModule('content');
204 
205  include_once('./Services/Style/classes/class.ilObjStyleSheet.php');
206  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
207 
208  if(!ilPageObject::_exists('shop', self::SHOP_PAGE_EDITOR_PAGE_ID))
209  {
210  // doesn't exist -> create new one
211  $new_page_object = new ilPageObject('shop');
212  $new_page_object->setParentId(0);
213  $new_page_object->setId(self::SHOP_PAGE_EDITOR_PAGE_ID);
214  $new_page_object->createFromXML();
215  }
216 
217  $this->ctrl->setReturnByClass('ilpageobjectgui', 'edit');
218 
219  $page_gui = new ilPageObjectGUI('shop', self::SHOP_PAGE_EDITOR_PAGE_ID);
220  $page_gui->setIntLinkHelpDefault('StructureObject', self::SHOP_PAGE_EDITOR_PAGE_ID);
221  $page_gui->setTemplateTargetVar('ADM_CONTENT');
222  $page_gui->setLinkXML('');
223  $page_gui->setFileDownloadLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'downloadFile'));
224  $page_gui->setFullscreenLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'displayMediaFullscreen'));
225  $page_gui->setSourcecodeDownloadScript($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'download_paragraph'));
226  $page_gui->setPresentationTitle('');
227  $page_gui->setTemplateOutput(false);
228  $page_gui->setHeader('');
229  $page_gui->setEnabledRepositoryObjects(false);
230  $page_gui->setEnabledFileLists(true);
231  $page_gui->setEnabledMaps(true);
232  $page_gui->setEnabledPCTabs(true);
233 
234  return $this->ctrl->forwardCommand($page_gui);
235  }
236 
237  public function setFilter()
238  {
239  $this->setString($_POST['filter_text']);
240  $this->setType($_POST['sel_filter_type']);
241  $this->setTopicId($_POST['filter_topic_id']);
242 
243  $this->setSortingTypeTopics($_POST['topics_sorting_type']);
244  $this->setSortingDirectionTopics($_POST['topics_sorting_direction']);
245  $this->setSortField($_POST['order_field']);
246  $this->setSortDirection('asc');
247 
248  $this->performSearch();
249 
250  return true;
251  }
252 
253  public function showShopExplorer()
254  {
255  global $ilCtrl, $tree, $lng;
256 
257  $ilCtrl->setParameter($this, "active_node", $_GET["active_node"]);
258  $shop_explorer_tpl = new ilTemplate('tpl.shop_explorer.html', true, true, 'Services/Payment');
259 
260  include_once ("./Services/Payment/classes/class.ilShopRepositoryExplorer.php");
261 
262  $active_node = ($_GET["active_node"] >= 1)
263  ? $_GET["active_node"]
264  : ($_GET["ref_id"] >= 1)
265  ? $_GET["ref_id"]
266  : 0;
267 
268  $top_node = 0;
269 
270  $exp = new ilShopRepositoryExplorer("ilias.php", $top_node);
271  $exp->setUseStandardFrame(false);
272  $exp->setExpandTarget("ilias.php?baseClass=ilshopcontroller&ref_id=1&cmd=showTree");
273 
274  $exp->setFrameUpdater("tree", "updater");
275  $exp->setTargetGet("ref_id");
276 
277  if($_GET["repexpand"] == "")
278  {
279  $expanded = $tree->readRootId();
280  }
281  else
282  {
283  $expanded = $_GET["repexpand"];
284  }
285 
286  $exp->setExpand($expanded);
287 
288  if($active_node > 0)
289  {
290  $path = $tree->getPathId($active_node);
291  if($top_node > 0)
292  {
293  $exp->setForceOpenPath($path);
294  $exp->setExpand($expanded);
295  }
296  else
297  {
298  $exp->setForceOpenPath($path + array($top_node));
299  }
300  $exp->highlightNode($active_node);
301  }
302 
303  // build html-output
304  if($top_node > 0)
305  {
306  $head_tpl = new ilTemplate("tpl.cont_tree_head.html", true, true,
307  "Services/Repository");
308  $path = ilObject::_getIcon(ROOT_FOLDER_ID, "tiny", "root");
309  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
310  $title = $nd["title"];
311  if($title == "ILIAS")
312  {
313  $title = $lng->txt("repository");
314  }
315  $head_tpl->setVariable("IMG_SRC", $path);
316  $head_tpl->setVariable("ALT_IMG", $lng->txt("icon") . " " . $title);
317  $head_tpl->setVariable("LINK_TXT", $title);
318  $head_tpl->setVariable("LINK_HREF", "ilias.php?baseClass=ilshopcontroller&ref_id=1");
319  $exp->setTreeLead($head_tpl->get());
320 
321  $exp->initItemCounter(1);
322  $exp->setOutput($tree->getParentId($top_node), 1,
323  ilObject::_lookupObjId($tree->getParentId($top_node)));
324  }
325  else
326  {
327  $exp->setOutput(0);
328  }
329  $output = $exp->getOutput(true);
330 
331  // asynchronous output
332  if($ilCtrl->isAsynch())
333  {
334  echo $output;
335  exit;
336  }
337  $shop_explorer_tpl->setVariable("EXPLORER", $output);
338  $ilCtrl->setParameter($this, "repexpand", $_GET["repexpand"]);
339 
340  global $tpl;
341  $tpl->setLeftContent($shop_explorer_tpl->get());
342  }
343 
344  public function performSearch($oResult = null)
345  {
346  if(!is_object($oResult))
347  {
348  $oResult = new ilShopSearchResult(SHOP_CONTENT);
349  if((bool)$this->oGeneralSettings->get('topics_allow_custom_sorting'))
350  {
351  ilShopTopics::_getInstance()->setIdFilter((int)$this->getTopicId());
352  ilShopTopics::_getInstance()->enableCustomSorting(true);
353  ilShopTopics::_getInstance()->setSortingType((int)$this->getSortingTypeTopics());
354  ilShopTopics::_getInstance()->setSortingDirection(strtoupper($this->getSortingDirectionTopics()));
355  ilShopTopics::_getInstance()->read();
356  }
357  else
358  {
359  ilShopTopics::_getInstance()->setIdFilter((int)$this->getTopicId());
360  ilShopTopics::_getInstance()->enableCustomSorting(false);
361  ilShopTopics::_getInstance()->setSortingType((int)$this->oGeneralSettings->get('topics_sorting_type'));
362  ilShopTopics::_getInstance()->setSortingDirection(strtoupper($this->oGeneralSettings->get('topics_sorting_direction')));
363  ilShopTopics::_getInstance()->read();
364  }
365 
366  $topics = ilShopTopics::_getInstance()->getTopics();
367 
368  $oResult->setTopics($topics);
369  $oResult->setResultPageNumber((int)$_GET['page_number']);
370  }
371 
372  // query parser
373  include_once 'Services/Search/classes/class.ilQueryParser.php';
374  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->getString()));
375  $query_parser->setMinWordLength(0);
376  $query_parser->setCombination(QP_COMBINATION_AND);
377  $query_parser->parse();
378  if(!$query_parser->validate())
379  {
380  ilUtil::sendInfo($query_parser->getMessage());
381  }
382 
383  // search
384  $types = array('crs', 'lm', 'sahs', 'htlm', 'file', 'tst', 'exc', 'glo');
385  if($this->getType() == '' || $this->getType() == 'title' ||
386  $query_parser->getQueryString() == ''
387  )
388  {
389  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
390  $object_search = ilObjectSearchFactory::_getShopObjectSearchInstance($query_parser);
391  $object_search->setFields(array('title'));
392  $object_search->setFilter($types);
393  $object_search->setCustomSearchResultObject($oResult);
394  $object_search->setFilterShopTopicId((int)$this->getTopicId());
395  $res = $object_search->performSearch();
396  }
397  else if($this->getType() == 'author')
398  {
399  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
400  $meta_search = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser);
401  $meta_search->setMode('contribute');
402  $meta_search->setFilter($types);
403  $meta_search->setFilterShopTopicId((int)$this->getTopicId());
404  $meta_search->setCustomSearchResultObject($oResult);
405  $res = $meta_search->performSearch();
406  }
407  else
408  {
409  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
410  $meta_search = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser);
411  $meta_search->setMode('title');
412  $meta_search->setFilter($types);
413  $meta_search->setCustomSearchResultObject($oResult);
414  $meta_search->setFilterShopTopicId((int)$this->getTopicId());
415  $res = $meta_search->performSearch();
416 
417  $meta_search = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser);
418  $meta_search->setMode('keyword');
419  $meta_search->setFilter($types);
420  $meta_search->setCustomSearchResultObject($oResult);
421  $meta_search->setFilterShopTopicId((int)$this->getTopicId());
422  $res->mergeEntries($meta_search->performSearch());
423  }
424 
425  $res->filter(ROOT_FOLDER_ID, true);
426  $res->save();
427 
428  if(!count($res->getResults()))
429  {
430  #ilUtil::sendInfo($this->lng->txt('payment_shop_not_objects_found'));
431  $this->tpl->setVariable('ERROR', $this->lng->txt('payment_shop_not_objects_found'));
432 
433  }
434 
435  $this->showShopContent($res);
436 
437  include_once 'Services/Payment/classes/class.ilShopResultPresentationGUI.php';
438  $search_result_presentation = new ilShopResultPresentationGUI($res);
439  $search_result_presentation->setSortField(strtolower(trim($this->getSortField())));
440  $search_result_presentation->setSortDirection(trim($this->getSortDirection()));
441 
442  $this->tpl->setVariable('RESULTS', $search_result_presentation->showResults());
443  $this->addPager($res, 'shop_content_maxpage');
444 
445  return true;
446  }
447 
448  public function resetFilter()
449  {
450  unset($_SESSION['content_filter']);
451  unset($_POST['sel_filter_type']);
452  unset($_POST['filter_text']);
453  unset($_POST['filter_topic_id']);
454  unset($_POST['order_field']);
455  unset($_POST['order_direction']);
456  unset($_POST['topics_sorting_type']);
457  unset($_POST['topics_sorting_direction']);
458 
459  unset($_POST['updateView']);
460  unset($_POST['show_filter']);
461 
462  ilUtil::sendInfo($this->lng->txt('paya_filter_reseted'));
463  $this->setString('');
464  $this->setType('');
465  $this->setTopicId(0);
466 
467  $this->performSearch();
468 
469  return true;
470  }
471 
472  //showSpecialContent
473  public function showSpecialContent()
474  {
475  global $ilUser, $rbacreview, $ilToolbar;
476 
477  if($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
478  {
479  $ilToolbar->addButton($this->lng->txt('edit_page'), $this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'edit'));
480  }
481 
482  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.shop_content.html', 'Services/Payment');
483  $this->tpl->setVariable('PAGE_CONTENT', $this->getPageHTML());
484 
485  include_once './Services/Payment/classes/class.ilPaymentObject.php';
486  #$this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.shop_content.html', 'Services/Payment');
487 
489  if(count($pobjects))
490  {
491  foreach($pobjects as $result)
492  {
493  $obj_id = ilObject::_lookupObjId($result['ref_id']);
494  $title = ilObject::_lookupTitle($obj_id);
495  $description = ilObject::_lookupDescription($obj_id);
496  $type = ilObject::_lookupType($obj_id);
497 
498  $presentation_results[$result['pt_topic_fk']][$type][] =
499  array(
500  'ref_id' => $result['ref_id'],
501  'title' => $title,
502  'description' => $description,
503  'type' => $type,
504  'obj_id' => $obj_id,
505  'topic_id' => $result['pt_topic_fk'],
506  'child' => $result['child']
507  );
508  }
509  $this->tpl->setVariable('PAGE_CONTENT', $this->getPageHTML());
510  }
511  else
512  {
513  $this->tpl->setVariable('PAGE_CONTENT', $this->lng->txt('please_choose_category'));
514  }
515 
516  include_once 'Services/Payment/classes/class.ilShopResultPresentationGUI.php';
517  $search_result_presentation = new ilShopResultPresentationGUI($presentation_results);
518  $search_result_presentation->setSortField(strtolower(trim($this->getSortField())));
519  $search_result_presentation->setSortDirection(trim($this->getSortDirection()));
520 
521  $html = $search_result_presentation->showSpecials();
522 
523  $this->tpl->setVariable('RESULTS', $html);
524 
525  $show_general_filter = $this->oGeneralSettings->get('show_general_filter');
526  $show_topics_filter = $this->oGeneralSettings->get('show_topics_filter');
527  $show_shop_explorer = $this->oGeneralSettings->get('show_shop_explorer');
528 
529  if($show_general_filter)
530  {
531  $g_filter_html = $this->showGeneralFilter(count($search_result_presentation));
532  $this->tpl->setVariable('FORM', $g_filter_html);
533  }
534  if($show_topics_filter)
535  {
536  $this->showTopicsFilter(count($search_result_presentation));
537  }
538  if($show_shop_explorer)
539  {
540  $this->showShopExplorer();
541  }
542  }
543 
544  public function showShopContent($oResult)
545  {
546  global $ilUser, $rbacreview, $ilToolbar;
547 
548  if($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
549  {
550  $ilToolbar->addButton($this->lng->txt('edit_page'), $this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'edit'));
551  }
552 
553  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.shop_content.html', 'Services/Payment');
554  if(!count($oResult->getResults()))
555  {
556  $this->tpl->setVariable('ERROR', $this->lng->txt('payment_shop_not_objects_found'));
557  #$this->tpl->setVariable('ERROR',ilUtil::sendInfo($this->lng->txt('payment_shop_not_objects_found')));
558  }
559 
560  $show_general_filter = $this->oGeneralSettings->get('show_general_filter');
561  $show_topics_filter = $this->oGeneralSettings->get('show_topics_filter');
562  $show_shop_explorer = $this->oGeneralSettings->get('show_shop_explorer');
563 
564  if($show_general_filter)
565  {
566  $g_filter_html = $this->showGeneralFilter(count($oResult->getResults()));
567  $this->tpl->setVariable('FORM', $g_filter_html);
568  }
569  if($show_topics_filter)
570  {
571  $this->showTopicsFilter(count($oResult->getResults()));
572  }
573  if($show_shop_explorer)
574  {
575  $this->showShopExplorer();
576  }
577  }
578 
579  //showContainerContent
580  /*
581  * show buyable "sub"-objects of containers (cat, catr, crs, grp, ...)
582  */
583  public function showContainerContent()
584  {
585  global $ilUser, $rbacreview, $ilToolbar;
586 
587  if($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
588  {
589  $ilToolbar->addButton($this->lng->txt('edit_page'), $this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'edit'));
590  }
591 
592  include_once './Services/Payment/classes/class.ilPaymentObject.php';
593 
594  $is_buyable = ilPaymentObject::_isBuyable($this->cur_ref_id);
595 
596  if($is_buyable)
597  {
599 
600  $obj_id = ilObject::_lookupObjId($this->cur_ref_id);
601  $title = ilObject::_lookupTitle($obj_id);
602  $description = ilObject::_lookupDescription($obj_id);
603  $type = ilObject::_lookupType($obj_id);
604 
605  $presentation_results[$pobjects['pt_topic_fk']][$type][] =
606  array(
607  'ref_id' => $pobjects['ref_id'],
608  'title' => $title,
609  'description' => $description,
610  'type' => $type,
611  'obj_id' => $obj_id,
612  'topic_id' => $pobjects['pt_topic_fk'],
613  'child' => $pobjects['child']
614  );
615  }
616  else
617  {
618  $pobjects = ilPaymentObject::_getContainerObjects($this->cur_ref_id);
619 
620  if(count($pobjects) >= 1)
621  {
622  foreach($pobjects as $result)
623  {
624  $obj_id = $result['obj_id'];
625  $title = $result['title'];
626  $description = $result['description'];
627  $type = $result['type'];
628 
629  $presentation_results[$result['pt_topic_fk']][$type][] =
630  array(
631  'ref_id' => $result['ref_id'],
632  'title' => $title,
633  'description' => $description,
634  'type' => $type,
635  'obj_id' => $obj_id,
636  'topic_id' => $result['pt_topic_fk'],
637  'child' => $result['child']
638  );
639  }
640  }
641  }
642 
643  $shop_content_tpl = new ilTemplate('tpl.shop_content.html', true, true,'Services/Payment');
644  $shop_content_tpl->setVariable('PAGE_CONTENT', $this->getPageHTML());
645 
646  include_once 'Services/Payment/classes/class.ilShopResultPresentationGUI.php';
647  $search_result_presentation = new ilShopResultPresentationGUI($presentation_results);
648  $search_result_presentation->setSortField(strtolower(trim($this->getSortField())));
649  $search_result_presentation->setSortDirection(trim($this->getSortDirection()));
650 
651  $html = $search_result_presentation->showSpecials();
652 
653  $shop_content_tpl->setVariable('RESULTS', $html);
654 
655  $show_general_filter = $this->oGeneralSettings->get('show_general_filter');
656  $show_topics_filter = $this->oGeneralSettings->get('show_topics_filter');
657  $show_shop_explorer = $this->oGeneralSettings->get('show_shop_explorer');
658 
659  if($show_general_filter)
660  {
661  $g_filter_html = $this->showGeneralFilter(count($search_result_presentation));
662  $shop_content_tpl->setVariable('FORM', $g_filter_html);
663  }
664  if($show_topics_filter)
665  {
666  $this->showTopicsFilter(count($search_result_presentation));
667  }
668  if($show_shop_explorer)
669  {
670  $this->showShopExplorer();
671  }
672  global $tpl;
673  $tpl->setContent($shop_content_tpl->parse());
674  }
675 
676  public function showGeneralFilter($a_count_result = 0)
677  {
678  global $ilUser;
679 
680  if(!$_POST['show_filter'] && $_POST['updateView'] == '1')
681  {
682  $this->resetFilter();
683  }
684  else
685  if($_POST['updateView'] == 1)
686  {
687  $_SESSION['content_filter']['updateView'] = $_POST['updateView'];
688  $_SESSION['content_filter']['show_filter'] = $_POST['show_filter'];
689  $_SESSION['content_filter']['sel_filter_type'] = $_POST['sel_filter_type'];
690  $_SESSION['content_filter']['filter_text'] = $_POST['filter_text'];
691  $_SESSION['content_filter']['filter_topic_id'] = $_POST['filter_topic_id'];
692 
693  $_SESSION['content_filter']['order_field'] = $_POST['order_field'];
694  $_SESSION['content_filter']['order_direction'] = $_POST['order_direction'];
695 
696  $_SESSION['content_filter']['topics_sorting_type'] = $_POST['topics_sorting_type'];
697  $_SESSION['content_filter']['topics_sorting_direction'] = $_POST['topics_sorting_direction'];
698  }
699 
700 
701  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
702  // FILTER FORM
703  $filter_form = new ilPropertyFormGUI();
704  $filter_form->setFormAction($this->ctrl->getFormAction($this));
705  $filter_form->setTitle($this->lng->txt('pay_filter'));
706  $filter_form->setId('formular');
707  $filter_form->setTableWidth('100 %');
708 
709  $o_hide_check = new ilCheckBoxInputGUI($this->lng->txt('show_filter'), 'show_filter');
710  $o_hide_check->setValue(1);
711  $o_hide_check->setChecked($_SESSION['content_filter']['show_filter'] ? 1 : 0);
712 
713  $o_hidden = new ilHiddenInputGUI('updateView');
714  $o_hidden->setValue(1);
715  $o_hidden->setPostVar('updateView');
716  $o_hide_check->addSubItem($o_hidden);
717 
718  $o_filter = new ilSelectInputGUI();
719  $filter_option = array(
720  'title' => $this->lng->txt('title'),
721  'author' => $this->lng->txt('author'),
722  'metadata' => $this->lng->txt('meta_data')
723  );
724  $o_filter->setTitle($this->lng->txt('search_in'));
725  $o_filter->setOptions($filter_option);
726  $o_filter->setValue($_SESSION['content_filter']['sel_filter_type']);
727  $o_filter->setPostVar('sel_filter_type');
728  $o_hide_check->addSubItem($o_filter);
729  $o_filter_by = new ilTextInputGUI($this->lng->txt('filter_by'));
730  $o_filter_by->setValue($_SESSION['content_filter']['filter_text']);
731  $o_filter_by->setPostVar('filter_text');
732  $o_hide_check->addSubItem($o_filter_by);
733 
734  ilShopTopics::_getInstance()->setIdFilter(false);
735  ilShopTopics::_getInstance()->read();
736  $topic_option = array();
737  if(count(ilShopTopics::_getInstance()->getTopics()))
738  {
739  $topic_option[''] = $this->lng->txt('please_select');
740  foreach(ilShopTopics::_getInstance()->getTopics() as $oTopic)
741  {
742  $topic_option[$oTopic->getId()] = $oTopic->getTitle();
743  }
744  }
745  else
746  {
747  $topic_option[''] = $this->lng->txt('no_topics_yet');
748  }
749  $o_topic = new ilSelectInputGUI();
750  $o_topic->setTitle($this->lng->txt('topic'));
751  $o_topic->setOptions($topic_option);
752  $o_topic->setValue($_SESSION['content_filter']['filter_topic_id']);
753  $o_topic->setPostVar('filter_topic_id');
754  $o_hide_check->addSubItem($o_topic);
755 
756  #if(count($oResult->getResults()))
757  if($a_count_result)
758  {
759  $objects = (bool)$this->oGeneralSettings->get('objects_allow_custom_sorting');
760  if($objects)
761  {
762  // sorting form
763  $allow_objects_option = array(
764  'title' => $this->lng->txt('title'),
765  'author' => $this->lng->txt('author'),
766  'price' => $this->lng->txt('price_a')
767  );
768  $o_allow_objects = new ilSelectInputGUI();
769  $o_allow_objects->setTitle($this->lng->txt('sort_by'));
770  $o_allow_objects->setOptions($allow_objects_option);
771  $o_allow_objects->setValue($this->getSortField());
772  $o_allow_objects->setPostVar('order_field'); //objects_sorting_type
773  $o_hide_check->addSubItem($o_allow_objects);
774 
775  $direction_option = array(
776  'asc' => $this->lng->txt('sort_asc'),
777  'desc' => $this->lng->txt('sort_desc')
778  );
779 
780  $o_object_direction = new ilSelectInputGUI();
781 
782  $o_object_direction->setOptions($direction_option);
783  $o_object_direction->setValue($this->getSortDirection());
784  $o_object_direction->setPostVar('order_direction'); //objects_sorting_direction
785 
786  $o_hide_check->addSubItem($o_object_direction);
787  }
788 
789  $topics = (bool)$this->oGeneralSettings->get('topics_allow_custom_sorting');
790  if($topics)
791  {
792  // sorting form
793  $allow_topics_option = array(
794  ilShopTopics::TOPICS_SORT_BY_TITLE => $this->lng->txt('sort_topics_by_title'),
795  ilShopTopics::TOPICS_SORT_BY_CREATEDATE => $this->lng->txt('sort_topics_by_date')
796  );
797  if(ANONYMOUS_USER_ID != $ilUser->getId())
798  {
799  $allow_topics_option[ilShopTopics::TOPICS_SORT_MANUALLY] = $this->lng->txt('sort_topics_manually');
800  }
801 
802  $o_allow_topics = new ilSelectInputGUI();
803  $o_allow_topics->setTitle($this->lng->txt('sort_topics_by'));
804  $o_allow_topics->setOptions($allow_topics_option);
805 
806  $o_allow_topics->setValue($this->getSortingTypeTopics());
807  $o_allow_topics->setPostVar('topics_sorting_type');
808  $o_hide_check->addSubItem($o_allow_topics);
809 
810  $direction_option = array(
811  'asc' => $this->lng->txt('sort_asc'),
812  'desc' => $this->lng->txt('sort_desc')
813  );
814 
815  $o_topics_direction = new ilSelectInputGUI();
816  $o_topics_direction->setOptions($direction_option);
817  $o_topics_direction->setValue($this->getSortingDirectionTopics());
818  $o_topics_direction->setPostVar('topics_sorting_direction'); //objects_sorting_type
819 
820  $o_hide_check->addSubItem($o_topics_direction);
821  }
822  }
823 
824  $filter_form->addCommandButton('setFilter', $this->lng->txt('pay_update_view'));
825  $filter_form->addCommandButton('resetFilter', $this->lng->txt('pay_reset_filter'));
826  $filter_form->addItem($o_hide_check);
827 
828  return $filter_form->getHTML();
829  }
830 
831  public function showTopicsFilter($a_count_result = 0)
832  {
833  global $ilUser;
834 
835  $this->tpl->setCurrentBlock('show_topics_filter');
836 
837  ilShopTopics::_getInstance()->setIdFilter(false);
838  ilShopTopics::_getInstance()->read();
839 
840  if(count(ilShopTopics::_getInstance()->getTopics()))
841  {
842  $this->tpl->setVariable('PAGE_CONTENT', $this->getPageHTML());
843  $this->tpl->setVariable('SORTING_FORM_ACTION', $this->ctrl->getFormAction($this, 'setFilter'));
844 
845  $this->tpl->setVariable('SET_FILTER_VAL', $this->lng->txt('pay_update_view'));
846 
847  $this->tpl->setCurrentBlock('topics_option');
848  $this->tpl->setVariable('SORT_TOPICS', $this->lng->txt('topic'));
849 
850  $this->tpl->setVariable('FILTER_TOPIC_ID', 'no_selection');
851  $this->tpl->setVariable('FILTER_TOPIC_TEXT', '------------');
852  if($_POST['cmd'] == 'firstpage')
853  $this->tpl->setVariable('FILTER_TOPIC_SELECTED', 'selected');
854  $this->tpl->parseCurrentBlock('topics_option');
855 
856  $this->tpl->setVariable('FILTER_TOPIC_ID', 'all');
857  $this->tpl->setVariable('FILTER_TOPIC_TEXT', $this->lng->txt('all'));
858  if($_POST['filter_topic_id'] == 'all')
859  $this->tpl->setVariable('FILTER_TOPIC_SELECTED', 'selected');
860  $this->tpl->parseCurrentBlock('topics_option');
861 
862  $oTopics = array();
863  $oTopics = ilShopTopics::_getInstance()->getTopics();
864  foreach($oTopics as $oTopic)
865  {
866  $this->tpl->setVariable('FILTER_TOPIC_ID', $oTopic->getId());
867  $this->tpl->setVariable('FILTER_TOPIC_TEXT', $oTopic->getTitle());
868  if($_POST['filter_topic_id'] == $oTopic->getId())
869  $this->tpl->setVariable('FILTER_TOPIC_SELECTED', 'selected');
870  $this->tpl->parseCurrentBlock('topics_option');
871  }
872  }
873 
874  if($a_count_result)
875  {
876  $objects = (bool)$this->oGeneralSettings->get('objects_allow_custom_sorting');
877  if($objects)
878  {
879  // sorting form
880  $allow_objects_option = array(
881  'title' => $this->lng->txt('title'),
882  'author' => $this->lng->txt('author'),
883  'price' => $this->lng->txt('price_a')
884  );
885  $this->tpl->setCurrentBlock('order_field');
886  $this->tpl->setVariable('SORT_BY_TEXT', $this->lng->txt('sort_by'));
887 
888  foreach($allow_objects_option as $key=> $value)
889  {
890  $this->tpl->setVariable('ORDER_FIELD_VALUE', $key);
891  $this->tpl->setVariable('ORDER_FIELD_TEXT', $value);
892  if($_POST['order_field'] == $key)
893  $this->tpl->setVariable('ORDER_FIELD_SELECTED', 'selected');
894  $this->tpl->parseCurrentBlock('order_field');
895  }
896  }
897 
898  $topics = (bool)$this->oGeneralSettings->get('topics_allow_custom_sorting');
899 
900  if($topics)
901  {
902  // sorting form
903  $allow_topics_option = array(
904  ilShopTopics::TOPICS_SORT_BY_TITLE => $this->lng->txt('sort_topics_by_title'),
905  ilShopTopics::TOPICS_SORT_BY_CREATEDATE => $this->lng->txt('sort_topics_by_date')
906  );
907  if(ANONYMOUS_USER_ID != $ilUser->getId())
908  {
909  $allow_topics_option[ilShopTopics::TOPICS_SORT_MANUALLY] = $this->lng->txt('sort_topics_manually');
910  }
911 // $direction_option = array(
912 // 'asc' => $this->lng->txt('sort_asc'),
913 // 'desc' => $this->lng->txt('sort_desc')
914 // );
915  }
916  }
917  }
918 
919  public function setTopicId($a_topic_id)
920  {
921  $this->topic_id = $a_topic_id;
922  }
923 
924  public function getTopicId()
925  {
926  return $this->topic_id;
927  }
928 
929  public function setString($a_str)
930  {
931  $this->string = $a_str;
932  }
933 
934  public function getString()
935  {
936  return $this->string;
937  }
938 
939  public function setType($a_type)
940  {
941  $this->type = $a_type;
942  }
943 
944  public function getType()
945  {
946  return $this->type;
947  }
948 
949  public function setSortDirection($a_sort_direction)
950  {
951  $this->sort_direction = $a_sort_direction;
952  }
953 
954  public function getSortDirection()
955  {
956  return $this->sort_direction;
957  }
958 
959  public function setSortField($a_field)
960  {
961  $this->sort_field = $a_field;
962  }
963 
964  public function getSortField()
965  {
966  return $this->sort_field;
967  }
968 
969  public function setSortingTypeTopics($a_field)
970  {
971  global $ilUser;
972 
973  if(ANONYMOUS_USER_ID == $ilUser->getId() &&
975  )
976  {
978  }
979 
980  $this->sort_type_topics = $a_field;
981  }
982 
983  public function getSortingTypeTopics()
984  {
985  global $ilUser;
986 
987  if(ANONYMOUS_USER_ID == $ilUser->getId() &&
988  $this->sort_type_topics == ilShopTopics::TOPICS_SORT_MANUALLY
989  )
990  {
991  $this->sort_type_topics = ilShopTopics::TOPICS_SORT_BY_TITLE;
992  }
993 
995  }
996 
997  public function setSortingDirectionTopics($a_sort_direction)
998  {
999  $_SESSION['shop_content']['shop_topics_sorting_direction'] = $this->sort_direction_topics = $a_sort_direction;
1000  }
1001 
1002  public function getSortingDirectionTopics()
1003  {
1005  }
1006 
1007  protected function prepareOutput()
1008  {
1009  global $ilTabs;
1010 
1012  $ilTabs->setTabActive('content');
1013  }
1014 }