ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExerciseGSToolProvider.php
Go to the documentation of this file.
1<?php
2
23
30{
31 public const SHOW_EXC_ASSIGNMENT_INFO = 'show_exc_assignment_info';
32 public const EXC_ASS_IDS = 'exc_ass_ids';
33 public const EXC_ASS_BUTTONS = "exc_ass_buttons";
34
36 {
37 return $this->context_collection->main()->main();
38 }
39
40 public function getToolsForContextStack(
41 CalledContexts $called_contexts
42 ): array {
43 global $DIC;
44
45 $lng = $DIC->language();
46 $lng->loadLanguageModule("exc");
47
48 $title = $lng->txt("exc_assignment");
49 $icon = $this->dic->ui()->factory()->symbol()->icon()->standard("exc", $title);
50
51 $tools = [];
52 $additional_data = $called_contexts->current()->getAdditionalData();
53 if ($additional_data->is(self::SHOW_EXC_ASSIGNMENT_INFO, true)) {
54 $iff = function ($id) {
55 return $this->identification_provider->contextAwareIdentifier($id);
56 };
57 $l = function (string $content) {
58 return $this->dic->ui()->factory()->legacy()->content($content);
59 };
60 $tools[] = $this->factory->tool($iff("exc_ass_info"))
61 ->withTitle($title)
62 ->withSymbol($icon)
63 ->withContentWrapper(
68 function () use ($l, $additional_data) {
69 $buttons = $additional_data->exists(self::EXC_ASS_BUTTONS)
70 ? $additional_data->get(self::EXC_ASS_BUTTONS)
71 : [];
72 return $l($this->getAssignmentInfo(
73 $additional_data->get(self::EXC_ASS_IDS),
74 $buttons
75 ));
76 }
77 );
78 }
79
80 return $tools;
81 }
82
90 private function getAssignmentInfo(
91 array $ass_ids,
92 array $buttons
93 ): string {
94 global $DIC;
95
96 $lng = $DIC->language();
97 $user = $DIC->user();
98 $ui = $DIC->ui();
99 $access = $DIC->access();
100 $link_service = $DIC->exercise()->internal()->gui()->permanentLink();
101
102 $html = "";
103
104 foreach ($ass_ids as $ass_id) {
105 $info = new ilExAssignmentInfo($ass_id, $user->getId());
107 $readable_ref_id = 0;
108 foreach (ilObject::_getAllReferences($exc_id) as $ref_id) {
109 if ($access->checkAccess("read", "", $ref_id)) {
110 $readable_ref_id = $ref_id;
111 }
112 }
113
114 $tpl = new ilTemplate("tpl.ass_info_tool.html", true, true, "components/ILIAS/Exercise");
115 $assignment = new ilExAssignment($ass_id);
116
117 $title = ilObject::_lookupTitle($exc_id) . ": " . $assignment->getTitle();
118 if ($readable_ref_id > 0) {
119 $title = $ui->renderer()->render(
120 $ui->factory()->link()->standard($title, $link_service->getPermanentLink($readable_ref_id, $ass_id))
121 );
122 }
123
124 $this->addSection($tpl, $lng->txt("exc_assignment"), $title);
125
126 // schedule info
127 $schedule = $info->getScheduleInfo();
128 $list = $ui->factory()->listing()->unordered(array_map(function ($i) {
129 return $i["txt"] . ": " . $i["value"];
130 }, $schedule));
131 $this->addSection($tpl, $lng->txt("exc_schedule"), $ui->renderer()->render($list));
132
133 // latest submission
134 $subm = $info->getSubmissionInfo();
135 if (isset($subm["submitted"])) {
136 $this->addSection($tpl, $subm["submitted"]["txt"], $subm["submitted"]["value"]);
137 }
138
139 // instruction
140 $inst = $info->getInstructionInfo();
141 if (count($inst)) {
142 $this->addSection($tpl, $inst["instruction"]["txt"], $inst["instruction"]["value"]);
143 }
144
145 // instruction files
146 $files = $info->getInstructionFileInfo($readable_ref_id);
147 if (is_array($files)) {
148 $list = $ui->factory()->listing()->unordered(array_map(function ($i) use ($ui) {
149 $v = $i["txt"];
150 if ($i["value"] != "") {
151 $v = $ui->renderer()->render($ui->factory()->button()->shy($v, $i["value"]));
152 }
153 return $v;
154 }, $files));
155 $this->addSection($tpl, $lng->txt("exc_instruction_files"), $ui->renderer()->render($list));
156 }
157
158 // buttons
159 if (isset($buttons[$ass_id])) {
160 $tpl->setVariable("BUTTONS", implode(" ", array_map(function ($b) use ($ui) {
161 return $ui->renderer()->render($b);
162 }, $buttons[$ass_id])));
163 }
164
165 $tpl->setCurrentBlock("ass_info");
166 $tpl->parseCurrentBlock();
167 $html .= $tpl->get();
168 }
169 return $html;
170 }
171
172 protected function addSection(
173 ilTemplate $tpl,
174 string $title,
175 string $content
176 ): void {
177 $tpl->setCurrentBlock("section");
178 $tpl->setVariable("TITLE", $title);
179 $tpl->setVariable("CONTENT", $content);
180 $tpl->parseCurrentBlock();
181 }
182}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
factory()
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Exercise assignment.
static lookupExerciseId(int $a_ass_id)
getAssignmentInfo(array $ass_ids, array $buttons)
addSection(ilTemplate $tpl, string $title, string $content)
getToolsForContextStack(CalledContexts $called_contexts)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
special template class to simplify handling of ITX/PEAR
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
$info
Definition: entry_point.php:21
This describes commonalities between standard and primary buttons.
Definition: Button.php:34
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26