ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
base.php
Go to the documentation of this file.
1 <?php
5 function base()
6 {
7 
8  //Step 0: Declare dependencies
9  global $DIC;
10 
11  $ui = $DIC->ui()->factory();
12  $data = new ILIAS\Data\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 }
$data
Definition: storeScorm.php:23
$result
base()
Definition: base.php:4
$format
Definition: metadata.php:218
$DIC
Definition: xapitoken.php:46