ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAccessKey.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  // function id constants
14  const NEXT = 1;
15  const PREVIOUS = 2;
16  const DELETE = 3;
17  const LAST_VISITED = 4;
18  const TREE_ON = 5;
19  const TREE_OFF = 6;
20  const REPLY = 7;
21  const FORWARD_MAIL = 8;
22  const MARK_ALL_READ = 9;
23 
24  public static $func_def = array(
25  ilAccessKey::NEXT => array(
26  "component" => array("global"),
27  "lang" => "acc_next"),
28  ilAccessKey::PREVIOUS => array(
29  "component" => array("global"),
30  "lang" => "acc_previous"),
31  ilAccessKey::DELETE => array(
32  "component" => array("global"),
33  "lang" => "acc_delete"),
35  "component" => array("global"),
36  "lang" => "acc_last_visited"),
37  ilAccessKey::TREE_ON => array(
38  "component" => array("global"),
39  "lang" => "acc_tree_on"),
40  ilAccessKey::TREE_OFF => array(
41  "component" => array("global"),
42  "lang" => "acc_tree_off"),
43  ilAccessKey::REPLY => array(
44  "component" => array("mail"),
45  "lang" => "acc_reply"),
47  "component" => array("mail"),
48  "lang" => "acc_forward_mail"),
49  );
50 
56  private static function getAllKeysEmpty()
57  {
58  $empty_keys = array();
59  foreach (self::$func_def as $f => $c)
60  {
61  $empty_keys[$f] = "";
62  }
63 
64  return $empty_keys;
65  }
66 
70  static function getFunctionName($a_func_id)
71  {
72  global $lng;
73 
74  return $lng->txt(self::$func_def[$a_func_id]["lang"]);
75  }
76 
80  static function getComponentNames($a_func_id)
81  {
82  global $lng;
83 
84  $c_str = $lim = "";
85  foreach (self::$func_def[$a_func_id]["component"] as $c)
86  {
87  $c_str.= $lim.$lng->txt("acc_comp_".$c);
88  $lim = ", ";
89  }
90  return $c_str;
91  }
92 
93 
99  static function getKeys($lang_key = "0", $a_ignore_default = false)
100  {
101  global $ilDB;
102 
104 
105  // get defaults
106  if ($lang_key != "0" && !$a_ignore_default)
107  {
108  $keys = ilAccessKey::getKeys();
109  }
110 
111  // get keys of selected language
112  $set = $ilDB->query("SELECT * FROM acc_access_key ".
113  " WHERE lang_key = ".$ilDB->quote($lang_key, "text")
114  );
115  while ($rec = $ilDB->fetchAssoc($set))
116  {
117  $keys[$rec["function_id"]] = $rec["access_key"];
118  }
119 
120  return $keys;
121  }
122 
128  static function getKey($a_func_id, $lang_key = "0", $a_ignore_default = false)
129  {
130  global $ilDB;
131 
132  $key = "";
133 
134  // get defaults
135  if ($lang_key != "0" && !$a_ignore_default)
136  {
137  $key = ilAccessKey::getKey($a_func_id);
138  }
139 
140  // get keys of selected language
141  $set = $ilDB->query("SELECT * FROM acc_access_key ".
142  " WHERE lang_key = ".$ilDB->quote($lang_key, "text").
143  " AND function_id = ".$ilDB->quote($a_func_id, "integer")
144  );
145  if ($rec = $ilDB->fetchAssoc($set))
146  {
147  $key = $rec["access_key"];
148  }
149 
150  return $key;
151  }
152 
158  static function writeKeys($a_keys, $a_lang_key = "0")
159  {
160  global $ilDB;
161 
162  $ilDB->manipulate("DELETE FROM acc_access_key WHERE ".
163  "lang_key = ".$ilDB->quote($a_lang_key, "text")
164  );
165 
166  foreach ($a_keys as $func_id => $acc_key)
167  {
168  $ilDB->manipulate("INSERT INTO acc_access_key ".
169  "(lang_key, function_id, access_key) VALUES (".
170  $ilDB->quote($a_lang_key, "text").",".
171  $ilDB->quote($func_id, "integer").",".
172  $ilDB->quote(strtolower(trim($acc_key)), "text").
173  ")");
174  }
175  }
176 
177 }