ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilUserCertificateGUI Class Reference
+ Collaboration diagram for ilUserCertificateGUI:

Public Member Functions

 __construct (ilTemplate $template=null, ilCtrl $controller=null, ilLanguage $language=null, ilObjUser $user=null, ilUserCertificateRepository $userCertificateRepository=null, GuzzleHttp\Psr7\Request $request=null, ilLogger $certificateLogger=null, ilSetting $certificateSettings=null, Factory $uiFactory=null, Renderer $uiRenderer=null, \ilAccessHandler $access=null, \ILIAS\Filesystem\Filesystem $filesystem=null, ilCertificateMigrationValidator $migrationVisibleValidator=null)
 
 executeCommand ()
 
 listCertificates (bool $migrationWasStarted=false)
 
 download ()
 

Data Fields

const SORTATION_SESSION_KEY = 'my_certificates_sorting'
 

Protected Member Functions

 getCurrentSortation ()
 
 applySortation ()
 

Protected Attributes

 $certificateSettings
 
 $uiFactory
 
 $uiRenderer
 
 $access
 
 $sortationOptions
 
 $defaultSorting = 'date_DESC'
 

Private Member Functions

 getDefaultCommand ()
 

Private Attributes

 $template
 
 $controller
 
 $language
 
 $userCertificateRepository
 
 $user
 
 $request
 
 $certificateLogger
 
 $filesystem
 
 $migrationVisibleValidator
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilUserCertificateGUI::__construct ( ilTemplate  $template = null,
ilCtrl  $controller = null,
ilLanguage  $language = null,
ilObjUser  $user = null,
ilUserCertificateRepository  $userCertificateRepository = null,
GuzzleHttp\Psr7\Request  $request = null,
ilLogger  $certificateLogger = null,
ilSetting  $certificateSettings = null,
Factory  $uiFactory = null,
Renderer  $uiRenderer = null,
\ilAccessHandler  $access = null,
\ILIAS\Filesystem\Filesystem  $filesystem = null,
ilCertificateMigrationValidator  $migrationVisibleValidator = null 
)
Parameters
ilTemplate | null$template
ilCtrl | null$controller
ilLanguage | null$language
ilObjUser$user
ilUserCertificateRepository | null$userCertificateRepository
\GuzzleHttp\Psr7\Request | null$request
ilLogger$certificateLogger
ilSetting | null$certificateSettings
Factory | null$uiFactory
Renderer | null$uiRenderer
\ilAccessHandler | null$access
\ILIAS\Filesystem\Filesystem | null$filesystem
ilCertificateMigrationValidator | null$migrationVisibleValidator

Definition at line 85 of file class.ilUserCertificateGUI.php.

References $access, $certificateLogger, $certificateSettings, $controller, $DIC, $filesystem, $language, $migrationVisibleValidator, $request, $template, $uiFactory, $uiRenderer, $user, $userCertificateRepository, and user().

