ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
with_fields.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
35function with_fields()
36{
37 global $DIC;
38 $ui_factory = $DIC['ui.factory'];
39 $renderer = $DIC['ui.renderer'];
40 $data_factory = new \ILIAS\Data\Factory();
41 $request = $DIC->http()->request();
42 $ctrl = $DIC['ilCtrl'];
43 $spacer = $ui_factory->divider()->horizontal();
44
45 $url = $data_factory->uri($DIC->http()->request()->getUri()->__toString());
46 $url = $url->withParameter('launcher_redirect', '');
47
48 //A Launcher with a checkbox-form
49 $description = '<p>Before you can join this group, you will have to accept the terms and conditions</p>';
50 $instruction = $ui_factory->messageBox()->info('Accept the conditions.');
51 $group = $ui_factory->input()->field()->group([
52 $ui_factory->input()->field()->checkbox('Understood', 'ok')
53 ]);
54 $evaluation = function (Result $result, Launcher &$launcher) use ($ctrl, $ui_factory) {
55 if ($result->isOK() && $result->value()[0]) {
56 $ctrl->redirectToURL(
57 (string) $launcher->getTarget()->getURL()->withParameter('launcher_redirect', 'terms accepted (' . $launcher->getButtonLabel() . ')')
58 );
59 }
60 $launcher = $launcher->withStatusMessageBox($ui_factory->messageBox()->failure('You must accept the conditions.'));
61 };
62
63 $target = $data_factory->link('Join Group', $url->withParameter('launcher_id', 'l1'));
64
65 $launcher = $ui_factory->launcher()
66 ->inline($target)
67 ->withDescription($description)
68 ->withInputs($group, $evaluation, $instruction);
69
70 if (array_key_exists('launcher_id', $request->getQueryParams()) && $request->getQueryParams()['launcher_id'] === 'l1') {
71 $launcher = $launcher->withRequest($request);
72 }
73
74 //A Launcher with icon
75 $icon = $ui_factory->symbol()->icon()->standard('auth', 'authentification needed', 'large');
76 $description = '<p>Before you can take the survey, you have to agree to our terms and conditions.</p>';
77 $target = $data_factory->link('Take Survey', $url->withParameter('launcher_id', 'l2'));
78 $launcher2 = $ui_factory->launcher()
79 ->inline($target)
80 ->withStatusIcon($icon)
81 ->withButtonLabel('Take Survey')
82 ->withDescription($description)
83 ->withInputs($group, $evaluation);
84
85 if (array_key_exists('launcher_id', $request->getQueryParams()) && $request->getQueryParams()['launcher_id'] === 'l2') {
86 $launcher2 = $launcher2->withRequest($request);
87 }
88
89
90 //A Launcher with password field
91 $icon = $ui_factory->symbol()->icon()->standard('ps', 'authentification needed', 'large');
92 $status_message = $ui_factory->messageBox()->info("You will be asked for your personal passcode when you start the test.");
93 $instruction = $ui_factory->messageBox()->info('Fill the form; use password "ilias" to pass');
94 $group = $ui_factory->input()->field()->group([
95 $ui_factory->input()->field()->password('pwd', 'Password')
96 ]);
97 $evaluation = function (Result $result, Launcher &$launcher) use ($ctrl, $ui_factory) {
98 if ($result->isOK() && $result->value()[0]->toString() === 'ilias') {
99 $ctrl->redirectToURL(
100 (string) $launcher->getTarget()->getURL()->withParameter('launcher_redirect', 'password protected')
101 );
102 }
103 $launcher = $launcher->withStatusMessageBox($ui_factory->messageBox()->failure('nope. wrong pass.'));
104 };
105
106 $target = $data_factory->link('Begin Exam', $url->withParameter('launcher_id', 'l3'));
107 $launcher3 = $ui_factory->launcher()
108 ->inline($target)
109 ->withDescription('')
110 ->withInputs($group, $evaluation, $instruction)
111 ->withStatusIcon($icon)
112 ->withStatusMessageBox($status_message)
113 ->withModalSubmitLabel('Begin Exam')
114 ->withModalCancelLabel('Cancel')
115 ;
116
117 if (array_key_exists('launcher_id', $request->getQueryParams()) && $request->getQueryParams()['launcher_id'] === 'l3') {
118 $launcher3 = $launcher3->withRequest($request);
119 }
120
121
122 $result = "not submitted or wrong pass";
123
124 if (array_key_exists('launcher_redirect', $request->getQueryParams())
125 && $v = $request->getQueryParams()['launcher_redirect']
126 ) {
127 $result = "<b>sucessfully redirected ($v)</b>";
128 }
129
130 return $result . "<hr/>" . $renderer->render([
131 $launcher,
132 $spacer,
133 $launcher2,
134 $spacer,
135 $launcher3
136 ]);
137}
$renderer
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29
isOK()
Get to know if the result is ok.
value()
Get the encapsulated value.
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68