ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
ilShopSearchResult Class Reference

searchResult stores all result of a search query. More...

+ Inheritance diagram for ilShopSearchResult:
+ Collaboration diagram for ilShopSearchResult:

Public Member Functions

 _getInstance ($a_search_type)
 
 setSearchType ($_search_type)
 
 getSearchType ()
 
 getFilterMode ()
 
 setFilterMode ($filter_mode)
 
 filter ($a_root_node, $check_and)
 Filter search result. More...
 
 __initSearchSettingsObject ()
 
 getResultsForPresentation ()
 
 getTopics ()
 
 setTopics ($a_topics=array())
 
 setResultPageNumber ($a_result_page_number)
 
 getResultPageNumber ()
 
 addPresentationResult ($a_presentation_result=array())
 
 getPresentationResults ()
 
 addEntry ($a_ref_id, $a_type, $found, $a_child_id=0)
 
 __updateEntryChilds ($a_ref_id, $a_childs)
 
 mergeEntries (&$result_obj)
 
 diffEntriesFromResult (&$result_obj)
 
 getUniqueResults ()
 
- Public Member Functions inherited from ilSearchResult
 ilSearchResult ($a_user_id=0)
 Constructor public. More...
 
 setRequiredPermission ($a_permission)
 Set the required permission for the rbac checks in function 'filter()'. More...
 
 getRequiredPermission ()
 
 setUserId ($a_user_id)
 
 getUserId ()
 
 getEntries ()
 
 isLimitReached ()
 
 setMaxHits ($a_max_hits)
 
 getMaxHits ()
 
 isOffsetReached ($a_counter)
 Check if offset is reached. More...
 
 addEntry ($a_obj_id, $a_type, $found, $a_child_id=0)
 add search result entry Entries are stored with 'obj_id'. More...
 
 numEntries ()
 Check number of entries public. More...
 
 mergeEntries (&$result_obj)
 merge entries of this instance and another result object More...
 
 diffEntriesFromResult (&$result_obj)
 diff entries of this instance and another result object Used for search in results More...
 
 intersectEntries (&$result_obj)
 Build intersection of entries (all entries that are present in both result sets) More...
 
 addResult ($a_ref_id, $a_obj_id, $a_type)
 add search result Results are stored with 'ref_id'. More...
 
 getResults ()
 
 getResultIds ()
 get result ids More...
 
 getResultsByObjId ()
 
 getUniqueResults ()
 Get unique results. More...
 
 getResultsForPresentation ()
 
 getSubitemIds ()
 
 filter ($a_root_node, $check_and)
 Filter search result. More...
 
 filterResults ($a_root_node)
 Filter search area of result set public. More...
 
 save ($a_type=DEFAULT_SEARCH)
 Save search results. More...
 
 read ($a_type=DEFAULT_SEARCH)
 read search results More...
 
 __updateEntryChilds ($a_obj_id, $a_childs)
 Update childs for a specific entry. More...
 
 __updateResultChilds ($a_ref_id, $a_childs)
 Update childs for a specific result. More...
 
 __initSearchSettingsObject ()
 
 preventOverwritingMaxhits ($a_flag=null)
 If you call this function and pass "true" the maxhits setting will not be overwritten in __initSearchSettingsObject() More...
 
 addObserver (&$a_class, $a_method)
 The observer is used to call functions for filtering result. More...
 
 callListeners ($a_ref_id, &$a_data)
 

Data Fields

const SHOW_SPECIAL_CONTENT = 1
 
const SHOW_CONTAINER_CONTENT = 2
 
const SHOW_TOPICS_CONTENT = 3
 
 $filter_mode = null
 
- Data Fields inherited from ilSearchResult
 $permission = 'visible'
 
 $user_id
 
 $entries = array()
 
 $results = array()
 
 $observers = array()
 
 $ilias
 
 $ilAccess
 
 $limit_reached = false
 
 $result
 

Protected Member Functions

 assignEntries ($a_entries)
 
 initUserSearchCache ()
 
- Protected Member Functions inherited from ilSearchResult
 initUserSearchCache ()
 Init user search cache. More...
 

Protected Attributes

 $result_page_number = 0
 
 $topics = array()
 
 $presentation_results = array()
 
 $search_type = SHOP_CONTENT
 
- Protected Attributes inherited from ilSearchResult
 $search_cache = null
 
 $offset = 0
 
 $preventOverwritingMaxhits = false
 

Private Member Functions

 __construct ($a_search_type)
 

Static Private Attributes

static $_instance
 

Detailed Description

searchResult stores all result of a search query.

Offers methods like mergeResults. To merge result sets of different queries.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de
Version
$Id:$

Definition at line 16 of file class.ilShopSearchResult.php.

Constructor & Destructor Documentation

◆ __construct()

ilShopSearchResult::__construct (   $a_search_type)
private
Parameters
int$a_search_typeSHOP_CONTENT | SHOP_ADVANCED_SEARCH

