ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilUserCertificateGUI Class Reference

@ilCtrl_IsCalledBy 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, private readonly ilSetting $certificateSettings=new ilSetting('certificate'), ?Factory $uiFactory=null, ?Renderer $uiRenderer=null, ?ilAccessHandler $access=null, ?Filesystem $filesystem=null, ?ilHelpGUI $help=null, ?ilDBInterface $db=null, private ?IRSS $irss=null)
 
 executeCommand ()
 
 listCertificates ()
 
 download ()
 

Data Fields

final const SORTATION_SESSION_KEY = 'my_certificates_sorting'
 

Protected Member Functions

 getCurrentSortation ()
 
 applySortation ()
 

Protected Attributes

array $sortationOptions
 
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 Factory $uiFactory
 
readonly Renderer $uiRenderer
 
readonly ilAccessHandler $access
 
readonly ilHelpGUI $help
 
readonly ilDBInterface $db
 
readonly Filesystem $filesystem
 

Detailed Description

@ilCtrl_IsCalledBy ilUserCertificateGUI: ilAchievementsGUI

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

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,
private readonly ilSetting  $certificateSettings = new ilSetting('certificate'),
?Factory  $uiFactory = null,
?Renderer  $uiRenderer = null,
?ilAccessHandler  $access = null,
?Filesystem  $filesystem = null,
?ilHelpGUI  $help = null,
?ilDBInterface  $db = null,
private ?IRSS  $irss = null 
)

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

76 {
77 global $DIC;
78
79 $this->template = $template ?? $DIC->ui()->mainTemplate();
80 $this->ctrl = $ctrl ?? $DIC->ctrl();
81 $this->user = $user ?? $DIC->user();
82 $this->language = $language ?? $DIC->language();
83 $this->request = $request ?? $DIC->http()->request();
84 $this->certificateLogger = $certificateLogger ?? $DIC->logger()->cert();
85 $this->uiFactory = $uiFactory ?? $DIC->ui()->factory();
86 $this->uiRenderer = $uiRenderer ?? $DIC->ui()->renderer();
87 $this->access = $access ?? $DIC->access();
88 $this->filesystem = $filesystem ?? $DIC->filesystem()->web();
89 $this->userCertificateRepository = $userCertificateRepository ?? new ilUserCertificateRepository(null, $this->certificateLogger);
90 $this->help = $help ?? $DIC->help();
91 $this->db = $db ?? $DIC->database();
92 $this->irss = $irss ?? $DIC->resourceStorage();
93
94 $this->language->loadLanguageModule('cert');
95 }
readonly ServerRequestInterface $request
readonly ilAccessHandler $access
readonly ilUserCertificateRepository $userCertificateRepository
readonly ilCtrlInterface $ctrl
readonly ilGlobalTemplateInterface $template
readonly ilDBInterface $db
readonly ilLogger $certificateLogger
global $DIC
Definition: shib_login.php:26

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

+ Here is the call graph for this function:

Member Function Documentation

◆ applySortation()

ilUserCertificateGUI::applySortation ( )
protected
Exceptions
ilWACException
ilDateTimeException

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

277 : void
278 {
279 $sorting = $this->request->getQueryParams()['sort_by'] ?? $this->defaultSorting;
280 if (!array_key_exists($sorting, $this->sortationOptions)) {
281 $sorting = $this->defaultSorting;
282 }
283 ilSession::set(self::SORTATION_SESSION_KEY, $sorting);
284
285 $this->listCertificates();
286 }
static set(string $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 291 of file class.ilUserCertificateGUI.php.

291 : void
292 {
293 $pdfGenerator = new ilPdfGenerator($this->userCertificateRepository);
294
295 $userCertificateId = (int) $this->request->getQueryParams()['certificate_id'];
296
297 try {
298 $userCertificate = $this->userCertificateRepository->fetchCertificate($userCertificateId);
299 if ($userCertificate->getUserId() !== $this->user->getId()) {
300 throw new ilException(sprintf('User "%s" tried to access certificate: "%s"', $this->user->getLogin(), $userCertificateId));
301 }
302 } catch (ilException $exception) {
303 $this->certificateLogger->warning($exception->getMessage());
304 $this->template->setOnScreenMessage('failure', $this->language->txt('cert_error_no_access'));
305 $this->listCertificates();
306
307 return;
308 }
309
310 $pdfAction = new ilCertificatePdfAction(
311 $pdfGenerator,
313 $this->language->txt('error_creating_certificate_pdf')
314 );
315
316 $pdfAction->downloadPdf($userCertificate->getUserId(), $userCertificate->getObjId());
317
318 $this->listCertificates();
319 }
Just a wrapper class to create Unit Test for other classes.
Base class for ILIAS Exception handling.

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

+ Here is the call graph for this function:

◆ executeCommand()

ilUserCertificateGUI::executeCommand ( )

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

102 : bool
103 {
104 $cmd = $this->ctrl->getCmd();
105
106 if (!$this->certificateSettings->get('active', '0')) {
107 $this->ctrl->returnToParent($this);
108 }
109
110 $this->template->setTitle($this->language->txt('obj_cert'));
111 if (!method_exists($this, $cmd)) {
112 $cmd = $this->getDefaultCommand();
113 }
114 $this->{$cmd}();
115
116 return true;
117 }

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

+ Here is the call graph for this function:

◆ getCurrentSortation()

ilUserCertificateGUI::getCurrentSortation ( )
protected

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

263 : string
264 {
265 $sorting = ilSession::get(self::SORTATION_SESSION_KEY);
266 if (!array_key_exists($sorting, $this->sortationOptions)) {
267 $sorting = $this->defaultSorting;
268 }
269
270 return $sorting;
271 }
static get(string $a_var)

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

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

97 : string
98 {
99 return 'listCertificates';
100 }

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ listCertificates()

ilUserCertificateGUI::listCertificates ( )
Exceptions
ilDateTimeException
ilWACException

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

123 : void
124 {
125 $this->help->setScreenIdComponent('cert');
126
127 if (!$this->certificateSettings->get('active', '0')) {
128 $this->ctrl->redirect($this);
129 }
130
131 $this->template->setPermanentLink('cert', null, 'list');
132
134 $this->db,
135 $this->certificateLogger,
136 $this->language->txt('certificate_no_object_title')
137 );
138
139 $sorting = $this->getCurrentSortation();
140 $data = $provider->fetchDataSet(
141 $this->user->getId(),
142 [
143 'order_field' => explode('_', $sorting)[0],
144 'order_direction' => explode('_', $sorting)[1],
145 'language' => $this->user->getLanguage()
146 ],
147 []
148 );
149
150 $uiComponents = [];
151
152 if ($data['items'] !== []) {
154 $cards = [];
155
156 foreach ($this->sortationOptions as $fieldAndDirection => $lngVariable) {
157 $sortationOptions[$fieldAndDirection] = $this->language->txt($lngVariable);
158 }
159
160 $sortViewControl = $this->uiFactory
161 ->viewControl()
162 ->sortation($sortationOptions, $sorting)
163 ->withTargetURL($this->ctrl->getLinkTarget($this, 'applySortation'), 'sort_by');
164
165 $uiComponents[] = $sortViewControl;
166
167 foreach ($data['items'] as $certificateData) {
168 $tile_image_identification = $certificateData['tile_image_ident'] ?? '';
169 $imagePath = '';
170 if ($tile_image_identification === '' || $tile_image_identification === '-') {
171 $tile_image_identification = $certificateData['tile_image_path'] ?? '';
172 if ($tile_image_identification !== '' && $this->filesystem->has($tile_image_identification)) {
173 $imagePath = ilWACSignedPath::signFile(
174 ilFileUtils::getWebspaceDir() . $tile_image_identification
175 );
176 }
177 } else {
178 $tile_image_rid = $this->irss->manage()->find($tile_image_identification);
179 if ($tile_image_rid instanceof ResourceIdentification) {
180 $imagePath = $this->irss->consume()->src($tile_image_rid)->getSrc(true);
181 }
182 }
183
184 if ($imagePath === '') {
185 $imagePath = ilUtil::getImagePath('standard/icon_cert.svg');
186 }
187
188 $cardImage = $this->uiFactory->image()->standard(
189 $imagePath,
190 $certificateData['title']
191 );
192
193 $sections = [];
194
195 if ($certificateData['description'] !== '') {
196 $sections[] = $this->uiFactory->listing()->descriptive([
197 $this->language->txt('cert_description_label') => $certificateData['description']
198 ]);
199 }
200
201 $oldDatePresentationStatus = ilDatePresentation::useRelativeDates();
203 $sections[] = $this->uiFactory->listing()->descriptive([
204 $this->language->txt('cert_issued_on_label') => ilDatePresentation::formatDate(
205 new ilDateTime($certificateData['date'], IL_CAL_UNIX)
206 )
207 ]);
208 ilDatePresentation::setUseRelativeDates($oldDatePresentationStatus);
209
210 $objectTypeIcon = $this->uiFactory
211 ->symbol()
212 ->icon()
213 ->standard($certificateData['obj_type'], $certificateData['obj_type'])
214 ;
215
216 $objectTitle = $certificateData['title'];
217 $refIds = ilObject::_getAllReferences((int) $certificateData['obj_id']);
218 foreach ($refIds as $refId) {
219 if ($this->access->checkAccess('read', '', $refId)) {
220 $objectTitle = $this->uiRenderer->render(
221 $this->uiFactory->link()->standard($objectTitle, ilLink::_getLink($refId))
222 );
223
224 break;
225 }
226 }
227
228 $sections[] = $this->uiFactory->listing()->descriptive([$this->language->txt('cert_object_label') => implode(
229 '',
230 [
231 $this->uiRenderer->render($objectTypeIcon),
232 $objectTitle
233 ]
234 )
235 ]);
236
237 $this->ctrl->setParameter($this, 'certificate_id', $certificateData['id']);
238 $downloadHref = $this->ctrl->getLinkTarget($this, 'download');
239 $this->ctrl->clearParameters($this);
240 $sections[] = $this->uiFactory->button()->standard('Download', $downloadHref);
241
242 $card = $this->uiFactory
243 ->card()
244 ->standard($certificateData['title'], $cardImage)
245 ->withSections($sections)
246 ;
247
248 $cards[] = $card;
249 }
250
251 $deck = $this->uiFactory->deck($cards)->withSmallCardsSize();
252
253 $uiComponents[] = $this->uiFactory->divider()->horizontal();
254
255 $uiComponents[] = $deck;
256 } else {
257 $this->template->setOnScreenMessage('info', $this->language->txt('cert_currently_no_certs'));
258 }
259
260 $this->template->setContent($this->uiRenderer->render($uiComponents));
261 }
const IL_CAL_UNIX
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static _getAllReferences(int $id)
get all reference ids for object ID
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static signFile(string $path_to_file)
$provider
Definition: ltitoken.php:80
$refId
Definition: xapitoken.php:58

References $data, $provider, $refId, $sortationOptions, 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

readonly ilAccessHandler ilUserCertificateGUI::$access
private

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

◆ $certificateLogger

readonly ilLogger ilUserCertificateGUI::$certificateLogger
private

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

Referenced by __construct().

◆ $ctrl

readonly ilCtrlInterface ilUserCertificateGUI::$ctrl
private

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

◆ $db

readonly ilDBInterface ilUserCertificateGUI::$db
private

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

Referenced by __construct().

◆ $defaultSorting

string ilUserCertificateGUI::$defaultSorting = 'date_DESC'
protected

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

Referenced by applySortation(), and getCurrentSortation().

◆ $filesystem

readonly Filesystem ilUserCertificateGUI::$filesystem
private

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

◆ $help

readonly ilHelpGUI ilUserCertificateGUI::$help
private

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

◆ $language

readonly ilLanguage ilUserCertificateGUI::$language
private

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

◆ $request

readonly ServerRequestInterface ilUserCertificateGUI::$request
private

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

Referenced by __construct().

◆ $sortationOptions

array 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 51 of file class.ilUserCertificateGUI.php.

Referenced by listCertificates().

◆ $template

readonly ilGlobalTemplateInterface ilUserCertificateGUI::$template
private

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

◆ $uiFactory

readonly Factory ilUserCertificateGUI::$uiFactory
private

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

Referenced by __construct().

◆ $uiRenderer

readonly Renderer ilUserCertificateGUI::$uiRenderer
private

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

Referenced by __construct().

◆ $user

readonly ilObjUser ilUserCertificateGUI::$user
private

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

◆ $userCertificateRepository

readonly ilUserCertificateRepository ilUserCertificateGUI::$userCertificateRepository
private

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

Referenced by __construct().

◆ SORTATION_SESSION_KEY

final const ilUserCertificateGUI::SORTATION_SESSION_KEY = 'my_certificates_sorting'

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


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