ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilUserCertificateGUI Class Reference

ilUserCertificateGUI: ilAchievementsGUI More...

+ Collaboration diagram for ilUserCertificateGUI:

Public Member Functions

 __construct (?ilGlobalTemplateInterface $template=null, ?ilCtrlInterface $ctrl=null, ?ilLanguage $language=null, ?ilObjUser $user=null, ?ilUserCertificateRepository $userCertificateRepository=null, ?ServerRequestInterface $request=null, ?ilLogger $certificateLogger=null, ?ilSetting $certificateSettings=null, ?Factory $uiFactory=null, ?Renderer $uiRenderer=null, ?ilAccessHandler $access=null, ?Filesystem $filesystem=null, ?ilHelpGUI $help=null)
 
 executeCommand ()
 
 listCertificates ()
 
 download ()
 

Data Fields

final const SORTATION_SESSION_KEY = 'my_certificates_sorting'
 

Protected Member Functions

 getCurrentSortation ()
 
 applySortation ()
 

Protected Attributes

ilSetting $certificateSettings
 
Factory $uiFactory
 
Renderer $uiRenderer
 
ilAccessHandler $access
 
ilHelpGUI $help
 
array $sortationOptions
 
array string $defaultSorting = 'date_DESC'
 

Private Member Functions

 getDefaultCommand ()
 

Private Attributes

readonly ilGlobalTemplateInterface $template
 
readonly ilCtrlInterface $ctrl
 
readonly ilLanguage $language
 
readonly ilUserCertificateRepository $userCertificateRepository
 
readonly ilObjUser $user
 
readonly ServerRequestInterface $request
 
readonly ilLogger $certificateLogger
 
readonly Filesystem $filesystem
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilUserCertificateGUI::__construct ( ?ilGlobalTemplateInterface  $template = null,
?ilCtrlInterface  $ctrl = null,
?ilLanguage  $language = null,
?ilObjUser  $user = null,
?ilUserCertificateRepository  $userCertificateRepository = null,
?ServerRequestInterface  $request = null,
?ilLogger  $certificateLogger = null,
?ilSetting  $certificateSettings = null,
?Factory  $uiFactory = null,
?Renderer  $uiRenderer = null,
?ilAccessHandler  $access = null,
?Filesystem  $filesystem = null,
?ilHelpGUI  $help = null 
)

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

References $access, $certificateLogger, $certificateSettings, $ctrl, $DIC, $filesystem, $language, $request, $template, $uiFactory, $uiRenderer, $user, $userCertificateRepository, ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ILIAS\Repository\filesystem(), ILIAS\Repository\help(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), and ILIAS\Repository\user().

71  {
72  global $DIC;
73 
74  if ($template === null) {
75  $template = $DIC->ui()->mainTemplate();
76  }
77  $this->template = $template;
78 
79  if ($ctrl === null) {
80  $ctrl = $DIC->ctrl();
81  }
82  $this->ctrl = $ctrl;
83 
84  if ($language === null) {
85  $language = $DIC->language();
86  }
87  $this->language = $language;
88 
89  if ($user === null) {
90  $user = $DIC->user();
91  }
92  $this->user = $user;
93 
94  if ($request === null) {
95  $request = $DIC->http()->request();
96  }
97  $this->request = $request;
98 
99  if ($certificateLogger === null) {
100  $certificateLogger = $DIC->logger()->cert();
101  }
102  $this->certificateLogger = $certificateLogger;
103 
104  if ($certificateSettings === null) {
105  $certificateSettings = new ilSetting("certificate");
106  }
107  $this->certificateSettings = $certificateSettings;
108 
109  if (null === $uiFactory) {
110  $uiFactory = $DIC->ui()->factory();
111  }
112  $this->uiFactory = $uiFactory;
113 
114  if (null === $uiRenderer) {
115  $uiRenderer = $DIC->ui()->renderer();
116  }
117  $this->uiRenderer = $uiRenderer;
118 
119  if (null === $access) {
120  $access = $DIC->access();
121  }
122  $this->access = $access;
123 
124  if (null === $filesystem) {
125  $filesystem = $DIC->filesystem()->web();
126  }
127  $this->filesystem = $filesystem;
128 
129  if ($userCertificateRepository === null) {
130  $userCertificateRepository = new ilUserCertificateRepository(null, $this->certificateLogger);
131  }
132  $this->userCertificateRepository = $userCertificateRepository;
133 
134  $this->help = $help ?? $DIC->help();
135 
136  $this->language->loadLanguageModule('cert');
137  }
readonly ilLogger $certificateLogger
global $DIC
Definition: feed.php:28
readonly ilCtrlInterface $ctrl
readonly ServerRequestInterface $request
readonly ilGlobalTemplateInterface $template
readonly ilUserCertificateRepository $userCertificateRepository
+ Here is the call graph for this function:

