ILIAS  eassessment Revision 61809
 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/Form/classes/class.ilPropertyFormGUI.php';
6 
16 class ilShopGUI extends ilShopBaseGUI
17 {
18  const SHOP_PAGE_EDITOR_PAGE_ID = 99999999;
19 
20  private $sort_type_topics = '';
21  private $sort_direction_topics = '';
22  private $sort_field = '';
23  private $sort_direction = '';
24  private $string = '';
25  private $type = '';
26  private $topic_id = 0;
27 
28  private $form = null;
29 
30  public function __construct()
31  {
33 
34  // set filter settings
35  $this->setType($_SESSION['shop_content']['type']);
36  $this->setString($_SESSION['shop_content']['text']);
37  $this->setTopicId($_SESSION['shop_content']['shop_topic_id']);
38 
39  // set sorting
40  $this->setSortingTypeTopics($_SESSION['shop_content']['order_topics_sorting_type']);
41  $this->setSortingDirectionTopics($_SESSION['shop_content']['shop_topics_sorting_direction']);
42  $this->setSortField($_SESSION['shop_content']['shop_order_field']);
43  $this->setSortDirection($_SESSION['shop_content']['shop_order_direction']);
44  }
45 
46  function executeCommand()
47  {
48  global $ilUser;
49 
50  // Check for incomplete profile
51  if($ilUser->getProfileIncomplete())
52  {
53  ilUtil::redirect('ilias.php?baseClass=ilPersonalDesktopGUI');
54  }
55 
56  // check whether password of user have to be changed
57  // due to first login or password of user is expired
58  if( $ilUser->isPasswordChangeDemanded() || $ilUser->isPasswordExpired() )
59  {
60  ilUtil::redirect('ilias.php?baseClass=ilPersonalDesktopGUI');
61  }
62 
63  $next_class = $this->ctrl->getNextClass($this);
64  $cmd = $this->ctrl->getCmd();
65 
66  switch($next_class)
67  {
68  case 'ilpageobjectgui':
69  $this->prepareOutput();
70  $ret = $this->forwardToPageObject();
71  if($ret != '')
72  {
73  $this->tpl->setContent($ret);
74  }
75  break;
76  default:
77  if(!$cmd)
78  {
79  $cmd = 'performSearch';
80  }
81  $this->prepareOutput();
82  $this->$cmd();
83 
84  break;
85  }
86 
87  return true;
88  }
89 
90  public function clearFilter()
91  {
92  $this->setString('');
93  $this->setType('');
94  $this->setTopicId(0);
95 
96  return $this->performSearch();
97  }
98 
99  public function getPageHTML()
100  {
101  // page object
102  include_once 'Services/COPage/classes/class.ilPageObject.php';
103  include_once 'Services/COPage/classes/class.ilPageObjectGUI.php';
104 
105  // if page does not exist, return nothing
106  if(!ilPageObject::_exists('shop', self::SHOP_PAGE_EDITOR_PAGE_ID))
107  {
108  return '';
109  }
110 
111  include_once 'Services/Style/classes/class.ilObjStyleSheet.php';
112  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
113 
114  // get page object
115  $page_gui = new ilPageObjectGUI('shop', self::SHOP_PAGE_EDITOR_PAGE_ID);
116  $page_gui->setIntLinkHelpDefault('StructureObject', self::SHOP_PAGE_EDITOR_PAGE_ID);
117  $page_gui->setLinkXML('');
118  $page_gui->setFileDownloadLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'downloadFile'));
119  $page_gui->setFullscreenLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'displayMediaFullscreen'));
120  $page_gui->setSourcecodeDownloadScript($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'download_paragraph'));
121  $page_gui->setPresentationTitle('');
122  $page_gui->setTemplateOutput(false);
123  $page_gui->setHeader('');
124  $page_gui->setEnabledRepositoryObjects(false);
125  $page_gui->setEnabledFileLists(true);
126  $page_gui->setEnabledPCTabs(true);
127  $page_gui->setEnabledMaps(true);
128 
129  return $page_gui->showPage();
130  }
131 
132  public function forwardToPageObject()
133  {
134  global $lng, $ilTabs;
135 
136  $ilTabs->clearTargets();
137  $ilTabs->setBackTarget($lng->txt('back'), $this->ctrl->getLinkTarget($this), '_top');
138 
139  // page object
140  include_once 'Services/COPage/classes/class.ilPageObject.php';
141  include_once 'Services/COPage/classes/class.ilPageObjectGUI.php';
142 
143  $lng->loadLanguageModule('content');
144 
145  include_once('./Services/Style/classes/class.ilObjStyleSheet.php');
146  $this->tpl->setVariable('LOCATION_CONTENT_STYLESHEET', ilObjStyleSheet::getContentStylePath(0));
147 
148  if(!ilPageObject::_exists('shop', self::SHOP_PAGE_EDITOR_PAGE_ID))
149  {
150  // doesn't exist -> create new one
151  $new_page_object = new ilPageObject('shop');
152  $new_page_object->setParentId(0);
153  $new_page_object->setId(self::SHOP_PAGE_EDITOR_PAGE_ID);
154  $new_page_object->createFromXML();
155  }
156 
157  $this->ctrl->setReturnByClass('ilpageobjectgui', 'edit');
158 
159  $page_gui = new ilPageObjectGUI('shop', self::SHOP_PAGE_EDITOR_PAGE_ID);
160  $page_gui->setIntLinkHelpDefault('StructureObject', self::SHOP_PAGE_EDITOR_PAGE_ID);
161  $page_gui->setTemplateTargetVar('ADM_CONTENT');
162  $page_gui->setLinkXML('');
163  $page_gui->setFileDownloadLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'downloadFile'));
164  $page_gui->setFullscreenLink($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'displayMediaFullscreen'));
165  $page_gui->setSourcecodeDownloadScript($this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'download_paragraph'));
166  $page_gui->setPresentationTitle('');
167  $page_gui->setTemplateOutput(false);
168  $page_gui->setHeader('');
169  $page_gui->setEnabledRepositoryObjects(false);
170  $page_gui->setEnabledFileLists(true);
171  $page_gui->setEnabledMaps(true);
172  $page_gui->setEnabledPCTabs(true);
173 
174  return $this->ctrl->forwardCommand($page_gui);
175  }
176 
177  public function setFilter()
178  {
179  $this->setString($_POST['filter_text']);
180  $this->setType($_POST['sel_filter_type']);
181  $this->setTopicId($_POST['filter_topic_id']);
182 
183  $this->setSortingTypeTopics($_POST['topics_sorting_type']);
184  $this->setSortingDirectionTopics($_POST['topics_sorting_direction']);
185  $this->setSortField($_POST['order_field']);
186  $this->setSortDirection($_POST['order_direction']);
187 
188  $this->performSearch();
189 
190  return true;
191  }
192 
193 
194  public function performSearch($oResult = null)
195  {
196  global $ilUser;
197 
198  if(!is_object($oResult))
199  {
200  $oResult = new ilShopSearchResult(SHOP_CONTENT);
201  if((bool)$this->oGeneralSettings->get('topics_allow_custom_sorting'))
202  {
203  ilShopTopics::_getInstance()->setIdFilter((int)$this->getTopicId());
204  ilShopTopics::_getInstance()->enableCustomSorting(true);
205  ilShopTopics::_getInstance()->setSortingType((int)$this->getSortingTypeTopics());
206  ilShopTopics::_getInstance()->setSortingDirection(strtoupper($this->getSortingDirectionTopics()));
207  ilShopTopics::_getInstance()->read();
208  }
209  else
210  {
211  ilShopTopics::_getInstance()->setIdFilter((int)$this->getTopicId());
212  ilShopTopics::_getInstance()->enableCustomSorting(false);
213  ilShopTopics::_getInstance()->setSortingType((int)$this->oGeneralSettings->get('topics_sorting_type'));
214  ilShopTopics::_getInstance()->setSortingDirection(strtoupper($this->oGeneralSettings->get('topics_sorting_direction')));
215  ilShopTopics::_getInstance()->read();
216  }
217  $oResult->setTopics(ilShopTopics::_getInstance()->getTopics());
218  $oResult->setResultPageNumber((int)$_GET['page_number']);
219  }
220 
221  // query parser
222  include_once 'Services/Search/classes/class.ilQueryParser.php';
223  $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->getString()));
224  $query_parser->setMinWordLength(0);
225  $query_parser->setCombination(QP_COMBINATION_AND);
226  $query_parser->parse();
227  if (!$query_parser->validate())
228  {
229  ilUtil::sendInfo($query_parser->getMessage());
230  }
231 
232  // search
233  $types = array('crs', 'lm', 'sahs', 'htlm', 'file', 'tst');
234  if ($this->getType() == '' || $this->getType() == 'title' ||
235  $query_parser->getQueryString() == '')
236  {
237  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
238  $object_search = ilObjectSearchFactory::_getShopObjectSearchInstance($query_parser);
239  $object_search->setFields(array('title'));
240  $object_search->setFilter($types);
241  $object_search->setCustomSearchResultObject($oResult);
242  $object_search->setFilterShopTopicId((int)$this->getTopicId());
243  $res = $object_search->performSearch();
244  }
245  else if($this->getType() == 'author')
246  {
247 
248  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
249  $meta_search = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser);
250  $meta_search->setMode('contribute');
251  $meta_search->setFilter($types);
252  $meta_search->setFilterShopTopicId((int)$this->getTopicId());
253  $meta_search->setCustomSearchResultObject($oResult);
254  $res = $meta_search->performSearch();
255  }
256  else
257  {
258  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
259  $meta_search = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser);
260  $meta_search->setMode('title');
261  $meta_search->setFilter($types);
262  $meta_search->setCustomSearchResultObject($oResult);
263  $meta_search->setFilterShopTopicId((int)$this->getTopicId());
264  $res = $meta_search->performSearch();
265 
266  $meta_search = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser);
267  $meta_search->setMode('keyword');
268  $meta_search->setFilter($types);
269  $meta_search->setCustomSearchResultObject($oResult);
270  $meta_search->setFilterShopTopicId((int)$this->getTopicId());
271  $res->mergeEntries($meta_search->performSearch());
272  }
273 
274  $res->filter(ROOT_FOLDER_ID, true);
275  $res->save();
276 
277  if(!count($res->getResults()))
278  {
279  ilUtil::sendInfo($this->lng->txt('payment_shop_not_objects_found'));
280  }
281 
282  $this->showShopContent($res);
283 
284  include_once 'Services/Payment/classes/class.ilShopResultPresentationGUI.php';
285  $search_result_presentation = new ilShopResultPresentationGUI($res);
286  $search_result_presentation->setSortField(strtolower(trim($this->getSortField())));
287  $search_result_presentation->setSortDirection(trim($this->getSortDirection()));
288 
289  $this->tpl->setVariable('RESULTS', $search_result_presentation->showResults());
290  $this->addPager($res, 'shop_content_maxpage');
291  return true;
292  }
293  public function resetFilter()
294  {
295  unset($_SESSION['content_filter']);
296  unset($_POST['sel_filter_type']);
297  unset($_POST['filter_text']);
298  unset($_POST['filter_topic_id']);
299  unset($_POST['order_field']);
300  unset($_POST['order_direction']);
301  unset($_POST['topics_sorting_type']);
302  unset($_POST['topics_sorting_direction']);
303 
304  unset($_POST['updateView']);
305  unset($_POST['show_filter']);
306 
307  ilUtil::sendInfo($this->lng->txt('paya_filter_reseted'));
308  $this->setString('');
309  $this->setType('');
310  $this->setTopicId(0);
311 
312  $this->performSearch();
313 
314  return true;
315  }
316  public function showShopContent($oResult)
317  {
318  global $ilUser, $rbacreview, $ilToolbar;
319 
320 // include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
321 
322  if($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID))
323  {
324  $ilToolbar->addButton($this->lng->txt('edit_page'), $this->ctrl->getLinkTargetByClass(array('ilpageobjectgui'), 'edit'));
325  }
326 
327  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.shop_content.html', 'Services/Payment');
328 
329  $this->tpl->setVariable('PAGE_CONTENT', $this->getPageHTML());
330 
331  if(!$_POST['show_filter'] && $_POST['updateView'] == '1')
332  {
333  $this->resetFilter();
334  }
335  else
336  if ($_POST['updateView'] == 1)
337  {
338  $_SESSION['content_filter']['updateView'] = $_POST['updateView'];
339  $_SESSION['content_filter']['show_filter'] = $_POST['show_filter'];
340  $_SESSION['content_filter']['sel_filter_type'] = $_POST['sel_filter_type'];
341  $_SESSION['content_filter']['filter_text'] = $_POST['filter_text'];
342  $_SESSION['content_filter']['filter_topic_id'] = $_POST['filter_topic_id'];
343 
344  $_SESSION['content_filter']['order_field'] = $_POST['order_field'];
345  $_SESSION['content_filter']['order_direction'] = $_POST['order_direction'];
346 
347  $_SESSION['content_filter']['topics_sorting_type'] = $_POST['topics_sorting_type'];
348  $_SESSION['content_filter']['topics_sorting_direction'] = $_POST['topics_sorting_direction'];
349  }
350 
351  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
352  // FILTER FORM
353  $filter_form = new ilPropertyFormGUI();
354  $filter_form->setFormAction($this->ctrl->getFormAction($this));
355  $filter_form->setTitle($this->lng->txt('pay_filter'));
356  $filter_form->setId('formular');
357  $filter_form->setTableWidth('100 %');
358 
359  $o_hide_check = new ilCheckBoxInputGUI($this->lng->txt('show_filter'),'show_filter');
360  $o_hide_check->setValue(1);
361  $o_hide_check->setChecked($_SESSION['content_filter']['show_filter'] ? 1 : 0);
362 
363  $o_hidden = new ilHiddenInputGUI('updateView');
364  $o_hidden->setValue(1);
365  $o_hidden->setPostVar('updateView');
366  $o_hide_check->addSubItem($o_hidden);
367 
368  $o_filter = new ilSelectInputGUI();
369  $filter_option = array(
370  'title' => $this->lng->txt('title'),
371  'author' => $this->lng->txt('author'),
372  'metadata' => $this->lng->txt('meta_data')
373  );
374  $o_filter->setTitle($this->lng->txt('search_in'));
375  $o_filter->setOptions($filter_option);
376  $o_filter->setValue($_SESSION['content_filter']['sel_filter_type']);
377  $o_filter->setPostVar('sel_filter_type');
378  $o_hide_check->addSubItem($o_filter);
379 
380  $o_filter_by = new ilTextInputGUI($this->lng->txt('filter_by'));
381  $o_filter_by->setValue($_SESSION['content_filter']['filter_text']);
382  $o_filter_by->setPostVar('filter_text');
383  $o_hide_check->addSubItem($o_filter_by);
384 
385  ilShopTopics::_getInstance()->setIdFilter(false);
386  ilShopTopics::_getInstance()->read();
387  $topic_option = array();
388  if(count(ilShopTopics::_getInstance()->getTopics()))
389  {
390  $topic_option[''] = $this->lng->txt('please_select');
391  foreach(ilShopTopics::_getInstance()->getTopics() as $oTopic)
392  {
393  $topic_option[$oTopic->getId()] = $oTopic->getTitle();
394  }
395  }
396  else
397  {
398  $topic_option[''] = $this->lng->txt('no_topics_yet');
399  }
400  $o_topic = new ilSelectInputGUI();
401  $o_topic->setTitle($this->lng->txt('topic'));
402  $o_topic->setOptions($topic_option);
403  $o_topic->setValue($_SESSION['content_filter']['filter_topic_id']);
404  $o_topic->setPostVar('filter_topic_id');
405  $o_hide_check->addSubItem($o_topic);
406 
407  if(count($oResult->getResults()))
408  {
409  $objects = (bool)$this->oGeneralSettings->get('objects_allow_custom_sorting');
410  if($objects)
411  {
412  // sorting form
413  $allow_objects_option = array(
414  'title' => $this->lng->txt('title'),
415  'author' => $this->lng->txt('author'),
416  'price' => $this->lng->txt('price_a')
417  );
418  $o_allow_objects = new ilSelectInputGUI();
419  $o_allow_objects->setTitle($this->lng->txt('sort_by'));
420  $o_allow_objects->setOptions($allow_objects_option);
421  $o_allow_objects->setValue($this->getSortField());
422  $o_allow_objects->setPostVar('order_field'); //objects_sorting_type
423  $o_hide_check->addSubItem($o_allow_objects);
424 
425  $direction_option = array(
426  'asc' => $this->lng->txt('sort_asc'),
427  'desc' => $this->lng->txt('sort_desc')
428  );
429 
430  $o_object_direction = new ilSelectInputGUI();
431 
432  $o_object_direction->setOptions($direction_option);
433  $o_object_direction->setValue($this->getSortDirection());
434  $o_object_direction->setPostVar('order_direction'); //objects_sorting_direction
435 
436  $o_hide_check->addSubItem($o_object_direction);
437  }
438 
439  $topics = (bool)$this->oGeneralSettings->get('topics_allow_custom_sorting');
440  if($topics)
441  {
442  // sorting form
443  $allow_topics_option = array(
444  ilShopTopics::TOPICS_SORT_BY_TITLE => $this->lng->txt('sort_topics_by_title'),
445  ilShopTopics::TOPICS_SORT_BY_CREATEDATE => $this->lng->txt('sort_topics_by_date')
446  );
447  if(ANONYMOUS_USER_ID != $ilUser->getId())
448  {
449  $allow_topics_option[ilShopTopics::TOPICS_SORT_MANUALLY] = $this->lng->txt('sort_topics_manually');
450  }
451 
452  $o_allow_topics = new ilSelectInputGUI();
453  $o_allow_topics->setTitle($this->lng->txt('sort_topics_by'));
454  $o_allow_topics->setOptions($allow_topics_option);
455 
456  $o_allow_topics->setValue($this->getSortingTypeTopics());
457  $o_allow_topics->setPostVar('topics_sorting_type');
458  $o_hide_check->addSubItem($o_allow_topics);
459 
460  $direction_option = array(
461  'asc' => $this->lng->txt('sort_asc'),
462  'desc' => $this->lng->txt('sort_desc')
463  );
464 
465  $o_topics_direction = new ilSelectInputGUI();
466  $o_topics_direction->setOptions($direction_option);
467  $o_topics_direction->setValue($this->getSortingDirectionTopics());
468  $o_topics_direction->setPostVar('topics_sorting_direction'); //objects_sorting_type
469 
470  $o_hide_check->addSubItem($o_topics_direction);
471  }
472  }
473 
474  $filter_form->addCommandButton('setFilter', $this->lng->txt('pay_update_view'));
475  $filter_form->addCommandButton('resetFilter', $this->lng->txt('pay_reset_filter'));
476  $filter_form->addItem($o_hide_check);
477 
478  $this->tpl->setVariable('FORM', $filter_form->getHTML());
479 
480  }
481 
482  public function setTopicId($a_topic_id)
483  {
484  $_SESSION['shop_content']['shop_topic_id'] = $this->topic_id = $a_topic_id;
485  }
486  public function getTopicId()
487  {
488  return $this->topic_id;
489  }
490  public function setString($a_str)
491  {
492  $_SESSION['shop_content']['text'] = $this->string = $a_str;
493  }
494  public function getString()
495  {
496  return $this->string;
497  }
498  public function setType($a_type)
499  {
500  $_SESSION['shop_content']['type'] = $this->type = $a_type;
501  }
502  public function getType()
503  {
504  return $this->type;
505  }
506  public function setSortDirection($a_sort_direction)
507  {
508  $_SESSION['shop_content']['order_direction'] = $this->sort_direction = $a_sort_direction;
509  }
510  public function getSortDirection()
511  {
512  return $this->sort_direction;
513  }
514  public function setSortField($a_field)
515  {
516  $_SESSION['shop_content']['shop_order_field'] = $this->sort_field = $a_field;
517  }
518  public function getSortField()
519  {
520  return $this->sort_field;
521  }
522  public function setSortingTypeTopics($a_field)
523  {
524  global $ilUser;
525 
526  if(ANONYMOUS_USER_ID == $ilUser->getId() &&
528  {
530  }
531 
532  $_SESSION['shop_content']['order_topics_sorting_type'] = $this->sort_type_topics = $a_field;
533  }
534  public function getSortingTypeTopics()
535  {
536  global $ilUser;
537 
538  if(ANONYMOUS_USER_ID == $ilUser->getId() &&
539  $this->sort_type_topics == ilShopTopics::TOPICS_SORT_MANUALLY)
540  {
541  $this->sort_type_topics = ilShopTopics::TOPICS_SORT_BY_TITLE;
542  }
543 
544  else
545 
547  }
548  public function setSortingDirectionTopics($a_sort_direction)
549  {
550  $_SESSION['shop_content']['shop_topics_sorting_direction'] = $this->sort_direction_topics = $a_sort_direction;
551  }
552  public function getSortingDirectionTopics()
553  {
555  }
556 
557  protected function prepareOutput()
558  {
559  global $ilTabs;
560 
562 
563  $ilTabs->setTabActive('content');
564  }
565 }
566 ?>