ILIAS  release_7 Revision v7.30-3-g800a261c036
base.php File Reference

Go to the source code of this file.

Functions

 base ()
 Base example showing how to plug date-inputs into a form. More...
 

Function Documentation

◆ base()

base ( )

Base example showing how to plug date-inputs into a form.

Definition at line 5 of file base.php.

6{
7
8 //Step 0: Declare dependencies
9 global $DIC;
10
11 $ui = $DIC->ui()->factory();
13 $renderer = $DIC->ui()->renderer();
14 $request = $DIC->http()->request();
15 $ctrl = $DIC->ctrl();
16
17 //Step 1: define the inputs
18 $date = $ui->input()->field()->dateTime("Pick a date/time", "This is the byline text");
19 $formatted = $date
20 ->withMinValue(new DateTimeImmutable())
21 ->withFormat($data->dateFormat()->germanShort());
22 $time = $date->withTimeOnly(true);
23 $both = $date->withUseTime(true);
24
25 //setting a timezone will return a date with this timezone.
26 $tz = 'Asia/Tokyo';
27 $timezoned = $both->withTimezone($tz)->withByline('Result-value will have TZ ' . $tz);
28
29 //if you want a date converted to the timezone, do it on the date:
30 $date_now = new DateTime('now');
31 $date_zoned = new DateTime('now', new \DateTimeZone($tz));
32
33
34 //here is the usage of Data/DateFormat
35 $format = $timezoned->getFormat()->toString() . ' H:i';
36 $timezoned_preset1 = $timezoned->withValue($date_now->format($format))
37 ->withByline('This is local "now"');
38 $timezoned_preset2 = $timezoned->withValue($date_zoned->format($format))
39 ->withByline('This is "now" in ' . $tz);
40
41 //Step 2: define form and form actions
42 $form = $ui->input()->container()->form()->standard('#', [
43 'date' => $date,
44 'formatted' => $formatted,
45 'time' => $time,
46 'both' => $both,
47 'timezoned' => $timezoned,
48 'timezoned_preset1' => $timezoned_preset1,
49 'timezoned_preset2' => $timezoned_preset2,
50 'disabled' => $date
51 ->withValue($date_now->format($format))
52 ->withLabel('disabled')
53 ->withDisabled(true)
54 ]);
55
56 //Step 3: implement some form data processing.
57 if ($request->getMethod() == "POST") {
58 $form = $form->withRequest($request);
59 $result = $form->getData();
60 } else {
61 $result = "No result yet.";
62 }
63
64 //Step 4: Render the form.
65 return
66 "<pre>" . print_r($result, true) . "</pre><br/>" .
67 $renderer->render($form);
68}
$result
Builds data types.
Definition: Factory.php:20
global $DIC
Definition: goto.php:24
$format
Definition: metadata.php:218
$data
Definition: storeScorm.php:23

References $data, $DIC, $format, and $result.