ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilBadgeBackpack Class Reference
+ Collaboration diagram for ilBadgeBackpack:

Public Member Functions

 __construct ($a_email)
 
 getGroups ()
 
 getBadges ($a_group_id)
 

Data Fields

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

Protected Member Functions

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

Protected Attributes

 $email
 
 $uid
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilBadgeBackpack::__construct (   $a_email)

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

20 {
21 $this->email = $a_email;
22 }

Member Function Documentation

◆ authenticate()

ilBadgeBackpack::authenticate ( )
protected

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

25 {
26 $json = $this->sendRequest(
27 self::URL_DISPLAYER . "convert/email",
28 array("email" => $this->email),
29 true
30 );
31
32 if (!isset($json->status) ||
33 $json->status != "okay") {
34 return false;
35 }
36
37 $this->uid = $json->userId;
38 return true;
39 }
sendRequest($a_url, array $a_param=array(), $a_is_post=false)

References sendRequest().

Referenced by getBadges(), and getGroups().

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

◆ getBadges()

ilBadgeBackpack::getBadges (   $a_group_id)

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

62 {
63 if ($this->authenticate()) {
64 $json = $this->sendRequest(
65 self::URL_DISPLAYER . $this->uid . "/group/" . $a_group_id . ".json"
66 );
67
68 if ($json->status &&
69 $json->status == "missing") {
70 return false;
71 }
72
73 $result = array();
74
75 foreach ($json->badges as $raw) {
76 $badge = $raw->assertion->badge;
77
78 // :TODO: not sure if this works reliably
79 $issued_on = is_numeric($raw->assertion->issued_on)
80 ? $raw->assertion->issued_on
81 : strtotime($raw->assertion->issued_on);
82
83 $result[] = array(
84 "title" => $badge->name,
85 "description" => $badge->description,
86 "image_url" => $badge->image,
87 "criteria_url" => $badge->criteria,
88 "issuer_name" => $badge->issuer->name,
89 "issuer_url" => $badge->issuer->origin,
90 "issued_on" => new ilDate($issued_on, IL_CAL_UNIX)
91 );
92 }
93
94 return $result;
95 }
96 }
$result
const IL_CAL_UNIX
Class for single dates.

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

+ Here is the call graph for this function:

◆ getGroups()

ilBadgeBackpack::getGroups ( )

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

42 {
43 if ($this->authenticate()) {
44 $json = $this->sendRequest(
45 self::URL_DISPLAYER . $this->uid . "/groups.json"
46 );
47
48 $result = array();
49
50 foreach ($json->groups as $group) {
51 $result[$group->groupId] = array(
52 "title" => $group->name,
53 "size" => $group->badges
54 );
55 }
56
57 return $result;
58 }
59 }

References $result, authenticate(), and sendRequest().

+ Here is the call graph for this function:

◆ sendRequest()

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

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

99 {
100 try {
101 $curl = new ilCurlConnection();
102 $curl->init(false);
103
104 $curl->setOpt(CURLOPT_FRESH_CONNECT, true);
105 $curl->setOpt(CURLOPT_RETURNTRANSFER, true);
106 $curl->setOpt(CURLOPT_FORBID_REUSE, true);
107 $curl->setOpt(CURLOPT_HEADER, 0);
108 $curl->setOpt(CURLOPT_CONNECTTIMEOUT, 3);
109 $curl->setOpt(CURLOPT_POSTREDIR, 3);
110
111 // :TODO: SSL problems on test server
112 $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
113
114 $curl->setOpt(CURLOPT_HTTPHEADER, array(
115 "Accept: application/json",
116 "Expect:"
117 ));
118
119 if ((bool) $a_is_post) {
120 $curl->setOpt(CURLOPT_POST, 1);
121 if (sizeof($a_param)) {
122 $curl->setOpt(CURLOPT_POSTFIELDS, http_build_query($a_param));
123 }
124 } else {
125 $curl->setOpt(CURLOPT_HTTPGET, 1);
126 if (sizeof($a_param)) {
127 $a_url = $a_url .
128 (strpos($a_url, "?") === false ? "?" : "") .
129 http_build_query($a_param);
130 }
131 }
132 $curl->setOpt(CURLOPT_URL, $a_url);
133
134 $answer = $curl->exec();
135 } catch (Exception $ex) {
136 ilUtil::sendFailure($ex->getMessage());
137 return;
138 }
139
140 return json_decode($answer);
141 }
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.

References ilUtil\sendFailure().

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

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

Field Documentation

◆ $email

ilBadgeBackpack::$email
protected

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

◆ $uid

ilBadgeBackpack::$uid
protected

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

◆ URL_DISPLAYER

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

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


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