ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilBadgeProfileGUI Class Reference
+ Collaboration diagram for ilBadgeProfileGUI:

Public Member Functions

 executeCommand ()
 

Data Fields

const BACKPACK_EMAIL = "badge_mozilla_bp"
 

Protected Member Functions

 setTabs ()
 
 getSubTabs ($a_active)
 
 listBadges ()
 
 manageBadges ()
 
 applyFilter ()
 
 resetFilter ()
 
 getMultiSelection ()
 
 activate ()
 
 deactivate ()
 
 addToBackpackMulti ()
 
 setBackpackSubTabs ()
 
 listBackpackGroups ()
 
 prepareBadge ($a_badge_id)
 
 addToBackpack ()
 
 getBackpackMail ()
 
 initSettingsForm ()
 
 editSettings (ilPropertyFormGUI $a_form=null)
 
 saveSettings ()
 

Detailed Description

Definition at line 13 of file class.ilBadgeProfileGUI.php.

Member Function Documentation

◆ activate()

ilBadgeProfileGUI::activate ( )
protected

Definition at line 194 of file class.ilBadgeProfileGUI.php.

195 {
196 global $lng, $ilCtrl;
197
198 foreach($this->getMultiSelection() as $ass)
199 {
200 // already active?
201 if(!$ass->getPosition())
202 {
203 $ass->setPosition(999);
204 $ass->store();
205 }
206 }
207
208 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
209 $ilCtrl->redirect($this, "manageBadges");
210 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17

References $ilCtrl, $lng, getMultiSelection(), and ilUtil\sendSuccess().

+ Here is the call graph for this function:

◆ addToBackpack()

ilBadgeProfileGUI::addToBackpack ( )
protected

Definition at line 367 of file class.ilBadgeProfileGUI.php.

368 {
369 global $ilCtrl;
370
371 if(!$ilCtrl->isAsynch() ||
372 !ilBadgeHandler::getInstance()->isObiActive())
373 {
374 return false;
375 }
376
377 $res = new stdClass();
378
379 $url = false;
380 $badge_id = (int)$_GET["id"];
381 if($badge_id)
382 {
383 $url = $this->prepareBadge($badge_id);
384 }
385
386 if($url !== false)
387 {
388 $res->error = false;
389 $res->url = $url;
390 }
391 else
392 {
393 $res->error = true;
394 $res->message = "missing badge id";
395 }
396
397 echo json_encode($res);
398 exit();
399 }
$_GET["client_id"]
static getInstance()
Constructor.
$url
Definition: shib_logout.php:72

References $_GET, $ilCtrl, $res, $url, exit, ilBadgeHandler\getInstance(), and prepareBadge().

+ Here is the call graph for this function:

◆ addToBackpackMulti()

ilBadgeProfileGUI::addToBackpackMulti ( )
protected

Definition at line 235 of file class.ilBadgeProfileGUI.php.

236 {
237 global $tpl, $ilTabs, $ilCtrl, $lng;
238
239 $res = array();
240 foreach($this->getMultiSelection() as $ass)
241 {
242 $url = $this->prepareBadge($ass->getBadgeId());
243 if($url !== false)
244 {
245 $badge = new ilBadge($ass->getBadgeId());
246 $titles[] = $badge->getTitle();
247 $res[] = $url;
248 }
249 }
250
251 // :TODO: use local copy instead?
252 $tpl->addJavascript("https://backpack.openbadges.org/issuer.js", false);
253
254 $tpl->addJavascript("Services/Badge/js/ilBadge.js");
255 $tpl->addOnloadCode("il.Badge.publishMulti(['".implode("','", $res)."']);");
256
257 $ilTabs->clearTargets();
258 $ilTabs->setBackTarget($lng->txt("back"),
259 $ilCtrl->getLinkTarget($this, "manageBadges"));
260
261 ilUtil::sendInfo(sprintf($lng->txt("badge_add_to_backpack_multi"), implode(", ", $titles)));
262 }
sprintf('%.4f', $callTime)
global $tpl
Definition: ilias.php:8
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.

References $ilCtrl, $lng, $res, $tpl, $url, getMultiSelection(), prepareBadge(), ilUtil\sendInfo(), and sprintf.

+ Here is the call graph for this function:

◆ applyFilter()

ilBadgeProfileGUI::applyFilter ( )
protected

Definition at line 144 of file class.ilBadgeProfileGUI.php.

145 {
146 include_once "Services/Badge/classes/class.ilBadgePersonalTableGUI.php";
147 $tbl = new ilBadgePersonalTableGUI($this, "manageBadges");
148 $tbl->resetOffset();
149 $tbl->writeFilterToSession();
150 $this->manageBadges();
151 }
TableGUI class for user badge listing.
$tbl
Definition: example_048.php:81

References $tbl, and manageBadges().

+ Here is the call graph for this function:

◆ deactivate()

ilBadgeProfileGUI::deactivate ( )
protected

Definition at line 212 of file class.ilBadgeProfileGUI.php.

213 {
214 global $lng, $ilCtrl;
215
216 foreach($this->getMultiSelection() as $ass)
217 {
218 // already inactive?
219 if($ass->getPosition())
220 {
221 $ass->setPosition(null);
222 $ass->store();
223 }
224 }
225
226 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
227 $ilCtrl->redirect($this, "manageBadges");
228 }

References $ilCtrl, $lng, getMultiSelection(), and ilUtil\sendSuccess().

+ Here is the call graph for this function:

◆ editSettings()

ilBadgeProfileGUI::editSettings ( ilPropertyFormGUI  $a_form = null)
protected

Definition at line 438 of file class.ilBadgeProfileGUI.php.

439 {
440 global $tpl, $ilCtrl, $ilTabs;
441
442 if(!ilBadgeHandler::getInstance()->isObiActive())
443 {
444 $ilCtrl->redirect($this, "listBadges");
445 }
446
447 $this->setBackpackSubTabs();
448 $ilTabs->activateSubTab("backpack_settings");
449
450 if(!$a_form)
451 {
452 $a_form = $this->initSettingsForm();
453 }
454
455 $tpl->setContent($a_form->getHTML());
456 }

References $ilCtrl, $tpl, ilBadgeHandler\getInstance(), initSettingsForm(), and setBackpackSubTabs().

Referenced by saveSettings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilBadgeProfileGUI::executeCommand ( )

Definition at line 17 of file class.ilBadgeProfileGUI.php.

18 {
19 global $ilCtrl, $lng, $tpl;
20
21 $lng->loadLanguageModule("badge");
22
23 $tpl->setTitle($lng->txt("obj_bdga"));
24 $tpl->setTitleIcon(ilUtil::getImagePath("icon_bdga.svg"));
25
26 switch($ilCtrl->getNextClass())
27 {
28 default:
29 $this->setTabs();
30 $cmd = $ilCtrl->getCmd("listBadges");
31 $this->$cmd();
32 break;
33 }
34 }
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$cmd
Definition: sahs_server.php:35

References $cmd, $ilCtrl, $lng, $tpl, ilUtil\getImagePath(), and setTabs().

+ Here is the call graph for this function:

◆ getBackpackMail()

ilBadgeProfileGUI::getBackpackMail ( )
protected

Definition at line 406 of file class.ilBadgeProfileGUI.php.

407 {
408 global $ilUser;
409
410 $mail = $ilUser->getPref(self::BACKPACK_EMAIL);
411 if(!$mail)
412 {
413 $mail = $ilUser->getEmail();
414 }
415 return $mail;
416 }
$ilUser
Definition: imgupload.php:18

References $ilUser.

Referenced by initSettingsForm(), listBackpackGroups(), and saveSettings().

+ Here is the caller graph for this function:

◆ getMultiSelection()

ilBadgeProfileGUI::getMultiSelection ( )
protected

Definition at line 162 of file class.ilBadgeProfileGUI.php.

163 {
164 global $lng, $ilCtrl, $ilUser;
165
166 $ids = $_POST["badge_id"];
167 if(!$ids && is_numeric($_GET["badge_id"]))
168 {
169 $ids = array($_GET["badge_id"]);
170 }
171 if(is_array($ids))
172 {
173 $res = array();
174 include_once "Services/Badge/classes/class.ilBadge.php";
175 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
176 foreach($ids as $id)
177 {
178 $ass = new ilBadgeAssignment($id, $ilUser->getId());
179 if($ass->getTimestamp())
180 {
181 $res[] = $ass;
182 }
183 }
184
185 return $res;
186 }
187 else
188 {
189 ilUtil::sendFailure($lng->txt("select_one"), true);
190 $ilCtrl->redirect($this, "manageBadges");
191 }
192 }
$_POST["username"]
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.

References $_GET, $_POST, $ilCtrl, $ilUser, $lng, $res, and ilUtil\sendFailure().

Referenced by activate(), addToBackpackMulti(), and deactivate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSubTabs()

ilBadgeProfileGUI::getSubTabs (   $a_active)
protected

Definition at line 57 of file class.ilBadgeProfileGUI.php.

58 {
59 global $ilTabs, $lng, $ilCtrl;
60
61 if(ilBadgeHandler::getInstance()->isObiActive())
62 {
63 $ilTabs->addSubTab("list",
64 $lng->txt("badge_profile_view"),
65 $ilCtrl->getLinkTarget($this, "listBadges"));
66 $ilTabs->addSubTab("manage",
67 $lng->txt("badge_profile_manage"),
68 $ilCtrl->getLinkTarget($this, "manageBadges"));
69 $ilTabs->activateTab("ilias_badges");
70 $ilTabs->activateSubTab($a_active);
71 }
72 else
73 {
74 $ilTabs->addTab("list",
75 $lng->txt("badge_profile_view"),
76 $ilCtrl->getLinkTarget($this, "listBadges"));
77 $ilTabs->addTab("manage",
78 $lng->txt("badge_profile_manage"),
79 $ilCtrl->getLinkTarget($this, "manageBadges"));
80 $ilTabs->activateTab($a_active);
81 }
82
83 }

References $ilCtrl, $lng, and ilBadgeHandler\getInstance().

Referenced by listBadges(), and manageBadges().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initSettingsForm()

ilBadgeProfileGUI::initSettingsForm ( )
protected

Definition at line 418 of file class.ilBadgeProfileGUI.php.

419 {
420 global $lng, $ilCtrl;
421
422 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
423 $form = new ilPropertyFormGUI();
424 $form->setFormAction($ilCtrl->getFormAction($this, "saveSettings"));
425 $form->setTitle($lng->txt("settings"));
426
427 $email = new ilEMailInputGUI($lng->txt("badge_backpack_email"), "email");
428 // $email->setRequired(true);
429 $email->setInfo($lng->txt("badge_backpack_email_info"));
430 $email->setValue($this->getBackpackMail());
431 $form->addItem($email);
432
433 $form->addCommandButton("saveSettings", $lng->txt("save"));
434
435 return $form;
436 }
This class represents a email property in a property form.
This class represents a property form user interface.

References $ilCtrl, $lng, and getBackpackMail().

Referenced by editSettings(), and saveSettings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listBackpackGroups()

ilBadgeProfileGUI::listBackpackGroups ( )
protected

Definition at line 279 of file class.ilBadgeProfileGUI.php.

280 {
281 global $lng, $tpl, $ilCtrl, $ilTabs;
282
283 if(!ilBadgeHandler::getInstance()->isObiActive())
284 {
285 $ilCtrl->redirect($this, "listBadges");
286 }
287
288 $this->setBackpackSubTabs();
289 $ilTabs->activateSubTab("backpack_badges");
290
291 ilUtil::sendInfo($lng->txt("badge_backpack_gallery_info"));
292
293 include_once "Services/Badge/classes/class.ilBadgeBackpack.php";
294 $bp = new ilBadgeBackpack($this->getBackpackMail());
295 $bp_groups = $bp->getGroups();
296
297 if(!is_array($bp_groups))
298 {
299 ilUtil::sendInfo(sprintf($lng->txt("badge_backpack_connect_failed"), $this->getBackpackMail()));
300 return;
301 }
302 else if(!sizeof($bp_groups))
303 {
304 ilUtil::sendInfo($lng->txt("badge_backpack_no_groups"));
305 return;
306 }
307
308 $tmpl = new ilTemplate("tpl.badge_backpack.html", true, true, "Services/Badge");
309
310 $tmpl->setVariable("BACKPACK_TITLE", $lng->txt("badge_backpack_list"));
311
313
314 foreach($bp_groups as $group_id => $group)
315 {
316 $bp_badges = $bp->getBadges($group_id);
317 if(sizeof($bp_badges))
318 {
319 foreach($bp_badges as $idx => $badge)
320 {
321 $tmpl->setCurrentBlock("badge_bl");
322 $tmpl->setVariable("BADGE_TITLE", $badge["title"]);
323 $tmpl->setVariable("BADGE_DESC", $badge["description"]);
324 $tmpl->setVariable("BADGE_IMAGE", $badge["image_url"]);
325 $tmpl->setVariable("BADGE_CRITERIA", $badge["criteria_url"]);
326 $tmpl->setVariable("BADGE_ISSUER", $badge["issuer_name"]);
327 $tmpl->setVariable("BADGE_ISSUER_URL", $badge["issuer_url"]);
328 $tmpl->setVariable("BADGE_DATE", ilDatePresentation::formatDate($badge["issued_on"]));
329 $tmpl->parseCurrentBlock();
330 }
331 }
332
333 $tmpl->setCurrentBlock("group_bl");
334 $tmpl->setVariable("GROUP_TITLE", $group["title"]);
335 $tmpl->parseCurrentBlock();
336 }
337
338 $tpl->setContent($tmpl->get());
339 }
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date)
Format a date @access public.
special template class to simplify handling of ITX/PEAR

