ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilBadgeProfileGUI Class Reference
+ Collaboration diagram for ilBadgeProfileGUI:

Public Member Functions

 __construct ()
 Constructor. More...
 
 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 ()
 

Protected Attributes

 $ctrl
 
 $lng
 
 $tpl
 
 $tabs
 
 $user
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilBadgeProfileGUI::__construct ( )

Constructor.

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

45 {
46 global $DIC;
47
48 $this->ctrl = $DIC->ctrl();
49 $this->lng = $DIC->language();
50 $this->tpl = $DIC["tpl"];
51 $this->tabs = $DIC->tabs();
52 $this->user = $DIC->user();
53 }
user()
Definition: user.php:4
global $DIC
Definition: saml.php:7

References $DIC, and user().

+ Here is the call graph for this function:

Member Function Documentation

◆ activate()

ilBadgeProfileGUI::activate ( )
protected

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

242 {
245
246 foreach ($this->getMultiSelection() as $ass) {
247 // already active?
248 if (!$ass->getPosition()) {
249 $ass->setPosition(999);
250 $ass->store();
251 }
252 }
253
254 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
255 $ilCtrl->redirect($this, "manageBadges");
256 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
global $ilCtrl
Definition: ilias.php:18

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

+ Here is the call graph for this function:

◆ addToBackpack()

ilBadgeProfileGUI::addToBackpack ( )
protected

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

413 {
415
416 if (!$ilCtrl->isAsynch() ||
417 !ilBadgeHandler::getInstance()->isObiActive()) {
418 return false;
419 }
420
421 $res = new stdClass();
422
423 $url = false;
424 $badge_id = (int) $_GET["id"];
425 if ($badge_id) {
426 $url = $this->prepareBadge($badge_id);
427 }
428
429 if ($url !== false) {
430 $res->error = false;
431 $res->url = $url;
432 } else {
433 $res->error = true;
434 $res->message = "missing badge id";
435 }
436
437 echo json_encode($res);
438 exit();
439 }
$_GET["client_id"]
static getInstance()
Constructor.
$url
foreach($_POST as $key=> $value) $res

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

+ Here is the call graph for this function:

◆ addToBackpackMulti()

ilBadgeProfileGUI::addToBackpackMulti ( )
protected

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

281 {
283 $ilTabs = $this->tabs;
286
287 $res = array();
288 foreach ($this->getMultiSelection() as $ass) {
289 $url = $this->prepareBadge($ass->getBadgeId());
290 if ($url !== false) {
291 $badge = new ilBadge($ass->getBadgeId());
292 $titles[] = $badge->getTitle();
293 $res[] = $url;
294 }
295 }
296
297 // :TODO: use local copy instead?
298 $tpl->addJavascript("https://backpack.openbadges.org/issuer.js", false);
299
300 $tpl->addJavascript("Services/Badge/js/ilBadge.js");
301 $tpl->addOnloadCode("il.Badge.publishMulti(['" . implode("','", $res) . "']);");
302
303 $ilTabs->clearTargets();
304 $ilTabs->setBackTarget(
305 $lng->txt("back"),
306 $ilCtrl->getLinkTarget($this, "manageBadges")
307 );
308
309 ilUtil::sendInfo(sprintf($lng->txt("badge_add_to_backpack_multi"), implode(", ", $titles)));
310 }
sprintf('%.4f', $callTime)
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.

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

+ Here is the call graph for this function:

◆ applyFilter()

ilBadgeProfileGUI::applyFilter ( )
protected

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

196 {
197 include_once "Services/Badge/classes/class.ilBadgePersonalTableGUI.php";
198 $tbl = new ilBadgePersonalTableGUI($this, "manageBadges");
199 $tbl->resetOffset();
200 $tbl->writeFilterToSession();
201 $this->manageBadges();
202 }
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 258 of file class.ilBadgeProfileGUI.php.

259 {
262
263 foreach ($this->getMultiSelection() as $ass) {
264 // already inactive?
265 if ($ass->getPosition()) {
266 $ass->setPosition(null);
267 $ass->store();
268 }
269 }
270
271 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
272 $ilCtrl->redirect($this, "manageBadges");
273 }

References $ctrl, $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 478 of file class.ilBadgeProfileGUI.php.

479 {
482 $ilTabs = $this->tabs;
483
484 if (!ilBadgeHandler::getInstance()->isObiActive()) {
485 $ilCtrl->redirect($this, "listBadges");
486 }
487
488 $this->setBackpackSubTabs();
489 $ilTabs->activateSubTab("backpack_settings");
490
491 if (!$a_form) {
492 $a_form = $this->initSettingsForm();
493 }
494
495 $tpl->setContent($a_form->getHTML());
496 }

References $ctrl, $ilCtrl, $tabs, $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 57 of file class.ilBadgeProfileGUI.php.

58 {
62
63 $lng->loadLanguageModule("badge");
64
65 $tpl->setTitle($lng->txt("obj_bdga"));
66 $tpl->setTitleIcon(ilUtil::getImagePath("icon_bdga.svg"));
67
68 switch ($ilCtrl->getNextClass()) {
69 default:
70 $this->setTabs();
71 $cmd = $ilCtrl->getCmd("listBadges");
72 $this->$cmd();
73 break;
74 }
75 }
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)

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

