ILIAS  release_8 Revision v8.24
class.ilObjTestVerificationGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
32{
33 public function __construct(int $id = 0, int $id_type = self::REPOSITORY_NODE_ID, int $parent_node_id = 0)
34 {
35 parent::__construct($id, $id_type, $parent_node_id);
36 }
37
38 public function getType(): string
39 {
40 return "tstv";
41 }
42
43 public function create(): void
44 {
45 global $DIC;
46 $ilTabs = $DIC['ilTabs'];
47
48 $this->lng->loadLanguageModule("tstv");
49
50 $ilTabs->setBackTarget(
51 $this->lng->txt("back"),
52 $this->ctrl->getLinkTarget($this, "cancel")
53 );
54
55 $table = new ilTestVerificationTableGUI($this, "create");
56 $this->tpl->setContent($table->getHTML());
57 }
58
59 public function save(): void
60 {
61 global $DIC;
62 $ilUser = $DIC['ilUser'];
63
64 $objectId = $this->getRequestValue("tst_id");
65 if ($objectId) {
66 $certificateVerificationFileService = new ilCertificateVerificationFileService(
67 $DIC->language(),
68 $DIC->database(),
69 $DIC->logger()->root(),
71 );
72
73 $userCertificateRepository = new ilUserCertificateRepository();
74
75 $userCertificatePresentation = $userCertificateRepository->fetchActiveCertificateForPresentation(
76 (int) $ilUser->getId(),
77 (int) $objectId
78 );
79
80 $newObj = null;
81 try {
82 $newObj = $certificateVerificationFileService->createFile($userCertificatePresentation);
83 } catch (\Exception $exception) {
84 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('error_creating_certificate_pdf'));
85 $this->create();
86 }
87
88 if ($newObj) {
90 $this->node_id = null;
91 $this->putObjectInTree($newObj, $parent_id);
92
93 $this->afterSave($newObj);
94 } else {
95 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_failed"));
96 }
97 } else {
98 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"));
99 }
100 $this->create();
101 }
102
103 public function deliver(): void
104 {
105 $file = $this->object->getFilePath();
106 if ($file) {
107 ilFileDelivery::deliverFileLegacy($file, $this->object->getTitle() . ".pdf");
108 }
109 }
110
111 public function render(bool $a_return = false, string $a_url = ''): string
112 {
113 global $DIC;
114 $ilUser = $DIC['ilUser'];
115 $lng = $DIC['lng'];
116
117 if (!$a_return) {
118 $this->deliver();
119 } else {
120 $tree = new ilWorkspaceTree($ilUser->getId());
121 $wsp_id = $tree->lookupNodeId($this->object->getId());
122 $caption = $lng->txt("wsp_type_tstv") . ' "' . $this->object->getTitle() . '"';
123
124 $valid = true;
125 $message = '';
126 if (!file_exists($this->object->getFilePath())) {
127 $valid = false;
128 $message = $lng->txt("url_not_found");
129 } elseif (!$a_url) {
131 if (!$access_handler->checkAccess("read", "", $wsp_id)) {
132 $valid = false;
133 $message = $lng->txt("permission_denied");
134 }
135 }
136
137 if ($valid) {
138 if (!$a_url) {
139 $a_url = $this->getAccessHandler()->getGotoLink($wsp_id, $this->object->getId());
140 }
141 return '<div><a href="' . $a_url . '">' . $caption . '</a></div>';
142 }
143
144 return '<div>' . $caption . ' (' . $message . ')</div>';
145 }
146
147 return "";
148 }
149
150 public function downloadFromPortfolioPage(ilPortfolioPage $a_page): void
151 {
152 global $DIC;
153 $ilErr = $DIC['ilErr'];
154
155 if (ilPCVerification::isInPortfolioPage($a_page, $this->object->getType(), $this->object->getId())) {
156 $this->deliver();
157 }
158
159 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
160 }
161
162 public static function _goto(string $a_target): void
163 {
164 global $DIC;
165 $id = explode("_", $a_target);
166 $DIC->ctrl()->setParameterByClass('ilsharedresourceGUI', 'wsp_id', $id[0]);
167 $DIC->ctrl()->redirectByClass('ilsharedresourceGUI');
168 }
169
175 protected function getRequestValue(string $key, $default = null)
176 {
177 if (isset($this->request->getQueryParams()[$key])) {
178 return $this->request->getQueryParams()[$key];
179 }
180
181 if (isset($this->request->getParsedBody()[$key])) {
182 return $this->request->getParsedBody()[$key];
183 }
184
185 return $default ?? null;
186 }
187}
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...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getRequestValue(string $key, $default=null)
downloadFromPortfolioPage(ilPortfolioPage $a_page)
render(bool $a_return=false, string $a_url='')
__construct(int $id=0, int $id_type=self::REPOSITORY_NODE_ID, int $parent_node_id=0)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$valid
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$ilErr
Definition: raiseError.php:17
$message
Definition: xapiexit.php:32