99  {
100  global $DIC;
101 
102  $logger = $DIC->logger()->cert();
103 
104  if ($template === null) {
105  $template = $DIC->ui()->mainTemplate();
106  }
107  $this->template = $template;
108 
109  if ($controller === null) {
110  $controller = $DIC->ctrl();
111  }
112  $this->controller = $controller;
113 
114  if ($language === null) {
115  $language = $DIC->language();
116  }
117  $this->language = $language;
118 
119  if ($userCertificateRepository === null) {
120  $userCertificateRepository = new ilUserCertificateRepository($DIC->database(), $logger);
121  }
122  $this->userCertificateRepository = $userCertificateRepository;
123 
124  if ($user === null) {
125  $user = $DIC->user();
126  }
127  $this->user = $user;
128 
129  if ($request === null) {
130  $request = $DIC->http()->request();
131  }
132  $this->request = $request;
133 
134  if ($certificateLogger === null) {
135  $certificateLogger = $DIC->logger()->cert();
136  }
137  $this->certificateLogger = $certificateLogger;
138 
139  if ($certificateSettings === null) {
140  $certificateSettings = new ilSetting("certificate");
141  }
142  $this->certificateSettings = $certificateSettings;
143 
144  if (null === $uiFactory) {
145  $uiFactory = $DIC->ui()->factory();
146  }
147  $this->uiFactory = $uiFactory;
148 
149  if (null === $uiRenderer) {
150  $uiRenderer = $DIC->ui()->renderer();
151  }
152  $this->uiRenderer = $uiRenderer;
153 
154  if (null === $access) {
155  $access = $DIC->access();
156  }
157  $this->access = $access;
158 
159  if (null === $filesystem) {
160  $filesystem = $DIC->filesystem()->web();
161  }
162  $this->filesystem = $filesystem;
163 
164  if (null === $migrationVisibleValidator) {
165  $migrationVisibleValidator = new ilCertificateMigrationValidator($this->certificateSettings);
166  }
167  $this->migrationVisibleValidator = $migrationVisibleValidator;
168 
169  $this->language->loadLanguageModule('cert');
170  }
global $DIC
Definition: saml.php:7
user()
Definition: user.php:4
+ Here is the call graph for this function:

Member Function Documentation

◆ applySortation()

ilUserCertificateGUI::applySortation ( )
protected

Definition at line 381 of file class.ilUserCertificateGUI.php.

References $defaultSorting, listCertificates(), and ilSession\set().

382  {
383  $sorting = $this->request->getQueryParams()['sort_by'] ?? $this->defaultSorting;
384  if (!array_key_exists($sorting, $this->sortationOptions)) {
385  $sorting = $this->defaultSorting;
386  }
387  \ilSession::set(self::SORTATION_SESSION_KEY, $sorting);
388 
389  $this->listCertificates();
390  }
static set($a_var, $a_val)
Set a value.
listCertificates(bool $migrationWasStarted=false)
+ Here is the call graph for this function:

◆ download()

ilUserCertificateGUI::download ( )
Exceptions

Definition at line 395 of file class.ilUserCertificateGUI.php.

References $DIC, $language, $user, $userCertificateRepository, ilCertificatePdfAction\downloadPdf(), listCertificates(), and ilUtil\sendFailure().

396  {
397  global $DIC;
398 
399  $user = $DIC->user();
400  $language = $DIC->language();
401 
402  $userCertificateRepository = new ilUserCertificateRepository(null, $this->certificateLogger);
403  $pdfGenerator = new ilPdfGenerator($userCertificateRepository, $this->certificateLogger);
404 
405  $userCertificateId = (int) $this->request->getQueryParams()['certificate_id'];
406 
407  try {
408  $userCertificate = $userCertificateRepository->fetchCertificate($userCertificateId);
409  if ((int) $userCertificate->getUserId() !== (int) $user->getId()) {
410  throw new ilException(sprintf('User "%s" tried to access certificate: "%s"', $user->getLogin(), $userCertificateId));
411  }
412  } catch (ilException $exception) {
413  $this->certificateLogger->warning($exception->getMessage());
414  ilUtil::sendFailure($language->txt('cert_error_no_access'));
415  $this->listCertificates();
416  return;
417  }
418 
419  $pdfAction = new ilCertificatePdfAction(
420  $this->certificateLogger,
421  $pdfGenerator,
423  $this->language->txt('error_creating_certificate_pdf')
424  );
425 
426  $pdfAction->downloadPdf($userCertificate->getUserId(), $userCertificate->getObjId());
427 
428  $this->listCertificates();
429  }
Class ilPdfGeneratorConstantsTest.
global $DIC
Definition: saml.php:7
listCertificates(bool $migrationWasStarted=false)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Just a wrapper class to create Unit Test for other classes.
downloadPdf(int $userId, int $objectId)
+ Here is the call graph for this function:

◆ executeCommand()

