public function performSearch($oResult = null) { if (!is_object($oResult)) { $oResult = new ilShopSearchResult(SHOP_CONTENT); if ((bool) $this->oGeneralSettings->get('topics_allow_custom_sorting')) { ilShopTopics::_getInstance()->setIdFilter((int) $this->getTopicId()); ilShopTopics::_getInstance()->enableCustomSorting(true); ilShopTopics::_getInstance()->setSortingType((int) $this->getSortingTypeTopics()); ilShopTopics::_getInstance()->setSortingDirection(strtoupper($this->getSortingDirectionTopics())); ilShopTopics::_getInstance()->read(); } else { ilShopTopics::_getInstance()->setIdFilter((int) $this->getTopicId()); ilShopTopics::_getInstance()->enableCustomSorting(false); ilShopTopics::_getInstance()->setSortingType((int) $this->oGeneralSettings->get('topics_sorting_type')); ilShopTopics::_getInstance()->setSortingDirection(strtoupper($this->oGeneralSettings->get('topics_sorting_direction'))); ilShopTopics::_getInstance()->read(); } $topics = ilShopTopics::_getInstance()->getTopics(); $oResult->setTopics($topics); $oResult->setResultPageNumber((int) $_GET['page_number']); } // query parser include_once 'Services/Search/classes/class.ilQueryParser.php'; $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->getString())); $query_parser->setMinWordLength(0); $query_parser->setCombination(QP_COMBINATION_AND); $query_parser->parse(); if (!$query_parser->validate()) { ilUtil::sendInfo($query_parser->getMessage()); } // search $types = array('crs', 'lm', 'sahs', 'htlm', 'file', 'tst', 'exc', 'glo'); if ($this->getType() == '' || $this->getType() == 'title' || $query_parser->getQueryString() == '') { include_once 'Services/Search/classes/class.ilObjectSearchFactory.php'; $object_search = ilObjectSearchFactory::_getShopObjectSearchInstance($query_parser); $object_search->setFields(array('title')); $object_search->setFilter($types); $object_search->setCustomSearchResultObject($oResult); $object_search->setFilterShopTopicId((int) $this->getTopicId()); $res = $object_search->performSearch(); } else { if ($this->getType() == 'author') { include_once 'Services/Search/classes/class.ilObjectSearchFactory.php'; $meta_search = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser); $meta_search->setMode('contribute'); $meta_search->setFilter($types); $meta_search->setFilterShopTopicId((int) $this->getTopicId()); $meta_search->setCustomSearchResultObject($oResult); $res = $meta_search->performSearch(); } else { include_once 'Services/Search/classes/class.ilObjectSearchFactory.php'; $meta_search = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser); $meta_search->setMode('title'); $meta_search->setFilter($types); $meta_search->setCustomSearchResultObject($oResult); $meta_search->setFilterShopTopicId((int) $this->getTopicId()); $res = $meta_search->performSearch(); $meta_search = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser); $meta_search->setMode('keyword'); $meta_search->setFilter($types); $meta_search->setCustomSearchResultObject($oResult); $meta_search->setFilterShopTopicId((int) $this->getTopicId()); $res->mergeEntries($meta_search->performSearch()); } } $res->filter(ROOT_FOLDER_ID, true); $res->save(); if (!count($res->getResults())) { #ilUtil::sendInfo($this->lng->txt('payment_shop_not_objects_found')); $this->tpl->setVariable('ERROR', $this->lng->txt('payment_shop_not_objects_found')); } $this->showShopContent($res); include_once 'Services/Payment/classes/class.ilShopResultPresentationGUI.php'; $search_result_presentation = new ilShopResultPresentationGUI($res); $search_result_presentation->setSortField(strtolower(trim($this->getSortField()))); $search_result_presentation->setSortDirection(trim($this->getSortDirection())); $this->tpl->setVariable('RESULTS', $search_result_presentation->showResults()); $this->addPager($res, 'shop_content_maxpage'); return true; }
public function showForm($result = null) { global $ilUser; $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.shop_advanced_search.html', 'Services/Payment'); $this->tpl->setVariable('TBL_TITLE', $this->lng->txt('advanced_search')); $this->tpl->setVariable('SEARCH_ACTION', $this->ctrl->getFormAction($this)); $this->tpl->setVariable('TXT_SEARCHTERM', $this->lng->txt('search_search_term')); $this->tpl->setVariable('TXT_AND', $this->lng->txt('search_all_words')); $this->tpl->setVariable('TXT_OR', $this->lng->txt('search_any_word')); $this->tpl->setVariable('TXT_OBJECT_TYPE', $this->lng->txt('obj_type')); $this->tpl->setVariable('TXT_TOPIC', $this->lng->txt('topic')); $this->tpl->setVariable('BTN_SEARCH', $this->lng->txt('search')); $this->tpl->setVariable('FORM_SEARCH_STR', ilUtil::prepareFormOutput($this->getString(), true)); if ($this->getCombination() == self::SEARCH_AND) { $this->tpl->setVariable('AND_CHECKED', 'checked="checked"'); } else { $this->tpl->setVariable('OR_CHECKED', 'checked="checked"'); } $this->tpl->setVariable('CRS', $this->lng->txt('courses')); $this->tpl->setVariable('LMS', $this->lng->txt('learning_resources')); $this->tpl->setVariable('TST', $this->lng->txt('tests')); $this->tpl->setVariable('FIL', $this->lng->txt('objs_file')); $details = $this->getDetails(); $this->tpl->setVariable('CHECK_CRS', ilUtil::formCheckbox($details['crs'] ? 1 : 0, 'search[details][crs]', 1)); $this->tpl->setVariable('CHECK_LMS', ilUtil::formCheckbox($details['lms'] ? 1 : 0, 'search[details][lms]', 1)); $this->tpl->setVariable('CHECK_TST', ilUtil::formCheckbox($details['tst'] ? 1 : 0, 'search[details][tst]', 1)); $this->tpl->setVariable('CHECK_FIL', ilUtil::formCheckbox($details['fil'] ? 1 : 0, 'search[details][fil]', 1)); $selectable_topics = array(); $selectable_topics[''] = $this->lng->txt('search_any'); ilShopTopics::_getInstance()->setIdFilter(false); ilShopTopics::_getInstance()->read(); foreach (ilShopTopics::_getInstance()->getTopics() as $oTopic) { $selectable_topics[$oTopic->getId()] = $oTopic->getTitle(); } $this->tpl->setVariable('SELECT_TOPIC', ilUtil::formSelect(array($this->getTopicId()), 'search[topic]', $selectable_topics, false, true)); // show results if (count($result->getResults())) { include_once 'Services/Payment/classes/class.ilShopResultPresentationGUI.php'; $search_result_presentation = new ilShopResultPresentationGUI($result); $this->tpl->setVariable('RESULTS', $search_result_presentation->showResults()); $objects = (bool) $this->oGeneralSettings->get('objects_allow_custom_sorting'); $topics = (bool) $this->oGeneralSettings->get('topics_allow_custom_sorting'); if ($objects) { $this->tpl->setCurrentBlock('objects_sort_block'); $order_fields = array('title' => $this->lng->txt('title'), 'author' => $this->lng->txt('author'), 'price' => $this->lng->txt('price_a')); foreach ($order_fields as $key => $value) { $this->tpl->setCurrentBlock('order_field'); $this->tpl->setVariable('ORDER_FIELD_VALUE', $key); $this->tpl->setVariable('ORDER_FIELD_TEXT', $value); if (strcmp(trim($this->getSortField()), $key) == 0) { $this->tpl->setVariable('ORDER_FIELD_SELECTED', ' selected="selected"'); } $this->tpl->parseCurrentBlock(); } $this->tpl->setVariable('SORT_BY_TEXT', $this->lng->txt('sort_by')); $this->tpl->setVariable('ASCENDING_TEXT', $this->lng->txt('sort_asc')); $this->tpl->setVariable('DESCENDING_TEXT', $this->lng->txt('sort_desc')); $this->tpl->setVariable('ORDER_DIRECTION_' . strtoupper(trim($this->getSortDirection())) . '_SELECTED', " selected=\"selected\""); $this->tpl->parseCurrentBlock(); } if ($topics) { $this->tpl->setCurrentBlock('topics_sort_block'); $this->tpl->setVariable('SORT_TOPICS_BY_TEXT', $this->lng->txt('sort_topics_by')); $this->tpl->setVariable('SORTING_TYPE_BY_TITLE', ilShopTopics::TOPICS_SORT_BY_TITLE); $this->tpl->setVariable('SORTING_TYPE_BY_TITLE_TEXT', $this->lng->txt('sort_topics_by_title')); if ($this->getSortingTypeTopics() == ilShopTopics::TOPICS_SORT_BY_TITLE) { $this->tpl->setVariable('SORTING_TYPE_BY_TITLE_SELECTED', ' selected="selected"'); } $this->tpl->setVariable('SORTING_TYPE_BY_DATE', ilShopTopics::TOPICS_SORT_BY_CREATEDATE); $this->tpl->setVariable('SORTING_TYPE_BY_DATE_TEXT', $this->lng->txt('sort_topics_by_date')); if ($this->getSortingTypeTopics() == ilShopTopics::TOPICS_SORT_BY_CREATEDATE) { $this->tpl->setVariable('SORTING_TYPE_BY_DATE_SELECTED', ' selected="selected"'); } if (ANONYMOUS_USER_ID != $ilUser->getId()) { $this->tpl->setCurrentBlock('sort_manually'); $this->tpl->setVariable('SORTING_TYPE_MANUALLY', ilShopTopics::TOPICS_SORT_MANUALLY); $this->tpl->setVariable('SORTING_TYPE_MANUALLY_TEXT', $this->lng->txt('sort_topics_manually')); if ($this->getSortingTypeTopics() == ilShopTopics::TOPICS_SORT_MANUALLY) { $this->tpl->setVariable('SORTING_TYPE_MANUALLY_SELECTED', ' selected="selected"'); } $this->tpl->parseCurrentBlock(); } $this->tpl->setVariable('SORTING_DIRECTION_ASCENDING_TEXT', $this->lng->txt('sort_asc')); $this->tpl->setVariable('SORTING_DIRECTION_DESCENDING_TEXT', $this->lng->txt('sort_desc')); if (in_array(strtoupper($this->getSortingDirectionTopics()), array('ASC', 'DESC'))) { $this->tpl->setVariable('SORTING_DIRECTION_' . strtoupper($this->getSortingDirectionTopics()) . '_SELECTED', ' selected="selected"'); } else { $this->tpl->setVariable('SORTING_DIRECTION_' . strtoupper(ilShopTopics::DEFAULT_SORTING_DIRECTION) . '_SELECTED', ' selected="selected"'); } $this->tpl->parseCurrentBlock(); } if ($objects || $topics) { $this->tpl->setCurrentBlock('sort_button'); $this->tpl->setVariable('SORTING_FORM_ACTION', $this->ctrl->getFormAction($this, 'setSorting')); $this->tpl->setVariable('CMD_SORT', 'setSorting'); $this->tpl->setVariable('SORT_TEXT', $this->lng->txt('sort')); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock('sorting'); $this->tpl->parseCurrentBlock(); } $this->addPager($result, 'shop_advanced_search_maxpage'); return true; }