ILIAS  Release_4_2_x_branch Revision 61807
 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  include_once './Services/JSON/classes/class.ilJsonUtil.php';
20  $result = new stdClass();
21  $result->response = new stdClass();
22  $result->response->results = array();
23  if (strlen($a_str) < 3)
24  {
26  }
27 
28  $a_str = str_replace('"', "", $a_str);
29 
30  $settings = new ilSearchSettings();
31 
32  $object_types = array('cat','dbk','crs','fold','frm','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl',
33  'chat','icrs','icla','webr','mcst','sess','pg','st','wiki');
34 
35  $set = $ilDB->query("SELECT title, obj_id FROM object_data WHERE "
36  .$ilDB->like('title', 'text', $a_str."%")." AND "
37  .$ilDB->in('type', $object_types, false, 'text')." ORDER BY title");
38  $max = ($settings->getAutoCompleteLength() > 0)
39  ? $settings->getAutoCompleteLength()
40  : 10;
41 
42  $cnt = 0;
43  $list = array();
44  $checked = array();
45  $lim = "";
46  while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max)
47  {
48  if (strpos($rec["title"], " ") > 0 || strpos($rec["title"], "-") > 0)
49  {
50  $rec["title"] = '"'.$rec["title"].'"';
51  }
52  if (!in_array($rec["title"], $list) && !in_array($rec["obj_id"], $checked))
53  {
55  {
56  $list[] = $lim.$rec["title"];
57  $cnt++;
58  }
59  $checked[] = $rec["obj_id"];
60  }
61  }
62 
63  $set = $ilDB->query("SELECT rbac_id,obj_id,obj_type, keyword FROM il_meta_keyword WHERE "
64  .$ilDB->like('keyword', 'text', $a_str."%")." AND "
65  .$ilDB->in('obj_type', $object_types, false, 'text')." ORDER BY keyword");
66  while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max)
67  {
68  if (strpos($rec["keyword"], " ") > 0)
69  {
70  $rec["keyword"] = '"'.$rec["keyword"].'"';
71  }
72  if (!in_array($rec["keyword"], $list) && !in_array($rec["rbac_id"], $checked))
73  {
75  {
76  $list[] = $lim.$rec["keyword"];
77  $cnt++;
78  }
79  }
80  $checked[] = $rec["rbac_id"];
81  }
82 
83  $i = 0;
84  foreach ($list as $l)
85  {
86  $result->response->results[$i] = new stdClass();
87  $result->response->results[$i]->term = $l;
88  $i++;
89  }
90 
92  }
93 
97  static function checkObjectPermission($a_obj_id)
98  {
99  global $ilAccess;
100 
101  $refs = ilObject::_getAllReferences($a_obj_id);
102  foreach ($refs as $ref)
103  {
104  if ($ilAccess->checkAccess("read", "", $ref))
105  {
106  return true;
107  }
108  }
109  return false;
110  }
111 }
112 ?>