ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilUserCertificateGUI Class Reference
+ 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)
 
 executeCommand ()
 
 listCertificates ()
 
 download ()
 

Data Fields

const SORTATION_SESSION_KEY = 'my_certificates_sorting'
 

Protected Member Functions

 getCurrentSortation ()
 
 applySortation ()
 

Protected Attributes

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

Private Member Functions

 getDefaultCommand ()
 

Private Attributes

ilGlobalTemplateInterface $template
 
ilCtrlInterface $ctrl
 
ilLanguage $language
 
ilUserCertificateRepository $userCertificateRepository
 
ilObjUser $user
 
ServerRequestInterface $request
 
ilLogger $certificateLogger
 
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 
)

Definition at line 54 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\UI\examples\Symbol\Glyph\Language\language(), and ILIAS\Repository\user().

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

Member Function Documentation

◆ applySortation()

ilUserCertificateGUI::applySortation ( )
protected
Exceptions
ilWACException
ilDateTimeException

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

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

307  : void
308  {
309  $sorting = $this->request->getQueryParams()['sort_by'] ?? $this->defaultSorting;
310  if (!array_key_exists($sorting, $this->sortationOptions)) {
311  $sorting = $this->defaultSorting;
312  }
313  ilSession::set(self::SORTATION_SESSION_KEY, $sorting);
314 
315  $this->listCertificates();
316  }
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 321 of file class.ilUserCertificateGUI.php.

References $DIC, $user, ilCertificatePdfAction\downloadPdf(), ilObject\getId(), ilObjUser\getLogin(), ILIAS\Repository\int(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), listCertificates(), and ilLanguage\txt().

321  : void
322  {
323  global $DIC;
324 
325  $user = $this->user;
326  $language = $DIC->language();
327 
328  $pdfGenerator = new ilPdfGenerator($this->userCertificateRepository, $this->certificateLogger);
329 
330  $userCertificateId = (int) $this->request->getQueryParams()['certificate_id'];
331 
332  try {
333  $userCertificate = $this->userCertificateRepository->fetchCertificate($userCertificateId);
334  if ($userCertificate->getUserId() !== $user->getId()) {
335  throw new ilException(sprintf(
336  'User "%s" tried to access certificate: "%s"',
337  $user->getLogin(),
338  $userCertificateId
339  ));
340  }
341  } catch (ilException $exception) {
342  $this->certificateLogger->warning($exception->getMessage());
343  $this->template->setOnScreenMessage('failure', $language->txt('cert_error_no_access'));
344  $this->listCertificates();
345  return;
346  }
347 
348  $pdfAction = new ilCertificatePdfAction(
349  $this->certificateLogger,
350  $pdfGenerator,
352  $this->language->txt('error_creating_certificate_pdf')
353  );
354 
355  $pdfAction->downloadPdf($userCertificate->getUserId(), $userCertificate->getObjId());
356 
357  $this->listCertificates();
358  }
Class ilPdfGeneratorConstantsTest.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
global $DIC
Definition: feed.php:28
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 141 of file class.ilUserCertificateGUI.php.

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

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

◆ getCurrentSortation()

ilUserCertificateGUI::getCurrentSortation ( )
protected

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

References $defaultSorting, and ilSession\get().

Referenced by listCertificates().

293  : string
294  {
295  $sorting = ilSession::get(self::SORTATION_SESSION_KEY);
296  if (!array_key_exists($sorting, $this->sortationOptions)) {
297  $sorting = $this->defaultSorting;
298  }
299 
300  return $sorting;
301  }
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 136 of file class.ilUserCertificateGUI.php.

Referenced by executeCommand().

136  : string
137  {
138  return 'listCertificates';
139  }
+ Here is the caller graph for this function:

◆ listCertificates()

ilUserCertificateGUI::listCertificates ( )
Exceptions
ilDateTimeException
ilWACException

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

References $certificateLogger, $data, $DIC, $provider, $refId, ilObject\_getAllReferences(), ilLink\_getLink(), ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ILIAS\Repository\filesystem(), ilDatePresentation\formatDate(), getCurrentSortation(), ilUtil\getImagePath(), ilFileUtils\getWebspaceDir(), 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().

167  : void
168  {
169  global $DIC;
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 (count($data['items']) > 0) {
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('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  if (count($refIds) > 0) {
249  foreach ($refIds as $refId) {
250  if ($this->access->checkAccess('read', '', $refId)) {
251  $objectTitle = $this->uiRenderer->render(
252  $this->uiFactory->link()->standard($objectTitle, ilLink::_getLink($refId))
253  );
254  break;
255  }
256  }
257  }
258 
259  $sections[] = $this->uiFactory->listing()->descriptive([$this->language->txt('cert_object_label') => implode(
260  '',
261  [
262  $this->uiRenderer->render($objectTypeIcon),
263  $objectTitle
264  ]
265  )
266  ]);
267 
268  $this->ctrl->setParameter($this, 'certificate_id', $certificateData['id']);
269  $downloadHref = $this->ctrl->getLinkTarget($this, 'download');
270  $this->ctrl->clearParameters($this);
271  $sections[] = $this->uiFactory->button()->standard('Download', $downloadHref);
272 
273  $card = $this->uiFactory
274  ->card()
275  ->standard($certificateData['title'], $cardImage)
276  ->withSections($sections);
277 
278  $cards[] = $card;
279  }
280 
281  $deck = $this->uiFactory->deck($cards)->withSmallCardsSize();
282 
283  $uiComponents[] = $this->uiFactory->divider()->horizontal();
284 
285  $uiComponents[] = $deck;
286  } else {
287  $this->template->setOnScreenMessage('info', $this->language->txt('cert_currently_no_certs'));
288  }
289 
290  $this->template->setContent($this->uiRenderer->render($uiComponents));
291  }
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)
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 43 of file class.ilUserCertificateGUI.php.

Referenced by __construct().

◆ $certificateLogger

ilLogger ilUserCertificateGUI::$certificateLogger
private

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

Referenced by __construct(), and listCertificates().

◆ $certificateSettings

ilSetting ilUserCertificateGUI::$certificateSettings
protected

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

Referenced by __construct().

◆ $ctrl

ilCtrlInterface ilUserCertificateGUI::$ctrl
private

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

Referenced by __construct().

◆ $defaultSorting

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

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

Referenced by applySortation(), and getCurrentSortation().

◆ $filesystem

Filesystem ilUserCertificateGUI::$filesystem
private

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

Referenced by __construct().

◆ $language

ilLanguage ilUserCertificateGUI::$language
private

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

Referenced by __construct().

◆ $request

ServerRequestInterface ilUserCertificateGUI::$request
private

Definition at line 38 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 45 of file class.ilUserCertificateGUI.php.

◆ $template

ilGlobalTemplateInterface ilUserCertificateGUI::$template
private

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

Referenced by __construct().

◆ $uiFactory

Factory ilUserCertificateGUI::$uiFactory
protected

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

Referenced by __construct().

◆ $uiRenderer

Renderer ilUserCertificateGUI::$uiRenderer
protected

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

Referenced by __construct().

◆ $user

ilObjUser ilUserCertificateGUI::$user
private

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

Referenced by __construct(), and download().

◆ $userCertificateRepository

ilUserCertificateRepository ilUserCertificateGUI::$userCertificateRepository
private

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

Referenced by __construct().

◆ SORTATION_SESSION_KEY

const ilUserCertificateGUI::SORTATION_SESSION_KEY = 'my_certificates_sorting'

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


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