ILIAS  release_8 Revision v8.24
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);
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
101 $html = "";
102
103 foreach ($ass_ids as $ass_id) {
104 $info = new ilExAssignmentInfo($ass_id, $user->getId());
105 $exc_id = ilExAssignment::lookupExerciseId($ass_id);
106 $readable_ref_id = 0;
107 foreach (ilObject::_getAllReferences($exc_id) as $ref_id) {
108 if ($access->checkAccess("read", "", $ref_id)) {
109 $readable_ref_id = $ref_id;
110 }
111 }
112
113 $tpl = new ilTemplate("tpl.ass_info_tool.html", true, true, "Modules/Exercise");
114 $assignment = new ilExAssignment($ass_id);
115
116 $title = ilObject::_lookupTitle($exc_id) . ": " . $assignment->getTitle();
117 if ($readable_ref_id > 0) {
118 $title = $ui->renderer()->render(
119 $ui->factory()->link()->standard($title, ilLink::_getLink($readable_ref_id))
120 );
121 }
122
123 $this->addSection($tpl, $lng->txt("exc_assignment"), $title);
124
125 // schedule info
126 $schedule = $info->getScheduleInfo();
127 $list = $ui->factory()->listing()->unordered(array_map(function ($i) {
128 return $i["txt"] . ": " . $i["value"];
129 }, $schedule));
130 $this->addSection($tpl, $lng->txt("exc_schedule"), $ui->renderer()->render($list));
131
132 // latest submission
133 $subm = $info->getSubmissionInfo();
134 if (isset($subm["submitted"])) {
135 $this->addSection($tpl, $subm["submitted"]["txt"], $subm["submitted"]["value"]);
136 }
137
138 // instruction
139 $inst = $info->getInstructionInfo();
140 if (count($inst)) {
141 $this->addSection($tpl, $inst["instruction"]["txt"], $inst["instruction"]["value"]);
142 }
143
144 // instruction files
145 $files = $info->getInstructionFileInfo($readable_ref_id);
146 if (is_array($files)) {
147 $list = $ui->factory()->listing()->unordered(array_map(function ($i) use ($ui) {
148 $v = $i["txt"];
149 if ($i["value"] != "") {
150 $v = $ui->renderer()->render($ui->factory()->button()->shy($v, $i["value"]));
151 }
152 return $v;
153 }, $files));
154 $this->addSection($tpl, $lng->txt("exc_instruction_files"), $ui->renderer()->render($list));
155 }
156
157 // buttons
158 if (isset($buttons[$ass_id])) {
159 $tpl->setVariable("BUTTONS", implode(" ", array_map(function ($b) use ($ui) {
160 return $ui->renderer()->render($b);
161 }, $buttons[$ass_id])));
162 }
163
164 $tpl->setCurrentBlock("ass_info");
165 $tpl->parseCurrentBlock();
166 $html .= $tpl->get();
167 }
168 return $html;
169 }
170
171 protected function addSection(
173 string $title,
174 string $content
175 ): void {
176 $tpl->setCurrentBlock("section");
177 $tpl->setVariable("TITLE", $title);
178 $tpl->setVariable("CONTENT", $content);
179 $tpl->parseCurrentBlock();
180 }
181}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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
global $DIC
Definition: feed.php:28
This describes commonalities between standard and primary buttons.
Definition: Button.php:32
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$ref_id
Definition: ltiauth.php:67
$i
Definition: metadata.php:41
$lng