ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilBadgeRenderer Class Reference
+ Collaboration diagram for ilBadgeRenderer:

Public Member Functions

 __construct (ilBadgeAssignment $a_assignment=null, ilBadge $a_badge=null)
 
 getHTML ()
 
 getHref ()
 
 renderModal ()
 

Static Public Member Functions

static initFromId ($a_id)
 

Protected Member Functions

 getBadgeHash ()
 

Protected Attributes

 $tpl
 
 $ctrl
 
 $lng
 
 $assignment
 
 $badge
 

Static Protected Attributes

static $init
 

Detailed Description

Definition at line 14 of file class.ilBadgeRenderer.php.

Constructor & Destructor Documentation

◆ __construct()

ilBadgeRenderer::__construct ( ilBadgeAssignment  $a_assignment = null,
ilBadge  $a_badge = null 
)

Definition at line 36 of file class.ilBadgeRenderer.php.

References $DIC.

37  {
38  global $DIC;
39 
40  $this->tpl = $DIC["tpl"];
41  $this->ctrl = $DIC->ctrl();
42  $this->lng = $DIC->language();
43  if ($a_assignment) {
44  $this->assignment = $a_assignment;
45  $this->badge = new ilBadge($this->assignment->getBadgeId());
46  } else {
47  $this->badge = $a_badge;
48  }
49  }
global $DIC
Definition: saml.php:7

Member Function Documentation

◆ getBadgeHash()

ilBadgeRenderer::getBadgeHash ( )
protected

Definition at line 141 of file class.ilBadgeRenderer.php.

Referenced by getHref(), getHTML(), and renderModal().

142  {
143  return md5("bdg-" .
144  ($this->assignment
145  ? $this->assignment->getUserId()
146  : "") . "-" .
147  $this->badge->getId());
148  }
+ Here is the caller graph for this function:

◆ getHref()

ilBadgeRenderer::getHref ( )

Definition at line 111 of file class.ilBadgeRenderer.php.

References $ctrl, $ilCtrl, $tpl, $url, and getBadgeHash().

112  {
114  $tpl = $this->tpl;
115 
116  if (!self::$init) {
117  self::$init = true;
118 
119  $url = $ilCtrl->getLinkTargetByClass(
120  "ilBadgeHandlerGUI",
121  "render",
122  "",
123  true,
124  false
125  );
126 
127  $tpl->addJavaScript("Services/Badge/js/ilBadgeRenderer.js");
128  $tpl->addOnLoadCode('il.BadgeRenderer.init("' . $url . '");');
129  }
130 
131  $hash = $this->getBadgeHash();
132 
133  return "#\" data-id=\"badge_" .
134  ($this->assignment
135  ? $this->assignment->getUserId()
136  : "") . "_" .
137  $this->badge->getId() . "_" .
138  $hash;
139  }
global $ilCtrl
Definition: ilias.php:18
$url
+ Here is the call graph for this function:

◆ getHTML()

ilBadgeRenderer::getHTML ( )

Definition at line 76 of file class.ilBadgeRenderer.php.

References $ctrl, $ilCtrl, $tpl, $url, getBadgeHash(), and ilWACSignedPath\signFile().

77  {
78  $tpl = $this->tpl;
80 
81  if (!self::$init) {
82  self::$init = true;
83 
84  $url = $ilCtrl->getLinkTargetByClass(
85  "ilBadgeHandlerGUI",
86  "render",
87  "",
88  true,
89  false
90  );
91 
92  $tpl->addJavaScript("Services/Badge/js/ilBadgeRenderer.js");
93  $tpl->addOnLoadCode('il.BadgeRenderer.init("' . $url . '");');
94  }
95 
96  $hash = $this->getBadgeHash();
97 
98  $btpl = new ilTemplate("tpl.badge_renderer.html", true, true, "Services/Badge");
99  $image_path = ilWACSignedPath::signFile($this->badge->getImagePath());
100  $btpl->setVariable("BADGE_IMG", $image_path);
101  $btpl->setVariable("BADGE_TXT", $this->badge->getTitle());
102  $btpl->setVariable("BADGE_ID", "badge_" .
103  ($this->assignment
104  ? $this->assignment->getUserId()
105  : "") . "_" .
106  $this->badge->getId() . "_" .
107  $hash);
108  return $btpl->get();
109  }
global $ilCtrl
Definition: ilias.php:18
special template class to simplify handling of ITX/PEAR
static signFile($path_to_file)
$url
+ Here is the call graph for this function:

◆ initFromId()

static ilBadgeRenderer::initFromId (   $a_id)
static

Definition at line 51 of file class.ilBadgeRenderer.php.

References $_GET, $assignment, $badge, and $id.

Referenced by ilBadgeHandlerGUI\render().

