ILIAS  release_7 Revision v7.30-3-g800a261c036
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)
 
 executeCommand ()
 
 listCertificates ()
 
 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
 

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 
)
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

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

92 {
93 global $DIC;
94
95 $logger = $DIC->logger()->cert();
96
97 if ($template === null) {
98 $template = $DIC->ui()->mainTemplate();
99 }
100 $this->template = $template;
101
102 if ($controller === null) {
103 $controller = $DIC->ctrl();
104 }
105 $this->controller = $controller;
106
107 if ($language === null) {
108 $language = $DIC->language();
109 }
110 $this->language = $language;
111
112 if ($user === null) {
113 $user = $DIC->user();
114 }
115 $this->user = $user;
116
117
118 if ($request === null) {
119 $request = $DIC->http()->request();
120 }
121 $this->request = $request;
122
123 if ($certificateLogger === null) {
124 $certificateLogger = $DIC->logger()->cert();
125 }
126 $this->certificateLogger = $certificateLogger;
127
128 if ($certificateSettings === null) {
129 $certificateSettings = new ilSetting("certificate");
130 }
131 $this->certificateSettings = $certificateSettings;
132
133 if (null === $uiFactory) {
134 $uiFactory = $DIC->ui()->factory();
135 }
136 $this->uiFactory = $uiFactory;
137
138 if (null === $uiRenderer) {
139 $uiRenderer = $DIC->ui()->renderer();
140 }
141 $this->uiRenderer = $uiRenderer;
142
143 if (null === $access) {
144 $access = $DIC->access();
145 }
146 $this->access = $access;
147
148 if (null === $filesystem) {
149 $filesystem = $DIC->filesystem()->web();
150 }
151 $this->filesystem = $filesystem;
152
153 if ($userCertificateRepository === null) {
154 $userCertificateRepository = new ilUserCertificateRepository(null, $this->certificateLogger);
155 }
156 $this->userCertificateRepository = $userCertificateRepository;
157
158 $this->language->loadLanguageModule('cert');
159 $this->language->loadLanguageModule('cert');
160 }
user()
Definition: user.php:4
ILIAS Setting Class.
global $DIC
Definition: goto.php:24
language()
Definition: language.php:2

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

+ Here is the call graph for this function:

Member Function Documentation

◆ applySortation()

ilUserCertificateGUI::applySortation ( )
protected

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

344 {
345 $sorting = $this->request->getQueryParams()['sort_by'] ?? $this->defaultSorting;
346 if (!array_key_exists($sorting, $this->sortationOptions)) {
347 $sorting = $this->defaultSorting;
348 }
349 \ilSession::set(self::SORTATION_SESSION_KEY, $sorting);
350
351 $this->listCertificates();
352 }
static set($a_var, $a_val)
Set a value.

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

+ Here is the call graph for this function:

◆ download()

ilUserCertificateGUI::download ( )
Exceptions

ilException

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

358 {
359 global $DIC;
360
362 $language = $DIC->language();
363
364 $pdfGenerator = new ilPdfGenerator($this->userCertificateRepository, $this->certificateLogger);
365
366 $userCertificateId = (int) $this->request->getQueryParams()['certificate_id'];
367
368 try {
369 $userCertificate = $this->userCertificateRepository->fetchCertificate($userCertificateId);
370 if ((int) $userCertificate->getUserId() !== (int) $user->getId()) {
371 throw new ilException(sprintf('User "%s" tried to access certificate: "%s"', $user->getLogin(), $userCertificateId));
372 }
373 } catch (ilException $exception) {
374 $this->certificateLogger->warning($exception->getMessage());
375 ilUtil::sendFailure($language->txt('cert_error_no_access'));
376 $this->listCertificates();
377 return;
378 }
379
380 $pdfAction = new ilCertificatePdfAction(
381 $this->certificateLogger,
382 $pdfGenerator,
384 $this->language->txt('error_creating_certificate_pdf')
385 );
386
387 $pdfAction->downloadPdf($userCertificate->getUserId(), $userCertificate->getObjId());
388
389 $this->listCertificates();
390 }
Just a wrapper class to create Unit Test for other classes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilPdfGeneratorConstantsTest.

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

+ Here is the call graph for this function:

◆ executeCommand()

ilUserCertificateGUI::executeCommand ( )
Returns
bool
Exceptions
ilDateTimeException
ilException

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

176 {
177 $nextClass = $this->controller->getNextClass($this);
178 $cmd = $this->controller->getCmd();
179
180 if (!$this->certificateSettings->get('active')) {
181 $this->controller->returnToParent($this);
182 }
183
184 $this->template->setTitle($this->language->txt('obj_cert'));
185
186 switch ($nextClass) {
187 default:
188 if (!method_exists($this, $cmd)) {
189 $cmd = $this->getDefaultCommand();
190 }
191 $this->{$cmd}();
192 }
193
194 return true;
195 }

References getDefaultCommand(), and language().

+ Here is the call graph for this function:

◆ getCurrentSortation()

ilUserCertificateGUI::getCurrentSortation ( )
protected
Returns
string

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

330 : string
331 {
332 $sorting = \ilSession::get(self::SORTATION_SESSION_KEY);
333 if (!array_key_exists($sorting, $this->sortationOptions)) {
334 $sorting = $this->defaultSorting;
335 }
336
337 return $sorting;
338 }
static get($a_var)
Get a value.

References $defaultSorting, and ilSession\get().