+ Here is the call graph for this function:

◆ getBackpackMail()

ilBadgeProfileGUI::getBackpackMail ( )
protected

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

447 {
449
450 $mail = $ilUser->getPref(self::BACKPACK_EMAIL);
451 if (!$mail) {
452 $mail = $ilUser->getEmail();
453 }
454 return $mail;
455 }
$ilUser
Definition: imgupload.php:18

References $ilUser, and $user.

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

+ Here is the caller graph for this function:

◆ getMultiSelection()

ilBadgeProfileGUI::getMultiSelection ( )
protected

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

214 {
218
219 $ids = $_POST["badge_id"];
220 if (!$ids && is_numeric($_GET["badge_id"])) {
221 $ids = array($_GET["badge_id"]);
222 }
223 if (is_array($ids)) {
224 $res = array();
225 include_once "Services/Badge/classes/class.ilBadge.php";
226 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
227 foreach ($ids as $id) {
228 $ass = new ilBadgeAssignment($id, $ilUser->getId());
229 if ($ass->getTimestamp()) {
230 $res[] = $ass;
231 }
232 }
233
234 return $res;
235 } else {
236 ilUtil::sendFailure($lng->txt("select_one"), true);
237 $ilCtrl->redirect($this, "manageBadges");
238 }
239 }
$_POST["username"]
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
if(!array_key_exists('StateId', $_REQUEST)) $id

References $_GET, $_POST, $ctrl, $id, $ilCtrl, $ilUser, $lng, $res, $user, 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 103 of file class.ilBadgeProfileGUI.php.

104 {
105 $ilTabs = $this->tabs;
108
109 if (ilBadgeHandler::getInstance()->isObiActive()) {
110 $ilTabs->addSubTab(
111 "list",
112 $lng->txt("badge_profile_view"),
113 $ilCtrl->getLinkTarget($this, "listBadges")
114 );
115 $ilTabs->addSubTab(
116 "manage",
117 $lng->txt("badge_profile_manage"),
118 $ilCtrl->getLinkTarget($this, "manageBadges")
119 );
120 $ilTabs->activateTab("ilias_badges");
121 $ilTabs->activateSubTab($a_active);
122 } else {
123 $ilTabs->addTab(
124 "list",
125 $lng->txt("badge_profile_view"),
126 $ilCtrl->getLinkTarget($this, "listBadges")
127 );
128 $ilTabs->addTab(
129 "manage",
130 $lng->txt("badge_profile_manage"),
131 $ilCtrl->getLinkTarget($this, "manageBadges")
132 );
133 $ilTabs->activateTab($a_active);
134 }
135 }

References $ctrl, $ilCtrl, $lng, $tabs, 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 457 of file class.ilBadgeProfileGUI.php.

458 {
461
462 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
463 $form = new ilPropertyFormGUI();
464 $form->setFormAction($ilCtrl->getFormAction($this, "saveSettings"));
465 $form->setTitle($lng->txt("settings"));
466
467 $email = new ilEMailInputGUI($lng->txt("badge_backpack_email"), "email");
468 // $email->setRequired(true);
469 $email->setInfo($lng->txt("badge_backpack_email_info"));
470 $email->setValue($this->getBackpackMail());
471 $form->addItem($email);
472
473 $form->addCommandButton("saveSettings", $lng->txt("save"));
474
475 return $form;
476 }
This class represents a email property in a property form.
This class represents a property form user interface.
if( $orgName !==null) if($spconfig->hasValue('contacts')) $email
Definition: metadata.php:193
if(isset($_POST['submit'])) $form

