ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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, ?ilHelpGUI $help=null, ?ilDBInterface $db=null, private ?IRSS $irss=null)
 
 executeCommand ()
 
 listCertificates ()
 
 download ()
 

Data Fields

final const string SORTATION_SESSION_KEY = 'my_certificates_sorting'
 

Protected Member Functions

 getCurrentSortation ()
 
 applySortation ()
 

Protected Attributes

array $sortation_options
 
string $default_sorting = 'date_DESC'
 

Private Member Functions

 getDefaultCommand ()
 

Private Attributes

readonly ilGlobalTemplateInterface $template
 
readonly ilCtrlInterface $ctrl
 
readonly ilLanguage $language
 
readonly ilUserCertificateRepository $user_certificate_repo
 
readonly ilObjUser $user
 
readonly ServerRequestInterface $request
 
readonly ilLogger $logger
 
readonly Factory $ui_factory
 
readonly Renderer $ui_renderer
 
readonly ilAccessHandler $access
 
readonly ilHelpGUI $help
 
readonly ilDBInterface $db
 

Detailed Description

@ilCtrl_IsCalledBy ilUserCertificateGUI: ilAchievementsGUI

Definition at line 30 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,
?ilHelpGUI  $help = null,
?ilDBInterface  $db = null,
private ?IRSS  $irss = null 
)

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

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

References $db, $DIC, $request, ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ILIAS\Repository\help(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), ILIAS\Repository\logger(), 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 264 of file class.ilUserCertificateGUI.php.

264 : void
265 {
266 $sorting = $this->request->getQueryParams()['sort_by'] ?? $this->default_sorting;
267 if (!array_key_exists($sorting, $this->sortation_options)) {
268 $sorting = $this->default_sorting;
269 }
270 ilSession::set(self::SORTATION_SESSION_KEY, $sorting);
271
272 $this->listCertificates();
273 }
static set(string $a_var, $a_val)
Set a value.

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

+ Here is the call graph for this function:

◆ download()

ilUserCertificateGUI::download ( )
Exceptions
ilException

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

