ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPCVerificationGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24require_once("./Services/COPage/classes/class.ilPCVerification.php");
25require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
26
38{
42 protected $user;
43
44
49 public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
50 {
51 global $DIC;
52
53 $this->tpl = $DIC["tpl"];
54 $this->ctrl = $DIC->ctrl();
55 $this->user = $DIC->user();
56 $this->lng = $DIC->language();
57 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
58 }
59
63 public function executeCommand()
64 {
65 // get next class that processes or forwards current command
66 $next_class = $this->ctrl->getNextClass($this);
67
68 // get current command
69 $cmd = $this->ctrl->getCmd();
70
71 switch ($next_class) {
72 default:
73 $ret = $this->$cmd();
74 break;
75 }
76
77 return $ret;
78 }
79
85 public function insert(ilPropertyFormGUI $a_form = null)
86 {
88
90
91 if (!$a_form) {
92 $a_form = $this->initForm(true);
93 }
94 $tpl->setContent($a_form->getHTML());
95 }
96
102 public function edit(ilPropertyFormGUI $a_form = null)
103 {
105
106 $this->displayValidationError();
107
108 if (!$a_form) {
109 $a_form = $this->initForm();
110 }
111 $tpl->setContent($a_form->getHTML());
112 }
113
121 protected function initForm($a_insert = false)
122 {
126
127 $form = new ilPropertyFormGUI();
128 $form->setFormAction($ilCtrl->getFormAction($this));
129 if ($a_insert) {
130 $form->setTitle($this->lng->txt("cont_insert_verification"));
131 } else {
132 $form->setTitle($this->lng->txt("cont_update_verification"));
133 }
134
135 $lng->loadLanguageModule("wsp");
136 $workspaceOptions = array();
137
138 $certificateSource = new ilRadioGroupInputGUI($this->lng->txt('certificate_selection'), 'certificate_selection');
139
140 $workspaceRadioButton = new ilRadioOption($this->lng->txt('certificate_workspace_option'), 'certificate_workspace_option');
141 $persistentRadioButton = new ilRadioOption($this->lng->txt('certificate_persistent_option'), 'certificate_persistent_option');
142
143 $tree = new ilWorkspaceTree($ilUser->getId());
144 $root = $tree->getRootId();
145 if ($root) {
146 $root = $tree->getNodeData($root);
147 foreach ($tree->getSubTree($root) as $node) {
148 if (in_array($node["type"], array("excv", "tstv", "crsv", "scov"))) {
149 $workspaceOptions[$node["obj_id"]] = $node["title"] . " (" . $lng->txt("wsp_type_" . $node["type"]) . ")";
150 }
151 }
152 asort($workspaceOptions);
153 }
154
155 $workspaceCertificates = new ilSelectInputGUI($this->lng->txt("cont_verification_object"), "object");
156 $workspaceCertificates->setRequired(true);
157 $workspaceCertificates->setOptions($workspaceOptions);
158
159 $repository = new ilUserCertificateRepository();
160
161 $certificates = $repository->fetchActiveCertificates($ilUser->getId());
162
163 $persistentOptions = array();
164 foreach ($certificates as $certificate) {
165 $userCertificate = $certificate->getUserCertificate();
166 $dateTime = ilDatePresentation::formatDate(new ilDateTime($userCertificate->getAcquiredTimestamp(), IL_CAL_UNIX));
167
168 $type = $lng->txt("wsp_type_" . $userCertificate->getObjType() . 'v');
169 $additionalInformation = ' (' . $type . ' / ' . $dateTime . ')';
170 $persistentOptions[$userCertificate->getObjId()] = $certificate->getObjectTitle() . $additionalInformation;
171 }
172
173 $persistentObject = new ilSelectInputGUI($this->lng->txt("cont_verification_object"), "persistent_object");
174 $persistentObject->setRequired(true);
175 $persistentObject->setOptions($persistentOptions);
176
177 $persistentRadioButton->addSubItem($persistentObject);
178 $workspaceRadioButton->addSubItem($workspaceCertificates);
179
180 $certificateSource->addOption($persistentRadioButton);
181 $certificateSource->addOption($workspaceRadioButton);
182
183 $certificateSource->setValue('certificate_persistent_option');
184
185 $form->addItem($certificateSource);
186
187 if ($a_insert) {
188 $form->addCommandButton("create_verification", $this->lng->txt("save"));
189 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
190 } else {
191 $data = $this->content_obj->getData();
192
193 if ($data['type'] === 'crta') {
194 $certificateSource->setValue('certificate_persistent_option');
195 $persistentObject->setValue($data["id"]);
196 } else {
197 $certificateSource->setValue('certificate_workspace_option');
198 $workspaceCertificates->setValue($data["id"]);
199 }
200
201
202 $form->addCommandButton("update", $this->lng->txt("save"));
203 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
204 }
205
206 return $form;
207 }
208
213 public function create()
214 {
215 $form = $this->initForm(true);
216 if ($form->checkInput()) {
217 $option = $form->getInput('certificate_selection');
218
219 if ('certificate_workspace_option' === $option) {
220 $type = ilObject::_lookupType($form->getInput("object"));
221 if ($type) {
222 $this->content_obj = new ilPCVerification($this->getPage());
223 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
224 $verificationObjectId = $form->getInput("object");
225
226 $this->content_obj->setData($type, $verificationObjectId);
227
228 $this->updated = $this->pg_obj->update();
229 if ($this->updated === true) {
230 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
231 }
232 }
233 } elseif ('certificate_persistent_option' === $option) {
234 $objectId = $form->getInput("persistent_object");
235
236 $userId = $this->user->getId();
237
238 $certificateFileService = new ilPortfolioCertificateFileService();
239 try {
240 $certificateFileService->createCertificateFile($userId, $objectId);
241 } catch (\ILIAS\Filesystem\Exception\FileAlreadyExistsException $e) {
242 ilUtil::sendInfo($this->lng->txt('certificate_file_not_found_error'), true);
243 $this->log->warning($e->getMessage());
244 } catch (\ILIAS\Filesystem\Exception\IOException $e) {
245 ilUtil::sendInfo($this->lng->txt('certificate_file_input_output_error'), true);
246 $this->log->error($e->getMessage());
247 return $this->ctrl->redirect($this, 'initForm');
248 } catch (ilException $e) {
249 ilUtil::sendFailure($this->lng->txt('error_creating_certificate_pdf'), true);
250 $this->log->error($e->getMessage());
251 return $this->ctrl->redirect($this, 'initForm');
252 }
253
254 $this->content_obj = new ilPCVerification($this->getPage());
255 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
256 $this->content_obj->setData('crta', $objectId);
257
258 $this->updated = $this->pg_obj->update();
259 if ($this->updated === true) {
260 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
261 }
262
263 $this->log->info('File could not be created');
264 }
265 }
266
267 $this->insert($form);
268 }
269
273 public function update()
274 {
275 $form = $this->initForm(true);
276 if ($form->checkInput()) {
277 $option = $form->getInput('certificate_selection');
278 if ('certificate_workspace_option' === $option) {
279 $object = $form->getInput("object");
280 $type = ilObject::_lookupType($object);
281 if ($type) {
282 $oldContentData = $this->content_obj->getData();
283
284 if ('crta' === $oldContentData['type']) {
285 $userId = $this->user->getId();
286 $oldObjectId = $oldContentData['id'];
287
288 $certificateFileService = new ilPortfolioCertificateFileService();
289 try {
290 $certificateFileService->deleteCertificateFile($userId, $oldObjectId);
291 } catch (\ILIAS\Filesystem\Exception\FileNotFoundException $e) {
292 ilUtil::sendInfo($this->lng->txt('certificate_file_not_found_error'));
293 $this->log->warning($e->getMessage());
294 } catch (\ILIAS\Filesystem\Exception\IOException $e) {
295 ilUtil::sendInfo($this->lng->txt('certificate_file_input_output_error'));
296 $this->log->warning($e->getMessage());
297 }
298 }
299
300 $this->content_obj->setData($type, $object);
301 $this->updated = $this->pg_obj->update();
302 if ($this->updated === true) {
303 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
304 }
305 }
306 } elseif ('certificate_persistent_option' === $option) {
307 $oldContentData = $this->content_obj->getData();
308
309 $objectId = $form->getInput("persistent_object");
310
311 $certificateFileService = new ilPortfolioCertificateFileService();
312
313 try {
314 $userId = $this->user->getId();
315
316 $certificateFileService->createCertificateFile($userId, $objectId);
317 if ('crta' === $oldContentData['type']) {
318 $oldObjectId = $oldContentData['id'];
319 $certificateFileService->deleteCertificateFile($userId, $oldObjectId);
320 }
321 } catch (\ILIAS\Filesystem\Exception\FileNotFoundException $e) {
322 ilUtil::sendInfo($this->lng->txt('certificate_file_not_found_error'), true);
323 $this->log->warning($e->getMessage());
324 } catch (\ILIAS\Filesystem\Exception\FileAlreadyExistsException $e) {
325 ilUtil::sendInfo($this->lng->txt('certificate_file_not_found_error'), true);
326 $this->log->warning($e->getMessage());
327 } catch (\ILIAS\Filesystem\Exception\IOException $e) {
328 ilUtil::sendInfo($this->lng->txt('certificate_file_input_output_error'), true);
329 $this->log->warning($e->getMessage());
330 } catch (ilException $e) {
331 ilUtil::sendFailure($this->lng->txt('error_creating_certificate_pdf'), true);
332 $this->log->error($e->getMessage());
333 return $this->ctrl->redirect($this, 'initForm');
334 }
335
336 $this->content_obj->setData('crta', $objectId);
337 $this->updated = $this->pg_obj->update();
338 if ($this->updated === true) {
339 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
340 }
341
342 $this->log->info('File could not be created');
343 }
344 }
345
346 $this->pg_obj->addHierIDs();
347 $this->edit($form);
348 }
349
350 private function initStorage(int $objectId, string $subDirectory = '')
351 {
352 $storage = new ilVerificationStorageFile($objectId);
353 $storage->create();
354
355 $path = $storage->getAbsolutePath() . "/";
356
357 if ($subDirectory !== '') {
358 $path .= $subDirectory . "/";
359
360 if (!is_dir($path)) {
361 mkdir($path);
362 }
363 }
364
365 return $path;
366 }
367}
user()
Definition: user.php:4
$path
Definition: aliased.php:25
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
Base class for ILIAS Exception handling.
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilPCVerificationGUI.
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
insert(ilPropertyFormGUI $a_form=null)
Insert new verification form.
initStorage(int $objectId, string $subDirectory='')
update()
Update verification.
edit(ilPropertyFormGUI $a_form=null)
Edit verification form.
initForm($a_insert=false)
Init verification form.
create()
Create new verification.
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.
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
Definition: example_052.php:77
global $ilCtrl
Definition: ilias.php:18
$certificates
Definition: metarefresh.php:39
Class FlySystemFileAccessTest.
Class BaseForm.
$ret
Definition: parser.php:6
$type
if(isset($_POST['submit'])) $form
$root
Definition: sabredav.php:45
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18
$data
Definition: bench.php:6