ILIAS  release_8 Revision v8.23
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 (string $a_email)
 
 getGroups ()
 
 getBadges (string $a_group_id)
 

Data Fields

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

string $email
 
int $uid
 

Private Attributes

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 ( string  $a_email)

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

References $DIC.

32  {
33  global $DIC;
34  $this->main_tpl = $DIC->ui()->mainTemplate();
35  $this->email = $a_email;
36  }
global $DIC
Definition: feed.php:28

Member Function Documentation

◆ authenticate()

ilBadgeBackpack::authenticate ( )
protected

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

References sendRequest().

Referenced by getBadges(), and getGroups().

38  : bool
39  {
40  $json = $this->sendRequest(
41  self::URL_DISPLAYER . "convert/email",
42  array("email" => $this->email),
43  true
44  );
45 
46  if (!isset($json->status) ||
47  $json->status !== "okay") {
48  return false;
49  }
50 
51  $this->uid = $json->userId;
52  return true;
53  }
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 76 of file class.ilBadgeBackpack.php.

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

76  : ?array
77  {
78  if ($this->authenticate()) {
79  $json = $this->sendRequest(
80  self::URL_DISPLAYER . $this->uid . "/group/" . $a_group_id . ".json"
81  );
82 
83  if ($json === null) {
84  return null;
85  }
86 
87  if (property_exists($json, 'status') && $json->status === "missing") {
88  return null;
89  }
90 
91  $result = [];
92 
93  foreach ($json->badges as $raw) {
94  $badge = $raw->assertion->badge;
95 
96  // :TODO: not sure if this works reliably
97  $issued_on = is_numeric($raw->assertion->issued_on)
98  ? $raw->assertion->issued_on
99  : strtotime($raw->assertion->issued_on);
100 
101  $result[] = [
102  "title" => $badge->name,
103  "description" => $badge->description,
104  "image_url" => $badge->image,
105  "criteria_url" => $badge->criteria,
106  "issuer_name" => $badge->issuer->name,
107  "issuer_url" => $badge->issuer->origin,
108  "issued_on" => new ilDate($issued_on, IL_CAL_UNIX)
109  ];
110  }
111 
112  return $result;
113  }
114  return null;
115  }
const IL_CAL_UNIX
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 55 of file class.ilBadgeBackpack.php.

References authenticate(), and sendRequest().

55  : array
56  {
57  if ($this->authenticate()) {
58  $json = $this->sendRequest(
59  self::URL_DISPLAYER . $this->uid . "/groups.json"
60  );
61 
62  $result = array();
63 
64  foreach ($json->groups as $group) {
65  $result[$group->groupId] = array(
66  "title" => $group->name,
67  "size" => $group->badges
68  );
69  }
70 
71  return $result;
72  }
73  return [];
74  }
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 117 of file class.ilBadgeBackpack.php.

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

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

Field Documentation

◆ $email

string ilBadgeBackpack::$email
protected

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

◆ $main_tpl

ilGlobalTemplateInterface ilBadgeBackpack::$main_tpl
private

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

◆ $uid

int ilBadgeBackpack::$uid
protected

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

◆ URL_DISPLAYER

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: