ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilUIFilterService Class Reference

Filter service. More...

+ Collaboration diagram for ilUIFilterService:

Public Member Functions

 __construct (ilUIService $service, ilUIServiceDependencies $deps)
 Constructor. More...
 
 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)
 Get data. More...
 

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 ($filter_id, $inputs)
 Write filter status to session (filter activated/expanded, inputs being rendered or not) More...
 
 handleRendering ($filter_id, $inputs)
 Handle rendering of inputs to session. More...
 
 handleReset (string $filter_id)
 Handle reset command. More...
 
 handleApplyAndToggle (string $filter_id, Filter\Standard $filter)
 Handle apply and toggle commands. More...
 

Protected Attributes

 $service
 
 $ui
 
 $session
 
 $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 15 of file class.ilUIFilterService.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Parameters
ilUIService$service
ilUIServiceDependencies$deps

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

References $service, ilUIServiceDependencies\getRequest(), ilUIServiceDependencies\getSession(), ui(), and ilUIServiceDependencies\ui().

52  {
53  $this->service = $service;
54  $this->session = $deps->getSession();
55  $this->request = $deps->getRequest();
56  $this->ui = $deps->ui();
57  }
ui()
Definition: ui.php:5
+ Here is the call graph for this function:

Member Function Documentation

◆ getData()

ilUIFilterService::getData ( Filter\Standard  $filter)

Get data.

Parameters
Filter\Standard$filter
Returns
array|null

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

References $i.

145  : ?array
146  {
147  $filter_data = null;
148  if ($filter->isActivated()) {
149  foreach ($filter->getInputs() as $k => $i) {
150  $filter_data[$k] = $i->getValue();
151  }
152  }
153  return $filter_data;
154  }
$i
Definition: metadata.php:24

◆ handleApplyAndToggle()

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

Handle apply and toggle commands.

Parameters
string$filter_id
Filter\Standard$filter
Returns
Filter

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

References $i, and $result.

Referenced by standard().

225  : Filter\Standard
226  {
227  if ((in_array(
228  $this->request->getFilterCmd(),
229  [self::CMD_APPLY, self::CMD_TOGGLE_ON, self::CMD_TOGGLE_OFF]
230  ))) {
231  $filter = $this->request->getFilterWithRequest($filter);
232 
233  // always expand the filter, when it is activated with empty input values
234  if ($this->request->getFilterCmd() == self::CMD_TOGGLE_ON) {
235  $result = $filter->getData();
236  $expand = true;
237  foreach ($result as $k => $v) {
238  if (!empty($v) || $v === 0 || $v === "0") {
239  $expand = false;
240  }
241  }
242  if ($expand) {
243  $this->session->writeExpanded($filter_id, true);
244  $filter = $filter->withExpanded();
245  }
246  }
247 
248  foreach ($filter->getInputs() as $input_id => $i) {
249  $this->session->writeValue($filter_id, $input_id, $i->getValue());
250  }
251  }
252  return $filter;
253  }
$result
$i
Definition: metadata.php:24
+ Here is the caller graph for this function:

◆ handleRendering()

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

Handle rendering of inputs to session.

Parameters
string$filter_id
array$inputs

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

References $i.

Referenced by writeFilterStatusToSession().

194  {
195  foreach ($inputs as $input_id => $i) {
196  if ($this->request->isInputRendered($input_id)) {
197  $this->session->writeRendered($filter_id, $input_id, true);
198  } else {
199  $this->session->writeRendered($filter_id, $input_id, false);
200  }
201  }
202  }
$i
Definition: metadata.php:24
+ Here is the caller graph for this function:

◆ handleReset()

ilUIFilterService::handleReset ( string  $filter_id)
protected

Handle reset command.

Parameters
string$filter_id

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

Referenced by standard().

210  {
211  // clear session, if reset is pressed
212  if ($this->request->getFilterCmd() == self::CMD_RESET) {
213  $this->session->reset($filter_id);
214  }
215  }
+ Here is the caller graph for this function:

◆ 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

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

References Vendor\Package\$e, $i, $ui, handleApplyAndToggle(), handleReset(), ui(), and writeFilterStatusToSession().

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

◆ writeFilterStatusToSession()

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

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

Parameters
string$filter_id
array$inputs

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

References handleRendering().

Referenced by standard().

162  {
163  if ($this->request->getFilterCmd() == self::CMD_TOGGLE_ON) {
164  $this->handleRendering($filter_id, $inputs);
165  $this->session->writeActivated($filter_id, true);
166  }
167 
168  if ($this->request->getFilterCmd() == self::CMD_TOGGLE_OFF) {
169  $this->handleRendering($filter_id, $inputs);
170  $this->session->writeActivated($filter_id, false);
171  }
172 
173  if ($this->request->getFilterCmd() == self::CMD_EXPAND) {
174  $this->session->writeExpanded($filter_id, true);
175  }
176 
177  if ($this->request->getFilterCmd() == self::CMD_COLLAPSE) {
178  $this->session->writeExpanded($filter_id, false);
179  }
180 
181  if ($this->request->getFilterCmd() == self::CMD_APPLY) {
182  $this->handleRendering($filter_id, $inputs);
183  // always activate the filter when it is applied
184  $this->session->writeActivated($filter_id, true);
185  }
186  }
handleRendering($filter_id, $inputs)
Handle rendering of inputs to session.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $request

ilUIFilterService::$request
protected

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

◆ $service

ilUIFilterService::$service
protected

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

Referenced by __construct().

◆ $session

ilUIFilterService::$session
protected

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

◆ $ui

ilUIFilterService::$ui
protected

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

Referenced by standard().

◆ CMD_APPLY

const ilUIFilterService::CMD_APPLY = "apply"

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

◆ CMD_COLLAPSE

const ilUIFilterService::CMD_COLLAPSE = "collapse"

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

◆ CMD_EXPAND

const ilUIFilterService::CMD_EXPAND = "expand"

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

◆ CMD_RESET

const ilUIFilterService::CMD_RESET = "reset"

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

◆ CMD_TOGGLE_OFF

const ilUIFilterService::CMD_TOGGLE_OFF = "toggleOff"

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

◆ CMD_TOGGLE_ON

const ilUIFilterService::CMD_TOGGLE_ON = "toggleOn"

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


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