ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
parameters.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
39 function parameters()
40 {
41  global $DIC;
42  $factory = $DIC->ui()->factory();
43  $renderer = $DIC->ui()->renderer();
44 
45  $df = new \ILIAS\Data\Factory();
46  $refinery = $DIC['refinery'];
47 
48  $here_uri = $df->uri($DIC->http()->request()->getUri()->__toString());
49  $url_builder = new URLBuilder($here_uri);
50 
51  //when expecting a state, we do not want to render other examples
52  $example_namespace = ['prompt', 'endpoints'];
53  list($url_builder, $endpointtoken) = $url_builder->acquireParameters($example_namespace, "endpoint");
54  $url_builder = $url_builder->withParameter($endpointtoken, "true");
55 
56  //build a prompt
57  $query_namespace = ['prompt', 'example1'];
58  list($url_builder, $action_token, $amount_token) = $url_builder->acquireParameters($query_namespace, "action", "amount");
59  $url_builder = $url_builder->withParameter($action_token, "showprompt");
60 
61  $default_uri = $url_builder->withParameter($amount_token, "1")->buildURI();
62  $prompt = $factory->prompt()->standard($default_uri);
63 
64  //build some endpoint
65  $query = $DIC->http()->wrapper()->query();
66  $icon = $factory->symbol()->icon()->standard('someExample', 'Example');
67  $item = $icon;
68  $links = [];
69 
70  if ($query->has($action_token->getName())) {
71  $action = $query->retrieve($action_token->getName(), $refinery->kindlyTo()->string());
72  $amount = $query->retrieve($amount_token->getName(), $refinery->kindlyTo()->int()) ;
73  switch ($action) {
74  case 'showprompt':
75  foreach (range(1, $amount) as $idx) {
76  $link_uri = $url_builder
77  ->withParameter($action_token, "promptlink")
78  ->withParameter($amount_token, (string) $idx)
79  ->buildURI()->__toString();
80  $links[] = $factory->link()->standard((string) $idx, $link_uri);
81  }
82  $buttons = [
83  $factory->button()->standard('OK', '#')->withOnLoadCode(
84  fn($id) => "$('#$id').on('click', (e)=> {alert('$id');});"
85  )
86  ];
87  $prompt_content = $factory->messageBox()->info('some text')
88  ->withLinks($links)
89  ->withButtons($buttons);
90  break;
91 
92  case 'promptlink':
93  $back_uri = $url_builder
94  ->withParameter($action_token, "showprompt")
95  ->withParameter($amount_token, (string) $amount)
96  ->buildURI()->__toString();
97  $back = $factory->button()->standard('back', '#')->withOnLoadCode(
98  fn($id) => "$('#$id').on('click', (e)=> {
99  let promptId = e.target.closest('.il-prompt').id;
100  il.UI.prompt.get(promptId).show('$back_uri');
101  });"
102  );
103  $prompt_content = $factory->messageBox()->info((string) $amount)
104  ->withButtons([$back]);
105  break;
106 
107  default:
108  throw new \Exception('?' . $action . $amount);
109  }
110 
111  $response = $factory->prompt()->state()->show($prompt_content);
112  echo($renderer->renderAsync($response));
113  exit();
114  }
115 
116  if (!$query->has($endpointtoken->getName())) {
117  $show_button = $factory->button()->standard('Show Simple Prompt', $prompt->getShowSignal());
118  $close_button = $factory->button()->standard('close Simple Prompt', $prompt->getCloseSignal());
119 
120  $uri = $url_builder->withParameter($amount_token, "8")->buildURI();
121  $show_button8 = $factory->button()->standard('Show Prompt with Parameter', $prompt->getShowSignal($uri));
122 
123  $uri = $url_builder->withParameter($amount_token, "78")->buildURI();
124  $show_button78 = $factory->button()->standard('Show Prompt with a lot of Items', $prompt->getShowSignal($uri));
125 
126  return $renderer->render([
127  $prompt,
128  $show_button, $show_button8, $show_button78
129  ]);
130  }
131 }
parameters()
description: > This shows how different states are being used in the same Prompt according to parame...
Definition: parameters.php:39
$renderer
$response
Definition: xapitoken.php:93
global $DIC
Definition: shib_login.php:22
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
URLBuilder.
Definition: URLBuilder.php:40
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...