References $ctrl, $email, $form, $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 333 of file class.ilBadgeProfileGUI.php.

334 {
338 $ilTabs = $this->tabs;
339
340 if (!ilBadgeHandler::getInstance()->isObiActive()) {
341 $ilCtrl->redirect($this, "listBadges");
342 }
343
344 $this->setBackpackSubTabs();
345 $ilTabs->activateSubTab("backpack_badges");
346
347 ilUtil::sendInfo($lng->txt("badge_backpack_gallery_info"));
348
349 include_once "Services/Badge/classes/class.ilBadgeBackpack.php";
350 $bp = new ilBadgeBackpack($this->getBackpackMail());
351 $bp_groups = $bp->getGroups();
352
353 if (!is_array($bp_groups)) {
354 ilUtil::sendInfo(sprintf($lng->txt("badge_backpack_connect_failed"), $this->getBackpackMail()));
355 return;
356 } elseif (!sizeof($bp_groups)) {
357 ilUtil::sendInfo($lng->txt("badge_backpack_no_groups"));
358 return;
359 }
360
361 $tmpl = new ilTemplate("tpl.badge_backpack.html", true, true, "Services/Badge");
362
363 $tmpl->setVariable("BACKPACK_TITLE", $lng->txt("badge_backpack_list"));
364
366
367 foreach ($bp_groups as $group_id => $group) {
368 $bp_badges = $bp->getBadges($group_id);
369 if (sizeof($bp_badges)) {
370 foreach ($bp_badges as $idx => $badge) {
371 $tmpl->setCurrentBlock("badge_bl");
372 $tmpl->setVariable("BADGE_TITLE", $badge["title"]);
373 $tmpl->setVariable("BADGE_DESC", $badge["description"]);
374 $tmpl->setVariable("BADGE_IMAGE", $badge["image_url"]);
375 $tmpl->setVariable("BADGE_CRITERIA", $badge["criteria_url"]);
376 $tmpl->setVariable("BADGE_ISSUER", $badge["issuer_name"]);
377 $tmpl->setVariable("BADGE_ISSUER_URL", $badge["issuer_url"]);
378 $tmpl->setVariable("BADGE_DATE", ilDatePresentation::formatDate($badge["issued_on"]));
379 $tmpl->parseCurrentBlock();
380 }
381 }
382
383 $tmpl->setCurrentBlock("group_bl");
384 $tmpl->setVariable("GROUP_TITLE", $group["title"]);
385 $tmpl->parseCurrentBlock();
386 }
387
388 $tpl->setContent($tmpl->get());
389 }
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
special template class to simplify handling of ITX/PEAR

References $ctrl, $ilCtrl, $lng, $tabs, $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 137 of file class.ilBadgeProfileGUI.php.

138 {
141
142 $this->getSubTabs("list");
143
144 $data = array();
145
146 // see ilBadgePersonalTableGUI::getItems()
147 include_once "Services/Badge/classes/class.ilBadge.php";
148 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
149 include_once "Services/Badge/classes/class.ilBadgeRenderer.php";
150 foreach (ilBadgeAssignment::getInstancesByUserId($ilUser->getId()) as $ass) {
151 $badge = new ilBadge($ass->getBadgeId());
152
153 $data[] = array(
154 "id" => $badge->getId(),
155 "title" => $badge->getTitle(),
156 "description" => $badge->getDescription(),
157 "image" => $badge->getImagePath(),
158 "issued_on" => $ass->getTimestamp(),
159 "renderer" => new ilBadgeRenderer($ass)
160 );
161 }
162
163 // :TODO:
164 $data = ilUtil::sortArray($data, "issued_on", "desc", true);
165
166 $tmpl = new ilTemplate("tpl.badge_backpack.html", true, true, "Services/Badge");
167
169
170 foreach ($data as $badge) {
171 $tmpl->setCurrentBlock("badge_bl");
172 $tmpl->setVariable("BADGE_TITLE", $badge["title"]);
173 // $tmpl->setVariable("BADGE_DESC", $badge["description"]); :TODO:
174 $tmpl->setVariable("BADGE_IMAGE", $badge["image"]);
175 $tmpl->setVariable("BADGE_CRITERIA", $badge["renderer"]->getHref());
176 $tmpl->setVariable("BADGE_DATE", ilDatePresentation::formatDate(new ilDateTime($badge["issued_on"], IL_CAL_UNIX)));
177 $tmpl->parseCurrentBlock();
178 }
179
180 $tpl->setContent($tmpl->get());
181 }
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, $user, 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 183 of file class.ilBadgeProfileGUI.php.

