ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Numeric.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;
12 
16 class Numeric extends Input implements C\Input\Field\Numeric
17 {
18 
26  public function __construct(
27  DataFactory $data_factory,
28  ValidationFactory $validation_factory,
29  TransformationFactory $transformation_factory,
30  $label,
31  $byline
32  ) {
33  parent::__construct($data_factory, $validation_factory, $transformation_factory, $label, $byline);
34 
35  $this->setAdditionalTransformation(
36  $this->transformation_factory->custom(
37  function ($v) {
38  if (trim($v) === '') {
39  return null;
40  }
41  return $v;
42  }
43  )
44  );
45 
46  //TODO: Is there a better way to do this? Note, that "withConstraint" is not
47  // usable here (clone).
48  $this->setAdditionalConstraint(
49  $this->validation_factory->or(
50  [
51  $this->validation_factory->isNumeric(),
52  $this->validation_factory->isNull()
53  ]
54  )
55  );
56  }
57 
58 
62  protected function isClientSideValueOk($value)
63  {
64  return is_numeric($value) || $value === "" || $value === null;
65  }
66 
67 
71  protected function getConstraintForRequirement()
72  {
73  return $this->validation_factory->isNumeric();
74  }
75 }
This describes numeric inputs.
Definition: Numeric.php:11
This describes commonalities between all inputs.
Definition: Input.php:30
__construct(DataFactory $data_factory, ValidationFactory $validation_factory, TransformationFactory $transformation_factory, $label, $byline)
Numeric constructor.
Definition: Numeric.php:26
Factory for basic transformations.
Definition: Factory.php:11
Builds data types.
Definition: Factory.php:14