52  {
53  $id = explode("_", $_GET["id"]);
54  if (sizeof($id) == 3) {
55  $user_id = $id[0];
56  $badge_id = $id[1];
57  $hash = $id[2];
58 
59  if ($user_id) {
60  include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
61  $assignment = new ilBadgeAssignment($badge_id, $user_id);
62  if ($assignment->getTimestamp()) {
63  $obj = new self($assignment);
64  }
65  } else {
66  include_once "Services/Badge/classes/class.ilBadge.php";
67  $badge = new ilBadge($badge_id);
68  $obj = new self(null, $badge);
69  }
70  if ($hash == $obj->getBadgeHash()) {
71  return $obj;
72  }
73  }
74  }
$_GET["client_id"]
if(!array_key_exists('StateId', $_REQUEST)) $id
+ Here is the caller graph for this function:

◆ renderModal()

ilBadgeRenderer::renderModal ( )

Definition at line 150 of file class.ilBadgeRenderer.php.

References $lng, $tpl, ilDatePresentation\formatDate(), getBadgeHash(), ilModalGUI\getInstance(), IL_CAL_UNIX, and ilModalGUI\TYPE_SMALL.

151  {
152  $lng = $this->lng;
153 
154  include_once "Services/UIComponent/Modal/classes/class.ilModalGUI.php";
155 
156  // only needed for modal-js-calls
157  // ilModalGUI::initJS();
158 
159  $modal = ilModalGUI::getInstance();
160  $modal->setId("badge_modal_" . $this->getBadgeHash());
161  $modal->setType(ilModalGUI::TYPE_SMALL);
162  $modal->setHeading($this->badge->getTitle());
163 
164  $lng->loadLanguageModule("badge");
165 
166  $tpl = new ilTemplate("tpl.badge_modal.html", true, true, "Services/Badge");
167 
168  $tpl->setVariable("IMG_SRC", $this->badge->getImagePath());
169  $tpl->setVariable("IMG_TXT", $this->badge->getImage());
170 
171  $tpl->setVariable("TXT_DESC", $lng->txt("description"));
172  $tpl->setVariable("DESC", nl2br($this->badge->getDescription()));
173 
174  $tpl->setVariable("TXT_CRITERIA", $lng->txt("badge_criteria"));
175  $tpl->setVariable("CRITERIA", nl2br($this->badge->getCriteria()));
176 
177  if ($this->assignment) {
178  $tpl->setVariable("TXT_TSTAMP", $lng->txt("badge_issued_on"));
179  $tpl->setVariable(
180  "TSTAMP",
181  ilDatePresentation::formatDate(new ilDateTime($this->assignment->getTimestamp(), IL_CAL_UNIX))
182  );
183  }
184 
185  if ($this->badge->getParentId()) {
186  $parent = $this->badge->getParentMeta();
187  if ($parent["type"] != "bdga") {
188  $tpl->setVariable("TXT_PARENT", $lng->txt("object"));
189  $tpl->setVariable("PARENT", $parent["title"]);
190  $tpl->setVariable("PARENT_TYPE", $lng->txt("obj_" . $parent["type"]));
191  $tpl->setVariable(
192  "PARENT_ICON",
193  ilObject::_getIcon($parent["id"], "big", $parent["type"])
194  );
195  }
196  }
197 
198  if ($this->badge->getValid()) {
199  $tpl->setVariable("TXT_VALID", $lng->txt("badge_valid"));
200  $tpl->setVariable("VALID", $this->badge->getValid());
201  }
202 
203  $modal->setBody($tpl->get());
204 
205  return $modal->getHTML();
206  }
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
special template class to simplify handling of ITX/PEAR
Date and time handling
static getInstance()
Get instance.
+ Here is the call graph for this function:

Field Documentation

◆ $assignment

ilBadgeRenderer::$assignment
protected

Definition at line 31 of file class.ilBadgeRenderer.php.

Referenced by initFromId().

◆ $badge

ilBadgeRenderer::$badge
protected

Definition at line 32 of file class.ilBadgeRenderer.php.

Referenced by initFromId().

◆ $ctrl

ilBadgeRenderer::$ctrl
protected

Definition at line 24 of file class.ilBadgeRenderer.php.

Referenced by getHref(), and getHTML().

◆ $init

ilBadgeRenderer::$init
staticprotected

Definition at line 34 of file class.ilBadgeRenderer.php.

◆ $lng

ilBadgeRenderer::$lng
protected

Definition at line 29 of file class.ilBadgeRenderer.php.

Referenced by renderModal().

◆ $tpl

ilBadgeRenderer::$tpl
protected

Definition at line 19 of file class.ilBadgeRenderer.php.

Referenced by getHref(), getHTML(), and renderModal().


The documentation for this class was generated from the following file: