ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
DatetimeFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
33 
35 {
36  protected Refinery $refinery;
38 
39  public function __construct(
43  Refinery $refinery,
44  DataHelperInterface $data_helper
45  ) {
46  parent::__construct($ui_factory, $presenter, $constraint_dictionary);
47  $this->refinery = $refinery;
48  $this->data_helper = $data_helper;
49  }
50 
51  public function getInput(
52  ElementInterface $element,
53  ElementInterface $context_element
54  ): FormInput {
55  return $this->rawInput($element, $context_element);
56  }
57 
58  public function getInputInCondition(
59  ElementInterface $element,
60  ElementInterface $context_element,
61  SlotIdentifier $conditional_slot
62  ): FormInput {
63  return $this->rawInput($element, $context_element);
64  }
65 
66  protected function rawInput(
67  ElementInterface $element,
68  ElementInterface $context_element,
69  SlotIdentifier $conditional_slot = SlotIdentifier::NULL
70  ): FormInput {
71  $dh = $this->data_helper;
72  $input = $this->ui_factory
73  ->dateTime($this->getInputLabelFromElement($this->presenter, $element, $context_element))
74  ->withFormat($this->presenter->utilities()->getUserDateFormat())
76  $this->refinery->custom()->transformation(
77  function ($v) use ($dh) {
78  return isset($v) ? $dh->datetimeFromObject($v) : '';
79  }
80  )
81  );
82 
83  if ($element->getData()->type() !== Type::NULL) {
84  $input = $input->withValue($this->dataValueForInput($element->getData()));
85  }
86  return $this->addConstraintsFromElement($this->constraint_dictionary, $element, $input);
87  }
88 
89  protected function dataValueForInput(DataInterface $data): string
90  {
91  $date = $this->data_helper->datetimeToObject($data->value());
92  return $this->presenter->utilities()->getUserDateFormat()->applyTo($date);
93  }
94 }
rawInput(ElementInterface $element, ElementInterface $context_element, SlotIdentifier $conditional_slot=SlotIdentifier::NULL)
getInput(ElementInterface $element, ElementInterface $context_element)
getInputInCondition(ElementInterface $element, ElementInterface $context_element, SlotIdentifier $conditional_slot)
__construct(UIFactory $ui_factory, PresenterInterface $presenter, ConstraintDictionary $constraint_dictionary, Refinery $refinery, DataHelperInterface $data_helper)
__construct(Container $dic, ilPlugin $plugin)
This describes inputs that can be used in forms.
Definition: FormInput.php:32
value()
Value of the data, in a format according to its type.