25 public const URL_DISPLAYER =
"https://backpack.openbadges.org/displayer/";
34 $this->main_tpl = $DIC->ui()->mainTemplate();
35 $this->email = $a_email;
41 self::URL_DISPLAYER .
"convert/email",
42 array(
"email" => $this->email),
46 if (!isset($json->status) ||
47 $json->status !==
"okay") {
51 $this->uid = $json->userId;
59 self::URL_DISPLAYER . $this->uid .
"/groups.json" 64 foreach ($json->groups as $group) {
65 $result[$group->groupId] = array(
66 "title" => $group->name,
67 "size" => $group->badges
76 public function getBadges(
string $a_group_id): ?array
80 self::URL_DISPLAYER . $this->uid .
"/group/" . $a_group_id .
".json" 87 if (property_exists($json,
'status') && $json->status ===
"missing") {
93 foreach ($json->badges as $raw) {
94 $badge = $raw->assertion->badge;
97 $issued_on = is_numeric($raw->assertion->issued_on)
98 ? $raw->assertion->issued_on
99 : strtotime($raw->assertion->issued_on);
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,
119 array $a_param = array(),
120 bool $a_is_post =
false 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);
134 $curl->setOpt(CURLOPT_SSL_VERIFYPEER,
false);
136 $curl->setOpt(CURLOPT_HTTPHEADER, array(
137 "Accept: application/json",
142 $curl->setOpt(CURLOPT_POST, 1);
143 if (count($a_param)) {
144 $curl->setOpt(CURLOPT_POSTFIELDS, http_build_query($a_param));
147 $curl->setOpt(CURLOPT_HTTPGET, 1);
148 if (count($a_param)) {
149 $a_url .= (strpos($a_url,
"?") ===
false ?
"?" :
"") . http_build_query($a_param);
152 $curl->setOpt(CURLOPT_URL, $a_url);
154 $answer = $curl->exec();
156 $this->main_tpl->setOnScreenMessage(
'failure', $ex->getMessage());
160 return json_decode($answer,
false, 512, JSON_THROW_ON_ERROR);
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(string $a_email)
sendRequest(string $a_url, array $a_param=array(), bool $a_is_post=false)
getBadges(string $a_group_id)
ilGlobalTemplateInterface $main_tpl