ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ModalBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Badge;
22
26use ilLanguage;
27use ilDateTime;
32
34{
39
40 public function __construct(?ilBadgeAssignment $assignment = null)
41 {
42 global $DIC;
43
44 $this->ui_factory = $DIC->ui()->factory();
45 $this->ui_renderer = $DIC->ui()->renderer();
46 $this->lng = $DIC->language();
47 $this->lng->loadLanguageModule('badge');
48
49 if ($assignment) {
50 $this->assignment = $assignment;
51 }
52 }
53
57 public function constructModal(
58 ?Image $badge_image,
59 string $badge_title,
60 array $badge_properties = []
61 ): Modal {
62 if ($badge_image !== null) {
63 $modal_content[] = $badge_image;
64 }
65
66 if ($this->assignment) {
67 $badge_properties['badge_issued_on'] = ilDatePresentation::formatDate(
68 new ilDateTime($this->assignment->getTimestamp(), IL_CAL_UNIX)
69 );
70 }
71
72 $badge_properties = $this->translateKeysWithValidDataAttribute($badge_properties);
73
74 $modal_content[] = $this->ui_factory->item()
75 ->standard($badge_title)
76 ->withDescription('')
77 ->withProperties($badge_properties);
78
79 $card = $this->ui_factory->card()
80 ->standard($badge_title)
81 ->withHiddenSections($modal_content);
82
83 return $this->ui_factory->modal()->lightbox(
84 $this->ui_factory->modal()->lightboxCardPage($card)
85 );
86 }
87
88 public function renderModal(Modal $modal): string
89 {
90 return $this->ui_renderer->render($modal);
91 }
92
93 public function renderShyButton(string $label, Modal $modal): string
94 {
95 return $this->ui_renderer->render($this->ui_factory->button()->shy($label, $modal->getShowSignal()));
96 }
97
102 private function translateKeysWithValidDataAttribute(array $properties): array
103 {
104 $translations = [];
105
106 if (\count($properties) > 0) {
107 foreach ($properties as $lang_var => $data) {
108 if ($data !== '') {
109 $translations[$this->lng->txt($lang_var)] = $data;
110 }
111 }
112 }
113 return $translations;
114 }
115}
translateKeysWithValidDataAttribute(array $properties)
__construct(?ilBadgeAssignment $assignment=null)
renderShyButton(string $label, Modal $modal)
constructModal(?Image $badge_image, string $badge_title, array $badge_properties=[])
ilBadgeAssignment $assignment
renderModal(Modal $modal)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for date presentation.
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
language handling
This describes commonalities between the different modals.
Definition: Modal.php:35
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26