ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
with_fields.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
10 
15 function with_fields()
16 {
17  global $DIC;
18  $ui_factory = $DIC['ui.factory'];
19  $renderer = $DIC['ui.renderer'];
20  $data_factory = new \ILIAS\Data\Factory();
21  $request = $DIC->http()->request();
22  $ctrl = $DIC['ilCtrl'];
23  $spacer = $ui_factory->divider()->horizontal();
24 
25  $url = $data_factory->uri($DIC->http()->request()->getUri()->__toString());
26  $url = $url->withParameter('launcher_redirect', '');
27 
28  //A Launcher with a checkbox-form
29  $description = '<p>Before you can join this group, you will have to accept the terms and conditions</p>';
30  $instruction = $ui_factory->messageBox()->info('Accept the conditions.');
31  $group = $ui_factory->input()->field()->group([
32  $ui_factory->input()->field()->checkbox('Understood', 'ok')
33  ]);
34  $evaluation = function (Result $result, Launcher &$launcher) use ($ctrl, $ui_factory) {
35  if ($result->isOK() && $result->value()[0]) {
36  $ctrl->redirectToURL(
37  (string)$launcher->getTarget()->getURL()->withParameter('launcher_redirect', 'terms accepted (' . $launcher->getButtonLabel() . ')')
38  );
39  }
40  $launcher = $launcher->withStatusMessageBox($ui_factory->messageBox()->failure('You must accept the conditions.'));
41  };
42 
43  $target = $data_factory->link('Join Group', $url->withParameter('launcher_id', 'l1'));
44 
45  $launcher = $ui_factory->launcher()
46  ->inline($target)
47  ->withDescription($description)
48  ->withInputs($group, $evaluation, $instruction);
49 
50  if (array_key_exists('launcher_id', $request->getQueryParams()) && $request->getQueryParams()['launcher_id'] === 'l1') {
51  $launcher = $launcher->withRequest($request);
52  }
53 
54  //A Launcher with icon
55  $icon = $ui_factory->symbol()->icon()->standard('auth', 'authentification needed', 'large');
56  $description = '<p>Before you can take the survey, you have to agree to our terms and conditions.</p>';
57  $target = $data_factory->link('Take Survey', $url->withParameter('launcher_id', 'l2'));
58  $launcher2 = $ui_factory->launcher()
59  ->inline($target)
60  ->withStatusIcon($icon)
61  ->withButtonLabel('Take Survey')
62  ->withDescription($description)
63  ->withInputs($group, $evaluation);
64 
65  if (array_key_exists('launcher_id', $request->getQueryParams()) && $request->getQueryParams()['launcher_id'] === 'l2') {
66  $launcher2 = $launcher2->withRequest($request);
67  }
68 
69 
70  //A Launcher with password field
71  $icon = $ui_factory->symbol()->icon()->standard('ps', 'authentification needed', 'large');
72  $status_message = $ui_factory->messageBox()->info("You will be asked for your personal passcode when you start the test.");
73  $instruction = $ui_factory->messageBox()->info('Fill the form; use password "ilias" to pass');
74  $group = $ui_factory->input()->field()->group([
75  $ui_factory->input()->field()->password('pwd', 'Password')
76  ]);
77  $evaluation = function (Result $result, Launcher &$launcher) use ($ctrl, $ui_factory) {
78  if ($result->isOK() && $result->value()[0]->toString() === 'ilias') {
79  $ctrl->redirectToURL(
80  (string)$launcher->getTarget()->getURL()->withParameter('launcher_redirect', 'password protected')
81  );
82  }
83  $launcher = $launcher->withStatusMessageBox($ui_factory->messageBox()->failure('nope. wrong pass.'));
84  };
85 
86  $target = $data_factory->link('Begin Exam', $url->withParameter('launcher_id', 'l3'));
87  $launcher3 = $ui_factory->launcher()
88  ->inline($target)
89  ->withDescription('')
90  ->withInputs($group, $evaluation, $instruction)
91  ->withStatusIcon($icon)
92  ->withStatusMessageBox($status_message)
93  ->withModalSubmitLabel('Begin Exam')
94  ->withModalCancelLabel('Cancel')
95  ;
96 
97  if (array_key_exists('launcher_id', $request->getQueryParams()) && $request->getQueryParams()['launcher_id'] === 'l3') {
98  $launcher3 = $launcher3->withRequest($request);
99  }
100 
101 
102  $result = "not submitted or wrong pass";
103 
104  if (array_key_exists('launcher_redirect', $request->getQueryParams())
105  && $v = $request->getQueryParams()['launcher_redirect']
106  ) {
107  $result = "<b>sucessfully redirected ($v)</b>";
108  }
109 
110  return $result . "<hr/>" . $renderer->render([
111  $launcher,
112  $spacer,
113  $launcher2,
114  $spacer,
115  $launcher3
116  ]);
117 }
isOK()
Get to know if the result is ok.
value()
Get the encapsulated value.
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:14
global $DIC
Definition: feed.php:28
with_fields()
In this example, the Launcher is configured with inputs; a Modal containing a Form will open upon cli...
Definition: with_fields.php:15
$url
Definition: ltiregstart.php:35