ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTablePropertiesStorageGUI.php
Go to the documentation of this file.
1<?php
2
24{
26 protected ilObjUser $user;
27 protected ilCtrl $ctrl;
28 protected ilDBInterface $db;
29 public array $properties = array(
30 "filter" => array("storage" => "db"),
31 "direction" => array("storage" => "db"),
32 "order" => array("storage" => "db"),
33 "rows" => array("storage" => "db"),
34 "offset" => array("storage" => "session"),
35 "selfields" => array("storage" => "db"),
36 "selfilters" => array("storage" => "db"),
37 "filter_values" => array("storage" => "db")
38 );
39
40 public function __construct()
41 {
42 global $DIC;
43
44 $this->user = $DIC->user();
45 $this->ctrl = $DIC->ctrl();
46 $this->db = $DIC->database();
47 if (isset($DIC["http"])) {
48 $this->table_request = new \ILIAS\Table\TableGUIRequest(
49 $DIC->http(),
50 $DIC->refinery()
51 );
52 }
53 }
54
55
56 public function executeCommand(): void
57 {
58 $ilCtrl = $this->ctrl;
59 $cmd = $ilCtrl->getCmd();
60 $this->$cmd();
61 }
62
63 public function showFilter(): void
64 {
65 $ilUser = $this->user;
66
67 $requested_user_id = $this->table_request->getUserId();
68 $requested_table_id = $this->table_request->getTableId();
69
70 if ($requested_user_id == $ilUser->getId()) {
71 $this->storeProperty(
72 $requested_table_id,
74 "filter",
75 1
76 );
77 }
78 }
79
80 public function hideFilter(): void
81 {
82 $ilUser = $this->user;
83
84 $requested_user_id = $this->table_request->getUserId();
85 $requested_table_id = $this->table_request->getTableId();
86 if ($requested_user_id == $ilUser->getId()) {
87 $this->storeProperty(
88 $requested_table_id,
90 "filter",
91 0
92 );
93 }
94 }
95
96 public function storeProperty(
97 string $a_table_id,
98 int $a_user_id,
99 string $a_property,
100 string $a_value
101 ): void {
102 $ilDB = $this->db;
103
104 if ($a_table_id == "" || !$this->isValidProperty($a_property)) {
105 return;
106 }
107
108 $storage = $this->properties[$a_property]["storage"];
109 if ($a_user_id == ANONYMOUS_USER_ID) {
110 $storage = "session";
111 }
112 switch ($storage) {
113 case "session":
114 ilSession::set("table_" . $a_table_id . "_" . $a_user_id . "_" . $a_property, $a_value);
115 break;
116
117 case "db":
118 $ilDB->replace(
119 "table_properties",
120 array(
121 "table_id" => array("text", $a_table_id),
122 "user_id" => array("integer", $a_user_id),
123 "property" => array("text", $a_property)),
124 array(
125 "value" => array("text", $a_value)
126 )
127 );
128 }
129 }
130
131 public function getProperty(
132 string $a_table_id,
133 int $a_user_id,
134 string $a_property
135 ): string {
136 $ilDB = $this->db;
137
138 if ($a_table_id == "" || !$this->isValidProperty($a_property)) {
139 return "";
140 }
141
142 $storage = $this->properties[$a_property]["storage"];
143 if ($a_user_id == ANONYMOUS_USER_ID) {
144 $storage = "session";
145 }
146
147 switch ($storage) {
148 case "session":
149 return ilSession::get("table_" . $a_table_id . "_" . $a_user_id . "_" . $a_property) ?? "";
150
151 case "db":
152 $set = $ilDB->query(
153 $q = "SELECT value FROM table_properties " .
154 " WHERE table_id = " . $ilDB->quote($a_table_id, "text") .
155 " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
156 " AND property = " . $ilDB->quote($a_property, "text")
157 );
158 $rec = $ilDB->fetchAssoc($set);
159 return $rec["value"] ?? '';
160 }
161 return "";
162 }
163
168 public function isValidProperty($a_property): bool
169 {
170 if (array_key_exists($a_property, $this->properties)) {
171 return true;
172 }
173 return false;
174 }
175}
Class ilCtrl provides processing control methods.
getCmd(?string $fallback_command=null)
@inheritDoc
User class.
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getProperty(string $a_table_id, int $a_user_id, string $a_property)
storeProperty(string $a_table_id, int $a_user_id, string $a_property, string $a_value)
const ANONYMOUS_USER_ID
Definition: constants.php:27
$requested_user_id
Definition: feed.php:39
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23