Member Function Documentation

◆ applySortation()

ilUserCertificateGUI::applySortation ( )
protected
Exceptions
ilWACException
ilDateTimeException

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

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

305  : void
306  {
307  $sorting = $this->request->getQueryParams()['sort_by'] ?? $this->defaultSorting;
308  if (!array_key_exists($sorting, $this->sortationOptions)) {
309  $sorting = $this->defaultSorting;
310  }
311  ilSession::set(self::SORTATION_SESSION_KEY, $sorting);
312 
313  $this->listCertificates();
314  }
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

◆ download()

ilUserCertificateGUI::download ( )
Exceptions
ilException

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

References ilCertificatePdfAction\downloadPdf(), ILIAS\Repository\int(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), listCertificates(), and ILIAS\Repository\user().

319  : void
320  {
321  $pdfGenerator = new ilPdfGenerator($this->userCertificateRepository);
322 
323  $userCertificateId = (int) $this->request->getQueryParams()['certificate_id'];
324 
325  try {
326  $userCertificate = $this->userCertificateRepository->fetchCertificate($userCertificateId);
327  if ($userCertificate->getUserId() !== $this->user->getId()) {
328  throw new ilException(sprintf(
329  'User "%s" tried to access certificate: "%s"',
330  $this->user->getLogin(),
331  $userCertificateId
332  ));
333  }
334  } catch (ilException $exception) {
335  $this->certificateLogger->warning($exception->getMessage());
336  $this->template->setOnScreenMessage('failure', $this->language->txt('cert_error_no_access'));
337  $this->listCertificates();
338  return;
339  }
340 
341  $pdfAction = new ilCertificatePdfAction(
342  $pdfGenerator,
344  $this->language->txt('error_creating_certificate_pdf')
345  );
346 
347  $pdfAction->downloadPdf($userCertificate->getUserId(), $userCertificate->getObjId());
348 
349  $this->listCertificates();
350  }
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 ( )

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

References ILIAS\Repository\ctrl(), getDefaultCommand(), and ILIAS\UI\examples\Symbol\Glyph\Language\language().

144  : bool
145  {
146  $cmd = $this->ctrl->getCmd();
147 
148  if (!$this->certificateSettings->get('active', '0')) {
149  $this->ctrl->returnToParent($this);
150  }
151 
152  $this->template->setTitle($this->language->txt('obj_cert'));
153  if (!method_exists($this, $cmd)) {
154  $cmd = $this->getDefaultCommand();
155  }
156  $this->{$cmd}();
157 
158  return true;
159  }
+ Here is the call graph for this function:

◆ getCurrentSortation()

ilUserCertificateGUI::getCurrentSortation ( )
protected

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

References $defaultSorting, and ilSession\get().

Referenced by listCertificates().

291  : string
292  {
293  $sorting = ilSession::get(self::SORTATION_SESSION_KEY);
294  if (!array_key_exists($sorting, $this->sortationOptions)) {
295  $sorting = $this->defaultSorting;
296  }
297 
298  return $sorting;
299  }
static get(string $a_var)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultCommand()

