ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjCourseVerificationGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
4 
22 
29 {
30  private Container $dic;
32 
33  protected ilTabsGUI $tabs;
34 
35  public function __construct(int $a_id = 0, int $a_id_type = self::REPOSITORY_NODE_ID, int $a_parent_node_id = 0)
36  {
37  global $DIC;
38  $this->dic = $DIC;
39  $this->error = $DIC->error();
40  $this->tabs = $DIC->tabs();
41 
42  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
43  }
44 
45  public function getType(): string
46  {
47  return "crsv";
48  }
49 
50  public function create(): void
51  {
52  $this->lng->loadLanguageModule("crsv");
53 
54  $this->tabs->setBackTarget(
55  $this->lng->txt("back"),
56  $this->ctrl->getLinkTarget($this, "cancel")
57  );
58 
59  $table = new ilCourseVerificationTableGUI($this, "create");
60  $this->tpl->setContent($table->getHTML());
61  }
62 
63  public function save(): void
64  {
65  $ilUser = $this->dic->user();
66 
67  $objectId = $this->getRequestValue("crs_id");
68  if ($objectId) {
69  $certificateVerificationFileService = new ilCertificateVerificationFileService(
70  $this->dic->language(),
71  $this->dic->database(),
72  $this->dic->logger()->root(),
74  );
75 
76  $userCertificateRepository = new ilUserCertificateRepository();
77 
78  $userCertificatePresentation = $userCertificateRepository->fetchActiveCertificateForPresentation(
79  $ilUser->getId(),
80  (int) $objectId
81  );
82 
83  $newObj = null;
84  try {
85  $newObj = $certificateVerificationFileService->createFile($userCertificatePresentation);
86  } catch (Exception $exception) {
87  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('error_creating_certificate_pdf'));
88  $this->create();
89  return;
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 
105  $this->create();
106  }
107 
108  public function deliver(): void
109  {
110  $file = $this->object->getFilePath();
111  if ($file) {
112  ilFileDelivery::deliverFileLegacy($file, $this->object->getTitle() . ".pdf");
113  }
114  }
115 
116  public function render(bool $a_return = false, string $a_url = ''): string
117  {
118  $ilUser = $this->dic->user();
119  $lng = $this->dic->language();
120 
121  if (!$a_return) {
122  $this->deliver();
123  } else {
124  $tree = new ilWorkspaceTree($ilUser->getId());
125  $wsp_id = $tree->lookupNodeId($this->object->getId());
126 
127  $caption = $lng->txt("wsp_type_crsv") . ' "' . $this->object->getTitle() . '"';
128 
129  $valid = true;
130  $message = '';
131  if (!file_exists($this->object->getFilePath())) {
132  $valid = false;
133  $message = $lng->txt("url_not_found");
134  } elseif (!$a_url) {
136  if (!$access_handler->checkAccess("read", "", $wsp_id)) {
137  $valid = false;
138  $message = $lng->txt("permission_denied");
139  }
140  }
141 
142  if ($valid) {
143  if (!$a_url) {
144  $a_url = $this->getAccessHandler()->getGotoLink($wsp_id, $this->object->getId());
145  }
146  return '<div><a href="' . $a_url . '">' . $caption . '</a></div>';
147  }
148 
149  return '<div>' . $caption . ' (' . $message . ')</div>';
150  }
151 
152  return "";
153  }
154 
155  public function downloadFromPortfolioPage(ilPortfolioPage $a_page): void
156  {
157  if (ilPCVerification::isInPortfolioPage($a_page, $this->object->getType(), $this->object->getId())) {
158  $this->deliver();
159  }
160  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
161  }
162 
163  public static function _goto(string $a_target): void
164  {
165  global $DIC;
166 
167  $ctrl = $DIC->ctrl();
168 
169  $id = explode("_", $a_target);
170 
172  ilSharedResourceGUI::class,
173  'wsp_id',
174  $id[0]
175  );
176  $ctrl->redirectByClass(ilSharedResourceGUI::class);
177  }
178 
183  protected function getRequestValue(string $key, $default = null)
184  {
185  if (isset($this->request->getQueryParams()[$key])) {
186  return $this->request->getQueryParams()[$key];
187  }
188 
189  if (isset($this->request->getParsedBody()[$key])) {
190  return $this->request->getParsedBody()[$key];
191  }
192 
193  return $default ?? null;
194  }
195 }
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)
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...
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
New implementation of ilObjectGUI.
List all completed course for current user.
static isInPortfolioPage(ilPortfolioPage $a_page, string $a_type, int $a_id)
$valid
render(bool $a_return=false, string $a_url='')
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
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)
global $DIC
Definition: feed.php:28
GUI class for course verification.
getRequestValue(string $key, $default=null)
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.
downloadFromPortfolioPage(ilPortfolioPage $a_page)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Error Handling & global info handling uses PEAR error class.
__construct(Container $dic, ilPlugin $plugin)
$ilUser
Definition: imgupload.php:34
$message
Definition: xapiexit.php:32