ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjCmiXapiVerificationGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
31 {
32  public function getType(): string
33  {
34  return "cmxv";
35  }
36 
40  public function create(): void
41  {
42  global $ilTabs;
43 
44  $this->lng->loadLanguageModule("cmxv");
45 
46  $ilTabs->setBackTarget(
47  $this->lng->txt("back"),
48  $this->ctrl->getLinkTarget($this, "cancel")
49  );
50  $table = new ilCmiXapiVerificationTableGUI($this, "create");
51  $this->tpl->setContent($table->getHTML());
52  }
53 
57  public function save(): void
58  {
59  global $DIC; /* @var \ILIAS\DI\Container $DIC */
60 
61  $objId = $this->getRequestValue("cmix_id");
62  if ($objId) {
63  $certificateVerificationFileService = new ilCertificateVerificationFileService(
64  $DIC->language(),
65  $DIC->database(),
66  $DIC->logger()->root(),
68  );
69 
70  $userCertificateRepository = new ilUserCertificateRepository();
71 
72  $userCertificatePresentation = $userCertificateRepository->fetchActiveCertificateForPresentation(
73  $DIC->user()->getId(),
74  (int) $objId
75  );
76 
77  $newObj = null;
78  try {
79  $newObj = $certificateVerificationFileService->createFile($userCertificatePresentation);
80  } catch (\Exception $exception) {
81  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('error_creating_certificate_pdf'));
82 // $this->create();
83  }
84 
85  if ($newObj !== null) {
87  $this->node_id = null;
88  $this->putObjectInTree($newObj, $parent_id);
89 
90  $this->afterSave($newObj);
91  } else {
92  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_failed"));
93  }
94  } else {
95  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"));
96  }
97 
98  $this->create();
99  }
100 
101  public function deliver(): void
102  {
103  $file = $this->object->getFilePath();
104 
105  if ($file) {
106  ilFileDelivery::deliverFileLegacy($file, $this->object->getTitle() . ".pdf");
107  }
108  }
109 
113  public function render(bool $a_return = false, bool $a_url = false): string
114  {
115  global $ilUser, $lng;
116 
117  if (!$a_return) {
118  $this->deliver();
119  return "";
120  } else {
121  $tree = new ilWorkspaceTree($ilUser->getId());
122  $wsp_id = $tree->lookupNodeId($this->object->getId());
123 
124  $caption = $lng->txt("wsp_type_cmxv") . ' "' . $this->object->getTitle() . '"';
125 
126  $valid = true;
127  $message = '';
128  if (!file_exists($this->object->getFilePath())) {
129  $valid = false;
130  $message = $lng->txt("url_not_found");
131  } elseif (!$a_url) {
133  if (!$access_handler->checkAccess("read", "", $wsp_id)) {
134  $valid = false;
135  $message = $lng->txt("permission_denied");
136  }
137  }
138 
139  if ($valid) {
140  if (!$a_url) {
141  $a_url = $this->getAccessHandler()->getGotoLink($wsp_id, $this->object->getId());
142  }
143  return '<div><a href="' . $a_url . '">' . $caption . '</a></div>';
144  } else {
145  return '<div>' . $caption . ' (' . $message . ')</div>';
146  }
147  }
148  }
149 
150  public function downloadFromPortfolioPage(ilPortfolioPage $a_page): void
151  {
152  global $ilErr;
153  if (ilPCVerification::isInPortfolioPage($a_page, $this->object->getType(), $this->object->getId())) {
154  $this->deliver();
155  }
156 
157  $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
158  }
159 
160  public static function _goto($a_target): void
161  {
162  global $DIC;
163  $ctrl = $DIC->ctrl();
164  $id = explode("_", $a_target);
165 
167  "ilsharedresourceGUI",
168  "wsp_id",
169  $id[0]
170  );
171  $ctrl->redirectByClass(ilSharedResourceGUI::class);
172  }
173 
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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
render(bool $a_return=false, bool $a_url=false)
Render content.
New implementation of ilObjectGUI.
static isInPortfolioPage(ilPortfolioPage $a_page, string $a_type, int $a_id)
$valid
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$objId
Definition: xapitoken.php:57
setParameterByClass(string $a_class, string $a_parameter, $a_value)
createFile(ilUserCertificatePresentation $userCertificatePresentation)
putObjectInTree(ilObject $obj, int $parent_node_id=null)
Add object to tree at given position.
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...
afterSave(ilObject $new_object)
Post (successful) object creation hook.
create()
List all tests in which current user participated.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
save()
create new instance and save it
$ilUser
Definition: imgupload.php:34
$message
Definition: xapiexit.php:32