ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
FilterContextRenderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 use LogicException;
31 use Closure;
34 
40 {
42 
43  public function render(Component\Component $component, RendererInterface $default_renderer): string
44  {
45  if ($component instanceof FilterInput) {
46  $component = $this->setSignals($component);
47  }
48 
49  $this->original_default_renderer = $default_renderer;
50 
51  switch (true) {
52  case ($component instanceof F\Duration):
53  return $this->renderDurationField($component, $default_renderer);
54 
55  case ($component instanceof F\Group):
56  return $this->renderFieldGroups($component, $default_renderer);
57 
58  case ($component instanceof F\Text):
59  return $this->renderTextField($component, $default_renderer);
60 
61  case ($component instanceof F\Numeric):
62  return $this->renderNumericField($component, $default_renderer);
63 
64  case ($component instanceof F\Select):
65  return $this->renderSelectField($component, $default_renderer);
66 
67  case ($component instanceof F\MultiSelect):
68  return $this->renderMultiSelectField($component, $default_renderer);
69 
70  case ($component instanceof F\DateTime):
71  return $this->renderDateTimeField($component, $default_renderer);
72 
73  default:
74  $this->cannotHandleComponent($component);
75  }
76  }
77 
79  {
81  }
82 
83 
84  protected function renderFieldGroups(Group $group, RendererInterface $default_renderer): string
85  {
86  $inputs = "";
87  $input_labels = array();
88  foreach ($group->getInputs() as $input) {
89  $inputs .= $default_renderer->render($input);
90  $input_labels[] = $input->getLabel();
91  }
92  $inputs .= $this->renderAddField($input_labels, $default_renderer);
93 
94  return $inputs;
95  }
96 
97  protected function renderAddField(array $input_labels, RendererInterface $default_renderer): string
98  {
99  $f = $this->getUIFactory();
100  $tpl = $this->getTemplate("tpl.context_filter.html", true, true);
101  $add_tpl = $this->getTemplate("tpl.filter_add_list.html", true, true);
102 
103  $links = array();
104  foreach ($input_labels as $label) {
105  $links[] = $f->button()->shy($label, "")->withAdditionalOnLoadCode(fn($id) => "$('#$id').on('click', function(event) {
106  il.UI.filter.onAddClick(event, '$id');
107  return false; // stop event propagation
108  });");
109  }
110  $add_tpl->setVariable("LIST", $default_renderer->render($f->listing()->unordered($links)));
111  $list = $f->legacy()->content($add_tpl->get());
112  $popover = $f->popover()->standard($list)->withVerticalPosition();
113  $tpl->setVariable("POPOVER", $default_renderer->render($popover));
114  $add = $f->button()->bulky($f->symbol()->glyph()->add(), "", "")->withOnClick($popover->getShowSignal());
115 
116  $tpl->setCurrentBlock("filter_field");
117  $tpl->setVariable("FILTER_FIELD", $default_renderer->render($add));
118  $tpl->parseCurrentBlock();
119 
120  return $tpl->get();
121  }
122 
123  protected function wrapInFormContext(
124  FormInput $component,
125  string $label,
126  string $input_html,
127  ?string $id_for_label = null,
128  ?string $dependant_group_html = null
129  ): string {
130  return $this->wrapInFilterContext($component, $input_html, $this->getOriginalDefaultRenderer(), $id_for_label);
131  }
132 
133  protected function wrapInFilterContext(
134  FormInput $component,
135  string $input_html,
136  RendererInterface $default_renderer,
137  ?string $id_pointing_to_input = null,
138  string $dependant_group_html = ''
139  ): string {
140  $f = $this->getUIFactory();
141  $tpl = $this->getTemplate("tpl.context_filter.html", true, true);
142 
146  $remove_glyph = $f->symbol()->glyph()->remove("")->withAdditionalOnLoadCode(fn($id) => "$('#$id').on('click', function(event) {
147  il.UI.filter.onRemoveClick(event, '$id');
148  return false; // stop event propagation
149  });");
150 
151  $tpl->setCurrentBlock("addon_left");
152  $tpl->setVariable("LABEL", $component->getLabel());
153  if ($id_pointing_to_input) {
154  $tpl->setCurrentBlock("for");
155  $tpl->setVariable("ID", $id_pointing_to_input);
156  $tpl->parseCurrentBlock();
157  }
158  $tpl->parseCurrentBlock();
159  $tpl->setCurrentBlock("filter_field");
160  if ($component->isComplex()) {
161  $tpl->setVariable("FILTER_FIELD", $this->renderProxyField($input_html, $default_renderer));
162  } else {
163  $tpl->setVariable("FILTER_FIELD", $input_html);
164  }
165  $tpl->parseCurrentBlock();
166  $tpl->setCurrentBlock("addon_right");
167  $tpl->setVariable("DELETE", $default_renderer->render($remove_glyph));
168  $tpl->parseCurrentBlock();
169 
170  return $tpl->get();
171  }
172 
173  protected function maybeDisable(FormInput $component, Template $tpl): void
174  {
175  // Do nothing, because Filter Inputs should not be deactivatable
176  }
177 
178  protected function renderProxyField(
179  string $input_html,
180  RendererInterface $default_renderer
181  ): string {
182  $f = $this->getUIFactory();
183  $tpl = $this->getTemplate("tpl.filter_field.html", true, true);
184 
185  $popover = $f->popover()->standard($f->legacy()->content($input_html))->withVerticalPosition();
186  $tpl->setVariable("POPOVER", $default_renderer->render($popover));
187 
188  $prox = new ProxyFilterField();
189  $prox = $prox->withOnClick($popover->getShowSignal());
190  $tpl->touchBlock("tabindex");
191 
192  $this->bindJSandApplyId($prox, $tpl);
193  return $tpl->get();
194  }
195 
196  protected function renderDurationField(F\Duration $component, RendererInterface $default_renderer): string
197  {
198  $inputs = $component->getInputs();
199 
200  $input = array_shift($inputs); //from
201  list($input, $tpl) = $this->internalRenderDateTimeField($input, $default_renderer);
202  $first_input_id = $this->bindJSandApplyId($input, $tpl);
203  $input_html = $default_renderer->render($input);
204 
205  $input = array_shift($inputs) //until
206  ->withAdditionalPickerconfig(['useCurrent' => false]);
207  $input_html .= $default_renderer->render($input);
208 
209  $tpl = $this->getTemplate("tpl.duration.html", true, true);
210  $id = $this->bindJSandApplyId($component, $tpl);
211  $tpl->setVariable('DURATION', $input_html);
212 
213  return $this->wrapInFormContext($component, $component->getLabel(), $tpl->get());
214  }
215 
216  public function registerResources(ResourceRegistry $registry): void
217  {
218  parent::registerResources($registry);
219  $registry->register('assets/js/filter.js');
220  }
221 }
bindJSandApplyId(Component\JavaScriptBindable $component, Template $tpl)
Definition: Renderer.php:227
Registry for resources required by rendered output like Javascript or CSS.
renderFieldGroups(Group $group, RendererInterface $default_renderer)
renderDurationField(F\Duration $component, RendererInterface $default_renderer)
renderProxyField(string $input_html, RendererInterface $default_renderer)
renderAddField(array $input_labels, RendererInterface $default_renderer)
wrapInFormContext(FormInput $component, string $label, string $input_html, ?string $id_for_label=null, ?string $dependant_group_html=null)
render(Component\Component $component, RendererInterface $default_renderer)
This implements the text input.
Definition: Text.php:32
renderNumericField(F\Numeric $component, RendererInterface $default_renderer)
Definition: Renderer.php:299
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
An internal class for the clickable, non-editable Input Fields within Filters.
This implements the duration input group.
Definition: Duration.php:37
renderMultiSelectField(F\MultiSelect $component, RendererInterface $default_renderer)
Definition: Renderer.php:628
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
This implements the multi-select input.
Definition: MultiSelect.php:31
renderDateTimeField(F\DateTime $component, RendererInterface $default_renderer)
Definition: Renderer.php:654
This implements the numeric input.
Definition: Numeric.php:33
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
renderSelectField(F\Select $component, RendererInterface $default_renderer)
Definition: Renderer.php:454
register(string $name)
Add a dependency.
internalRenderDateTimeField(F\DateTime $component, RendererInterface $default_renderer)
Definition: Renderer.php:665
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This interface must be implemented by all Inputs that support Filter Containers.
Definition: FilterInput.php:35
This describes inputs that can be used in forms.
Definition: FormInput.php:32
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.