ILIAS  release_8 Revision v8.24
ilUIFilterService Class Reference

Filter service. More...

+ Collaboration diagram for ilUIFilterService:

Public Member Functions

 __construct (ilUIService $service, ilUIServiceDependencies $deps)
 
 standard (string $filter_id, string $base_action, array $inputs, array $is_input_initially_rendered, bool $is_activated=false, bool $is_expanded=false)
 Get standard filter instance. More...
 
 getData (Filter\Standard $filter)
 

Data Fields

const CMD_TOGGLE_ON = "toggleOn"
 
const CMD_TOGGLE_OFF = "toggleOff"
 
const CMD_EXPAND = "expand"
 
const CMD_COLLAPSE = "collapse"
 
const CMD_APPLY = "apply"
 
const CMD_RESET = "reset"
 

Protected Member Functions

 writeFilterStatusToSession (string $filter_id, array $inputs)
 Write filter status to session (filter activated/expanded, inputs being rendered or not) More...
 
 handleRendering (string $filter_id, array $inputs)
 Handle rendering of inputs to session. More...
 
 handleReset (string $filter_id)
 
 handleApplyAndToggle (string $filter_id, Filter\Standard $filter)
 

Protected Attributes

ilUIService $service
 
UIServices $ui
 
ilUIFilterServiceSessionGateway $session
 
ilUIFilterRequestAdapter $request
 

Detailed Description

Filter service.

Wraps around KS filter container.

Author
killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 30 of file class.ilUIFilterService.php.

Constructor & Destructor Documentation

◆ __construct()

ilUIFilterService::__construct ( ilUIService  $service,
ilUIServiceDependencies  $deps 
)

Member Function Documentation

◆ getData()

ilUIFilterService::getData ( Filter\Standard  $filter)

Definition at line 133 of file class.ilUIFilterService.php.

133 : ?array
134 {
135 $filter_data = null;
136 if ($filter->isActivated()) {
137 foreach ($filter->getInputs() as $k => $i) {
138 $filter_data[$k] = $i->getValue();
139 }
140 }
141
142 return $filter_data;
143 }
$i
Definition: metadata.php:41

References $i.

◆ handleApplyAndToggle()

ilUIFilterService::handleApplyAndToggle ( string  $filter_id,
Filter\Standard  $filter 
)
protected

Definition at line 203 of file class.ilUIFilterService.php.

203 : Filter\Standard
204 {
205 if ((in_array(
206 $this->request->getFilterCmd(),
207 [self::CMD_APPLY, self::CMD_TOGGLE_ON, self::CMD_TOGGLE_OFF]
208 ))) {
209 $filter = $this->request->getFilterWithRequest($filter);
210
211 // always expand the filter, when it is activated with empty input values
212 if ($this->request->getFilterCmd() == self::CMD_TOGGLE_ON) {
213 $result = $filter->getData();
214 $expand = true;
215 foreach ($result as $k => $v) {
216 if (!empty($v) || $v === 0 || $v === "0") {
217 $expand = false;
218 }
219 }
220 if ($expand) {
221 $this->session->writeExpanded($filter_id, true);
222 $filter = $filter->withExpanded();
223 }
224 }
225
226 foreach ($filter->getInputs() as $input_id => $i) {
227 $this->session->writeValue($filter_id, $input_id, $i->getValue());
228 }
229 }
230
231 return $filter;
232 }

References $i, and ILIAS\UI\Component\Input\Container\Filter\Filter\getData().

+ Here is the call graph for this function:

◆ handleRendering()

ilUIFilterService::handleRendering ( string  $filter_id,
array  $inputs 
)
protected

Handle rendering of inputs to session.

Parameters
string$filter_id
FilterInput[]$inputs

Definition at line 184 of file class.ilUIFilterService.php.

184 : void
185 {
186 foreach ($inputs as $input_id => $i) {
187 if ($this->request->isInputRendered($input_id)) {
188 $this->session->writeRendered($filter_id, $input_id, true);
189 } else {
190 $this->session->writeRendered($filter_id, $input_id, false);
191 }
192 }
193 }

References $i, and ILIAS\UI\Implementation\Component\Input\$inputs.

◆ handleReset()

ilUIFilterService::handleReset ( string  $filter_id)
protected

Definition at line 195 of file class.ilUIFilterService.php.

195 : void
196 {
197 // clear session, if reset is pressed
198 if ($this->request->getFilterCmd() == self::CMD_RESET) {
199 $this->session->reset($filter_id);
200 }
201 }

◆ standard()

ilUIFilterService::standard ( string  $filter_id,
string  $base_action,
array  $inputs,
array  $is_input_initially_rendered,
bool  $is_activated = false,
bool  $is_expanded = false 
)

Get standard filter instance.

Parameters
string$filter_id
string$base_action
FilterInput[]$inputs
bool[]$is_input_initially_rendered
bool$is_activated
bool$is_expanded
Returns
Filter\Standard

Definition at line 65 of file class.ilUIFilterService.php.