ilUserCertificateGUI::getDefaultCommand ( )
private

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

Referenced by executeCommand().

139  : string
140  {
141  return 'listCertificates';
142  }
+ Here is the caller graph for this function:

◆ listCertificates()

ilUserCertificateGUI::listCertificates ( )
Exceptions
ilDateTimeException
ilWACException

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

References $certificateLogger, $data, $DIC, $provider, $refId, ilObject\_getAllReferences(), ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ILIAS\Repository\filesystem(), ilDatePresentation\formatDate(), getCurrentSortation(), ilUtil\getImagePath(), ilFileUtils\getWebspaceDir(), ILIAS\Repository\help(), IL_CAL_UNIX, ILIAS\UI\examples\Symbol\Glyph\Language\language(), ilDatePresentation\setUseRelativeDates(), ilWACSignedPath\signFile(), ILIAS\Repository\user(), and ilDatePresentation\useRelativeDates().

Referenced by applySortation(), and download().

165  : void
166  {
167  global $DIC;
168 
169  $this->help->setScreenIdComponent('cert');
170 
171  if (!$this->certificateSettings->get('active', '0')) {
172  $this->ctrl->redirect($this);
173  }
174 
176  $DIC->database(),
178  $this->language->txt('certificate_no_object_title')
179  );
180 
181  $sorting = $this->getCurrentSortation();
182  $data = $provider->fetchDataSet(
183  $this->user->getId(),
184  [
185  'order_field' => explode('_', $sorting)[0],
186  'order_direction' => explode('_', $sorting)[1],
187  'language' => $this->user->getLanguage()
188  ],
189  []
190  );
191 
192  $uiComponents = [];
193 
194  if ($data['items'] !== []) {
195  $sortationOptions = [];
196  $cards = [];
197 
198  foreach ($this->sortationOptions as $fieldAndDirection => $lngVariable) {
199  $sortationOptions[$fieldAndDirection] = $this->language->txt($lngVariable);
200  }
201 
202  $sortViewControl = $this->uiFactory
203  ->viewControl()
204  ->sortation($sortationOptions)
205  ->withLabel($this->language->txt($this->sortationOptions[$sorting]))
206  ->withTargetURL($this->ctrl->getLinkTarget($this, 'applySortation'), 'sort_by');
207  $uiComponents[] = $sortViewControl;
208 
209  foreach ($data['items'] as $certificateData) {
210  $thumbnailImagePath = $certificateData['thumbnail_image_path'];
211  $imagePath = ilFileUtils::getWebspaceDir() . $thumbnailImagePath;
212  if ($thumbnailImagePath === null
213  || $thumbnailImagePath === ''
214  || !$this->filesystem->has($thumbnailImagePath)
215  ) {
216  $imagePath = ilUtil::getImagePath('standard/icon_cert.svg');
217  }
218 
219  $cardImage = $this->uiFactory->image()->standard(
220  ilWACSignedPath::signFile($imagePath),
221  $certificateData['title']
222  );
223 
224  $sections = [];
225 
226  if ($certificateData['description'] !== '') {
227  $sections[] = $this->uiFactory->listing()->descriptive([
228  $this->language->txt('cert_description_label') => $certificateData['description']
229  ]);
230  }
231 
232  $oldDatePresentationStatus = ilDatePresentation::useRelativeDates();
234  $sections[] = $this->uiFactory->listing()->descriptive([
235  $this->language->txt('cert_issued_on_label') => ilDatePresentation::formatDate(
236  new ilDateTime($certificateData['date'], IL_CAL_UNIX)
237  )
238  ]);
239  ilDatePresentation::setUseRelativeDates($oldDatePresentationStatus);
240 
241  $objectTypeIcon = $this->uiFactory
242  ->symbol()
243  ->icon()
244  ->standard($certificateData['obj_type'], $certificateData['obj_type']);
245 
246  $objectTitle = $certificateData['title'];
247  $refIds = ilObject::_getAllReferences((int) $certificateData['obj_id']);
248  foreach ($refIds as $refId) {
249  if ($this->access->checkAccess('read', '', $refId)) {
250  $objectTitle = $this->uiRenderer->render(
251  $this->uiFactory->link()->standard($objectTitle, ilLink::_getLink($refId))
252  );
253  break;
254  }
255  }
256 
257  $sections[] = $this->uiFactory->listing()->descriptive([$this->language->txt('cert_object_label') => implode(
258  '',
259  [
260  $this->uiRenderer->render($objectTypeIcon),
261  $objectTitle
262  ]
263  )
264  ]);
265 
266  $this->ctrl->setParameter($this, 'certificate_id', $certificateData['id']);
267  $downloadHref = $this->ctrl->getLinkTarget($this, 'download');
268  $this->ctrl->clearParameters($this);
269  $sections[] = $this->uiFactory->button()->standard('Download', $downloadHref);
270 
271  $card = $this->uiFactory
272  ->card()
273  ->standard($certificateData['title'], $cardImage)
274  ->withSections($sections);
275 
276  $cards[] = $card;
277  }
278 
279  $deck = $this->uiFactory->deck($cards)->withSmallCardsSize();
280 
281  $uiComponents[] = $this->uiFactory->divider()->horizontal();
282 
283  $uiComponents[] = $deck;
284  } else {
285  $this->template->setOnScreenMessage('info', $this->language->txt('cert_currently_no_certs'));
286  }
287 
288  $this->template->setContent($this->uiRenderer->render($uiComponents));
289  }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static _getAllReferences(int $id)
get all reference ids for object ID
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
readonly ilLogger $certificateLogger
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
$refId
Definition: xapitoken.php:58
const IL_CAL_UNIX
global $DIC
Definition: feed.php:28
$provider
Definition: ltitoken.php:83
static signFile(string $path_to_file)
static setUseRelativeDates(bool $a_status)
set use relative dates
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilUserCertificateGUI::$access
protected

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

