ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
Renderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Renderer as RendererInterface;
27
29{
33 public function render(Component\Component $component, RendererInterface $default_renderer): string
34 {
35 if ($component instanceof Entity) {
36 return $this->renderEntity($component, $default_renderer);
37 }
38 $this->cannotHandleComponent($component);
39 }
40
41 protected function renderEntity(Entity $component, RendererInterface $default_renderer): string
42 {
43 $tpl = $this->getTemplate('tpl.entity.html', true, true);
44
45 $this->renderPrimaryIdentifier($component, $default_renderer, $tpl);
46 $this->renderSecondaryIdentifier($component, $default_renderer, $tpl);
47 $this->renderBlockingConditions($component, $default_renderer, $tpl);
48 $this->renderFeatures($component, $default_renderer, $tpl);
49 $this->renderPersonalStatus($component, $default_renderer, $tpl);
50 $this->renderMainDetails($component, $default_renderer, $tpl);
51 $this->renderAvailability($component, $default_renderer, $tpl);
52 $this->renderDetails($component, $default_renderer, $tpl);
53
54 if (null !== $component->getWorkflow()) {
55 $button_components = $this->createUnfinishedWorkflowActions($component->getWorkflow());
56 $tpl->setVariable('WORKFLOW_ACTIONS', $default_renderer->render($button_components));
57 }
58 if ($actions = $component->getManagingActions()) {
59 $actions_dropdown = $this->getUIFactory()->dropdown()->standard($actions);
60 $tpl->setVariable('MANAGING_ACTIONS', $default_renderer->render($actions_dropdown));
61 }
62 if ($reactions = $component->getReactions()) {
63 $tpl->setVariable('REACTIONS', $default_renderer->render($reactions));
64 }
65 if ($prio_reactions = $component->getPrioritizedReactions()) {
66 $tpl->setVariable('PRIO_REACTIONS', $default_renderer->render($prio_reactions));
67 }
68
69 return $tpl->get();
70 }
71
72 protected function renderPrimaryIdentifier(
73 Entity $component,
74 RendererInterface $default_renderer,
76 ): void {
77 $primary_identifier = $component->getPrimaryIdentifier();
78 if (!is_string($primary_identifier)) {
79 $primary_identifier = $this->maybeRender($default_renderer, $primary_identifier);
80 }
81 $tpl->setVariable('PRIMARY_IDENTIFIER', $primary_identifier);
82 $tpl->setVariable('PRIMARY_IDENTIFIER_ID', $this->createId());
83 }
84
85 protected function renderSecondaryIdentifier(
86 Entity $component,
87 RendererInterface $default_renderer,
89 ): void {
90 $secondary_identifier = $component->getSecondaryIdentifier();
91 if (is_string($secondary_identifier)) {
92 $tpl->touchBlock('secondid_string');
93 } elseif ($secondary_identifier instanceof Component\Image\Image) {
94 $tpl->touchBlock('secondid_image');
95 } elseif ($secondary_identifier instanceof Component\Symbol\Symbol) {
96 $tpl->touchBlock('secondid_symbol');
97 } elseif ($secondary_identifier instanceof Component\Link\Link) {
98 $tpl->touchBlock('secondid_link');
99 } elseif ($secondary_identifier instanceof Component\Button\Shy) {
100 $tpl->touchBlock('secondid_shy');
101 }
102 if (!is_string($secondary_identifier)) {
103 $secondary_identifier = $this->maybeRender($default_renderer, $secondary_identifier);
104 }
105 $tpl->setVariable('SECONDARY_IDENTIFIER', $secondary_identifier);
106 }
107
108 protected function renderBlockingConditions(Entity $component, RendererInterface $default_renderer, Template $tpl): void
109 {
110 $tpl->setVariable('BLOCKING_CONDITIONS', $this->maybeRender($default_renderer, ...$component->getBlockingAvailabilityConditions()));
111 }
112
113 protected function renderFeatures(Entity $component, RendererInterface $default_renderer, Template $tpl): void
114 {
115 $tpl->setVariable('FEATURES', $this->maybeRender($default_renderer, ...$component->getFeaturedProperties()));
116 }
117
118 protected function renderPersonalStatus(Entity $component, RendererInterface $default_renderer, Template $tpl): void
119 {
120 $tpl->setVariable('PERSONAL_STATUS', $this->maybeRender($default_renderer, ...$component->getPersonalStatus()));
121 }
122
123 protected function renderMainDetails(Entity $component, RendererInterface $default_renderer, Template $tpl): void
124 {
125 $tpl->setVariable('MAIN_DETAILS', $this->maybeRender($default_renderer, ...$component->getMainDetails()));
126 }
127
128 protected function renderAvailability(Entity $component, RendererInterface $default_renderer, Template $tpl): void
129 {
130 $tpl->setVariable('AVAILABILITY', $this->maybeRender($default_renderer, ...$component->getAvailability()));
131 }
132
133 protected function renderDetails(Entity $component, RendererInterface $default_renderer, Template $tpl): void
134 {
135 $tpl->setVariable('DETAILS', $this->maybeRender($default_renderer, ...$component->getDetails()));
136 }
137
138 protected function maybeRender(RendererInterface $default_renderer, Component\Component | null ...$values): ?string
139 {
140 //$values = array_filter($values);
141 if ($values === []) {
142 return null;
143 }
144
145 return $default_renderer->render($values);
146 }
147
150 {
151 $actions = [];
152 foreach ($workflow->getSteps() as $step) {
153 if (null === $step->getAction() ||
154 $step->getAvailability() !== Component\Listing\Workflow\Step::AVAILABLE ||
155 ($step->getStatus() !== Component\Listing\Workflow\Step::NOT_STARTED &&
156 $step->getStatus() !== Component\Listing\Workflow\Step::IN_PROGRESS)
157 ) {
158 continue;
159 }
160 $actions[] = $this->getUIFactory()->button()->standard($step->getLabel(), $step->getAction());
161 }
162 return $actions;
163 }
164}
renderSecondaryIdentifier(Entity $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:85
renderPrimaryIdentifier(Entity $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:72
maybeRender(RendererInterface $default_renderer, Component\Component|null ... $values)
Definition: Renderer.php:138
renderBlockingConditions(Entity $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:108
createUnfinishedWorkflowActions(Component\Listing\Workflow\Workflow $workflow)
Definition: Renderer.php:149
renderPersonalStatus(Entity $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:118
renderEntity(Entity $component, RendererInterface $default_renderer)
Definition: Renderer.php:41
renderMainDetails(Entity $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:123
renderDetails(Entity $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:133
renderAvailability(Entity $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:128
renderFeatures(Entity $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:113
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:33
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
touchBlock(string $block)
overwrites ITX::touchBlock.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This describes a symbol.
Definition: Symbol.php:30
Interface to templating as it is used in the UI framework.
Definition: Template.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31
readonly ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21