References $ilCtrl, $lng, $tpl, ilDatePresentation\formatDate(), getBackpackMail(), ilBadgeHandler\getInstance(), ilUtil\sendInfo(), setBackpackSubTabs(), ilDatePresentation\setUseRelativeDates(), and sprintf.

+ Here is the call graph for this function:

◆ listBadges()

ilBadgeProfileGUI::listBadges ( )
protected

Definition at line 85 of file class.ilBadgeProfileGUI.php.

86 {
87 global $tpl, $ilUser;
88
89 $this->getSubTabs("list");
90
91 $data = array();
92
93 // see ilBadgePersonalTableGUI::getItems()
94 include_once "Services/Badge/classes/class.ilBadge.php";
95 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
96 include_once "Services/Badge/classes/class.ilBadgeRenderer.php";
97 foreach(ilBadgeAssignment::getInstancesByUserId($ilUser->getId()) as $ass)
98 {
99 $badge = new ilBadge($ass->getBadgeId());
100
101 $data[] = array(
102 "id" => $badge->getId(),
103 "title" => $badge->getTitle(),
104 "description" => $badge->getDescription(),
105 "image" => $badge->getImagePath(),
106 "issued_on" => $ass->getTimestamp(),
107 "renderer" => new ilBadgeRenderer($ass)
108 );
109 }
110
111 // :TODO:
112 $data = ilUtil::sortArray($data, "issued_on", "desc", true);
113
114 $tmpl = new ilTemplate("tpl.badge_backpack.html", true, true, "Services/Badge");
115
117
118 foreach($data as $badge)
119 {
120 $tmpl->setCurrentBlock("badge_bl");
121 $tmpl->setVariable("BADGE_TITLE", $badge["title"]);
122 // $tmpl->setVariable("BADGE_DESC", $badge["description"]); :TODO:
123 $tmpl->setVariable("BADGE_IMAGE", $badge["image"]);
124 $tmpl->setVariable("BADGE_CRITERIA", $badge["renderer"]->getHref());
125 $tmpl->setVariable("BADGE_DATE", ilDatePresentation::formatDate(new ilDateTime($badge["issued_on"], IL_CAL_UNIX)));
126 $tmpl->parseCurrentBlock();
127 }
128
129 $tpl->setContent($tmpl->get());
130 }
const IL_CAL_UNIX
static getInstancesByUserId($a_user_id)
@classDescription Date and time handling
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray

