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
4docs/LICENSE */
5
7
8use ILIAS\Data\Factory as DataFactory;
10use ILIAS\Validation\Factory as ValidationFactory;
11use ILIAS\Transformation\Factory as TransformationFactory;
15
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}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:15
Factory for basic transformations.
Definition: Factory.php:12
withValue($value)
Get an input like this with another value displayed on the client side.InvalidArgumentException if va...
Definition: Checkbox.php:52
This describes checkbox inputs.
Definition: Checkbox.php:16
This describes commonalities between all inputs.
Definition: Input.php:31
withValue($value)
Get an input like this with another value displayed on the client side.
Describes how Input-Elements want to interact with posted data.
Definition: PostData.php:13
getOr($name, $default)
Get a named value from the data and fallback to default if that name does not exist.
trait DependantGroupHelper
This is a trait for inputs providing dependant groups, such as checkboxes, e.g.
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.