ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSearchAutoComplete.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Search/classes/class.ilSearchSettings.php';
5 
11 {
15  static function getList($a_str)
16  {
17  global $ilDB;
18 
19  $a_str = str_replace('"', "", $a_str);
20 
21  $settings = new ilSearchSettings();
22 
23  $object_types = array('cat','dbk','crs','fold','frm','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl',
24  'chat','icrs','icla','webr','mcst','sess','pg','st','gdf','wiki');
25 
26  $set = $ilDB->query("SELECT title, obj_id FROM object_data WHERE "
27  .$ilDB->like('title', 'text', $a_str."%")." AND "
28  .$ilDB->in('type', $object_types, false, 'text')." ORDER BY title");
29  $max = ($settings->getAutoCompleteLength() > 0)
30  ? $settings->getAutoCompleteLength()
31  : 10;
32 
33  $cnt = 0;
34  $list = array();
35  $checked = array();
36  $lim = "";
37  while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max)
38  {
39  if (strpos($rec["title"], " ") > 0 || strpos($rec["title"], "-") > 0)
40  {
41  $rec["title"] = '"'.$rec["title"].'"';
42  }
43  if (!in_array($rec["title"], $list) && !in_array($rec["obj_id"], $checked))
44  {
46  {
47  $list[] = $lim.$rec["title"];
48  $cnt++;
49  }
50  $checked[] = $rec["obj_id"];
51  }
52  }
53 
54  $set = $ilDB->query("SELECT rbac_id,obj_id,obj_type, keyword FROM il_meta_keyword WHERE "
55  .$ilDB->like('keyword', 'text', $a_str."%")." AND "
56  .$ilDB->in('obj_type', $object_types, false, 'text')." ORDER BY keyword");
57  while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max)
58  {
59  if (strpos($rec["keyword"], " ") > 0)
60  {
61  $rec["keyword"] = '"'.$rec["keyword"].'"';
62  }
63  if (!in_array($rec["keyword"], $list) && !in_array($rec["rbac_id"], $checked))
64  {
66  {
67  $list[] = $lim.$rec["keyword"];
68  $cnt++;
69  }
70  }
71  $checked[] = $rec["rbac_id"];
72  }
73 
74  $i = 0;
75  $result = array();
76  foreach ($list as $l)
77  {
78  $result[$i] = new stdClass();
79  $result[$i]->value = $l;
80  $i++;
81  }
82 
83  include_once './Services/JSON/classes/class.ilJsonUtil.php';
85  }
86 
90  static function checkObjectPermission($a_obj_id)
91  {
92  global $ilAccess;
93 
94  $refs = ilObject::_getAllReferences($a_obj_id);
95  foreach ($refs as $ref)
96  {
97  if ($ilAccess->checkAccess("read", "", $ref))
98  {
99  return true;
100  }
101  }
102  return false;
103  }
104 }
105 ?>