ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
OptionalGroup.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 use LogicException;
29 
33 class OptionalGroup extends Group implements I\OptionalGroup
34 {
36  use Triggerer;
37 
38  protected bool $null_value_was_explicitly_set = false;
39 
43  protected function getConstraintForRequirement(): ?Constraint
44  {
45  if ($this->requirement_constraint !== null) {
47  }
48 
49  return null;
50  }
51 
55  protected function isClientSideValueOk($value): bool
56  {
57  if ($value === null) {
58  return true;
59  }
61  }
62 
64  {
67  }
68 
69  public function isRequired(): bool
70  {
71  return $this->is_required;
72  }
73 
77  public function withValue($value): self
78  {
79  if ($value === null) {
80  $clone = clone $this;
81  $clone->value = $value;
82  $clone->null_value_was_explicitly_set = true;
83  return $clone;
84  }
85 
86  $clone = parent::withValue($value);
87  $clone->null_value_was_explicitly_set = false;
88  return $clone;
89  }
90 
94  public function getValue()
95  {
96  if ($this->null_value_was_explicitly_set) {
97  return null;
98  }
99  return parent::getValue();
100  }
101 
102 
106  public function withInput(InputData $input): self
107  {
108  if ($this->getName() === null) {
109  throw new LogicException("Can only collect if input has a name.");
110  }
111 
112  if (!$this->isDisabled()) {
113  $value = $input->getOr($this->getName(), null);
114  if ($value === null) {
115  $clone = $this->withValue(null);
116  // Ugly hack to prevent shortcutting behaviour of applyOperationsTo
117  $temp = $clone->is_required;
118  $clone->is_required = true;
119  $clone->content = $clone->applyOperationsTo(null);
120  $clone->is_required = $temp;
121  return $clone;
122  }
123  }
124 
125  $clone = parent::withInput($input);
126  // If disabled keep, else false, because the null case is already handled.
127  $clone->null_value_was_explicitly_set = $this->isDisabled() && $this->null_value_was_explicitly_set;
128  return $clone;
129  }
130 }
withValue($value)
Get an input like this with another value displayed on the client side.if value does not fit client s...
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:29
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:49
getOr(string $name, $default)
Get a named value from the data and fallback to default if that name does not exist.
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
A constraint encodes some resrtictions on values.
Definition: Constraint.php:31
withInput(InputData $input)
Collects the input, applies trafos and forwards the input to its children and returns a new input gro...
Definition: Group.php:77
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
withRequired($is_required, ?Constraint $requirement_constraint=null)
getValue()
Get the value that is displayed in the input client side.mixed
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
withRequired(bool $is_required, ?Constraint $requirement_constraint=null)
Definition: FormInput.php:120
withInput(InputData $input)
Get an input like this with input from post data.static