ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilBadgeRenderer.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "Services/Badge/classes/class.ilBadge.php";
5
15{
16 protected $assignment; // [ilBadgeAssignment]
17 protected $badge; // [ilBadge]
18
19 protected static $init; // [bool]
20
21 public function __construct(ilBadgeAssignment $a_assignment = null, ilBadge $a_badge = null)
22 {
23 if($a_assignment)
24 {
25 $this->assignment = $a_assignment;
26 $this->badge = new ilBadge($this->assignment->getBadgeId());
27 }
28 else
29 {
30 $this->badge = $a_badge;
31 }
32 }
33
34 public static function initFromId($a_id)
35 {
36 $id = explode("_", $_GET["id"]);
37 if(sizeof($id) == 3)
38 {
39 $user_id = $id[0];
40 $badge_id = $id[1];
41 $hash = $id[2];
42
43 if($user_id)
44 {
45 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
46 $assignment = new ilBadgeAssignment($badge_id, $user_id);
47 if($assignment->getTimestamp())
48 {
49 $obj = new self($assignment);
50 }
51 }
52 else
53 {
54 include_once "Services/Badge/classes/class.ilBadge.php";
55 $badge = new ilBadge($badge_id);
56 $obj = new self(null, $badge);
57 }
58 if($hash == $obj->getBadgeHash())
59 {
60 return $obj;
61 }
62 }
63 }
64
65 public function getHTML()
66 {
67 global $tpl, $ilCtrl;
68
69 if(!self::$init)
70 {
71 self::$init = true;
72
73 $url = $ilCtrl->getLinkTargetByClass("ilBadgeHandlerGUI",
74 "render", "", true, false);
75
76 $tpl->addJavaScript("Services/Badge/js/ilBadgeRenderer.js");
77 $tpl->addOnLoadCode('il.BadgeRenderer.init("'.$url.'");');
78 }
79
80 $hash = $this->getBadgeHash();
81
82 $btpl = new ilTemplate("tpl.badge_renderer.html", true, true, "Services/Badge");
83 $btpl->setVariable("BADGE_IMG", $this->badge->getImagePath());
84 $btpl->setVariable("BADGE_TXT", $this->badge->getTitle());
85 $btpl->setVariable("BADGE_ID", "badge_".
86 ($this->assignment
87 ? $this->assignment->getUserId()
88 : "")."_".
89 $this->badge->getId()."_".
90 $hash);
91 return $btpl->get();
92 }
93
94 public function getHref()
95 {
96 global $ilCtrl, $tpl;
97
98 if(!self::$init)
99 {
100 self::$init = true;
101
102 $url = $ilCtrl->getLinkTargetByClass("ilBadgeHandlerGUI",
103 "render", "", true, false);
104
105 $tpl->addJavaScript("Services/Badge/js/ilBadgeRenderer.js");
106 $tpl->addOnLoadCode('il.BadgeRenderer.init("'.$url.'");');
107 }
108
109 $hash = $this->getBadgeHash();
110
111 return "#\" data-id=\"badge_".
112 ($this->assignment
113 ? $this->assignment->getUserId()
114 : "")."_".
115 $this->badge->getId()."_".
116 $hash;
117 }
118
119 protected function getBadgeHash()
120 {
121 return md5("bdg-".
122 ($this->assignment
123 ? $this->assignment->getUserId()
124 : "")."-".
125 $this->badge->getId());
126 }
127
128 public function renderModal()
129 {
130 global $lng;
131
132 include_once "Services/UIComponent/Modal/classes/class.ilModalGUI.php";
133
134 // only needed for modal-js-calls
135 // ilModalGUI::initJS();
136
137 $modal = ilModalGUI::getInstance();
138 $modal->setId("badge_modal_".$this->getBadgeHash());
139 $modal->setType(ilModalGUI::TYPE_SMALL);
140 $modal->setHeading($this->badge->getTitle());
141
142 $lng->loadLanguageModule("badge");
143
144 $tpl = new ilTemplate("tpl.badge_modal.html", true, true, "Services/Badge");
145
146 $tpl->setVariable("IMG_SRC", $this->badge->getImagePath());
147 $tpl->setVariable("IMG_TXT", $this->badge->getImage());
148
149 $tpl->setVariable("TXT_DESC", $lng->txt("description"));
150 $tpl->setVariable("DESC", nl2br($this->badge->getDescription()));
151
152 $tpl->setVariable("TXT_CRITERIA", $lng->txt("badge_criteria"));
153 $tpl->setVariable("CRITERIA", nl2br($this->badge->getCriteria()));
154
155 if($this->assignment)
156 {
157 $tpl->setVariable("TXT_TSTAMP", $lng->txt("badge_issued_on"));
158 $tpl->setVariable("TSTAMP",
159 ilDatePresentation::formatDate(new ilDateTime($this->assignment->getTimestamp(), IL_CAL_UNIX)));
160 }
161
162 if($this->badge->getParentId())
163 {
164 $parent = $this->badge->getParentMeta();
165 if($parent["type"] != "bdga")
166 {
167 $tpl->setVariable("TXT_PARENT", $lng->txt("object"));
168 $tpl->setVariable("PARENT", $parent["title"]);
169 $tpl->setVariable("PARENT_TYPE", $lng->txt("obj_".$parent["type"]));
170 $tpl->setVariable("PARENT_ICON",
171 ilObject::_getIcon($parent["id"], "big", $parent["type"]));
172 }
173 }
174
175 if($this->badge->getValid())
176 {
177 $tpl->setVariable("TXT_VALID", $lng->txt("badge_valid"));
178 $tpl->setVariable("VALID", $this->badge->getValid());
179 }
180
181 $modal->setBody($tpl->get());
182
183 return $modal->getHTML();
184 }
185}
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
__construct(ilBadgeAssignment $a_assignment=null, ilBadge $a_badge=null)
static initFromId($a_id)
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
static getInstance()
Get instance.
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
special template class to simplify handling of ITX/PEAR
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$url
Definition: shib_logout.php:72