ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjSCORMVerificationGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 {
28  public function getType(): string
29  {
30  return "scov";
31  }
32 
36  public function create(): void
37  {
38  global $DIC;
39  $ilTabs = $DIC->tabs();
40 
41  $this->lng->loadLanguageModule("scov");
42 
43  $ilTabs->setBackTarget(
44  $this->lng->txt("back"),
45  $this->ctrl->getLinkTarget($this, "cancel")
46  );
47 
48  $table = new ilSCORMVerificationTableGUI($this, "create");
49  $this->tpl->setContent($table->getHTML());
50  }
51 
57  public function save(): void
58  {
59  global $DIC;
60 
61  $ilUser = $DIC->user();
62 
63  $objectId = $this->getRequestValue("lm_id");
64  if ($objectId) {
65  $certificateVerificationFileService = new ilCertificateVerificationFileService(
66  $DIC->language(),
67  $DIC->database(),
68  $DIC->logger()->root(),
70  );
71 
72  $userCertificateRepository = new ilUserCertificateRepository();
73 
74  $userCertificatePresentation = $userCertificateRepository->fetchActiveCertificateForPresentation(
75  (int) $ilUser->getId(),
76  (int) $objectId
77  );
78 
79  try {
80  $newObj = $certificateVerificationFileService->createFile($userCertificatePresentation);
81  } catch (\Exception $exception) {
82  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('error_creating_certificate_pdf'));
83  $this->create();
84  }
85 
86  $newObj = null;
87  if ($newObj) {
89  $this->node_id = null;
90  $this->putObjectInTree($newObj, $parent_id);
91 
92  $this->afterSave($newObj);
93  } else {
94  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_failed"));
95  }
96  } else {
97  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"));
98  }
99  $this->create();
100  }
101 
102  public function deliver(): void
103  {
104  $file = $this->object->getFilePath();
105  if ($file) {
106  ilFileDelivery::deliverFileLegacy($file, $this->object->getTitle() . ".pdf");
107  }
108  }
109 
110  public function render(bool $a_return = false, string $a_url = ''): string
111  {
112  global $DIC;
113  $ilUser = $DIC->user();
114  $lng = $DIC->language();
115 
116  if (!$a_return) {
117  $this->deliver();
118  } else {
119  $tree = new ilWorkspaceTree($ilUser->getId());
120  $wsp_id = $tree->lookupNodeId($this->object->getId());
121 
122  $caption = $lng->txt("wsp_type_scov") . ' "' . $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 
167  $DIC->ctrl->setParameterByClass(
168  "ilsharedresourceGUI",
169  "wsp_id",
170  $id[0]
171  );
172  $DIC->ctrl->redirectByClass(ilSharedResourceGUI::class);
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  return $this->request->getParsedBody()[$key] ?? $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...
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...
New implementation of ilObjectGUI.
static isInPortfolioPage(ilPortfolioPage $a_page, string $a_type, int $a_id)
$valid
downloadFromPortfolioPage(ilPortfolioPage $a_page)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createFile(ilUserCertificatePresentation $userCertificatePresentation)
putObjectInTree(ilObject $obj, int $parent_node_id=null)
Add object to tree at given position.
getRequestValue(string $key, $default=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ilErr
Definition: raiseError.php:17
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
global $DIC
Definition: feed.php:28
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
render(bool $a_return=false, string $a_url='')
afterSave(ilObject $new_object)
Post (successful) object creation hook.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ilUser
Definition: imgupload.php:34
$message
Definition: xapiexit.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...