ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PanelBuilderUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
28use function PHPUnit\Framework\isInstanceOf;
29
31{
32 protected \ILIAS\UI\Renderer $ui_renderer;
33 protected \ilCtrl $ctrl;
34 protected \ilLanguage $lng;
36 protected \ILIAS\UI\Factory $ui_factory;
37
38 public function __construct(
44 ) {
45 $this->ui_factory = $ui_factory;
46 $this->ui_renderer = $ui_renderer;
47 $this->prop_builder = $prop_builder;
48 $this->ctrl = $ctrl;
49 $this->lng = $lng;
50 }
51
52 protected function addPropertyToItemProperties(array &$props, ?array $prop): void
53 {
54 if ($prop) {
55 $props[$prop["prop"]] = $prop["val"];
56 }
57 }
58
59 public function getPanel(Assignment $ass, int $user_id): \ILIAS\UI\Component\Panel\Standard
60 {
62 $pb->build($ass, $user_id);
63
64 // schedule card
65 $sections = [];
66 foreach ($pb->getProperties($pb::SEC_SCHEDULE) as $prop) {
67 $sections[] = $this->ui_factory->legacy()->content($prop["prop"] . ": " . $prop["val"]);
68 }
69 $schedule_card = $this->ui_factory->card()->standard($this->lng->txt("exc_schedule"))
70 ->withSections($sections);
71
72 $sub_panels = [];
73 $include_schedule = $pb->getInstructionsHidden();
74 foreach ($pb->getSections($include_schedule) as $sec => $title) {
75 $sec_empty = true;
76 $ctpl = new \ilTemplate(
77 "tpl.panel_content.html",
78 true,
79 true,
80 "components/ILIAS/Exercise/Assignment"
81 );
82
83 // properties
84 foreach ($pb->getProperties($sec) as $prop) {
85 if ($prop["prop"] === "") {
86 $ctpl->setCurrentBlock("entry_no_label");
87 $ctpl->setVariable("VALUE_NO_LABEL", $prop["val"]);
88 $ctpl->parseCurrentBlock();
89 } else {
90 $ctpl->setCurrentBlock("entry");
91 $ctpl->setVariable("LABEL", $prop["prop"]);
92 $ctpl->setVariable("VALUE", $prop["val"]);
93 $ctpl->parseCurrentBlock();
94 }
95 $sec_empty = false;
96 }
97
98 // actions
99 $this->renderActionButton($ctpl, $pb->getMainAction($sec));
100 foreach ($pb->getActions($sec) as $action) {
101 $this->renderActionButton($ctpl, $action);
102 $sec_empty = false;
103 }
104
105 if (count($pb->getActions($sec)) > 0) {
106 $sec_empty = false;
107 }
108
109 // links
110 $this->renderLinkList($ctpl, $sec);
111
112 $sub_panel = $this->ui_factory->panel()->sub(
113 $title,
114 $this->ui_factory->legacy()->content($ctpl->get())
115 );
116 if ($sec === $pb::SEC_INSTRUCTIONS && !$pb->getInstructionsHidden()) {
117 $sub_panel = $sub_panel->withFurtherInformation($schedule_card);
118 $sec_empty = false;
119 }
120 if (!$sec_empty) {
121 $sub_panels[] = $sub_panel;
122 }
123 }
124
125 $panel = $this->ui_factory->panel()->standard(
126 $ass->getTitle(),
127 $sub_panels
128 );
129
130 return $panel;
131 }
132
133 protected function renderActionButton(\ilTemplate $tpl, ?Component $c): void
134 {
135 if (!is_null($c) && $c instanceof Button) {
136 $tpl->setCurrentBlock("action");
137 $tpl->setVariable("BUTTON", $this->ui_renderer->render($c));
138 $tpl->parseCurrentBlock();
139 }
140 }
141
142 protected function renderLinkList(\ilTemplate $tpl, string $sec): void
143 {
144 foreach ($this->prop_builder->getActions($sec) as $action) {
145 if ($action instanceof Link) {
146 $tpl->setCurrentBlock("link");
147 $tpl->setVariable("LINK", $this->ui_renderer->render($action));
148 $tpl->parseCurrentBlock();
149 }
150 }
151 }
152
153 public function getPanelViews(Assignment $ass, int $user_id): array
154 {
156 $pb->build($ass, $user_id);
157 return $pb->getViews();
158 }
159}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Builds data types.
Definition: Factory.php:36
PropertyAndActionBuilderUI $prop_builder
getPanelViews(Assignment $ass, int $user_id)
__construct(PropertyAndActionBuilderUI $prop_builder, \ILIAS\UI\Factory $ui_factory, \ILIAS\UI\Renderer $ui_renderer, \ilCtrl $ctrl, \ilLanguage $lng)
addPropertyToItemProperties(array &$props, ?array $prop)
renderLinkList(\ilTemplate $tpl, string $sec)
getPanel(Assignment $ass, int $user_id)
renderActionButton(\ilTemplate $tpl, ?Component $c)
Definition: UI.php:24
Class ilCtrl provides processing control methods.
language handling
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
$c
Definition: deliver.php:25
This describes commonalities between standard and primary buttons.
Definition: Button.php:34
A component is the most general form of an entity in the UI.
Definition: Component.php:28
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.