184 {
186
187 $this->getSubTabs("manage");
188
189 include_once "Services/Badge/classes/class.ilBadgePersonalTableGUI.php";
190 $tbl = new ilBadgePersonalTableGUI($this, "manageBadges");
191
192 $tpl->setContent($tbl->getHTML());
193 }

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 391 of file class.ilBadgeProfileGUI.php.

392 {
394
395 // check if current user has given badge
396 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
397 $ass = new ilBadgeAssignment($a_badge_id, $ilUser->getId());
398 if ($ass->getTimestamp()) {
399 $url = null;
400 try {
401 $url = $ass->getStaticUrl();
402 } catch (Exception $ex) {
403 }
404 if ($url) {
405 return $url;
406 }
407 }
408
409 return false;
410 }

References $ilUser, $url, and $user.

Referenced by addToBackpack(), and addToBackpackMulti().

+ Here is the caller graph for this function:

◆ resetFilter()

ilBadgeProfileGUI::resetFilter ( )
protected

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

205 {
206 include_once "Services/Badge/classes/class.ilBadgePersonalTableGUI.php";
207 $tbl = new ilBadgePersonalTableGUI($this, "manageBadges");
208 $tbl->resetOffset();
209 $tbl->resetFilter();
210 $this->manageBadges();
211 }

References $tbl, and manageBadges().

+ Here is the call graph for this function:

◆ saveSettings()

ilBadgeProfileGUI::saveSettings ( )
protected

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

499 {
503
504 $form = $this->initSettingsForm();
505 if ($form->checkInput()) {
506 $new_email = $form->getInput("email");
507 $old_email = $this->getBackpackMail();
508
509 ilObjUser::_writePref($ilUser->getId(), self::BACKPACK_EMAIL, $new_email);
510
511 // if email was changed: delete badge files
512 if ($new_email != $old_email) {
513 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
515 }
516
517 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
518 $ilCtrl->redirect($this, "editSettings");
519 }
520
521 $form->setValuesByPost();
522 $this->editSettings($form);
523 }
static clearBadgeCache($a_user_id)
editSettings(ilPropertyFormGUI $a_form=null)
static _writePref($a_usr_id, $a_keyword, $a_value)

References $ctrl, $form, $ilCtrl, $ilUser, $lng, $user, 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 312 of file class.ilBadgeProfileGUI.php.

313 {
314 $ilTabs = $this->tabs;
317
318 $ilTabs->addSubTab(
319 "backpack_badges",
320 $lng->txt("obj_bdga"),
321 $ilCtrl->getLinkTarget($this, "listBackpackGroups")
322 );
323
324 $ilTabs->addSubTab(
325 "backpack_settings",
326 $lng->txt("settings"),
327 $ilCtrl->getLinkTarget($this, "editSettings")
328 );
329
330 $ilTabs->activateTab("backpack_badges");
331 }

References $ctrl, $ilCtrl, $lng, and $tabs.

Referenced by editSettings(), and listBackpackGroups().

+ Here is the caller graph for this function:

◆ setTabs()

ilBadgeProfileGUI::setTabs ( )
protected

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

78 {
79 $ilTabs = $this->tabs;
82
83 if (ilBadgeHandler::getInstance()->isObiActive()) {
84 $ilTabs->addTab(
85 "ilias_badges",
86 $lng->txt("badge_personal_badges"),
87 $ilCtrl->getLinkTarget($this, "listBadges")
88 );
89
90 $ilTabs->addTab(
91 "backpack_badges",
92 $lng->txt("badge_backpack_list"),
93 $ilCtrl->getLinkTarget($this, "listBackpackGroups")
94 );
95 }
96 }

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

Referenced by executeCommand().

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

Field Documentation

◆ $ctrl

◆ $lng

◆ $tabs

ilBadgeProfileGUI::$tabs
protected

◆ $tpl

ilBadgeProfileGUI::$tpl
protected

◆ $user

ilBadgeProfileGUI::$user
protected

◆ BACKPACK_EMAIL

const ilBadgeProfileGUI::BACKPACK_EMAIL = "badge_mozilla_bp"

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

Referenced by ilBadgeAssignment\prepareJson().


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