ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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;
31
33{
38
39 public function __construct(?ilBadgeAssignment $assignment = null)
40 {
41 global $DIC;
42
43 $this->ui_factory = $DIC->ui()->factory();
44 $this->ui_renderer = $DIC->ui()->renderer();
45 $this->lng = $DIC->language();
46 $this->lng->loadLanguageModule('badge');
47
48 if ($assignment) {
49 $this->assignment = $assignment;
50 }
51 }
52
56 public function constructModal(
57 ?Image $badge_image,
58 string $badge_title,
59 array $badge_properties = [],
60 bool $enclose_in_div = false
61 ): Modal {
62 if ($badge_image !== null) {
63 if ($enclose_in_div) {
64 $modal_content[] = $this->ui_factory->legacy()->content(
65 '<div class="ilBadgeImage">' . $this->ui_renderer->render($badge_image) . '</div>'
66 );
67 } else {
68 $modal_content[] = $badge_image;
69 }
70 }
71
72 if ($this->assignment) {
73 $badge_properties['badge_issued_on'] = ilDatePresentation::formatDate(
74 new ilDateTime($this->assignment->getTimestamp(), IL_CAL_UNIX)
75 );
76 }
77
78 $badge_properties = $this->translateKeysWithValidDataAttribute($badge_properties);
79
80 $modal_content[] = $this->ui_factory->item()
81 ->standard($badge_title)
82 ->withDescription('')
83 ->withProperties($badge_properties);
84
85 $card = $this->ui_factory->card()
86 ->standard($badge_title)
87 ->withHiddenSections($modal_content);
88
89 return $this->ui_factory->modal()->lightbox(
90 $this->ui_factory->modal()->lightboxCardPage($card)
91 );
92 }
93
94 public function renderModal(Modal $modal): string
95 {
96 return $this->ui_renderer->render($modal);
97 }
98
99 public function renderShyButton(string $label, Modal $modal): string
100 {
101 return $this->ui_renderer->render($this->ui_factory->button()->shy($label, $modal->getShowSignal()));
102 }
103
108 private function translateKeysWithValidDataAttribute(array $properties): array
109 {
110 $translations = [];
111
112 if (\count($properties) > 0) {
113 foreach ($properties as $lang_var => $data) {
114 if ($data !== '') {
115 $translations[$this->lng->txt($lang_var)] = $data;
116 }
117 }
118 }
119 return $translations;
120 }
121}
translateKeysWithValidDataAttribute(array $properties)
__construct(?ilBadgeAssignment $assignment=null)
renderShyButton(string $label, Modal $modal)
ilBadgeAssignment $assignment
renderModal(Modal $modal)
constructModal(?Image $badge_image, string $badge_title, array $badge_properties=[], bool $enclose_in_div=false)
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