ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilShopAdvancedSearchGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once 'Services/Payment/classes/class.ilShopBaseGUI.php';
5
15{
16 const SEARCH_OR = 'or';
17 const SEARCH_AND = 'and';
18
19 private $string = '';
20 private $combination = '';
21 private $details = array();
22 private $topic_id = 0;
23 private $sort_type_topics = '';
25 private $sort_field = '';
26 private $sort_direction = '';
27
28 public function __construct()
29 {
30 parent::__construct();
31
32 if($this->cmd == 'setFilter')
33 {
34 // set filter
35 $this->setCombination($_SESSION['shop_advanced_search']['combination']);
36 $this->setString($_SESSION['shop_advanced_search']['string']);
37 $this->setDetails($_SESSION['shop_advanced_search']['details']);
38 $this->setTopicId($_SESSION['shop_advanced_search']['topic']);
39
40 // set sorting
41 $this->setSortingTypeTopics($_SESSION['shop_advanced_search']['order_topics_sorting_type']);
42 $this->setSortingDirectionTopics($_SESSION['shop_advanced_search']['shop_topics_sorting_direction']);
43
44 $this->setSortField($_SESSION['shop_advanced_search']['shop_order_field']);
45 $this->setSortDirection($_SESSION['shop_advanced_search']['shop_order_direction']);
46 }
47 }
48
49 public function setSorting()
50 {
51 $this->setSortingTypeTopics($_POST['topics_sorting_type']);
52 $this->setSortingDirectionTopics($_POST['topics_sorting_direction']);
53 $this->setSortField($_POST['order_field']);
54 $this->setSortDirection($_POST['order_direction']);
55
56 $this->performSearch();
57
58 return true;
59 }
60
61 public function executeCommand()
62 {
63 $next_class = $this->ctrl->getNextClass($this);
64 $cmd = $this->ctrl->getCmd();
65
66 if(isset($_POST['cmd']) && $_POST['cmd'] == 'setFilter')
67 {
68 $this->cmd = 'setFilter';
69 }
70 else
71 {
72 $this->cmd = $this->ctrl->getCmd();
73 }
74
75 switch($next_class)
76 {
77 default:
78 if(!$cmd)
79 {
80 $cmd = 'performSearch';
81 }
82 $this->prepareOutput();
83 $this->$cmd();
84
85 break;
86 }
87
88 return true;
89 }
90
91 public function setFilter()
92 {
93 if(isset($_POST['search_combination']))
94 {
95 $this->setCombination($_POST['search_combination']);
96 }
97 if(isset($_POST['search_string']))
98 {
99 $this->setString($_POST['search_string']);
100
101 }
102 if(isset($_POST['search_details']))
103 {
104 $this->setDetails($_POST['search_details']);
105 }
106 if(isset($_POST['search_topic']))
107 {
108 $this->setTopicId($_POST['search_topic']);
109 }
110 $this->performSearch();
111 }
112
113
114 public function resetFilter()
115 {
116 unset($_SESSION['shop_advanced_search']);
117 return $this->showForm();
118 }
119
120 public function performSearch()
121 {
122 if(!$this->getDetails())
123 {
124 if(method_exists($this, $this->ctrl->getCmd()))
125 ilUtil::sendInfo($this->lng->txt('search_choose_object_type'));
127
128 return false;
129 }
130
131 // Step 1: parse query string
132 if(!is_object($query_parser = $this->parseQueryString()))
133 {
134 ilUtil::sendInfo($query_parser);
136
137 return false;
138 }
139
140 // Step 2: perform object search. Get an ObjectSearch object via factory. Depends on fulltext or like search type.
141 $result = $this->searchObjects($query_parser);
142
143 // Step 3:
144 $result->filter(ROOT_FOLDER_ID, $query_parser->getCombination() == 'and');
145 $result->save();
146
147 if(!count($result->getResults()))
148 {
149 ilUtil::sendInfo($this->lng->txt('payment_shop_not_objects_found'));
150 }
151
152 $this->showForm($result);
153
154 return true;
155 }
156
157 private function parseQueryString()
158 {
159 include_once 'Services/Search/classes/class.ilQueryParser.php';
160
161 $query_parser = new ilQueryParser(ilUtil::stripSlashes($this->getString()));
162 $query_parser->setCombination($this->getCombination());
163 $query_parser->parse();
164
165 if (!$query_parser->validate())
166 {
167 return $query_parser->getMessage();
168 }
169
170 return $query_parser;
171 }
172
173 private function searchObjects($query_parser)
174 {
175 // create new search result object and assign the sorted topics
177 if((bool)$this->settings->get('topics_allow_custom_sorting'))
178 {
179 ilShopTopics::_getInstance()->setIdFilter((int)$this->getTopicId());
180 ilShopTopics::_getInstance()->enableCustomSorting(true);
181 ilShopTopics::_getInstance()->setSortingType((int)$this->getSortingTypeTopics());
182 ilShopTopics::_getInstance()->setSortingDirection(strtoupper($this->getSortingDirectionTopics()));
184 }
185 else
186 {
187 ilShopTopics::_getInstance()->setIdFilter((int)$this->getTopicId());
188 ilShopTopics::_getInstance()->enableCustomSorting(false);
189 ilShopTopics::_getInstance()->setSortingType((int)$this->settings->get('topics_sorting_type'));
190 ilShopTopics::_getInstance()->setSortingDirection(strtoupper($this->settings->get('topics_sorting_direction')));
192 }
193 $oSearchResult->setTopics(ilShopTopics::_getInstance()->getTopics());
194 $oSearchResult->setResultPageNumber((int)$_GET['page_number']);
195
196 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
197 $res = null;
198
199 $obj_search = ilObjectSearchFactory::_getShopObjectSearchInstance($query_parser);
200 $obj_search->setFilterShopTopicId((int)$this->getTopicId());
201 $obj_search->setFilter($this->getFilter());
202 $obj_search->setCustomSearchResultObject($oSearchResult);
203 $res = $obj_search->performSearch();
204
205 $meta_search_c = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser);
206 $meta_search_c->setMode('contribute');
207 $meta_search_c->setFilter($this->getFilter());
208 $meta_search_c->setFilterShopTopicId((int)$this->getTopicId());
209 $meta_search_c->setCustomSearchResultObject($oSearchResult);
210 $res->mergeEntries($meta_search_c->performSearch());
211
212 $meta_search_t = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser);
213 $meta_search_t->setMode('title');
214 $meta_search_t->setFilter($this->getFilter());
215 $meta_search_t->setCustomSearchResultObject($oSearchResult);
216 $meta_search_t->setFilterShopTopicId((int)$this->getTopicId());
217 $res->mergeEntries($meta_search_t->performSearch());
218
219 $meta_search_k = ilObjectSearchFactory::_getShopMetaDataSearchInstance($query_parser);
220 $meta_search_k->setMode('keyword');
221 $meta_search_k->setFilter($this->getFilter());
222 $meta_search_k->setCustomSearchResultObject($oSearchResult);
223 $meta_search_k->setFilterShopTopicId((int)$this->getTopicId());
224 $res->mergeEntries($meta_search_k->performSearch());
225
226 return $res;
227 }
228
229 private function getFilter()
230 {
231 foreach($this->getDetails() as $key => $detail_type)
232 {
233 switch($detail_type)
234 {
235 case 'crs':
236 $filter[] = 'crs';
237 break;
238 case 'lms':
239 $filter[] = 'lm';
240 $filter[] = 'sahs';
241 $filter[] = 'htlm';
242 break;
243 case 'tst':
244 $filter[] = 'tst';
245 break;
246 case 'fil':
247 $filter[] = 'file';
248 break;
249 }
250 }
251 return $filter ? $filter : array();
252 }
253
254 public function showForm($result = null)
255 {
256 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.shop_advanced_search.html', 'Services/Payment');
257 include_once 'Services/Payment/classes/class.ilAdvancedSearchFilterGUI.php';
258 $filterGUI = new ilAdvancedSearchFilterGUI($this, $this->cmd);
259 $filterGUI->initFilter();
260 if($this->cmd == 'setFilter')
261 {
262 $filterGUI->writeFilterToSession();
263 }
264 else
265 {
266 $_SESSION['shop_advanced_search'] = array();
267 $filterGUI->resetFilter();
268 }
269 $this->tpl->setVariable('FILTER', $filterGUI->getHtml());
270
271 // show results
272 if($result && count($result->getResults()))
273 {
274 include_once 'Services/Payment/classes/class.ilShopResultPresentationGUI.php';
275 $search_result_presentation = new ilShopResultPresentationGUI($result);
276 $this->tpl->setVariable('RESULTS', $search_result_presentation->showAdvancedSearchResults());
277 }
278 else
279 {
280 $this->tpl->setVariable('RESULTS', $this->lng->txt('payment_shop_not_objects_found'));
281 }
282
283 if($result)
284 {
285 $this->addPager($result);
286 }
287
288// return true;
289 }
290
291 public function setCombination($a_combination)
292 {
293 $_SESSION['shop_advanced_search']['combination'] = $this->combination = $a_combination;
294 }
295 public function getCombination()
296 {
297 return $this->combination ? $this->combination : self::SEARCH_OR;
298 }
299 public function setString($a_str)
300 {
301 $_SESSION['shop_advanced_search']['string'] = $this->string = $a_str;
302 }
303 public function getString()
304 {
305 return $this->string;
306 }
307 public function setDetails($a_details)
308 {
309 $_SESSION['shop_advanced_search']['details'] = $this->details = $a_details;
310 }
311 public function getDetails()
312 {
313 return $this->details ? $this->details : array();
314 }
315 public function setTopicId($a_topic)
316 {
317 $_SESSION['shop_advanced_search']['topic'] = $this->topic_id = $a_topic;
318 }
319 public function getTopicId()
320 {
321 return $this->topic_id;
322 }
323
324 public function setSortDirection($a_sort_direction)
325 {
326 $_SESSION['shop_advanced_search']['order_direction'] = $this->sort_direction = $a_sort_direction;
327 }
328 public function getSortDirection()
329 {
331 }
332 public function setSortField($a_field)
333 {
334 $_SESSION['shop_advanced_search']['shop_order_field'] = $this->sort_field = $a_field;
335 }
336 public function getSortField()
337 {
338 return $this->sort_field;
339 }
340 public function setSortingTypeTopics($a_field)
341 {
342 global $ilUser;
343
344 if(ANONYMOUS_USER_ID == $ilUser->getId() &&
346 {
348 }
349
350 $_SESSION['shop_advanced_search']['order_topics_sorting_type'] = $this->sort_type_topics = $a_field;
351 }
352 public function getSortingTypeTopics()
353 {
354 global $ilUser;
355
356 if(ANONYMOUS_USER_ID == $ilUser->getId() &&
357 $this->sort_type_topics == ilShopTopics::TOPICS_SORT_MANUALLY)
358 {
359 $this->sort_type_topics = ilShopTopics::TOPICS_SORT_BY_TITLE;
360 }
361
363 }
364 public function setSortingDirectionTopics($a_sort_direction)
365 {
366 $_SESSION['shop_advanced_search']['shop_topics_sorting_direction'] = $this->sort_direction_topics = $a_sort_direction;
367 }
369 {
371 }
372
373 protected function prepareOutput()
374 {
375 global $ilTabs;
376
377 parent::prepareOutput();
378
379 $ilTabs->setTabActive('advanced_search');
380 }
381}
382?>
$result
$_GET["client_id"]
$_SESSION["AccountId"]
const SHOP_ADVANCED_SEARCH
Class ilAdvancedSearchFilterGUI.
static _getShopMetaDataSearchInstance($query_parser)
get reference of LikeShopMetaDataSearch.
static _getShopObjectSearchInstance($query_parser)
Class ilShopAdvancedSearchGUI.
Class ilShopBaseGUI.
Class ilShopResultPresentationGUI.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$_POST['username']
Definition: cron.php:12
$cmd
Definition: sahs_server.php:35
global $ilUser
Definition: imgupload.php:15