Definition at line 52 of file class.ilShopSearchResult.php.

References $ilUser.

53  {
54  global $ilUser;
55 
56  $this->search_type = $a_search_type;
57  parent::__construct($ilUser->getId());
58  }
global $ilUser
Definition: imgupload.php:15

Member Function Documentation

◆ __initSearchSettingsObject()

ilShopSearchResult::__initSearchSettingsObject ( )

Definition at line 187 of file class.ilShopSearchResult.php.

References ilPaymentSettings\_getInstance(), and ilSearchResult\setMaxHits().

Referenced by filter().

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  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __updateEntryChilds()

ilShopSearchResult::__updateEntryChilds (   $a_ref_id,
  $a_childs 
)

Definition at line 392 of file class.ilShopSearchResult.php.

Referenced by diffEntriesFromResult(), and mergeEntries().

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  }
+ Here is the caller graph for this function:

◆ _getInstance()

ilShopSearchResult::_getInstance (   $a_search_type)
Parameters
$a_search_type
Returns
ilShopSearchResult

Definition at line 39 of file class.ilShopSearchResult.php.

Referenced by ilShopGUI\__construct(), ilShopAdvancedSearchGUI\performSearch(), ilShopGUI\performSearch(), and ilShopAdvancedSearchGUI\searchObjects().

40  {
41  if(!isset(self::$_instance))
42  {
43  self::$_instance = new ilShopSearchResult($a_search_type);
44  }
45 
46  return self::$_instance;
47  }
searchResult stores all result of a search query.
+ Here is the caller graph for this function:

◆ addEntry()

ilShopSearchResult::addEntry (   $a_ref_id,
  $a_type,
  $found,
  $a_child_id = 0 
)

Definition at line 351 of file class.ilShopSearchResult.php.

Referenced by diffEntriesFromResult(), and mergeEntries().

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  }
+ Here is the caller graph for this function:

◆ addPresentationResult()

ilShopSearchResult::addPresentationResult (   $a_presentation_result = array())

Definition at line 335 of file class.ilShopSearchResult.php.

Referenced by getResultsForPresentation().

336  {
337  $this->presentation_results[] = $a_presentation_result;
338  }
+ Here is the caller graph for this function:

◆ assignEntries()

ilShopSearchResult::assignEntries (   $a_entries)
protected

Definition at line 88 of file class.ilShopSearchResult.php.

Referenced by filter().

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  }
+ Here is the caller graph for this function:

◆ diffEntriesFromResult()

ilShopSearchResult::diffEntriesFromResult ( $result_obj)

Definition at line 418 of file class.ilShopSearchResult.php.

References $ref_id, __updateEntryChilds(), addEntry(), and ilSearchResult\getEntries().

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  }
__updateEntryChilds($a_ref_id, $a_childs)
addEntry($a_ref_id, $a_type, $found, $a_child_id=0)
$ref_id
Definition: sahs_server.php:39
+ Here is the call graph for this function:

◆ filter()

ilShopSearchResult::filter (   $a_root_node,
  $check_and 
)

Filter search result.

Do RBAC checks.

Allows paging of results for referenced objects

Parameters
inta_root_node node id
boolcheck_and and boolean search
Returns
bool success status

Definition at line 128 of file class.ilShopSearchResult.php.

References $ref_id, __initSearchSettingsObject(), ilSearchResult\__updateResultChilds(), ilPaymentObject\_lookupTopicId(), ilObject\_lookupType(), ilSearchResult\addResult(), assignEntries(), ilSearchResult\callListeners(), ilSearchResult\getEntries(), and ilSearchResult\getRequiredPermission().

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  }
static _lookupTopicId($a_ref_id)
__updateResultChilds($a_ref_id, $a_childs)
Update childs for a specific result.
addResult($a_ref_id, $a_obj_id, $a_type)
add search result Results are stored with &#39;ref_id&#39;.
static _lookupType($a_id, $a_reference=false)
lookup object type
$ref_id
Definition: sahs_server.php:39
callListeners($a_ref_id, &$a_data)
+ Here is the call graph for this function:

◆ getFilterMode()

ilShopSearchResult::getFilterMode ( )
Returns
int

Definition at line 75 of file class.ilShopSearchResult.php.

References $filter_mode.

◆ getPresentationResults()

ilShopSearchResult::getPresentationResults ( )

Definition at line 339 of file class.ilShopSearchResult.php.

340  {
341  return is_array($this->presentation_results) ? $this->presentation_results : array();
342  }

◆ getResultPageNumber()

ilShopSearchResult::getResultPageNumber ( )

Definition at line 330 of file class.ilShopSearchResult.php.

References $result_page_number.

Referenced by getResultsForPresentation().

331  {
333  }
+ Here is the caller graph for this function:

◆ getResultsForPresentation()

ilShopSearchResult::getResultsForPresentation ( )

Definition at line 194 of file class.ilShopSearchResult.php.

