ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjExerciseVerificationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 public function getType(): string
30 {
31 return "excv";
32 }
33
34 public function create(): void
35 {
36 $ilTabs = $this->tabs_gui;
37
38 $this->lng->loadLanguageModule("excv");
39
40 $ilTabs->setBackTarget(
41 $this->lng->txt("back"),
42 $this->ctrl->getLinkTarget($this, "cancel")
43 );
44
45 $table = new ilExerciseVerificationTableGUI($this, "create");
46 $this->tpl->setContent($table->getHTML());
47 }
48
52 public function save(): void
53 {
54 global $DIC;
55
56 $ilUser = $this->user;
57
58 $objectId = $this->getRequestValue("exc_id");
59 if ($objectId) {
60 $certificateVerificationFileService = new ilCertificateVerificationFileService(
61 $DIC->language(),
62 $DIC->database(),
63 $DIC->logger()->root(),
65 );
66
67 $userCertificateRepository = new ilUserCertificateRepository();
68
69 $userCertificatePresentation = $userCertificateRepository->fetchActiveCertificateForPresentation(
70 $ilUser->getId(),
71 (int) $objectId
72 );
73
74 $newObj = null;
75 try {
76 $newObj = $certificateVerificationFileService->createFile($userCertificatePresentation);
77 } catch (Exception $exception) {
78 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('error_creating_certificate_pdf'));
79 $this->create();
80 return;
81 }
82
83 if ($newObj !== null) {
85 $this->node_id = null;
86 $this->putObjectInTree($newObj, $parent_id);
87
88 $this->afterSave($newObj);
89 } else {
90 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_failed"));
91 }
92 } else {
93 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"));
94 }
95 $this->create();
96 }
97
98 public function deliver(): void
99 {
100 $file = $this->object->getFilePath();
101 if ($file) {
102 ilFileDelivery::deliverFileLegacy($file, $this->object->getTitle() . ".pdf");
103 }
104 }
105
106 public function render(
107 $a_return = false,
108 $a_url = false
109 ): string {
110 $ilUser = $this->user;
112
113 if (!$a_return) {
114 $this->deliver();
115 } else {
116 $tree = new ilWorkspaceTree($ilUser->getId());
117 $wsp_id = $tree->lookupNodeId($this->object->getId());
118
119 $caption = $lng->txt("wsp_type_excv") . ' "' . $this->object->getTitle() . '"';
120
121 $valid = true;
122 $message = '';
123 if (!file_exists($this->object->getFilePath())) {
124 $valid = false;
125 $message = $lng->txt("url_not_found");
126 } elseif (!$a_url) {
128 if (!$access_handler->checkAccess("read", "", $wsp_id)) {
129 $valid = false;
130 $message = $lng->txt("permission_denied");
131 }
132 }
133
134 if ($valid) {
135 if (!$a_url) {
136 $a_url = $this->getAccessHandler()->getGotoLink($wsp_id, $this->object->getId());
137 }
138 return '<div><a href="' . $a_url . '">' . $caption . '</a></div>';
139 }
140
141 return '<div>' . $caption . ' (' . $message . ')</div>';
142 }
143 return "";
144 }
145
146
150 public function downloadFromPortfolioPage(ilPortfolioPage $a_page): void
151 {
152 if (ilPCVerification::isInPortfolioPage($a_page, $this->object->getType(), $this->object->getId())) {
153 $this->deliver();
154 }
155
156 throw new ilExerciseException($this->lng->txt('permission_denied'));
157 }
158
159 public static function _goto(string $a_target): void
160 {
162 global $DIC;
163
164 $ctrl = $DIC->ctrl();
165 $id = explode("_", $a_target);
166
167 $ctrl->setParameterByClass(
168 "ilsharedresourceGUI",
169 "wsp_id",
170 $id[0]
171 );
172 $ctrl->redirectByClass("ilsharedresourceGUI");
173 }
174
179 protected function getRequestValue(string $key, $default = null)
180 {
181 if (isset($this->request->getQueryParams()[$key])) {
182 return $this->request->getQueryParams()[$key];
183 }
184
185 if (isset($this->request->getParsedBody()[$key])) {
186 return $this->request->getParsedBody()[$key];
187 }
188
189 return $default ?? null;
190 }
191}
$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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
List all completed exercises for current user.
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
GUI class for exercise verification.
getType()
Functions that must be overwritten.
New implementation of ilObjectGUI.
putObjectInTree(ilObject $obj, ?int $parent_node_id=null)
Add object to tree at given position.
afterSave(ilObject $new_object)
Post (successful) object creation hook.
static isInPortfolioPage(ilPortfolioPage $a_page, string $a_type, int $a_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$valid
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31