ilUserCertificateGUI::executeCommand ( )
Returns
bool
Exceptions
ilDateTimeException
ilException

Definition at line 185 of file class.ilUserCertificateGUI.php.

References getDefaultCommand(), listCertificates(), and ilTemplate\MESSAGE_TYPE_SUCCESS.

186  {
187  $nextClass = $this->controller->getNextClass($this);
188  $cmd = $this->controller->getCmd();
189 
190  if (!$this->certificateSettings->get('active')) {
191  $this->controller->returnToParent($this);
192  }
193 
194  $this->template->setTitle($this->language->txt('obj_cert'));
195 
196  switch ($nextClass) {
197  case 'ilcertificatemigrationgui':
198  $migrationGui = new \ilCertificateMigrationGUI();
199  $resultMessageString = $this->controller->forwardCommand($migrationGui);
200  $this->template->setMessage(\ilTemplate::MESSAGE_TYPE_SUCCESS, $resultMessageString, true);
201  $this->listCertificates(true);
202  break;
203 
204  default:
205  if (!method_exists($this, $cmd)) {
206  $cmd = $this->getDefaultCommand();
207  }
208  $this->{$cmd}();
209  }
210 
211  return true;
212  }
listCertificates(bool $migrationWasStarted=false)
const MESSAGE_TYPE_SUCCESS
+ Here is the call graph for this function:

◆ getCurrentSortation()

ilUserCertificateGUI::getCurrentSortation ( )
protected
Returns
string

Definition at line 368 of file class.ilUserCertificateGUI.php.

References $defaultSorting, and ilSession\get().

Referenced by listCertificates().

368  : string
369  {
370  $sorting = \ilSession::get(self::SORTATION_SESSION_KEY);
371  if (!array_key_exists($sorting, $this->sortationOptions)) {
372  $sorting = $this->defaultSorting;
373  }
374 
375  return $sorting;
376  }
static get($a_var)
Get a value.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultCommand()

ilUserCertificateGUI::getDefaultCommand ( )
private
Returns
string

Definition at line 175 of file class.ilUserCertificateGUI.php.

Referenced by executeCommand().

175  : string
176  {
177  return 'listCertificates';
178  }
+ Here is the caller graph for this function:

◆ listCertificates()

ilUserCertificateGUI::listCertificates ( bool  $migrationWasStarted = false)
Parameters
bool$migrationWasStarted
Exceptions
ilDateTimeException
ilWACException

Definition at line 219 of file class.ilUserCertificateGUI.php.

References $certificateLogger, $controller, $data, $DIC, PHPMailer\PHPMailer\$provider, $sortationOptions, ilObject\_getAllReferences(), ilLink\_getLink(), ilDatePresentation\formatDate(), getCurrentSortation(), ilUtil\getImagePath(), ilUtil\getWebspaceDir(), IL_CAL_UNIX, ilUtil\sendInfo(), ilDatePresentation\setUseRelativeDates(), ilWACSignedPath\signFile(), user(), and ilDatePresentation\useRelativeDates().

Referenced by applySortation(), download(), and executeCommand().

