ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAccordionPropertiesStorage.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
17  protected $user;
18 
22  protected $ctrl;
23 
27  protected $db;
28 
29 
33  public function __construct()
34  {
35  global $DIC;
36 
37  $this->user = $DIC->user();
38  $this->ctrl = $DIC->ctrl();
39  $this->db = $DIC->database();
40  }
41 
42  public $properties = array(
43  "opened" => array("storage" => "session")
44  );
45 
49  public function &executeCommand()
50  {
53 
54  $cmd = $ilCtrl->getCmd();
55  // $next_class = $this->ctrl->getNextClass($this);
56 
57  $this->$cmd();
58  }
59 
63  public function setOpenedTab()
64  {
66 
67  if ($_GET["user_id"] == $ilUser->getId()) {
68  switch ($_GET["act"]) {
69 
70  case "add":
71  $cur = $this->getProperty(
72  $_GET["accordion_id"],
73  (int) $_GET["user_id"],
74  "opened"
75  );
76  $cur_arr = explode(";", $cur);
77  if (!in_array((int) $_GET["tab_nr"], $cur_arr)) {
78  $cur_arr[] = (int) $_GET["tab_nr"];
79  }
80  $this->storeProperty(
81  $_GET["accordion_id"],
82  (int) $_GET["user_id"],
83  "opened",
84  implode($cur_arr, ";")
85  );
86  break;
87 
88  case "rem":
89  $cur = $this->getProperty(
90  $_GET["accordion_id"],
91  (int) $_GET["user_id"],
92  "opened"
93  );
94  $cur_arr = explode(";", $cur);
95  if (($key = array_search((int) $_GET["tab_nr"], $cur_arr)) !== false) {
96  unset($cur_arr[$key]);
97  }
98  $this->storeProperty(
99  $_GET["accordion_id"],
100  (int) $_GET["user_id"],
101  "opened",
102  implode($cur_arr, ";")
103  );
104  break;
105 
106  case "clear":
107  $this->storeProperty(
108  $_GET["accordion_id"],
109  (int) $_GET["user_id"],
110  "opened",
111  ""
112  );
113  break;
114 
115  case "set":
116  default:
117  $this->storeProperty(
118  $_GET["accordion_id"],
119  (int) $_GET["user_id"],
120  "opened",
121  $_GET["tab_nr"]
122  );
123  break;
124  }
125  }
126  }
127 
131  public function storeProperty(
132  $a_table_id,
133  $a_user_id,
134  $a_property,
135  $a_value
136  ) {
137  $ilDB = $this->db;
138 
139  switch ($this->properties[$a_property]["storage"]) {
140  case "session":
141  $_SESSION["accordion"][$a_table_id][$a_user_id][$a_property]
142  = $a_value;
143  break;
144 
145  case "db":
146 /*
147  $ilDB->replace("table_properties", array(
148  "table_id" => array("text", $a_table_id),
149  "user_id" => array("integer", $a_user_id),
150  "property" => array("text", $a_property)),
151  array(
152  "value" => array("text", $a_value)
153  ));
154 */
155  }
156  }
157 
161  public function getProperty($a_table_id, $a_user_id, $a_property)
162  {
163  $ilDB = $this->db;
164 
165  switch ($this->properties[$a_property]["storage"]) {
166  case "session":
167  $r = $_SESSION["accordion"][$a_table_id][$a_user_id][$a_property];
168 //echo "<br><br><br><br><br><br><br><br>get-".$r;
169  return $r;
170  break;
171 
172  case "db":
173 /*
174  $set = $ilDB->query("SELECT value FROM table_properties ".
175  " WHERE table_id = ".$ilDB->quote($a_table_id, "text").
176  " AND user_id = ".$ilDB->quote($a_user_id, "integer").
177  " AND property = ".$ilDB->quote($a_property, "text")
178  );
179  $rec = $ilDB->fetchAssoc($set);
180  return $rec["value"];
181  break;
182 */
183  }
184  }
185 }
getProperty($a_table_id, $a_user_id, $a_property)
Get property in session or db.
$_SESSION["AccountId"]
global $DIC
Definition: saml.php:7
$_GET["client_id"]
user()
Definition: user.php:4
global $ilCtrl
Definition: ilias.php:18
$r
Definition: example_031.php:79
storeProperty( $a_table_id, $a_user_id, $a_property, $a_value)
Store property in session or db.
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
global $ilDB
Set document properties
$key
Definition: croninfo.php:18
Saves (mostly asynchronously) user properties of accordions.