ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Checkbox.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see
4 docs/LICENSE */
5 
7 
9 use ILIAS\UI\Component as C;
10 use ILIAS\Validation\Factory as ValidationFactory;
11 use ILIAS\Transformation\Factory as TransformationFactory;
15 
20 class Checkbox extends Input implements C\Input\Field\Checkbox, C\Changeable, C\Onloadable
21 {
23  use Triggerer;
25 
26 
30  protected function getConstraintForRequirement()
31  {
32  return null;
33  }
34 
38  protected function isClientSideValueOk($value)
39  {
40  if ($value == "checked" || $value === "" || is_bool($value)) {
41  return true;
42  } else {
43  return false;
44  }
45  }
46 
47 
52  public function withValue($value)
53  {
54  //be lenient to bool params for easier use
55  if ($value === true) {
56  $value = "checked";
57  } else {
58  if ($value === false) {
59  $value = "";
60  }
61  }
62 
63  return parent::withValue($value);
64  }
65 
66 
70  public function withInput(PostData $post_input)
71  {
72  if ($this->getName() === null) {
73  throw new \LogicException("Can only collect if input has a name.");
74  }
75 
76  $value = $post_input->getOr($this->getName(), "");
77  $clone = $this->withValue($value);
78  $clone->content = $this->applyOperationsTo($value);
79  if ($clone->content->isError()) {
80  return $clone->withError("" . $clone->content->error());
81  }
82 
83  $clone = $clone->withGroupInput($post_input);
84 
85  return $clone;
86  }
87 }
This describes commonalities between all inputs.
Definition: Input.php:30
getOr($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.
This describes checkbox inputs.
Definition: Checkbox.php:15
Factory for basic transformations.
Definition: Factory.php:11
Describes how Input-Elements want to interact with posted data.
Definition: PostData.php:12
Builds data types.
Definition: Factory.php:14
withValue($value)
Get an input like this with another value displayed on the client side.
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Checkbox.php:52
trait DependantGroupHelper
This is a trait for inputs providing dependant groups, such as checkboxes, e.g.