References $data, $ilUser, $tpl, ilDatePresentation\formatDate(), ilBadgeAssignment\getInstancesByUserId(), getSubTabs(), IL_CAL_UNIX, ilDatePresentation\setUseRelativeDates(), and ilUtil\sortArray().

+ Here is the call graph for this function:

◆ manageBadges()

ilBadgeProfileGUI::manageBadges ( )
protected

Definition at line 132 of file class.ilBadgeProfileGUI.php.

133 {
134 global $tpl;
135
136 $this->getSubTabs("manage");
137
138 include_once "Services/Badge/classes/class.ilBadgePersonalTableGUI.php";
139 $tbl = new ilBadgePersonalTableGUI($this, "manageBadges");
140
141 $tpl->setContent($tbl->getHTML());
142 }

References $tbl, $tpl, and getSubTabs().

Referenced by applyFilter(), and resetFilter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepareBadge()

ilBadgeProfileGUI::prepareBadge (   $a_badge_id)
protected

Definition at line 341 of file class.ilBadgeProfileGUI.php.

342 {
343 global $ilUser;
344
345 // check if current user has given badge
346 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
347 $ass = new ilBadgeAssignment($a_badge_id, $ilUser->getId());
348 if($ass->getTimestamp())
349 {
350 $url = null;
351 try
352 {
353 $url = $ass->getStaticUrl();
354 }
355 catch (Exception $ex) {
356
357 }
358 if($url)
359 {
360 return $url;
361 }
362 }
363
364 return false;
365 }