References $lng, $presentation_results, ilSearchResult\$result, ilSearchResult\$results, ilPaymentObject\_checkExcSubtype(), ilObject\_lookupDescription(), ilObject\_lookupTitle(), ilPaymentObject\_lookupTopicId(), addPresentationResult(), ilSearchResult\getMaxHits(), getResultPageNumber(), ilSearchResult\getResults(), and getTopics().

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 
314  return $presentation_results ? $presentation_results : array();
315  }
addPresentationResult($a_presentation_result=array())
static _lookupTitle($a_id)
lookup object title
static _lookupTopicId($a_ref_id)
static _lookupDescription($a_id)
lookup object description
global $lng
Definition: privfeed.php:40
static _checkExcSubtype($a_ref_id)
+ Here is the call graph for this function:

◆ getSearchType()

ilShopSearchResult::getSearchType ( )

Definition at line 67 of file class.ilShopSearchResult.php.

References $search_type.

◆ getTopics()

ilShopSearchResult::getTopics ( )

Definition at line 317 of file class.ilShopSearchResult.php.

Referenced by getResultsForPresentation().

318  {
319  return is_array($this->topics) ? $this->topics : array();
320  }
+ Here is the caller graph for this function:

◆ getUniqueResults()

ilShopSearchResult::getUniqueResults ( )

Definition at line 437 of file class.ilShopSearchResult.php.

References ilSearchResult\$results.

438  {
439  return $this->results;
440  }

◆ initUserSearchCache()

ilShopSearchResult::initUserSearchCache ( )
protected

Definition at line 344 of file class.ilShopSearchResult.php.

345  {
346  parent::initUserSearchCache();
347 
348  $this->search_cache->switchSearchType($this->search_type);
349  }

◆ mergeEntries()

ilShopSearchResult::mergeEntries ( $result_obj)

Definition at line 408 of file class.ilShopSearchResult.php.

References __updateEntryChilds(), and addEntry().

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  }
__updateEntryChilds($a_ref_id, $a_childs)
addEntry($a_ref_id, $a_type, $found, $a_child_id=0)
+ Here is the call graph for this function:

◆ setFilterMode()

ilShopSearchResult::setFilterMode (   $filter_mode)
Parameters
int$filter_mode

Definition at line 83 of file class.ilShopSearchResult.php.

References $filter_mode.

Referenced by ilShopGUI\executeCommand().

84  {
85  $this->filter_mode = $filter_mode;
86  }
+ Here is the caller graph for this function:

◆ setResultPageNumber()

ilShopSearchResult::setResultPageNumber (   $a_result_page_number)

Definition at line 326 of file class.ilShopSearchResult.php.

327  {
328  $this->result_page_number = (int)$a_result_page_number > 0 ? $a_result_page_number : 1;
329  }

◆ setSearchType()

ilShopSearchResult::setSearchType (   $_search_type)

Definition at line 60 of file class.ilShopSearchResult.php.

61  {
62  $this->search_type = $_search_type;
63 
64  return $this;
65  }

◆ setTopics()

ilShopSearchResult::setTopics (   $a_topics = array())

Definition at line 321 of file class.ilShopSearchResult.php.

322  {
323  $this->topics = $a_topics;
324  }

Field Documentation

◆ $_instance

ilShopSearchResult::$_instance
staticprivate

Definition at line 22 of file class.ilShopSearchResult.php.

◆ $filter_mode

ilShopSearchResult::$filter_mode = null

Definition at line 33 of file class.ilShopSearchResult.php.

Referenced by getFilterMode(), and setFilterMode().

◆ $presentation_results

ilShopSearchResult::$presentation_results = array()
protected

Definition at line 26 of file class.ilShopSearchResult.php.

Referenced by getResultsForPresentation().

◆ $result_page_number

ilShopSearchResult::$result_page_number = 0
protected

Definition at line 24 of file class.ilShopSearchResult.php.

Referenced by getResultPageNumber().

◆ $search_type

ilShopSearchResult::$search_type = SHOP_CONTENT
protected

Definition at line 31 of file class.ilShopSearchResult.php.

Referenced by getSearchType().

◆ $topics

ilShopSearchResult::$topics = array()
protected

Definition at line 25 of file class.ilShopSearchResult.php.

◆ SHOW_CONTAINER_CONTENT

const ilShopSearchResult::SHOW_CONTAINER_CONTENT = 2

Definition at line 19 of file class.ilShopSearchResult.php.

Referenced by ilShopGUI\executeCommand().

◆ SHOW_SPECIAL_CONTENT

const ilShopSearchResult::SHOW_SPECIAL_CONTENT = 1

Definition at line 18 of file class.ilShopSearchResult.php.

Referenced by ilShopGUI\executeCommand().

◆ SHOW_TOPICS_CONTENT

const ilShopSearchResult::SHOW_TOPICS_CONTENT = 3

Definition at line 20 of file class.ilShopSearchResult.php.


The documentation for this class was generated from the following file: