ILIAS  release_7 Revision v7.30-3-g800a261c036
base.php
Go to the documentation of this file.
1<?php
7function base()
8{
9 //Step 0: Declare dependencies
10 global $DIC;
11 $ui = $DIC->ui()->factory();
12 $lng = $DIC->language();
13 $renderer = $DIC->ui()->renderer();
14 $request = $DIC->http()->request();
15 $data = new \ILIAS\Data\Factory();
16 $refinery = new \ILIAS\Refinery\Factory($data, $lng);
17
18 //Step 1: Implement transformation and constraints
19 $sum = $refinery->custom()->transformation(function ($vs) {
20 list($l, $r) = $vs;
21 $s = $l + $r;
22 return $s;
23 });
24 $equal_ten = $refinery->custom()->constraint(function ($v) {
25 return $v == 10;
26 }, "The sum must equal ten");
27
28 //Step 2: Define inputs
29 $number_input = $ui->input()->field()->numeric("number", "Put in a number.");
30
31 //Step 3: Define the group, add the inputs to the group and attach the
32 //transformation and constraint
33 $group = $ui->input()->field()->section(
34 [ $number_input->withLabel("Left"), $number_input->withLabel("Right")],
35 "Equals 10",
36 "Left and Right must equal 10"
37 )
38 ->withAdditionalTransformation($sum)
39 ->withAdditionalTransformation($equal_ten);
40
41 //Step 3, define form and form actions, attach the group to the form
42 $form = $ui->input()->container()->form()->standard('#', [$group]);
43
44 //Step 4, implement some form data processing.
45 if ($request->getMethod() == "POST") {
46 $form = $form->withRequest($request);
47 $result = $form->getData()[0];
48 } else {
49 $result = "No result yet.";
50 }
51
52 //Return the rendered form
53 return
54 "<pre>" . print_r($result, true) . "</pre><br/>" .
55 $renderer->render($form);
56}
base()
Definition: base.php:4
$result
An exception for terminatinating execution or to throw for unit testing.
global $DIC
Definition: goto.php:24
$lng
$data
Definition: storeScorm.php:23