ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
Renderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
30 {
34  public function render(Component\Component $component, RendererInterface $default_renderer): string
35  {
36  if ($component instanceof I\Navigation\Sequence\Sequence) {
37  return $this->renderSequence($component, $default_renderer);
38  }
39 
40  $this->cannotHandleComponent($component);
41  }
42 
43  protected function renderSequence(
44  Sequence $component,
45  RendererInterface $default_renderer
46  ): string {
47  $tpl = $this->getTemplate("tpl.sequence.html", true, true);
48 
49  $binding = $component->getSegmentRetrieval();
50  $request = $component->getRequest();
51  $vc_data = $component->getViewControls()?->getData() ?? [];
52  $filter_data = [];
53  $positions = $binding->getAllPositions(
54  $request,
55  $vc_data,
56  $filter_data
57  );
58 
59  $position = $component->getCurrentPosition();
60  if ($position >= count($positions) || $position < 0) {
61  $position = 0;
62  $component = $component->withCurrentPosition($position);
63  }
64 
65  $segment = $binding->getSegment(
66  $request,
67  $positions[$position],
68  $vc_data,
69  $filter_data
70  );
71 
72  $ui_factory = $this->getUIFactory();
73  $back = $ui_factory->button()->standard($this->txt('back'), $component->getNext(-1)->__toString())
74  ->withSymbol($ui_factory->symbol()->glyph()->back())
75  ->withUnavailableAction($position - 1 < 0);
76 
77  $next = $ui_factory->button()->standard($this->txt('next'), $component->getNext(1)->__toString())
78  ->withSymbol($ui_factory->symbol()->glyph()->next())
79  ->withUnavailableAction($position + 1 === count($positions));
80 
81  $tpl->setVariable('BACK', $default_renderer->render($back));
82  $tpl->setVariable('NEXT', $default_renderer->render($next));
83 
84  if ($viewcontrols = $component->getViewControls()) {
85  $tpl->setVariable('VIEWCONTROLS', $default_renderer->render($viewcontrols));
86  }
87 
88  if ($actions = $component->getActions()) {
89  $tpl->setVariable('ACTIONS_GLOBAL', $default_renderer->render($actions));
90  }
91 
92  if ($actions = $segment->getSegmentActions()) {
93  $tpl->setVariable('ACTIONS_SEGMENT', $default_renderer->render($actions));
94  }
95 
96  $tpl->setVariable('SEGMENT_TITLE', $segment->getSegmentTitle());
97  $tpl->setVariable('SEGMENT_CONTENTS', $default_renderer->render($segment));
98 
99  $content_region_id = $this->createId();
100  $tpl->setVariable('CONTENT_REGION_ID', $content_region_id);
101 
102  $headline_id = $this->createId();
103  $tpl->setVariable('HEADLINE_ID', $headline_id);
104 
105  $navigation_id = $this->createId();
106  $tpl->setVariable('NAVIGATION_ID', $navigation_id);
107 
108  $navigation_description_id = $this->createId();
109  $tpl->setVariable('NAVIGATION_DESCRIPTION_ID', $navigation_description_id);
110 
111  $nav_label = $this->txt("ui_nav_sequence_control_label");
112  $tpl->setVariable('NAVIGATION_LABEL', $nav_label);
113 
114  $nav_description = $this->txt("ui_nav_sequence_description");
115  $tpl->setVariable('NAVIGATION_DESCRIPTION', $nav_description);
116 
117  return $tpl->get();
118  }
119 }
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:34
txt(string $id)
Get a text from the language file.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
renderSequence(Sequence $component, RendererInterface $default_renderer)
Definition: Renderer.php:43
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.