220  {
221  global $DIC;
222 
223  if (!$this->certificateSettings->get('active')) {
224  $this->controller->redirect($this);
225  return;
226  }
227 
228  $this->template->setBodyClass('iosMyCertificates');
229 
230  $showMigrationBox = $this->migrationVisibleValidator->isMigrationAvailable(
231  $this->user,
232  new \ilCertificateMigration($this->user->getId())
233  );
234  if (!$migrationWasStarted && true === $showMigrationBox) {
235  $migrationUiEl = new \ilCertificateMigrationUIElements();
236  $startMigrationCommand = $this->controller->getLinkTargetByClass(
237  ['ilCertificateMigrationGUI'],
238  'startMigrationAndReturnMessage',
239  false,
240  true,
241  false
242  );
243  $messageBoxHtml = $migrationUiEl->getMigrationMessageBox($startMigrationCommand);
244 
245  $this->template->setCurrentBlock('mess');
246  $this->template->setVariable('MESSAGE', $messageBoxHtml);
247  $this->template->parseCurrentBlock('mess');
248  }
249 
251  $DIC->database(),
254  $this->language->txt('certificate_no_object_title')
255  );
256 
257  $sorting = $this->getCurrentSortation();
258  $data = $provider->fetchDataSet(
259  $this->user->getId(),
260  [
261  'order_field' => explode('_', $sorting)[0],
262  'order_direction' => explode('_', $sorting)[1]
263  ],
264  []
265  );
266 
267  $uiComponents = [];
268 
269  if (count($data['items']) > 0) {
270  $sortationOptions = [];
271  $cards = [];
272 
273  foreach ($this->sortationOptions as $fieldAndDirection => $lngVariable) {
274  $sortationOptions[$fieldAndDirection] = $this->language->txt($lngVariable);
275  }
276 
277  $sortViewControl = $this->uiFactory
278  ->viewControl()
279  ->sortation($sortationOptions)
280  ->withLabel($this->language->txt($this->sortationOptions[$sorting]))
281  ->withTargetURL($this->controller->getLinkTarget($this, 'applySortation'), 'sort_by');
282  $uiComponents[] = $sortViewControl;
283 
284  foreach ($data['items'] as $certificateData) {
285  $thumbnailImagePath = $certificateData['thumbnail_image_path'];
286  $imagePath = ilUtil::getWebspaceDir() . $thumbnailImagePath;
287  if ($thumbnailImagePath === null
288  || $thumbnailImagePath === ''
289  || !$this->filesystem->has($thumbnailImagePath)
290  ) {
291  $imagePath = \ilUtil::getImagePath('icon_cert.svg');
292  }
293 
294  $cardImage = $this->uiFactory->image()->standard(
295  ilWACSignedPath::signFile($imagePath),
296  $certificateData['title']
297  );
298 
299 
300  $sections = [];
301 
302  if (strlen($certificateData['description']) > 0) {
303  $sections[] = $this->uiFactory->listing()->descriptive([
304  $this->language->txt('cert_description_label') => $certificateData['description']
305  ]);
306  }
307 
308 
309  $oldDatePresentationStatus = \ilDatePresentation::useRelativeDates();
311  $sections[] = $this->uiFactory->listing()->descriptive([
312  $this->language->txt('cert_issued_on_label') => \ilDatePresentation::formatDate(
313  new \ilDateTime($certificateData['date'], \IL_CAL_UNIX)
314  )
315  ]);
316  \ilDatePresentation::setUseRelativeDates($oldDatePresentationStatus);
317 
318  $objectTypeIcon = $this->uiFactory
319  ->icon()
320  ->standard($certificateData['obj_type'], $certificateData['obj_type'], 'small');
321 
322  $objectTitle = $certificateData['title'];
323  $refIds = \ilObject::_getAllReferences($certificateData['obj_id']);
324  if (count($refIds) > 0) {
325  foreach ($refIds as $refId) {
326  if ($this->access->checkAccess('read', '', $refId)) {
327  $objectTitle = $this->uiRenderer->render(
328  $this->uiFactory->link()->standard($objectTitle, \ilLink::_getLink($refId))
329  );
330  break;
331  }
332  }
333  }
334 
335  $sections[] = $this->uiFactory->listing()->descriptive([$this->language->txt('cert_object_label') => implode('', [
336  $this->uiRenderer->render($objectTypeIcon),
337  $objectTitle
338  ])]);
339 
340  $this->controller->setParameter($this, 'certificate_id', $certificateData['id']);
341  $downloadHref = $this->controller->getLinkTarget($this, 'download');
342  $this->controller->clearParameters($this);
343  $sections[] = $this->uiFactory->button()->standard('Download', $downloadHref);
344 
345  $card = $this->uiFactory
346  ->card()
347  ->standard($certificateData['title'], $cardImage)
348  ->withSections($sections);
349 
350  $cards[] = $card;
351  }
352 
353  $deck = $this->uiFactory->deck($cards);
354 
355  $uiComponents[] = $this->uiFactory->divider()->horizontal();
356 
357  $uiComponents[] = $deck;
358  } else {
359  \ilUtil::sendInfo($this->language->txt('cert_currently_no_certs'));
360  }
361 
362  $this->template->setContent($this->uiRenderer->render($uiComponents));
363  }
global $DIC
Definition: saml.php:7
static setUseRelativeDates($a_status)
set use relative dates
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
user()
Definition: user.php:4
static _getAllReferences($a_id)
get all reference ids of object
static useRelativeDates()
check if relative dates are used
Class ilCertificateMigration.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Date and time handling
static signFile($path_to_file)
static getWebspaceDir($mode="filesystem")
get webspace directory
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilUserCertificateGUI::$access
protected

