ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilBadgeBackpack Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilBadgeBackpack:

Public Member Functions

 __construct (protected string $email)
 
 getGroups ()
 
 getBadges (string $a_group_id)
 

Data Fields

final const URL_DISPLAYER = "https://backpack.openbadges.org/displayer/"
 

Protected Member Functions

 authenticate ()
 
 sendRequest (string $a_url, array $a_param=array(), bool $a_is_post=false)
 

Protected Attributes

int $uid
 

Private Attributes

readonly ilGlobalTemplateInterface $main_tpl
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilBadgeBackpack

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 23 of file class.ilBadgeBackpack.php.

Constructor & Destructor Documentation

◆ __construct()

ilBadgeBackpack::__construct ( protected string  $email)

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

References $DIC.

30  {
31  global $DIC;
32  $this->main_tpl = $DIC->ui()->mainTemplate();
33  }
global $DIC
Definition: shib_login.php:22

Member Function Documentation

◆ authenticate()

ilBadgeBackpack::authenticate ( )
protected

Definition at line 35 of file class.ilBadgeBackpack.php.

References sendRequest().

Referenced by getBadges(), and getGroups().

35  : bool
36  {
37  $json = $this->sendRequest(
38  self::URL_DISPLAYER . "convert/email",
39  array("email" => $this->email),
40  true
41  );
42 
43  if (!isset($json->status) ||
44  $json->status !== "okay") {
45  return false;
46  }
47 
48  $this->uid = $json->userId;
49  return true;
50  }
sendRequest(string $a_url, array $a_param=array(), bool $a_is_post=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBadges()

ilBadgeBackpack::getBadges ( string  $a_group_id)

Definition at line 73 of file class.ilBadgeBackpack.php.

References authenticate(), IL_CAL_UNIX, null, and sendRequest().

73  : ?array
74  {
75  if ($this->authenticate()) {
76  $json = $this->sendRequest(
77  self::URL_DISPLAYER . $this->uid . "/group/" . $a_group_id . ".json"
78  );
79 
80  if ($json === null) {
81  return null;
82  }
83 
84  if (property_exists($json, 'status') && $json->status === "missing") {
85  return null;
86  }
87 
88  $result = [];
89 
90  foreach ($json->badges as $raw) {
91  $badge = $raw->assertion->badge;
92 
93  // :TODO: not sure if this works reliably
94  $issued_on = is_numeric($raw->assertion->issued_on)
95  ? $raw->assertion->issued_on
96  : strtotime($raw->assertion->issued_on);
97 
98  $result[] = [
99  "title" => $badge->name,
100  "description" => $badge->description,
101  "image_url" => $badge->image,
102  "image_rid" => $badge->image_rid,
103  "criteria_url" => $badge->criteria,
104  "issuer_name" => $badge->issuer->name,
105  "issuer_url" => $badge->issuer->origin,
106  "issued_on" => new ilDate($issued_on, IL_CAL_UNIX)
107  ];
108  }
109 
110  return $result;
111  }
112  return null;
113  }
const IL_CAL_UNIX
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
sendRequest(string $a_url, array $a_param=array(), bool $a_is_post=false)
+ Here is the call graph for this function:

◆ getGroups()

ilBadgeBackpack::getGroups ( )

Definition at line 52 of file class.ilBadgeBackpack.php.

References authenticate(), and sendRequest().

52  : array
53  {
54  if ($this->authenticate()) {
55  $json = $this->sendRequest(
56  self::URL_DISPLAYER . $this->uid . "/groups.json"
57  );
58 
59  $result = array();
60 
61  foreach ($json->groups as $group) {
62  $result[$group->groupId] = array(
63  "title" => $group->name,
64  "size" => $group->badges
65  );
66  }
67 
68  return $result;
69  }
70  return [];
71  }
sendRequest(string $a_url, array $a_param=array(), bool $a_is_post=false)
+ Here is the call graph for this function:

◆ sendRequest()

ilBadgeBackpack::sendRequest ( string  $a_url,
array  $a_param = array(),
bool  $a_is_post = false 
)
protected

Definition at line 115 of file class.ilBadgeBackpack.php.

References null.

Referenced by authenticate(), getBadges(), and getGroups().

119  : ?stdClass {
120  try {
121  $curl = new ilCurlConnection();
122  $curl->init(false);
123 
124  $curl->setOpt(CURLOPT_FRESH_CONNECT, true);
125  $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
126  $curl->setOpt(CURLOPT_FORBID_REUSE, true);
127  $curl->setOpt(CURLOPT_HEADER, 0);
128  $curl->setOpt(CURLOPT_CONNECTTIMEOUT, 3);
129  $curl->setOpt(CURLOPT_POSTREDIR, 3);
130 
131  // :TODO: SSL problems on test server
132  $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
133 
134  $curl->setOpt(CURLOPT_HTTPHEADER, array(
135  "Accept: application/json",
136  "Expect:"
137  ));
138 
139  if ($a_is_post) {
140  $curl->setOpt(CURLOPT_POST, 1);
141  if (count($a_param)) {
142  $curl->setOpt(CURLOPT_POSTFIELDS, http_build_query($a_param));
143  }
144  } else {
145  $curl->setOpt(CURLOPT_HTTPGET, 1);
146  if (count($a_param)) {
147  $a_url .= (!str_contains($a_url, "?") ? "?" : "") . http_build_query($a_param);
148  }
149  }
150  $curl->setOpt(CURLOPT_URL, $a_url);
151 
152  $answer = $curl->exec();
153  } catch (Exception $ex) {
154  $this->main_tpl->setOnScreenMessage('failure', $ex->getMessage());
155  return null;
156  }
157 
158  return json_decode($answer, false, 512, JSON_THROW_ON_ERROR);
159  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

Field Documentation

◆ $main_tpl

readonly ilGlobalTemplateInterface ilBadgeBackpack::$main_tpl
private

Definition at line 27 of file class.ilBadgeBackpack.php.

◆ $uid

int ilBadgeBackpack::$uid
protected

Definition at line 26 of file class.ilBadgeBackpack.php.

◆ URL_DISPLAYER

final const ilBadgeBackpack::URL_DISPLAYER = "https://backpack.openbadges.org/displayer/"

Definition at line 25 of file class.ilBadgeBackpack.php.


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