ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPCVerificationGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
15{
16 private const SUPPORTED_TYPES = ['excv', 'tstv', 'crsv', 'cmxv', 'ltiv', 'scov'];
17
19 protected $user;
20
24 public function __construct($a_pg_obj, $a_content_obj, $a_hier_id = 0, $a_pc_id = "")
25 {
26 global $DIC;
27
28 $this->user = $DIC->user();
29 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
30 }
31
32 public function executeCommand()
33 {
34 $cmd = $this->ctrl->getCmd();
35 return $this->$cmd();
36 }
37
42 public function insert(ilPropertyFormGUI $a_form = null) : void
43 {
45
46 if (!$a_form) {
47 $a_form = $this->initForm(true);
48 }
49 $this->tpl->setContent($a_form->getHTML());
50 }
51
56 public function edit(ilPropertyFormGUI $a_form = null) : void
57 {
59
60 if (!$a_form) {
61 $a_form = $this->initForm();
62 }
63 $this->tpl->setContent($a_form->getHTML());
64 }
65
69 private function getValidWorkspaceCertificateNodeByIdMap() : array
70 {
71 $nodes = [];
72
73 $tree = new ilWorkspaceTree($this->user->getId());
74 $root = $tree->getRootId();
75 if ($root) {
76 $root = $tree->getNodeData($root);
77 foreach ($tree->getSubTree($root) as $node) {
78 if (in_array($node['type'], self::SUPPORTED_TYPES)) {
79 $nodes[$node['obj_id']] = $node;
80 }
81 }
82 }
83
84 return $nodes;
85 }
86
90 private function getValidCertificateByIdMap() : array
91 {
92 $certificates = [];
93
94 $repository = new ilUserCertificateRepository();
95 $activeCertificates = $repository->fetchActiveCertificates((int) $this->user->getId());
96 foreach ($activeCertificates as $certificate) {
97 $certificates[$certificate->getObjId()] = $certificate;
98 }
99
100 return $certificates;
101 }
102
108 protected function initForm(bool $a_insert = false) : ilPropertyFormGUI
109 {
110 $this->lng->loadLanguageModule('wsp');
111
112 $form = new ilPropertyFormGUI();
113 $form->setFormAction($this->ctrl->getFormAction($this));
114
115 $data = [];
116 if ($a_insert) {
117 $form->setTitle($this->lng->txt('cont_insert_verification'));
118 $form->addCommandButton('create_verification', $this->lng->txt('save'));
119 $form->addCommandButton('cancelCreate', $this->lng->txt('cancel'));
120 } else {
121 $form->setTitle($this->lng->txt('cont_update_verification'));
122 $form->addCommandButton('update', $this->lng->txt('save'));
123 $form->addCommandButton('cancelUpdate', $this->lng->txt('cancel'));
124 $data = $this->content_obj->getData();
125 }
126
127 $certificateOptions = [];
128 foreach ($this->getValidCertificateByIdMap() as $certificate) {
129 $userCertificate = $certificate->getUserCertificate();
130 $dateTime = ilDatePresentation::formatDate(new ilDateTime($userCertificate->getAcquiredTimestamp(), IL_CAL_UNIX));
131
132 $type = $this->lng->txt('wsp_type_' . $userCertificate->getObjType() . 'v');
133 if ('sahs' === $userCertificate->getObjType()) {
134 $type = $this->lng->txt('wsp_type_scov');
135 }
136 $additionalInformation = ' (' . $type . ' / ' . $dateTime . ')';
137 $certificateOptions[$userCertificate->getObjId()] = $certificate->getObjectTitle() . $additionalInformation;
138 }
139
140 if ($a_insert || (isset($data['type']) && 'crta' === $data['type'])) {
141 $certificate = new ilSelectInputGUI($this->lng->txt('certificate'), 'persistent_object');
142 $certificate->setRequired(true);
143 $certificate->setOptions($certificateOptions);
144 $form->addItem($certificate);
145 if (isset($data['id'])) {
146 $certificate->setValue($data['id']);
147 }
148
149 return $form;
150 }
151
152 $certificateSource = new ilRadioGroupInputGUI($this->lng->txt('certificate_selection'), 'certificate_selection');
153
154 $workspaceRadioButton = new ilRadioOption($this->lng->txt('certificate_workspace_option'), 'certificate_workspace_option');
155 $persistentRadioButton = new ilRadioOption($this->lng->txt('certificate_persistent_option'), 'certificate_persistent_option');
156
157 $workspaceCertificates = new ilSelectInputGUI($this->lng->txt('cont_verification_object'), 'object');
158 $workspaceCertificates->setRequired(true);
159 $workspaceOptions = [];
160 foreach ($this->getValidWorkspaceCertificateNodeByIdMap() as $node) {
161 $workspaceOptions[$node['obj_id']] = $node['title'] . ' (' . $this->lng->txt('wsp_type_' . $node['type']) . ')';
162 }
163 asort($workspaceOptions);
164 $workspaceCertificates->setOptions($workspaceOptions);
165
166 $certificate = new ilSelectInputGUI($this->lng->txt('cont_verification_object'), 'persistent_object');
167 $certificate->setRequired(true);
168 $certificate->setOptions($certificateOptions);
169 $persistentRadioButton->addSubItem($certificate);
170 $workspaceRadioButton->addSubItem($workspaceCertificates);
171
172 $certificateSource->addOption($persistentRadioButton);
173 $certificateSource->addOption($workspaceRadioButton);
174
175 $form->addItem($certificateSource);
176
177 $certificateSource->setValue('certificate_workspace_option');
178 $workspaceCertificates->setValue($data['id']);
179
180 return $form;
181 }
182
186 public function create() : void
187 {
188 $form = $this->initForm(true);
189 if ($form->checkInput()) {
190 $objectId = (int) $form->getInput('persistent_object');
191 $userId = (int) $this->user->getId();
192
193 $certificateFileService = new ilPortfolioCertificateFileService();
194 try {
195 $certificateFileService->createCertificateFile($userId, $objectId);
196 } catch (\ILIAS\Filesystem\Exception\FileAlreadyExistsException $e) {
197 ilUtil::sendInfo($this->lng->txt('certificate_file_not_found_error'), true);
198 $this->log->warning($e->getMessage());
199 } catch (\ILIAS\Filesystem\Exception\IOException $e) {
200 ilUtil::sendInfo($this->lng->txt('certificate_file_input_output_error'), true);
201 $this->log->error($e->getMessage());
202 $this->ctrl->redirect($this, 'initForm');
203 } catch (ilException $e) {
204 ilUtil::sendFailure($this->lng->txt('error_creating_certificate_pdf'), true);
205 $this->log->error($e->getMessage());
206 $this->ctrl->redirect($this, 'initForm');
207 }
208
209 $this->content_obj = new ilPCVerification($this->getPage());
210 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
211 $this->content_obj->setData('crta', $objectId);
212
213 $this->updated = $this->pg_obj->update();
214 if ($this->updated === true) {
215 $this->ctrl->returnToParent($this, 'jump' . $this->hier_id);
216 }
217
218 $this->log->info('File could not be created');
219 }
220
221 $this->insert($form);
222 }
223
227 public function update() : void
228 {
229 $form = $this->initForm();
230 if ($form->checkInput()) {
231 $option = 'certificate_persistent_option';
232 if ($form->getItemByPostVar('certificate_selection')) {
233 $option = $form->getInput('certificate_selection');
234 }
235
236 $oldContentData = $this->content_obj->getData();
237
238 if ('certificate_workspace_option' === $option) {
239 $objectId = (int) $form->getInput('object');
240 $validWorkSpaceCertificates = $this->getValidWorkspaceCertificateNodeByIdMap();
241
242 if (isset($validWorkSpaceCertificates[$objectId])) {
243 $this->content_obj->setData($validWorkSpaceCertificates[$objectId]['type'], $objectId);
244 }
245 } elseif ('certificate_persistent_option' === $option) {
246 try {
247 $objectId = (int) $form->getInput('persistent_object');
248 $validCertificates = $this->getValidCertificateByIdMap();
249
250 if (isset($validCertificates[$objectId])) {
251 $certificateFileService = new ilPortfolioCertificateFileService();
252 $certificateFileService->createCertificateFile(
253 (int) $this->user->getId(),
254 $objectId
255 );
256 $this->content_obj->setData('crta', $objectId);
257 }
258 } catch (\ILIAS\Filesystem\Exception\FileNotFoundException $e) {
259 ilUtil::sendInfo($this->lng->txt('certificate_file_not_found_error'), true);
260 $this->log->warning($e->getMessage());
261 } catch (\ILIAS\Filesystem\Exception\FileAlreadyExistsException $e) {
262 ilUtil::sendInfo($this->lng->txt('certificate_file_not_found_error'), true);
263 $this->log->warning($e->getMessage());
264 } catch (\ILIAS\Filesystem\Exception\IOException $e) {
265 ilUtil::sendInfo($this->lng->txt('certificate_file_input_output_error'), true);
266 $this->log->warning($e->getMessage());
267 } catch (ilException $e) {
268 ilUtil::sendFailure($this->lng->txt('error_creating_certificate_pdf'), true);
269 $this->log->error($e->getMessage());
270 $this->ctrl->redirect($this, 'initForm');
271 }
272 }
273
274 if ('crta' === $oldContentData['type']) {
275 try {
276 $certificateFileService = new ilPortfolioCertificateFileService();
277 $certificateFileService->deleteCertificateFile(
278 (int) $this->user->getId(),
279 (int) $oldContentData['id']
280 );
281 } catch (\ILIAS\Filesystem\Exception\FileNotFoundException $e) {
282 ilUtil::sendInfo($this->lng->txt('certificate_file_not_found_error'));
283 $this->log->warning($e->getMessage());
284 } catch (\ILIAS\Filesystem\Exception\IOException $e) {
285 ilUtil::sendInfo($this->lng->txt('certificate_file_input_output_error'));
286 $this->log->warning($e->getMessage());
287 }
288 }
289
290 $this->updated = $this->pg_obj->update();
291 if ($this->updated === true) {
292 $this->ctrl->returnToParent($this, 'jump' . $this->hier_id);
293 }
294 }
295
296 $this->pg_obj->addHierIDs();
297 $this->edit($form);
298 }
299}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPCVerificationGUI.
insert(ilPropertyFormGUI $a_form=null)
edit(ilPropertyFormGUI $a_form=null)
__construct($a_pg_obj, $a_content_obj, $a_hier_id=0, $a_pc_id="")
@ineritdoc
initForm(bool $a_insert=false)
Class ilPCVerification.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
displayValidationError()
display validation errors
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Tree handler for personal workspace.
global $DIC
Definition: goto.php:24
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
$type
$data
Definition: storeScorm.php:23