ILIAS  release_7 Revision v7.30-3-g800a261c036
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
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 "filter" => array("storage" => "db"),
42 "direction" => array("storage" => "db"),
43 "order" => array("storage" => "db"),
44 "rows" => array("storage" => "db"),
45 "offset" => array("storage" => "session"),
46 "selfields" => array("storage" => "db"),
47 "selfilters" => array("storage" => "db"),
48 "filter_values" => array("storage" => "db")
49 );
50
54 public function &executeCommand()
55 {
57 $ilCtrl = $this->ctrl;
58
59 $cmd = $ilCtrl->getCmd();
60 // $next_class = $this->ctrl->getNextClass($this);
61
62 $this->$cmd();
63 }
64
68 public function showFilter()
69 {
71
72 if ($_GET["user_id"] == $ilUser->getId()) {
73 $this->storeProperty(
74 $_GET["table_id"],
75 $_GET["user_id"],
76 "filter",
77 1
78 );
79 }
80 }
81
85 public function hideFilter()
86 {
88
89 if ($_GET["user_id"] == $ilUser->getId()) {
90 $this->storeProperty(
91 $_GET["table_id"],
92 $_GET["user_id"],
93 "filter",
94 0
95 );
96 }
97 }
98
102 public function storeProperty(
103 $a_table_id,
104 $a_user_id,
105 $a_property,
106 $a_value
107 ) {
109
110 if ($a_table_id == "" || !$this->isValidProperty($a_property)) {
111 return;
112 }
113
114 $storage = $this->properties[$a_property]["storage"];
115 if ($a_user_id == ANONYMOUS_USER_ID) {
116 $storage = "session";
117 }
118
119 switch ($storage) {
120 case "session":
121 $_SESSION["table"][$a_table_id][$a_user_id][$a_property]
122 = $a_value;
123 break;
124
125 case "db":
126 $ilDB->replace(
127 "table_properties",
128 array(
129 "table_id" => array("text", $a_table_id),
130 "user_id" => array("integer", $a_user_id),
131 "property" => array("text", $a_property)),
132 array(
133 "value" => array("text", $a_value)
134 )
135 );
136 }
137 }
138
142 public function getProperty($a_table_id, $a_user_id, $a_property)
143 {
145
146 if ($a_table_id == "" || !$this->isValidProperty($a_property)) {
147 return;
148 }
149
150 $storage = $this->properties[$a_property]["storage"];
151 if ($a_user_id == ANONYMOUS_USER_ID) {
152 $storage = "session";
153 }
154
155 switch ($storage) {
156 case "session":
157 return $_SESSION["table"][$a_table_id][$a_user_id][$a_property];
158 break;
159
160 case "db":
161 $set = $ilDB->query(
162 $q = "SELECT value FROM table_properties " .
163 " WHERE table_id = " . $ilDB->quote($a_table_id, "text") .
164 " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
165 " AND property = " . $ilDB->quote($a_property, "text")
166 );
167 $rec = $ilDB->fetchAssoc($set);
168 return $rec["value"];
169 break;
170 }
171 }
172
179 public function isValidProperty($a_property)
180 {
181 if (array_key_exists($a_property, $this->properties)) {
182 return true;
183 }
184 return false;
185 }
186}
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.
const ANONYMOUS_USER_ID
Definition: constants.php:25
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
global $ilDB