Referenced by listCertificates().

+ 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 165 of file class.ilUserCertificateGUI.php.

165 : string
166 {
167 return 'listCertificates';
168 }

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ listCertificates()

ilUserCertificateGUI::listCertificates ( )
Exceptions
ilDateTimeException
ilWACException

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

202 {
203 global $DIC;
204
205 if (!$this->certificateSettings->get('active')) {
206 $this->controller->redirect($this);
207 return;
208 }
209
210 $provider = new ilUserCertificateTableProvider(
211 $DIC->database(),
212 $this->certificateLogger,
213 $this->controller,
214 $this->language->txt('certificate_no_object_title')
215 );
216
217 $sorting = $this->getCurrentSortation();
218 $data = $provider->fetchDataSet(
219 $this->user->getId(),
220 [
221 'order_field' => explode('_', $sorting)[0],
222 'order_direction' => explode('_', $sorting)[1],
223 'language' => $this->user->getLanguage()
224 ],
225 []
226 );
227
228 $uiComponents = [];
229
230 if (count($data['items']) > 0) {
232 $cards = [];
233
234 foreach ($this->sortationOptions as $fieldAndDirection => $lngVariable) {
235 $sortationOptions[$fieldAndDirection] = $this->language->txt($lngVariable);
236 }
237
238 $sortViewControl = $this->uiFactory
239 ->viewControl()
240 ->sortation($sortationOptions)
241 ->withLabel($this->language->txt($this->sortationOptions[$sorting]))
242 ->withTargetURL($this->controller->getLinkTarget($this, 'applySortation'), 'sort_by');
243 $uiComponents[] = $sortViewControl;
244
245 foreach ($data['items'] as $certificateData) {
246 $thumbnailImagePath = $certificateData['thumbnail_image_path'];
247 $imagePath = ilUtil::getWebspaceDir() . $thumbnailImagePath;
248 if ($thumbnailImagePath === null
249 || $thumbnailImagePath === ''
250 || !$this->filesystem->has($thumbnailImagePath)
251 ) {
252 $imagePath = \ilUtil::getImagePath('icon_cert.svg');
253 }
254
255 $cardImage = $this->uiFactory->image()->standard(
256 ilWACSignedPath::signFile($imagePath),
257 $certificateData['title']
258 );
259
260
261 $sections = [];
262
263 if (strlen($certificateData['description']) > 0) {
264 $sections[] = $this->uiFactory->listing()->descriptive([
265 $this->language->txt('cert_description_label') => $certificateData['description']
266 ]);
267 }
268
269
270 $oldDatePresentationStatus = \ilDatePresentation::useRelativeDates();
272 $sections[] = $this->uiFactory->listing()->descriptive([
273 $this->language->txt('cert_issued_on_label') => \ilDatePresentation::formatDate(
274 new \ilDateTime($certificateData['date'], \IL_CAL_UNIX)
275 )
276 ]);
277 \ilDatePresentation::setUseRelativeDates($oldDatePresentationStatus);
278
279 $objectTypeIcon = $this->uiFactory
280 ->symbol()
281 ->icon()
282 ->standard($certificateData['obj_type'], $certificateData['obj_type'], 'small');
283
284 $objectTitle = $certificateData['title'];
285 $refIds = \ilObject::_getAllReferences($certificateData['obj_id']);
286 if (count($refIds) > 0) {
287 foreach ($refIds as $refId) {
288 if ($this->access->checkAccess('read', '', $refId)) {
289 $objectTitle = $this->uiRenderer->render(
290 $this->uiFactory->link()->standard($objectTitle, \ilLink::_getLink($refId))
291 );
292 break;
293 }
294 }
295 }
296
297 $sections[] = $this->uiFactory->listing()->descriptive([$this->language->txt('cert_object_label') => implode('', [
298 $this->uiRenderer->render($objectTypeIcon),
299 $objectTitle
300 ])]);
301
302 $this->controller->setParameter($this, 'certificate_id', $certificateData['id']);
303 $downloadHref = $this->controller->getLinkTarget($this, 'download');
304 $this->controller->clearParameters($this);
305 $sections[] = $this->uiFactory->button()->standard('Download', $downloadHref);
306
307 $card = $this->uiFactory
308 ->card()
309 ->standard($certificateData['title'], $cardImage)
310 ->withSections($sections);
311
312 $cards[] = $card;
313 }
314
315 $deck = $this->uiFactory->deck($cards)->withSmallCardsSize();
316
317 $uiComponents[] = $this->uiFactory->divider()->horizontal();
318
319 $uiComponents[] = $deck;
320 } else {
321 \ilUtil::sendInfo($this->language->txt('cert_currently_no_certs'));
322 }
323
324 $this->template->setContent($this->uiRenderer->render($uiComponents));
325 }
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
@classDescription Date and time handling
static _getAllReferences($a_id)
get all reference ids of object
static getWebspaceDir($mode="filesystem")
get webspace directory
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)
static signFile($path_to_file)
$data
Definition: storeScorm.php:23
$refId
Definition: xapitoken.php:40

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

Referenced by applySortation(), and download().

+ 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().

◆ $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().

◆ $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().

◆ $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',
'title_DESC' => 'cert_sortable_by_title_desc',
'date_ASC' => 'cert_sortable_by_issue_date_asc',
'date_DESC' => 'cert_sortable_by_issue_date_desc',
]

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().

◆ 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: