ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjTestVerificationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
34{
37
38 public function __construct(int $id = 0, int $id_type = self::REPOSITORY_NODE_ID, int $parent_node_id = 0)
39 {
41 global $DIC;
42 $this->db = $DIC['ilDB'];
43 $this->logger = $DIC->logger();
44
45 parent::__construct($id, $id_type, $parent_node_id);
46 }
47
48 public function getType(): string
49 {
50 return "tstv";
51 }
52
53 public function create(): void
54 {
55 $this->lng->loadLanguageModule("tstv");
56
57 $this->tabs_gui->setBackTarget(
58 $this->lng->txt("back"),
59 $this->ctrl->getLinkTarget($this, "cancel")
60 );
61
62 $table = new ilTestVerificationTableGUI($this, 'create', $this->db, $this->user, $this->logger->root());
63 $this->tpl->setContent($table->getHTML());
64 }
65
66 public function save(): void
67 {
68 $objectId = $this->getRequestValue("tst_id");
69 if ($objectId) {
70 $certificateVerificationFileService = new ilCertificateVerificationFileService(
71 $this->lng,
72 $this->db,
73 $this->logger->root(),
75 );
76
77 $userCertificateRepository = new ilUserCertificateRepository();
78
79 $userCertificatePresentation = $userCertificateRepository->fetchActiveCertificateForPresentation(
80 (int) $this->user->getId(),
81 (int) $objectId
82 );
83
84 $newObj = null;
85 try {
86 $newObj = $certificateVerificationFileService->createFile($userCertificatePresentation);
87 } catch (\Exception $exception) {
88 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('error_creating_certificate_pdf'));
89 $this->create();
90 }
91
92 if ($newObj) {
94 $this->node_id = null;
95 $this->putObjectInTree($newObj, $parent_id);
96
97 $this->afterSave($newObj);
98 } else {
99 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_failed"));
100 }
101 } else {
102 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"));
103 }
104 $this->create();
105 }
106
107 public function deliver(): void
108 {
109 $file = $this->object->getFilePath();
110 if ($file) {
111 ilFileDelivery::deliverFileLegacy($file, $this->object->getTitle() . ".pdf");
112 }
113 }
114
115 public function render(bool $a_return = false, string $a_url = ''): string
116 {
117 if (!$a_return) {
118 $this->deliver();
119 } else {
120 $tree = new ilWorkspaceTree($this->user->getId());
121 $wsp_id = $tree->lookupNodeId($this->object->getId());
122 $caption = $this->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 = $this->lng->txt("url_not_found");
129 } elseif (!$a_url) {
131 if (!$access_handler->checkAccess("read", "", $wsp_id)) {
132 $valid = false;
133 $message = $this->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 if (ilPCVerification::isInPortfolioPage($a_page, $this->object->getType(), $this->object->getId())) {
153 $this->deliver();
154 }
155
156 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
157 }
158
159 public static function _goto(string $a_target): void
160 {
161 global $DIC;
162 $id = explode("_", $a_target);
163 $DIC->ctrl()->setParameterByClass('ilsharedresourceGUI', 'wsp_id', $id[0]);
164 $DIC->ctrl()->redirectByClass('ilsharedresourceGUI');
165 }
166
172 protected function getRequestValue(string $key, $default = null)
173 {
174 if (isset($this->request->getQueryParams()[$key])) {
175 return $this->request->getQueryParams()[$key];
176 }
177
178 if (isset($this->request->getParsedBody()[$key])) {
179 return $this->request->getParsedBody()[$key];
180 }
181
182 return $default ?? null;
183 }
184}
Provides fluid interface to LoggingServices.
error(string $a_errmsg)
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)
GUI class for test verification.
getRequestValue(string $key, $default=null)
downloadFromPortfolioPage(ilPortfolioPage $a_page)
render(bool $a_return=false, string $a_url='')
getType()
Functions that must be overwritten.
New implementation of ilObjectGUI.
__construct(int $id=0, int $id_type=self::REPOSITORY_NODE_ID, int $parent_node_id=0)
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...
List all completed tests for current user.
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
Interface ilDBInterface.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31