ILIAS  release_8 Revision v8.24
class.ilBadgeRenderer.php
Go to the documentation of this file.
1<?php
2
23{
24 protected ilLanguage $lng;
25 protected \ILIAS\UI\Factory $factory;
26 protected \ILIAS\UI\Renderer $renderer;
27 protected ?ilBadgeAssignment $assignment = null;
28 protected ?ilBadge $badge = null;
29
30 public function __construct(
31 ilBadgeAssignment $a_assignment = null,
32 ilBadge $a_badge = null
33 ) {
34 global $DIC;
35
36 $this->lng = $DIC->language();
37 $this->factory = $DIC->ui()->factory();
38 $this->renderer = $DIC->ui()->renderer();
39 if ($a_assignment) {
40 $this->assignment = $a_assignment;
41 $this->badge = new ilBadge($this->assignment->getBadgeId());
42 } else {
43 $this->badge = $a_badge;
44 }
45 }
46
47 public function getHTML(): string
48 {
49 $components = array();
50
51 $modal = $this->factory->modal()->roundtrip(
52 $this->badge->getTitle(),
53 $this->factory->legacy($this->renderModalContent())
54 )->withCancelButtonLabel("ok");
55 $components[] = $modal;
56
57 $image_path = ilWACSignedPath::signFile($this->badge->getImagePath());
58 $image = $this->factory->image()->responsive($image_path, $this->badge->getTitle())
59 ->withAction($modal->getShowSignal());
60 $components[] = $image;
61
62 return $this->renderer->render($components);
63 }
64
65 public function renderModalContent(): string
66 {
68 $lng->loadLanguageModule("badge");
69
70 $modal_content = array();
71
72 $image = $this->factory->image()->responsive(ilWACSignedPath::signFile($this->badge->getImagePath()), $this->badge->getImage());
73 $modal_content[] = $image;
74
75 $badge_information = [
76 $lng->txt("description") => $this->badge->getDescription(),
77 $lng->txt("badge_criteria") => $this->badge->getCriteria(),
78 ];
79
80 if ($this->assignment) {
81 $badge_information[$lng->txt("badge_issued_on")] = ilDatePresentation::formatDate(
82 new ilDateTime($this->assignment->getTimestamp(), IL_CAL_UNIX)
83 );
84 }
85
86 if ($this->badge->getParentId()) {
87 $parent = $this->badge->getParentMeta();
88 if ($parent["type"] !== "bdga") {
89 $parent_icon = $this->factory->symbol()->icon()->custom(
90 ilObject::_getIcon((int) $parent["id"], "big", $parent["type"]),
91 $lng->txt("obj_" . $parent["type"])
92 )->withSize("medium");
93
94 $label = $parent['title'];
95 $ref = current(ilObject::_getAllReferences($parent['id']));
96 if ($ref) {
97 $label = $this->factory->link()->standard($label, ilLink::_getLink($ref, $parent['type']));
98 $label = $this->renderer->render($label);
99 }
100 $badge_information[$lng->txt('object')] = $this->renderer->render($parent_icon) . $label;
101 }
102 }
103
104 if ($this->badge->getValid()) {
105 $badge_information[$lng->txt("badge_valid")] = $this->badge->getValid();
106 }
107
108 $list = $this->factory->listing()->descriptive($badge_information);
109 $modal_content[] = $list;
110
111 return $this->renderer->render($modal_content);
112 }
113}
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS UI Factory $factory
__construct(ilBadgeAssignment $a_assignment=null, ilBadge $a_badge=null)
ilBadgeAssignment $assignment
ILIAS UI Renderer $renderer
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
language handling
loadLanguageModule(string $a_module)
Load language module.
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...
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _getAllReferences(int $id)
get all reference ids for object ID
static signFile(string $path_to_file)
global $DIC
Definition: feed.php:28