19 declare(strict_types=1);
36 private readonly ServerRequestInterface
$request;
49 'title_ASC' =>
'cert_sortable_by_title_asc',
50 'title_DESC' =>
'cert_sortable_by_title_desc',
51 'date_ASC' =>
'cert_sortable_by_issue_date_asc',
52 'date_DESC' =>
'cert_sortable_by_issue_date_desc',
63 ?ServerRequestInterface $request = null,
74 if ($template === null) {
75 $template = $DIC->ui()->mainTemplate();
84 if ($language === null) {
85 $language = $DIC->language();
94 if ($request === null) {
95 $request = $DIC->http()->request();
99 if ($certificateLogger === null) {
100 $certificateLogger = $DIC->logger()->cert();
104 if ($certificateSettings === null) {
105 $certificateSettings =
new ilSetting(
"certificate");
109 if (null === $uiFactory) {
110 $uiFactory = $DIC->ui()->factory();
114 if (null === $uiRenderer) {
115 $uiRenderer = $DIC->ui()->renderer();
119 if (null === $access) {
120 $access = $DIC->access();
124 if (null === $filesystem) {
125 $filesystem = $DIC->filesystem()->web();
129 if ($userCertificateRepository === null) {
134 $this->
help = $help ?? $DIC->help();
136 $this->
language->loadLanguageModule(
'cert');
141 return 'listCertificates';
146 $cmd = $this->
ctrl->getCmd();
148 if (!$this->certificateSettings->get(
'active',
'0')) {
149 $this->
ctrl->returnToParent($this);
152 $this->
template->setTitle($this->
language->txt(
'obj_cert'));
153 if (!method_exists($this, $cmd)) {
169 $this->
help->setScreenIdComponent(
'cert');
171 if (!$this->certificateSettings->get(
'active',
'0')) {
172 $this->
ctrl->redirect($this);
178 $this->
language->txt(
'certificate_no_object_title')
183 $this->
user->getId(),
185 'order_field' => explode(
'_', $sorting)[0],
186 'order_direction' => explode(
'_', $sorting)[1],
187 'language' => $this->
user->getLanguage()
194 if (
$data[
'items'] !== []) {
195 $sortationOptions = [];
198 foreach ($this->sortationOptions as $fieldAndDirection => $lngVariable) {
199 $sortationOptions[$fieldAndDirection] = $this->
language->txt($lngVariable);
202 $sortViewControl = $this->uiFactory
204 ->sortation($sortationOptions)
205 ->withLabel($this->
language->txt($this->sortationOptions[$sorting]))
206 ->withTargetURL($this->
ctrl->getLinkTarget($this,
'applySortation'),
'sort_by');
207 $uiComponents[] = $sortViewControl;
209 foreach (
$data[
'items'] as $certificateData) {
210 $thumbnailImagePath = $certificateData[
'thumbnail_image_path'];
212 if ($thumbnailImagePath === null
213 || $thumbnailImagePath ===
'' 214 || !$this->
filesystem->has($thumbnailImagePath)
219 $cardImage = $this->uiFactory->image()->standard(
221 $certificateData[
'title']
226 if ($certificateData[
'description'] !==
'') {
227 $sections[] = $this->uiFactory->listing()->descriptive([
228 $this->
language->txt(
'cert_description_label') => $certificateData[
'description']
234 $sections[] = $this->uiFactory->listing()->descriptive([
241 $objectTypeIcon = $this->uiFactory
244 ->standard($certificateData[
'obj_type'], $certificateData[
'obj_type']);
246 $objectTitle = $certificateData[
'title'];
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))
257 $sections[] = $this->uiFactory->listing()->descriptive([$this->
language->txt(
'cert_object_label') => implode(
260 $this->uiRenderer->render($objectTypeIcon),
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);
271 $card = $this->uiFactory
273 ->standard($certificateData[
'title'], $cardImage)
274 ->withSections($sections);
279 $deck = $this->uiFactory->deck($cards)->withSmallCardsSize();
281 $uiComponents[] = $this->uiFactory->divider()->horizontal();
283 $uiComponents[] = $deck;
285 $this->
template->setOnScreenMessage(
'info', $this->
language->txt(
'cert_currently_no_certs'));
288 $this->
template->setContent($this->uiRenderer->render($uiComponents));
294 if (!array_key_exists($sorting, $this->sortationOptions)) {
308 if (!array_key_exists($sorting, $this->sortationOptions)) {
321 $pdfGenerator =
new ilPdfGenerator($this->userCertificateRepository);
323 $userCertificateId = (
int) $this->request->getQueryParams()[
'certificate_id'];
326 $userCertificate = $this->userCertificateRepository->fetchCertificate($userCertificateId);
327 if ($userCertificate->getUserId() !== $this->
user->getId()) {
329 'User "%s" tried to access certificate: "%s"',
330 $this->
user->getLogin(),
335 $this->certificateLogger->warning($exception->getMessage());
336 $this->
template->setOnScreenMessage(
'failure', $this->
language->txt(
'cert_error_no_access'));
344 $this->
language->txt(
'error_creating_certificate_pdf')
347 $pdfAction->
downloadPdf($userCertificate->getUserId(), $userCertificate->getObjId());
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static get(string $a_var)
An entity that renders components to a string output.
ilUserCertificateGUI: ilAchievementsGUI
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
final const SORTATION_SESSION_KEY
__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)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
readonly Filesystem $filesystem
ilSetting $certificateSettings
static useRelativeDates()
readonly ilCtrlInterface $ctrl
array string $defaultSorting
readonly ServerRequestInterface $request
readonly ilLanguage $language
Just a wrapper class to create Unit Test for other classes.
readonly ilGlobalTemplateInterface $template
static signFile(string $path_to_file)
static setUseRelativeDates(bool $a_status)
set use relative dates
static set(string $a_var, $a_val)
Set a value.
readonly ilUserCertificateRepository $userCertificateRepository
downloadPdf(int $userId, int $objectId)