ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilTablePropertiesStorage.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 "filter" => array("storage" => "db"),
44 "direction" => array("storage" => "db"),
45 "order" => array("storage" => "db"),
46 "rows" => array("storage" => "db"),
47 "offset" => array("storage" => "session"),
48 "selfields" => array("storage" => "db"),
49 "selfilters" => array("storage" => "db"),
50 "filter_values" => array("storage" => "db")
51 );
52
56 public function &executeCommand()
57 {
60
61 $cmd = $ilCtrl->getCmd();
62 // $next_class = $this->ctrl->getNextClass($this);
63
64 $this->$cmd();
65 }
66
70 public function showFilter()
71 {
73
74 if ($_GET["user_id"] == $ilUser->getId()) {
75 $this->storeProperty(
76 $_GET["table_id"],
77 $_GET["user_id"],
78 "filter",
79 1
80 );
81 }
82 }
83
87 public function hideFilter()
88 {
90
91 if ($_GET["user_id"] == $ilUser->getId()) {
92 $this->storeProperty(
93 $_GET["table_id"],
94 $_GET["user_id"],
95 "filter",
96 0
97 );
98 }
99 }
100
104 public function storeProperty(
105 $a_table_id,
106 $a_user_id,
107 $a_property,
108 $a_value
109 ) {
111
112 if ($a_table_id == "" || !$this->isValidProperty($a_property)) {
113 return;
114 }
115
116 $storage = $this->properties[$a_property]["storage"];
117 if ($a_user_id == ANONYMOUS_USER_ID) {
118 $storage = "session";
119 }
120
121 switch ($storage) {
122 case "session":
123 $_SESSION["table"][$a_table_id][$a_user_id][$a_property]
124 = $a_value;
125 break;
126
127 case "db":
128 $ilDB->replace(
129 "table_properties",
130 array(
131 "table_id" => array("text", $a_table_id),
132 "user_id" => array("integer", $a_user_id),
133 "property" => array("text", $a_property)),
134 array(
135 "value" => array("text", $a_value)
136 )
137 );
138 }
139 }
140
144 public function getProperty($a_table_id, $a_user_id, $a_property)
145 {
147
148 if ($a_table_id == "" || !$this->isValidProperty($a_property)) {
149 return;
150 }
151
152 $storage = $this->properties[$a_property]["storage"];
153 if ($a_user_id == ANONYMOUS_USER_ID) {
154 $storage = "session";
155 }
156
157 switch ($storage) {
158 case "session":
159 return $_SESSION["table"][$a_table_id][$a_user_id][$a_property];
160 break;
161
162 case "db":
163 $set = $ilDB->query(
164 $q = "SELECT value FROM table_properties " .
165 " WHERE table_id = " . $ilDB->quote($a_table_id, "text") .
166 " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
167 " AND property = " . $ilDB->quote($a_property, "text")
168 );
169 $rec = $ilDB->fetchAssoc($set);
170 return $rec["value"];
171 break;
172 }
173 }
174
181 public function isValidProperty($a_property)
182 {
183 if (array_key_exists($a_property, $this->properties)) {
184 return true;
185 }
186 return false;
187 }
188}
user()
Definition: user.php:4
$_GET["client_id"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Saves (mostly asynchronously) user properties of tables (e.g.
storeProperty( $a_table_id, $a_user_id, $a_property, $a_value)
Store property in session or db.
isValidProperty($a_property)
Check if given property id is valid.
getProperty($a_table_id, $a_user_id, $a_property)
Get property in session or db.
global $ilCtrl
Definition: ilias.php:18
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18