ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilStudyProgrammeExpandableProgressListGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
25 protected ilAccess $access;
28
29 protected int $indent = 0;
30 protected bool $js_added = false;
31 protected bool $css_added = false;
32 protected string $alert_icon;
33
35 {
37
38 global $DIC;
39 $this->tpl = $DIC['tpl'];
40 $this->rbacsystem = $DIC['rbacsystem'];
41 $this->setting = $DIC['ilSetting'];
42 $this->access = $DIC['ilAccess'];
43 $this->request_wrapper = $DIC->http()->wrapper()->query();
44 $this->refinery = $DIC->refinery();
45
46 $ui_factory = $DIC['ui.factory'];
47 $ui_renderer = $DIC['ui.renderer'];
48 $this->alert_icon = $ui_renderer->render(
49 $ui_factory->symbol()->icon()
50 ->custom(ilUtil::getImagePath("standard/icon_alert.svg"), $this->lng->txt("warning"))
51 ->withSize('medium')
52 );
53 }
54
55 protected function getIndent(): int
56 {
57 return $this->indent;
58 }
59
60 public function setIndent(int $indent): void
61 {
62 assert($indent >= 0);
63 $this->indent = $indent;
64 }
65
66 public function getHTML(): string
67 {
68 $this->addJavaScript();
69 $this->addCSS();
70 return parent::getHTML();
71 }
72
73 protected function fillTemplate(ilTemplate $tpl): void
74 {
75 parent::fillTemplate($tpl);
76
77 if ($this->showMyProgress()) {
78 $tpl->setVariable("ACTIVE_HEAD", "il_PrgAccordionHeadActive");
79 }
80
81 $tpl->setVariable("ACCORDION_ID", 'id="' . $this->getAccordionId() . '"');
82 $tpl->setVariable("HREF_TITLE");
83
84 $content = $this->getAccordionContentHTML();
85
86 if (trim($content)) {
87 $tpl->setCurrentBlock("expand");
88 $tpl->setVariable("EXP_ALT", $this->lng->txt("expand"));
89 $tpl->setVariable("EXP_IMG", $this->getExpandedImageURL());
90 $tpl->setVariable("NOT_EXP_ALT", $this->lng->txt("expanded"));
91 $tpl->setVariable("NOT_EXP_IMG", $this->getNotExpandedImageURL());
92 $tpl->parseCurrentBlock();
93 } else {
94 $tpl->touchBlock("indent");
95 }
96
97 for ($i = 0; $i < $this->getIndent(); $i++) {
98 $tpl->touchBlock("indent");
99 }
100
101 $tpl->setCurrentBlock("accordion");
102 if ($this->showMyProgress()) {
103 $tpl->setVariable("ACCORDION_HIDE_CONTENT");
104 } else {
105 $tpl->setVariable("ACCORDION_HIDE_CONTENT", "ilAccHideContent");
106 }
107 $tpl->setVariable("ACCORDION_CONTENT", $content);
108 $this->tpl->addOnloadCode("il.Accordion.add(" . json_encode($this->getAccordionOptions(), JSON_THROW_ON_ERROR) . ");");
110 }
111
112 protected function getAccordionContentHTML(): string
113 {
114 $programme = ilObjStudyProgramme::getInstanceByObjId($this->progress->getNodeId());
115
116 if (!$programme->hasLPChildren()) {
117 return $this->getAccordionContentProgressesHTML();
118 }
119
120 return $this->getAccordionContentCoursesHTML();
121 }
122
123 protected function getAccordionContentProgressesHTML(): string
124 {
125 // Make shouldShowSubProgress and newSubItem protected again afterwards, do
126 // the same in the derived class ilStudyProgrammeIndividualPlanProgressListGUI.
127 $child_progresses = $this->progress->getSubnodes();
128
129 return implode("\n", array_map(function (ilPRGProgress $progress) {
130 if (!$this->shouldShowSubProgress($progress)) {
131 return "";
132 }
133 $gui = $this->newSubItem($progress);
134 $gui->setIndent($this->getIndent() + 1);
135 return $gui->getHTML();
136 }, $child_progresses));
137 }
138
140 {
141 if ($progress->isRelevant()) {
143
144 $can_read = $this->access->checkAccess("read", "", $prg->getRefId(), "prg", $prg->getId());
145 if ($this->visible_on_pd_mode === ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD_READ && !$can_read) {
146 return false;
147 }
148
149 return true;
150 }
151
152 return false;
153 }
154
156 {
158 }
159
160 protected function getAccordionContentCoursesHTML(): string
161 {
163
164 $crs = array();
165 $prg = ilObjStudyProgramme::getInstanceByObjId($this->progress->getNodeId());
166 foreach ($prg->getLPChildren() as $il_obj_crs_ref) {
167 if (ilObject::_exists($il_obj_crs_ref->getRefId(), true) &&
168 is_null(ilObject::_lookupDeletedDate($il_obj_crs_ref->getRefId()))
169 ) {
170 continue;
171 }
172
173 $course = ilObjectFactory::getInstanceByRefId($il_obj_crs_ref->getTargetRefId());
174 $preloader->addItem($course->getId(), $course->getType(), $course->getRefId());
175 $crs[] = $course;
176 }
177 $preloader->preload();
178
179 return implode("\n", array_map(function (ilObjCourse $course) {
180 $item_gui = new ilStudyProgrammeCourseListGUI();
181 $this->configureItemGUI($item_gui);
182 $item_gui->setContainerObject(new ilStudyProgrammeContainerObjectMock($course));
183 return $item_gui->getListItemHTML(
184 $course->getRefId(),
185 $course->getId(),
186 $course->getTitle(),
187 $course->getDescription()
188 );
189 }, $crs));
190 }
191
192 protected function configureItemGUI(ilStudyProgrammeCourseListGUI $item_gui): void
193 {
194 $item_gui->enableComments(false);
195 $item_gui->enableTags(false);
196 $item_gui->enableIcon(true);
197 $item_gui->enableDelete(false);
198 $item_gui->enableCut(false);
199 $item_gui->enableCopy(false);
200 $item_gui->enableLink(false);
201 $item_gui->enableInfoScreen(true);
202 $item_gui->enableSubscribe(true);
203 $item_gui->enableCheckbox(false);
204 $item_gui->enableDescription(true);
205 $item_gui->enableProperties(true);
206 $item_gui->enablePreconditions(true);
207 $item_gui->enableNoticeProperties(true);
208 $item_gui->enableCommands(true, true);
209 $item_gui->enableProgressInfo(true);
210 $item_gui->setIndent($this->getIndent() + 2);
211 }
212
213 protected function getAccordionOptions(): array
214 {
215 return [
216 "orientation" => "horizontal",
217 // Most propably we don't need this. Or do we want to call ilAccordion.initById?
218 "int_id" => "prg_progress_" . $this->progress->getId(),
219 "initial_opened" => null,
220 "behaviour" => "AllClosed", // or "FirstOpen"
221 "toggle_class" => 'il_PrgAccordionToggle',
222 "toggle_act_class" => 'foo',
223 "content_class" => 'il_PrgAccordionContent',
224 "width" => "auto",
225 "active_head_class" => "il_PrgAccordionHeadActive",
226 "height" => "auto",
227 "id" => $this->getAccordionId(),
228 "multi" => true,
229 "show_all_element" => null,
230 "hide_all_element" => null,
231 "reset_width" => true,
232 ];
233 }
234
235 protected function getAccordionId(): string
236 {
237 return "prg_progress_" . $this->progress->getId() . "_" . $this->getIndent();
238 }
239
240 protected function getExpandedImageURL(): string
241 {
242 return ilUtil::getImagePath("nav/tree_exp.svg");
243 }
244
245 protected function getNotExpandedImageURL(): string
246 {
247 return ilUtil::getImagePath("nav/tree_col.svg");
248 }
249
250 protected function getTitleAndIconTarget(ilPRGProgress $progress): ?string
251 {
252 return null;
253 }
254
255 protected function showMyProgress(): bool
256 {
257 $prg_progress_id = $this->request_wrapper->retrieve("prg_progress_id", $this->refinery->kindlyTo()->int());
258 return $prg_progress_id === $this->progress->getId();
259 }
260
264 protected function addJavaScript()
265 {
266 if ($this->js_added) {
267 return false;
268 }
269
271 $this->tpl->addJavaScript("assets/js/accordion.js", true, 3);
272 $this->js_added = true;
273 }
274
278 protected function addCSS()
279 {
280 if ($this->css_added) {
281 return false;
282 }
283
284 $this->tpl->addCSS("assets/css/ilStudyProgramme.css");
285 $this->css_added = true;
286 }
287}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Builds data types.
Definition: Factory.php:36
Class ilAccessHandler Checks access for ILIAS objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByObjId(int $obj_id)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
Preloader for object list GUIs.
enableDelete(bool $status)
enableDescription(bool $status)
enableProgressInfo(bool $status)
enablePreconditions(bool $status)
enableComments(bool $value, bool $enable_comments_settings=true)
enableInfoScreen(bool $info_screen)
enableCommands(bool $status, bool $std_only=false)
enableCheckbox(bool $status)
enableNoticeProperties(bool $status)
enableProperties(bool $status)
enableSubscribe(bool $status)
static _lookupDeletedDate(int $ref_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
A Progress is the status of a user on a single node of an assignment; it is unique by assignment_id:u...
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
ILIAS Setting Class.
Class ilStudyProgrammeCourseListGUI.
Class ilStudyProgrammeProgressListGUI.
special template class to simplify handling of ITX/PEAR
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static initjQueryUI(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components....
Interface RequestWrapper.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
touchBlock(string $block)
overwrites ITX::touchBlock.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26