ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 {
61 $ilUser = $this->user;
62
63 if ($this->user_id == $ilUser->getId()) {
64 switch ($this->request->getAction()) {
65 case "add":
66 $cur = $this->getProperty(
67 $this->req_acc_id,
68 $this->user_id,
69 "opened"
70 );
71 $cur_arr = explode(";", $cur);
72 if (!in_array($this->tab_nr, $cur_arr)) {
73 $cur_arr[] = $this->tab_nr;
74 }
75 $this->storeProperty(
76 $this->req_acc_id,
77 $this->user_id,
78 "opened",
79 implode(";", $cur_arr)
80 );
81 break;
82
83 case "rem":
84 $cur = $this->getProperty(
85 $this->req_acc_id,
86 $this->user_id,
87 "opened"
88 );
89 $cur_arr = explode(";", $cur);
90 if (($key = array_search($this->tab_nr, $cur_arr)) !== false) {
91 unset($cur_arr[$key]);
92 }
93 $this->storeProperty(
94 $this->req_acc_id,
95 $this->user_id,
96 "opened",
97 implode(";", $cur_arr)
98 );
99 break;
100
101 case "clear":
102 $this->storeProperty(
103 $this->req_acc_id,
104 $this->user_id,
105 "opened",
106 ""
107 );
108 break;
109
110 case "set":
111 default:
112 $this->storeProperty(
113 $this->req_acc_id,
114 $this->user_id,
115 "opened",
116 $this->tab_nr
117 );
118 break;
119 }
120 }
121 }
122
126 public function storeProperty(
127 string $a_table_id,
128 int $a_user_id,
129 string $a_property,
130 string $a_value
131 ): void {
132 switch ($this->properties[$a_property]["storage"]) {
133 case "session":
134 if (ilSession::has("accordion")) {
135 $acc = ilSession::get("accordion");
136 }
137 $acc[$a_table_id][$a_user_id][$a_property] = $a_value;
138 ilSession::set("accordion", $acc);
139 break;
140 }
141 }
142
143 public function getProperty(
144 string $a_table_id,
145 int $a_user_id,
146 string $a_property
147 ): string {
148 $acc = [];
149 if (ilSession::has("accordion")) {
150 $acc = ilSession::get("accordion");
151 }
152 return $acc[$a_table_id][$a_user_id][$a_property] ?? "";
153 }
154
155
157 string $id_starts_with,
158 int $user_id,
159 string $property
160 ): array {
161 $ret = [];
162 switch ($this->properties[$property]["storage"]) {
163 case "session":
164 if (ilSession::has("accordion")) {
165 $acc = ilSession::get("accordion");
166 foreach ($acc as $id => $user_values) {
167 if (substr($id, 0, strlen($id_starts_with)) === $id_starts_with) {
168 if (isset($user_values[$user_id][$property])) {
169 $ret[$id] = $user_values[$user_id][$property];
170 }
171 }
172 }
173 }
174 break;
175 }
176 return $ret;
177 }
178}
$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)
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