References $ilUser, and $url.

Referenced by addToBackpack(), and addToBackpackMulti().

+ Here is the caller graph for this function:

◆ resetFilter()

ilBadgeProfileGUI::resetFilter ( )
protected

Definition at line 153 of file class.ilBadgeProfileGUI.php.

154 {
155 include_once "Services/Badge/classes/class.ilBadgePersonalTableGUI.php";
156 $tbl = new ilBadgePersonalTableGUI($this, "manageBadges");
157 $tbl->resetOffset();
158 $tbl->resetFilter();
159 $this->manageBadges();
160 }

References $tbl, and manageBadges().

+ Here is the call graph for this function:

◆ saveSettings()

ilBadgeProfileGUI::saveSettings ( )
protected

Definition at line 458 of file class.ilBadgeProfileGUI.php.

459 {
460 global $ilUser, $lng, $ilCtrl;
461
462 $form = $this->initSettingsForm();
463 if($form->checkInput())
464 {
465 $new_email = $form->getInput("email");
466 $old_email = $this->getBackpackMail();
467
468 ilObjUser::_writePref($ilUser->getId(), self::BACKPACK_EMAIL, $new_email);
469
470 // if email was changed: delete badge files
471 if($new_email != $old_email)
472 {
473 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
475 }
476
477 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
478 $ilCtrl->redirect($this, "editSettings");
479 }
480
481 $form->setValuesByPost();
482 $this->editSettings($form);
483 }
static clearBadgeCache($a_user_id)
editSettings(ilPropertyFormGUI $a_form=null)
static _writePref($a_usr_id, $a_keyword, $a_value)

References $ilCtrl, $ilUser, $lng, ilObjUser\_writePref(), ilBadgeAssignment\clearBadgeCache(), editSettings(), getBackpackMail(), initSettingsForm(), and ilUtil\sendSuccess().

+ Here is the call graph for this function:

◆ setBackpackSubTabs()

ilBadgeProfileGUI::setBackpackSubTabs ( )
protected

Definition at line 264 of file class.ilBadgeProfileGUI.php.

265 {
266 global $ilTabs, $lng, $ilCtrl;
267
268 $ilTabs->addSubTab("backpack_badges",
269 $lng->txt("obj_bdga"),
270 $ilCtrl->getLinkTarget($this, "listBackpackGroups"));
271
272 $ilTabs->addSubTab("backpack_settings",
273 $lng->txt("settings"),
274 $ilCtrl->getLinkTarget($this, "editSettings"));
275
276 $ilTabs->activateTab("backpack_badges");
277 }

References $ilCtrl, and $lng.

Referenced by editSettings(), and listBackpackGroups().

+ Here is the caller graph for this function:

◆ setTabs()

ilBadgeProfileGUI::setTabs ( )
protected

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

37 {
38 global $ilTabs, $lng, $ilCtrl;
39
40 if(ilBadgeHandler::getInstance()->isObiActive())
41 {
42 $ilTabs->addTab("ilias_badges",
43 $lng->txt("badge_personal_badges"),
44 $ilCtrl->getLinkTarget($this, "listBadges"));
45
46 $ilTabs->addTab("backpack_badges",
47 $lng->txt("badge_backpack_list"),
48 $ilCtrl->getLinkTarget($this, "listBackpackGroups"));
49 }
50 }

References $ilCtrl, $lng, and ilBadgeHandler\getInstance().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ BACKPACK_EMAIL

const ilBadgeProfileGUI::BACKPACK_EMAIL = "badge_mozilla_bp"

Definition at line 15 of file class.ilBadgeProfileGUI.php.

Referenced by ilBadgeAssignment\prepareJson().


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