ILIAS  release_8 Revision v8.24
class.ilAccordionPropertiesStorageGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected string $tab_nr;
26 protected string $req_acc_id;
27 protected int $user_id;
28 protected \ILIAS\Accordion\StandardGUIRequest $request;
29 protected ilObjUser $user;
30 protected ilCtrl $ctrl;
31 protected ilDBInterface $db;
32 public array $properties = array(
33 "opened" => array("storage" => "session")
34 );
35
36 public function __construct()
37 {
38 global $DIC;
39
40 $this->user = $DIC->user();
41 $this->ctrl = $DIC->ctrl();
42 $this->db = $DIC->database();
43 $this->request = new \ILIAS\Accordion\StandardGUIRequest(
44 $DIC->http(),
45 $DIC->refinery()
46 );
47 $this->user_id = $this->request->getUserId();
48 $this->req_acc_id = $this->request->getId();
49 $this->tab_nr = $this->request->getTabNr();
50 }
51
52 public function executeCommand(): void
53 {
54 $ilCtrl = $this->ctrl;
55 $cmd = $ilCtrl->getCmd();
56 $this->$cmd();
57 }
58
59 public function setOpenedTab(): void
60 {
62
63 if ($this->user_id == $ilUser->getId()) {
64 switch ($this->request->getAction()) {
65
66 case "add":
67 $cur = $this->getProperty(
68 $this->req_acc_id,
69 $this->user_id,
70 "opened"
71 );
72 $cur_arr = explode(";", $cur);
73 if (!in_array($this->tab_nr, $cur_arr)) {
74 $cur_arr[] = $this->tab_nr;
75 }
76 $this->storeProperty(
77 $this->req_acc_id,
78 $this->user_id,
79 "opened",
80 implode(";", $cur_arr)
81 );
82 break;
83
84 case "rem":
85 $cur = $this->getProperty(
86 $this->req_acc_id,
87 $this->user_id,
88 "opened"
89 );
90 $cur_arr = explode(";", $cur);
91 if (($key = array_search($this->tab_nr, $cur_arr)) !== false) {
92 unset($cur_arr[$key]);
93 }
94 $this->storeProperty(
95 $this->req_acc_id,
96 $this->user_id,
97 "opened",
98 implode(";", $cur_arr)
99 );
100 break;
101
102 case "clear":
103 $this->storeProperty(
104 $this->req_acc_id,
105 $this->user_id,
106 "opened",
107 ""
108 );
109 break;
110
111 case "set":
112 default:
113 $this->storeProperty(
114 $this->req_acc_id,
115 $this->user_id,
116 "opened",
117 $this->tab_nr
118 );
119 break;
120 }
121 }
122 }
123
127 public function storeProperty(
128 string $a_table_id,
129 int $a_user_id,
130 string $a_property,
131 string $a_value
132 ): void {
133 switch ($this->properties[$a_property]["storage"]) {
134 case "session":
135 if (ilSession::has("accordion")) {
136 $acc = ilSession::get("accordion");
137 }
138 $acc[$a_table_id][$a_user_id][$a_property] = $a_value;
139 ilSession::set("accordion", $acc);
140 break;
141 }
142 }
143
144 public function getProperty(
145 string $a_table_id,
146 int $a_user_id,
147 string $a_property
148 ): string {
149 $acc = [];
150 if (ilSession::has("accordion")) {
151 $acc = ilSession::get("accordion");
152 }
153 return $acc[$a_table_id][$a_user_id][$a_property] ?? "";
154 }
155
156
158 string $id_starts_with,
159 int $user_id,
160 string $property
161 ): array {
162 $ret = [];
163 switch ($this->properties[$property]["storage"]) {
164 case "session":
165 if (ilSession::has("accordion")) {
166 $acc = ilSession::get("accordion");
167 foreach ($acc as $id => $user_values) {
168 if (substr($id, 0, strlen($id_starts_with)) === $id_starts_with) {
169 if (isset($user_values[$user_id][$property])) {
170 $ret[$id] = $user_values[$user_id][$property];
171 }
172 }
173 }
174 }
175 break;
176 }
177 return $ret;
178 }
179}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
storeProperty(string $a_table_id, int $a_user_id, string $a_property, string $a_value)
Store property in session.
getProperty(string $a_table_id, int $a_user_id, string $a_property)
getPropertyForIdStartsWith(string $id_starts_with, int $user_id, string $property)
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.
static has($a_var)
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
Interface ilCtrlBaseClassInterface describes ilCtrl base classes.
Interface ilDBInterface.
string $key
Consumer key/client ID value.
Definition: System.php:193