278 : void
279 {
280 $certificate_id = (int) $this->request->getQueryParams()['certificate_id'];
281
282 try {
283 $certificate = $this->user_certificate_repo->fetchCertificate($certificate_id);
284 if ($certificate->getUserId() !== $this->user->getId()) {
285 throw new ilException(
286 sprintf('User "%s" tried to access certificate: "%s"', $this->user->getLogin(), $certificate_id)
287 );
288 }
289 } catch (ilException $exception) {
290 $this->logger->warning($exception->getMessage());
291 $this->template->setOnScreenMessage('failure', $this->language->txt('cert_error_no_access'));
292 $this->listCertificates();
293
294 return;
295 }
296
297 $action = (new ilCertificatePdfAction(
298 (new ilPdfGenerator($this->user_certificate_repo))->withLogger($this->logger),
300 $this->language->txt('error_creating_certificate_pdf')
301 ))->withLogger($this->logger);
302 $action->downloadPdf($certificate->getUserId(), $certificate->getObjId());
303
304 $this->listCertificates();
305 }
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(), ILIAS\Repository\logger(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ executeCommand()

ilUserCertificateGUI::executeCommand ( )

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

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

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

250 : string
251 {
252 $sorting = ilSession::get(self::SORTATION_SESSION_KEY);
253 if (!array_key_exists($sorting, $this->sortation_options)) {
254 $sorting = $this->default_sorting;
255 }
256
257 return $sorting;
258 }
static get(string $a_var)

References $default_sorting, 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 93 of file class.ilUserCertificateGUI.php.

93 : string
94 {
95 return 'listCertificates';
96 }

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ listCertificates()

ilUserCertificateGUI::listCertificates ( )
Exceptions
ilDateTimeException
ilWACException

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

119 : void
120 {
121 $this->help->setScreenIdComponent('cert');
122
123 if (!$this->certificateSettings->get('active', '0')) {
124 $this->ctrl->redirect($this);
125 }
126
127 $this->template->setPermanentLink('cert', null, 'list');
128
130 $this->db,
131 $this->logger,
132 $this->language->txt('certificate_no_object_title')
133 );
134
135 $sorting = $this->getCurrentSortation();
136 $data = $provider->fetchDataSet(
137 $this->user->getId(),
138 [
139 'order_field' => explode('_', $sorting)[0],
140 'order_direction' => explode('_', $sorting)[1],
141 'language' => $this->user->getLanguage()
142 ],
143 []
144 );
145
146 $uiComponents = [];
147
148 if ($data['items'] !== []) {
149 $sortationOptions = [];
150 $cards = [];
151
152 foreach ($this->sortation_options as $fieldAndDirection => $lngVariable) {
153 $sortationOptions[$fieldAndDirection] = $this->language->txt($lngVariable);
154 }
155
156 $sortViewControl = $this->ui_factory
157 ->viewControl()
158 ->sortation($sortationOptions, $sorting)
159 ->withTargetURL($this->ctrl->getLinkTarget($this, 'applySortation'), 'sort_by');
160
161 $uiComponents[] = $sortViewControl;
162
163 foreach ($data['items'] as $certificateData) {
164 $tile_image_identification = $certificateData['tile_image_ident'] ?? '';
165 $imagePath = '';
166 $tile_image_rid = $this->irss->manage()->find($tile_image_identification);
167 if ($tile_image_rid instanceof ResourceIdentification) {
168 $imagePath = $this->irss->consume()->src($tile_image_rid)->getSrc(true);
169 }
170
171 if ($imagePath === '') {
172 $imagePath = ilUtil::getImagePath('standard/icon_cert.svg');
173 }
174
175 $cardImage = $this->ui_factory->image()->standard(
176 $imagePath,
177 $certificateData['title']
178 );
179
180 $sections = [];
181
182 if ($certificateData['description'] !== '') {
183 $sections[] = $this->ui_factory->listing()->descriptive([
184 $this->language->txt('cert_description_label') => $certificateData['description']
185 ]);
186 }
187
188 $oldDatePresentationStatus = ilDatePresentation::useRelativeDates();
190 $sections[] = $this->ui_factory->listing()->descriptive([
191 $this->language->txt('cert_issued_on_label') => ilDatePresentation::formatDate(
192 new ilDateTime($certificateData['date'], IL_CAL_UNIX)
193 )
194 ]);
195 ilDatePresentation::setUseRelativeDates($oldDatePresentationStatus);
196
197 $objectTypeIcon = $this->ui_factory
198 ->symbol()
199 ->icon()
200 ->standard($certificateData['obj_type'], $certificateData['obj_type'])
201 ;
202
203 $objectTitle = $certificateData['title'];
204 $refIds = ilObject::_getAllReferences((int) $certificateData['obj_id']);
205 foreach ($refIds as $refId) {
206 if ($this->access->checkAccess('read', '', $refId)) {
207 $objectTitle = $this->ui_renderer->render(
208 $this->ui_factory->link()->standard($objectTitle, ilLink::_getLink($refId))
209 );
210
211 break;
212 }
213 }
214
215 $sections[] = $this->ui_factory->listing()->descriptive([$this->language->txt('cert_object_label') => implode(
216 '',
217 [
218 $this->ui_renderer->render($objectTypeIcon),
219 $objectTitle
220 ]
221 )
222 ]);
223
224 $this->ctrl->setParameter($this, 'certificate_id', $certificateData['id']);
225 $downloadHref = $this->ctrl->getLinkTarget($this, 'download');
226 $this->ctrl->clearParameters($this);
227 $sections[] = $this->ui_factory->button()->standard('Download', $downloadHref);
228
229 $card = $this->ui_factory
230 ->card()
231 ->standard($certificateData['title'], $cardImage)
232 ->withSections($sections)
233 ;
234
235 $cards[] = $card;
236 }
237
238 $deck = $this->ui_factory->deck($cards)->withSmallCardsSize();
239
240 $uiComponents[] = $this->ui_factory->divider()->horizontal();
241
242 $uiComponents[] = $deck;
243 } else {
244 $this->template->setOnScreenMessage('info', $this->language->txt('cert_currently_no_certs'));
245 }
246
247 $this->template->setContent($this->ui_renderer->render($uiComponents));
248 }
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 _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)
$provider
Definition: ltitoken.php:80
$refId
Definition: xapitoken.php:56

References $data, $provider, $refId, ilObject\_getAllReferences(), ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ilDatePresentation\formatDate(), getCurrentSortation(), ilUtil\getImagePath(), ILIAS\Repository\help(), IL_CAL_UNIX, ILIAS\UI\examples\Symbol\Glyph\Language\language(), ILIAS\Repository\logger(), ilDatePresentation\setUseRelativeDates(), 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 43 of file class.ilUserCertificateGUI.php.

◆ $ctrl

readonly ilCtrlInterface ilUserCertificateGUI::$ctrl
private

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

◆ $db

readonly ilDBInterface ilUserCertificateGUI::$db
private

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

Referenced by __construct().

◆ $default_sorting

string ilUserCertificateGUI::$default_sorting = 'date_DESC'
protected

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

Referenced by applySortation(), and getCurrentSortation().

◆ $help

readonly ilHelpGUI ilUserCertificateGUI::$help
private

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

◆ $language

readonly ilLanguage ilUserCertificateGUI::$language
private

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

◆ $logger

readonly ilLogger ilUserCertificateGUI::$logger
private

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

◆ $request

readonly ServerRequestInterface ilUserCertificateGUI::$request
private

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

Referenced by __construct().

◆ $sortation_options

array ilUserCertificateGUI::$sortation_options
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 50 of file class.ilUserCertificateGUI.php.

◆ $template

readonly ilGlobalTemplateInterface ilUserCertificateGUI::$template
private

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

◆ $ui_factory

readonly Factory ilUserCertificateGUI::$ui_factory
private

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

◆ $ui_renderer

readonly Renderer ilUserCertificateGUI::$ui_renderer
private

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

◆ $user

readonly ilObjUser ilUserCertificateGUI::$user
private

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

◆ $user_certificate_repo

readonly ilUserCertificateRepository ilUserCertificateGUI::$user_certificate_repo
private

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

◆ SORTATION_SESSION_KEY

final const string ilUserCertificateGUI::SORTATION_SESSION_KEY = 'my_certificates_sorting'

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


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