ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
11 {
15  protected $user;
16 
20  protected $ctrl;
21 
25  protected $db;
26 
27 
31  public function __construct()
32  {
33  global $DIC;
34 
35  $this->user = $DIC->user();
36  $this->ctrl = $DIC->ctrl();
37  $this->db = $DIC->database();
38  }
39 
40  public $properties = array(
41  "opened" => array("storage" => "session")
42  );
43 
47  public function &executeCommand()
48  {
50  $ilCtrl = $this->ctrl;
51 
52  $cmd = $ilCtrl->getCmd();
53  // $next_class = $this->ctrl->getNextClass($this);
54 
55  $this->$cmd();
56  }
57 
61  public function setOpenedTab()
62  {
64 
65  if ($_GET["user_id"] == $ilUser->getId()) {
66  switch ($_GET["act"]) {
67 
68  case "add":
69  $cur = $this->getProperty(
70  $_GET["accordion_id"],
71  (int) $_GET["user_id"],
72  "opened"
73  );
74  $cur_arr = explode(";", $cur);
75  if (!in_array((int) $_GET["tab_nr"], $cur_arr)) {
76  $cur_arr[] = (int) $_GET["tab_nr"];
77  }
78  $this->storeProperty(
79  $_GET["accordion_id"],
80  (int) $_GET["user_id"],
81  "opened",
82  implode(";", $cur_arr)
83  );
84  break;
85 
86  case "rem":
87  $cur = $this->getProperty(
88  $_GET["accordion_id"],
89  (int) $_GET["user_id"],
90  "opened"
91  );
92  $cur_arr = explode(";", $cur);
93  if (($key = array_search((int) $_GET["tab_nr"], $cur_arr)) !== false) {
94  unset($cur_arr[$key]);
95  }
96  $this->storeProperty(
97  $_GET["accordion_id"],
98  (int) $_GET["user_id"],
99  "opened",
100  implode(";", $cur_arr)
101  );
102  break;
103 
104  case "clear":
105  $this->storeProperty(
106  $_GET["accordion_id"],
107  (int) $_GET["user_id"],
108  "opened",
109  ""
110  );
111  break;
112 
113  case "set":
114  default:
115  $this->storeProperty(
116  $_GET["accordion_id"],
117  (int) $_GET["user_id"],
118  "opened",
119  $_GET["tab_nr"]
120  );
121  break;
122  }
123  }
124  }
125 
129  public function storeProperty(
130  $a_table_id,
131  $a_user_id,
132  $a_property,
133  $a_value
134  ) {
135  $ilDB = $this->db;
136 
137  switch ($this->properties[$a_property]["storage"]) {
138  case "session":
139  $_SESSION["accordion"][$a_table_id][$a_user_id][$a_property]
140  = $a_value;
141  break;
142 
143  case "db":
144 /*
145  $ilDB->replace("table_properties", array(
146  "table_id" => array("text", $a_table_id),
147  "user_id" => array("integer", $a_user_id),
148  "property" => array("text", $a_property)),
149  array(
150  "value" => array("text", $a_value)
151  ));
152 */
153  }
154  }
155 
159  public function getProperty($a_table_id, $a_user_id, $a_property)
160  {
161  $ilDB = $this->db;
162 
163  switch ($this->properties[$a_property]["storage"]) {
164  case "session":
165  $r = $_SESSION["accordion"][$a_table_id][$a_user_id][$a_property];
166 //echo "<br><br><br><br><br><br><br><br>get-".$r;
167  return $r;
168  break;
169 
170  case "db":
171 /*
172  $set = $ilDB->query("SELECT value FROM table_properties ".
173  " WHERE table_id = ".$ilDB->quote($a_table_id, "text").
174  " AND user_id = ".$ilDB->quote($a_user_id, "integer").
175  " AND property = ".$ilDB->quote($a_property, "text")
176  );
177  $rec = $ilDB->fetchAssoc($set);
178  return $rec["value"];
179  break;
180 */
181  }
182  }
183 }
getProperty($a_table_id, $a_user_id, $a_property)
Get property in session or db.
$_SESSION["AccountId"]
$_GET["client_id"]
user()
Definition: user.php:4
storeProperty( $a_table_id, $a_user_id, $a_property, $a_value)
Store property in session or db.
global $DIC
Definition: goto.php:24
global $ilDB
$ilUser
Definition: imgupload.php:18
Saves (mostly asynchronously) user properties of accordions.