Referenced by __construct().

◆ $certificateLogger

readonly ilLogger ilUserCertificateGUI::$certificateLogger
private

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

Referenced by __construct(), and listCertificates().

◆ $certificateSettings

ilSetting ilUserCertificateGUI::$certificateSettings
protected

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

Referenced by __construct().

◆ $ctrl

readonly ilCtrlInterface ilUserCertificateGUI::$ctrl
private

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

Referenced by __construct().

◆ $defaultSorting

array string ilUserCertificateGUI::$defaultSorting = 'date_DESC'
protected

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

Referenced by applySortation(), and getCurrentSortation().

◆ $filesystem

readonly Filesystem ilUserCertificateGUI::$filesystem
private

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

Referenced by __construct().

◆ $help

ilHelpGUI ilUserCertificateGUI::$help
protected

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

◆ $language

readonly ilLanguage ilUserCertificateGUI::$language
private

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

Referenced by __construct().

◆ $request

readonly ServerRequestInterface ilUserCertificateGUI::$request
private

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

Referenced by __construct().

◆ $sortationOptions

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

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

◆ $template

readonly ilGlobalTemplateInterface ilUserCertificateGUI::$template
private

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

Referenced by __construct().

◆ $uiFactory

Factory ilUserCertificateGUI::$uiFactory
protected

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

Referenced by __construct().

◆ $uiRenderer

Renderer ilUserCertificateGUI::$uiRenderer
protected

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

Referenced by __construct().

◆ $user

readonly ilObjUser ilUserCertificateGUI::$user
private

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

Referenced by __construct().

◆ $userCertificateRepository

readonly ilUserCertificateRepository ilUserCertificateGUI::$userCertificateRepository
private

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

Referenced by __construct().

◆ SORTATION_SESSION_KEY

final const ilUserCertificateGUI::SORTATION_SESSION_KEY = 'my_certificates_sorting'

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


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