72 : Filter\Standard {
73 $ui = $this->ui->factory();
74
75 // write expand, activation, rendered inputs info to session
76 $this->writeFilterStatusToSession($filter_id, $inputs);
77
78 // handle the reset command
79 $this->handleReset($filter_id);
80
81 // determine activation/expand status
82 $is_activated = $this->session->isActivated($filter_id, $is_activated);
83 $is_expanded = $this->session->isExpanded($filter_id, $is_expanded);
84
85 // put data from session into filter
86 $inputs_with_session_data = [];
87 $is_input_initially_rendered_with_session = [];
88
89 if (count($inputs) != count($is_input_initially_rendered)) {
90 throw new \ArgumentCountError(
91 "Inputs and boolean values for initial rendering must be arrays of same size."
92 );
93 }
94
95 foreach ($inputs as $input_id => $i) {
96 // rendering information
97 $rendered =
98 $this->session->isRendered($filter_id, $input_id, current($is_input_initially_rendered));
99 $is_input_initially_rendered_with_session[] = $rendered;
100 next($is_input_initially_rendered);
101
102 // values
103 $val = $this->session->getValue($filter_id, $input_id);
104 if (!is_null($val)) {
105 try {
106 $i = $i->withValue($val);
107 } catch (InvalidArgumentException $e) {
108 }
109 }
110 $inputs_with_session_data[$input_id] = $i;
111 }
112
113 // get the filter
114 $filter = $ui->input()->container()->filter()->standard(
115 $this->request->getAction($base_action, self::CMD_TOGGLE_ON, true),
116 $this->request->getAction($base_action, self::CMD_TOGGLE_OFF, true),
117 $this->request->getAction($base_action, self::CMD_EXPAND),
118 $this->request->getAction($base_action, self::CMD_COLLAPSE),
119 $this->request->getAction($base_action, self::CMD_APPLY, true),
120 $this->request->getAction($base_action, self::CMD_RESET, true),
121 $inputs_with_session_data,
122 $is_input_initially_rendered_with_session,
123 $is_activated,
124 $is_expanded
125 );
126
127 // handle apply and toggle commands
128 $filter = $this->handleApplyAndToggle($filter_id, $filter);
129
130 return $filter;
131 }
writeFilterStatusToSession(string $filter_id, array $inputs)
Write filter status to session (filter activated/expanded, inputs being rendered or not)
handleApplyAndToggle(string $filter_id, Filter\Standard $filter)
handleReset(string $filter_id)

◆ writeFilterStatusToSession()

ilUIFilterService::writeFilterStatusToSession ( string  $filter_id,
array  $inputs 
)
protected

Write filter status to session (filter activated/expanded, inputs being rendered or not)

Parameters
string$filter_id
FilterInput[]$inputs

Definition at line 151 of file class.ilUIFilterService.php.

151 : void
152 {
153 if ($this->request->getFilterCmd() == self::CMD_TOGGLE_ON) {
154 $this->handleRendering($filter_id, $inputs);
155 $this->session->writeActivated($filter_id, true);
156 }
157
158 if ($this->request->getFilterCmd() == self::CMD_TOGGLE_OFF) {
159 $this->handleRendering($filter_id, $inputs);
160 $this->session->writeActivated($filter_id, false);
161 }
162
163 if ($this->request->getFilterCmd() == self::CMD_EXPAND) {
164 $this->session->writeExpanded($filter_id, true);
165 }
166
167 if ($this->request->getFilterCmd() == self::CMD_COLLAPSE) {
168 $this->session->writeExpanded($filter_id, false);
169 }
170
171 if ($this->request->getFilterCmd() == self::CMD_APPLY) {
172 $this->handleRendering($filter_id, $inputs);
173 // always activate the filter when it is applied
174 $this->session->writeActivated($filter_id, true);
175 }
176 }
handleRendering(string $filter_id, array $inputs)
Handle rendering of inputs to session.

References ILIAS\UI\Implementation\Component\Input\$inputs.

Field Documentation

◆ $request

ilUIFilterRequestAdapter ilUIFilterService::$request
protected

Definition at line 43 of file class.ilUIFilterService.php.

◆ $service

ilUIService ilUIFilterService::$service
protected

Definition at line 40 of file class.ilUIFilterService.php.

Referenced by __construct().

◆ $session

ilUIFilterServiceSessionGateway ilUIFilterService::$session
protected

Definition at line 42 of file class.ilUIFilterService.php.

◆ $ui

UIServices ilUIFilterService::$ui
protected

Definition at line 41 of file class.ilUIFilterService.php.

◆ CMD_APPLY

const ilUIFilterService::CMD_APPLY = "apply"

Definition at line 37 of file class.ilUIFilterService.php.

◆ CMD_COLLAPSE

const ilUIFilterService::CMD_COLLAPSE = "collapse"

Definition at line 36 of file class.ilUIFilterService.php.

◆ CMD_EXPAND

const ilUIFilterService::CMD_EXPAND = "expand"

Definition at line 35 of file class.ilUIFilterService.php.

◆ CMD_RESET

const ilUIFilterService::CMD_RESET = "reset"

Definition at line 38 of file class.ilUIFilterService.php.

◆ CMD_TOGGLE_OFF

const ilUIFilterService::CMD_TOGGLE_OFF = "toggleOff"

Definition at line 34 of file class.ilUIFilterService.php.

◆ CMD_TOGGLE_ON

const ilUIFilterService::CMD_TOGGLE_ON = "toggleOn"

Definition at line 33 of file class.ilUIFilterService.php.


The documentation for this class was generated from the following file: