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