ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DatetimeFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Refinery\Factory as Refinery;
33
35{
38
39 public function __construct(
40 UIFactory $ui_factory,
42 ConstraintDictionary $constraint_dictionary,
45 ) {
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}
Builds data types.
Definition: Factory.php:36
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)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes inputs that can be used in forms.
Definition: FormInput.php:33
This is what a factory for input fields looks like.
Definition: Factory.php:31
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the content of the input.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc