ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilShopSearchResult.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/Search/classes/class.ilSearchResult.php';
5
17{
21
22 private static $_instance;
23
24 protected $result_page_number = 0;
25 protected $topics = array();
26 protected $presentation_results = array();
27
32
33 public $filter_mode = null;
34
39 public function _getInstance($a_search_type)
40 {
41 if(!isset(self::$_instance))
42 {
43 self::$_instance = new ilShopSearchResult($a_search_type);
44 }
45
46 return self::$_instance;
47 }
48
52 private function __construct($a_search_type)
53 {
54 global $ilUser;
55
56 $this->search_type = $a_search_type;
57 parent::__construct($ilUser->getId());
58 }
59
60 public function setSearchType($_search_type)
61 {
62 $this->search_type = $_search_type;
63
64 return $this;
65 }
66
67 public function getSearchType()
68 {
69 return $this->search_type;
70 }
71
75 public function getFilterMode()
76 {
77 return $this->filter_mode;
78 }
79
83 public function setFilterMode($filter_mode)
84 {
85 $this->filter_mode = $filter_mode;
86 }
87
88 protected function assignEntries($a_entries)
89 {
90 $ordered_entries = array();
91
92 $num_entries = count($a_entries);
93 foreach($this->topics as $oTopic)
94 {
95 foreach($a_entries as $aEntry)
96 {
97 if($oTopic->getId() == $aEntry['topic_id'])
98 {
99 $ordered_entries[$aEntry['ref_id']] = $aEntry;
100 }
101 }
102 }
103 if(count($ordered_entries) < $num_entries)
104 {
105 foreach($a_entries as $aEntry)
106 {
107 if(0 == $aEntry['topic_id'])
108 {
109 $ordered_entries[$aEntry['ref_id']] = $aEntry;
110 }
111 }
112 }
113
114 return is_array($ordered_entries) ? $ordered_entries : array();
115 }
116
128 public function filter($a_root_node, $check_and)
129 {
130 global $tree;
131
133
134 // get ref_ids and check access
135
136 $tmp_entries = array();
137 foreach($this->getEntries() as $ref_id => $entry)
138 {
139 // boolean and failed continue
140 if($check_and && in_array(0, $entry['found']))
141 {
142 continue;
143 }
144 // Types like role, rolt, user do not need rbac checks
145 $type = ilObject::_lookupType($entry['obj_id']);
146 if($type == 'rolt' or $type == 'usr' or $type == 'role')
147 {
148 continue;
149 }
150
151 // Check access
152 if($this->ilAccess->checkAccessOfUser($this->getUserId(),
153 $this->getRequiredPermission(),
154 '',
155 $ref_id))
156 {
157 if($a_root_node == ROOT_FOLDER_ID || $tree->isGrandChild($a_root_node, $ref_id))
158 {
159 if($this->callListeners($ref_id, $entry))
160 {
161 $entry['ref_id'] = $ref_id;
162 $entry['type'] = $type;
163 $entry['topic_id'] = ilPaymentObject::_lookupTopicId($ref_id);
164 $tmp_entries[$ref_id] = $entry;
165 }
166 }
167 }
168 }
169
170 $this->results = array();
171
172 $tmp_entries = $this->assignEntries($tmp_entries);
173
174 foreach($tmp_entries as $entry)
175 {
176 if($this->callListeners($entry['ref_id'], $entry))
177 {
178 $this->addResult($entry['ref_id'], $entry['obj_id'], $entry['type']);
179 $this->search_cache->appendToChecked($entry['ref_id'], $entry['obj_id']);
180 $this->__updateResultChilds($entry['ref_id'], $entry['child']);
181 }
182 }
183 $this->search_cache->setResults($this->results);
184 return false;
185 }
186
188 {
189 include_once 'Services/Payment/classes/class.ilPaymentSettings.php';
190 $maxhits = ilPaymentSettings::_getInstance()->get('max_hits');
191 $this->setMaxHits(($maxhits > 0 ? $maxhits : 20));
192 }
193
195 {
196 global $lng;
197 $results = array();
198
199 $offset_counter = 0;
200 $counter = 0;
201
202 $objects_with_topics = array();
203 $objects_with_no_topcis = array();
204
205 foreach($this->getResults() as $result)
206 {
207 if($this->getMaxHits() * ($this->getResultPageNumber() - 1) > $offset_counter)
208 {
209 ++$offset_counter;
210 continue;
211 }
212
213 $results[] = $result;
214 ++$counter;
215
216 if($counter >= $this->getMaxHits())
217 {
218 break;
219 }
220 }
221
222 foreach($this->getTopics() as $oTopic)
223 {
224 foreach($results as $result)
225 {
226 $topic_id = ilPaymentObject::_lookupTopicId($result['ref_id']);
227
228 if(!(int)$topic_id && !array_key_exists($result['ref_id'], $objects_with_no_topcis))
229 {
230 $objects_with_no_topcis[$result['ref_id']] = $result;
231 continue;
232 }
233
234 if((int)$topic_id != $oTopic->getId())
235 {
236 continue;
237 }
238
239 if(!array_key_exists($result['ref_id'], $objects_with_topics))
240 {
241 $objects_with_topics[$result['ref_id']] = $result;
242 }
243
244 switch($result['type'])
245 {
246 // learning material
247 case "sahs":
248 case "lm":
249 case "dbk":
250 case "htlm":
251 $type = "lres";
252 break;
253
254 default:
255 $type = $result['type'];
256 break;
257 }
258 $title = ilObject::_lookupTitle($result['obj_id']);
259 $description = ilObject::_lookupDescription($result['obj_id']);
260
261 $subtype = '';
262 if($result['type'] == 'exc')
263 {
264 $check_sub = ilPaymentObject::_checkExcSubtype($result['ref_id']);
265 $subtype = ' ('.$lng->txt($check_sub[0]).')';
266 }
267
268 $presentation_results[$oTopic->getId()][$type][] = array('ref_id' => $result['ref_id'],
269 'title' => $title.' '.$subtype,
270 'description' => $description,
271 'type' => $result['type'],
272 'obj_id' => $result['obj_id'],
273 'topic_id' => $topic_id,
274 'child' => $result['child']);
275 $this->addPresentationResult($presentation_results[$oTopic->getId()][$type][count($presentation_results[$oTopic->getId()][$type]) - 1]);
276 }
277 }
278 foreach($results as $result)
279 {
280 if(!array_key_exists($result['ref_id'], $objects_with_topics) &&
281 !array_key_exists($result['ref_id'], $objects_with_no_topcis))
282 {
283 $objects_with_no_topcis[$result['ref_id']] = $result;
284 }
285 }
286 foreach($objects_with_no_topcis as $result)
287 {
288 switch($result['type'])
289 {
290 // learning material
291 case "sahs":
292 case "lm":
293 case "dbk":
294 case "htlm":
295 $type = "lres";
296 break;
297
298 default:
299 $type = $result['type'];
300 break;
301 }
302 $title = ilObject::_lookupTitle($result['obj_id']);
303 $description = ilObject::_lookupDescription($result['obj_id']);
304
305 $presentation_results[0][$type][] = array('ref_id' => $result['ref_id'],
306 'title' => $title,
307 'description' => $description,
308 'type' => $result['type'],
309 'obj_id' => $result['obj_id'],
310 'child' => $result['child']);
311 $this->addPresentationResult($presentation_results[0][$type][count($presentation_results[0][$type]) - 1]);
312 }
313
315 }
316
317 public function getTopics()
318 {
319 return is_array($this->topics) ? $this->topics : array();
320 }
321 public function setTopics($a_topics = array())
322 {
323 $this->topics = $a_topics;
324 }
325
326 public function setResultPageNumber($a_result_page_number)
327 {
328 $this->result_page_number = (int)$a_result_page_number > 0 ? $a_result_page_number : 1;
329 }
330 public function getResultPageNumber()
331 {
333 }
334
335 public function addPresentationResult($a_presentation_result = array())
336 {
337 $this->presentation_results[] = $a_presentation_result;
338 }
339 public function getPresentationResults()
340 {
341 return is_array($this->presentation_results) ? $this->presentation_results : array();
342 }
343
344 protected function initUserSearchCache()
345 {
346 parent::initUserSearchCache();
347
348 $this->search_cache->switchSearchType($this->search_type);
349 }
350
351 function addEntry($a_ref_id, $a_type, $found, $a_child_id = 0)
352 {
353 global $ilObjDataCache;
354
355 $a_obj_id = $ilObjDataCache->lookupObjId($a_ref_id);
356
357 // Create new entry if it not exists
358 if(!$this->entries[$a_ref_id])
359 {
360 $this->entries[$a_ref_id]['ref_id'] = $a_ref_id;
361 $this->entries[$a_ref_id]['obj_id'] = $a_obj_id;
362 $this->entries[$a_ref_id]['type'] = $a_type;
363 $this->entries[$a_ref_id]['found'] = $found;
364
365 if($a_child_id and $a_child_id != $a_ref_id)
366 {
367 $this->entries[$a_ref_id]['child'][$a_child_id] = $a_child_id;
368 }
369 }
370 else
371 {
372 // replace or add child ('pg','st') id
373 if($a_child_id and $a_child_id != $a_obj_id)
374 {
375 $this->entries[$a_ref_id]['child'][$a_child_id] = $a_child_id;
376 }
377
378 // UPDATE FOUND
379 $counter = 0;
380 foreach($found as $position)
381 {
382 if($position)
383 {
384 $this->entries[$a_ref_id]['found'][$counter] = $position;
385 }
386 $counter++;
387 }
388 }
389 return true;
390 }
391
392 function __updateEntryChilds($a_ref_id,$a_childs)
393 {
394 if($this->entries[$a_ref_id] and is_array($a_childs))
395 {
396 foreach($a_childs as $child_id)
397 {
398 if($child_id)
399 {
400 $this->entries[$a_ref_id]['child'][$child_id] = $child_id;
401 }
402 }
403 return true;
404 }
405 return false;
406 }
407
408 function mergeEntries(&$result_obj)
409 {
410 foreach($result_obj->getEntries() as $entry)
411 {
412 $this->addEntry($entry['ref_id'],$entry['type'],$entry['found']);
413 $this->__updateEntryChilds($entry['ref_id'],$entry['child']);
414 }
415 return true;
416 }
417
418 function diffEntriesFromResult(&$result_obj)
419 {
420 $new_entries = $this->getEntries();
421 $this->entries = array();
422
423 // Get all checked objects
424 foreach($this->search_cache->getCheckedItems() as $ref_id => $obj_id)
425 {
426 if(isset($new_entries[$ref_id]))
427 {
428 $this->addEntry($new_entries[$ref_id]['ref_id'],
429 $new_entries[$ref_id]['type'],
430 $new_entries[$ref_id]['found']);
431 $this->__updateEntryChilds($new_entries[$ref_id]['ref_id'],
432 $new_entries[$ref_id]['child']);
433 }
434 }
435 }
436
438 {
439 return $this->results;
440 }
441
442}
443?>
const SHOP_CONTENT
static _lookupTitle($a_id)
lookup object title
static _lookupDescription($a_id)
lookup object description
static _lookupType($a_id, $a_reference=false)
lookup object type
static _checkExcSubtype($a_ref_id)
static _lookupTopicId($a_ref_id)
callListeners($a_ref_id, &$a_data)
addResult($a_ref_id, $a_obj_id, $a_type)
add search result Results are stored with 'ref_id'.
__updateResultChilds($a_ref_id, $a_childs)
Update childs for a specific result.
searchResult stores all result of a search query.
mergeEntries(&$result_obj)
merge entries of this instance and another result object
setResultPageNumber($a_result_page_number)
__updateEntryChilds($a_ref_id, $a_childs)
Update childs for a specific entry.
diffEntriesFromResult(&$result_obj)
diff entries of this instance and another result object Used for search in results
addEntry($a_ref_id, $a_type, $found, $a_child_id=0)
add search result entry Entries are stored with 'obj_id'.
getUniqueResults()
Get unique results.
initUserSearchCache()
Init user search cache.
setTopics($a_topics=array())
filter($a_root_node, $check_and)
Filter search result.
addPresentationResult($a_presentation_result=array())
global $lng
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39
global $ilUser
Definition: imgupload.php:15