Definition at line 45 of file class.ilUserCertificateGUI.php.

Referenced by __construct().

◆ $certificateLogger

ilUserCertificateGUI::$certificateLogger
private

Definition at line 33 of file class.ilUserCertificateGUI.php.

Referenced by __construct(), and listCertificates().

◆ $certificateSettings

ilUserCertificateGUI::$certificateSettings
protected

Definition at line 36 of file class.ilUserCertificateGUI.php.

Referenced by __construct().

◆ $controller

ilUserCertificateGUI::$controller
private

Definition at line 18 of file class.ilUserCertificateGUI.php.

Referenced by __construct(), and listCertificates().

◆ $defaultSorting

ilUserCertificateGUI::$defaultSorting = 'date_DESC'
protected

Definition at line 60 of file class.ilUserCertificateGUI.php.

Referenced by applySortation(), and getCurrentSortation().

◆ $filesystem

ilUserCertificateGUI::$filesystem
private

Definition at line 63 of file class.ilUserCertificateGUI.php.

Referenced by __construct().

◆ $language

ilUserCertificateGUI::$language
private

Definition at line 21 of file class.ilUserCertificateGUI.php.

Referenced by __construct(), and download().

◆ $migrationVisibleValidator

ilUserCertificateGUI::$migrationVisibleValidator
private

Definition at line 68 of file class.ilUserCertificateGUI.php.

Referenced by __construct().

◆ $request

ilUserCertificateGUI::$request
private

Definition at line 30 of file class.ilUserCertificateGUI.php.

Referenced by __construct().

◆ $sortationOptions

ilUserCertificateGUI::$sortationOptions
protected
Initial value:
= [
'title_ASC' => 'cert_sortable_by_title_asc'

Definition at line 52 of file class.ilUserCertificateGUI.php.

Referenced by listCertificates().

◆ $template

ilUserCertificateGUI::$template
private

Definition at line 15 of file class.ilUserCertificateGUI.php.

Referenced by __construct().

◆ $uiFactory

ilUserCertificateGUI::$uiFactory
protected

Definition at line 39 of file class.ilUserCertificateGUI.php.

Referenced by __construct().

◆ $uiRenderer

ilUserCertificateGUI::$uiRenderer
protected

Definition at line 42 of file class.ilUserCertificateGUI.php.

Referenced by __construct().

◆ $user

ilUserCertificateGUI::$user
private

Definition at line 27 of file class.ilUserCertificateGUI.php.

Referenced by __construct(), and download().

◆ $userCertificateRepository

ilUserCertificateGUI::$userCertificateRepository
private

Definition at line 24 of file class.ilUserCertificateGUI.php.

Referenced by __construct(), and download().

◆ SORTATION_SESSION_KEY

const ilUserCertificateGUI::SORTATION_SESSION_KEY = 'my_certificates_sorting'

Definition at line 47 of file class.ilUserCertificateGUI.php.


The documentation for this class was generated from the following file: