ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBadgeRenderer.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
11 {
15  protected $lng;
16 
20  protected $factory;
21 
25  protected $renderer;
26 
27  protected $assignment; // [ilBadgeAssignment]
28  protected $badge; // [ilBadge]
29 
30  public function __construct(ilBadgeAssignment $a_assignment = null, ilBadge $a_badge = null)
31  {
32  global $DIC;
33 
34  $this->lng = $DIC->language();
35  $this->factory = $DIC->ui()->factory();
36  $this->renderer = $DIC->ui()->renderer();
37  if ($a_assignment) {
38  $this->assignment = $a_assignment;
39  $this->badge = new ilBadge($this->assignment->getBadgeId());
40  } else {
41  $this->badge = $a_badge;
42  }
43  }
44 
45  public function getHTML()
46  {
47  $components = array();
48 
49  $modal = $this->factory->modal()->roundtrip(
50  $this->badge->getTitle(),
51  $this->factory->legacy($this->renderModalContent())
52  )->withCancelButtonLabel("ok");
53  $components[] = $modal;
54 
55  $image_path = ilWACSignedPath::signFile($this->badge->getImagePath());
56  $image = $this->factory->image()->responsive($image_path, $this->badge->getTitle())
57  ->withAction($modal->getShowSignal());
58  $components[] = $image;
59 
60  return $this->renderer->render($components);
61  }
62 
63  public function renderModalContent()
64  {
65  $lng = $this->lng;
66  $lng->loadLanguageModule("badge");
67 
68  $modal_content = array();
69 
70  $image = $this->factory->image()->responsive($this->badge->getImagePath(), $this->badge->getImage());
71  $modal_content[] = $image;
72 
73  $badge_information = [
74  $lng->txt("description") => $this->badge->getDescription(),
75  $lng->txt("badge_criteria") => $this->badge->getCriteria(),
76  ];
77 
78  if ($this->assignment) {
79  $badge_information[$lng->txt("badge_issued_on")] = ilDatePresentation::formatDate(
80  new ilDateTime($this->assignment->getTimestamp(), IL_CAL_UNIX)
81  );
82  }
83 
84  if ($this->badge->getParentId()) {
85  $parent = $this->badge->getParentMeta();
86  if ($parent["type"] != "bdga") {
87  $parent_icon = $this->factory->symbol()->icon()->custom(
88  ilObject::_getIcon($parent["id"], "big", $parent["type"]),
89  $lng->txt("obj_" . $parent["type"])
90  )->withSize("medium");
91 
92  $parent_icon_with_text = $this->factory->legacy($this->renderer->render($parent_icon) . $parent["title"]);
93  $badge_information[$lng->txt("object")] = $parent_icon_with_text;
94  }
95  }
96 
97  if ($this->badge->getValid()) {
98  $badge_information[$lng->txt("badge_valid")] = $this->badge->getValid();
99  }
100 
101  $list = $this->factory->listing()->descriptive($badge_information);
102  $modal_content[] = $list;
103 
104  return $this->renderer->render($modal_content);
105  }
106 }
Class ilBadgeRenderer.
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
Class ilBadge.
Class ilBadgeAssignment.
static signFile($path_to_file)
$DIC
Definition: xapitoken.php:46
__construct(ilBadgeAssignment $a_assignment=null, ilBadge $a_badge=null)