Skip to content

Commit

Permalink
MDL-66357 core_badges: remove action=0 usage for issuer
Browse files Browse the repository at this point in the history
In MDL-67971, issuer_json.php was created, to display issuer JSON content.
However, some files were still using action=0 to display this information.
It has been replaced by issuer_json.php.
The action=0 support won't be removed (at least for now), because several
public badges URLs are using it.
  • Loading branch information
sarjona committed Apr 3, 2020
1 parent 6406281 commit faf0029
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
9 changes: 3 additions & 6 deletions badges/classes/assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,8 @@ public function get_badge_class($issued = true) {
$class['image'] = 'data:image/png;base64,' . $imagedata;
$class['criteria'] = $this->_url->out(false); // Currently issued badge URL.
if ($issued) {
if ($this->_obversion == OPEN_BADGES_V2) {
$issuerurl = new moodle_url('/badges/issuer_json.php', array('id' => $this->get_badge_id()));
} else {
$issuerurl = new moodle_url('/badges/assertion.php', array('b' => $this->_data->uniquehash, 'action' => 0));
}
$params = ['id' => $this->get_badge_id(), 'obversion' => $this->_obversion];
$issuerurl = new moodle_url('/badges/issuer_json.php', $params);
$class['issuer'] = $issuerurl->out(false);
}
$this->embed_data_badge_version2($class, OPEN_BADGES_V2_TYPE_BADGE);
Expand All @@ -223,7 +220,7 @@ public function get_issuer() {
$issuer = array();
if ($this->_data) {
// Required.
if (badges_open_badges_backpack_api() == OPEN_BADGES_V1) {
if ($this->_obversion == OPEN_BADGES_V1) {
$issuer['name'] = $this->_data->issuername;
$issuer['url'] = $this->_data->issuerurl;
// Optional.
Expand Down
29 changes: 20 additions & 9 deletions badges/classes/badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -925,17 +925,28 @@ public function markdown_badge_criteria() {
/**
* Define issuer information by format Open Badges specification version 2.
*
* @param int $obversion OB version to use.
* @return array Issuer informations of the badge.
*/
public function get_badge_issuer() {
$issuer = array();
$issuer['name'] = $this->issuername;
$issuer['url'] = $this->issuerurl;
$issuer['email'] = $this->issuercontact;
$issuer['@context'] = OPEN_BADGES_V2_CONTEXT;
$issueridurl = new moodle_url('/badges/issuer_json.php', array('id' => $this->id));
$issuer['id'] = $issueridurl->out(false);
$issuer['type'] = OPEN_BADGES_V2_TYPE_ISSUER;
public function get_badge_issuer(?int $obversion = null) {
global $DB;

$issuer = [];
if ($obversion == OPEN_BADGES_V1) {
$data = $DB->get_record('badge', ['id' => $this->id]);
$issuer['name'] = $data->issuername;
$issuer['url'] = $data->issuerurl;
$issuer['email'] = $data->issuercontact;
} else {
$issuer['name'] = $this->issuername;
$issuer['url'] = $this->issuerurl;
$issuer['email'] = $this->issuercontact;
$issuer['@context'] = OPEN_BADGES_V2_CONTEXT;
$issueridurl = new moodle_url('/badges/issuer_json.php', array('id' => $this->id));
$issuer['id'] = $issueridurl->out(false);
$issuer['type'] = OPEN_BADGES_V2_TYPE_ISSUER;
}

return $issuer;
}
}
4 changes: 3 additions & 1 deletion badges/issuer_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@


$id = optional_param('id', null, PARAM_INT);
// OB specification version. If it's not defined, the site will be used as default.
$obversion = optional_param('obversion', badges_open_badges_backpack_api(), PARAM_INT);

if (empty($id)) {
// Get the default issuer for this site.
Expand All @@ -38,7 +40,7 @@
// Get the issuer for this badge.
$badge = new badge($id);
if ($badge->status != BADGE_STATUS_INACTIVE) {
$json = $badge->get_badge_issuer();
$json = $badge->get_badge_issuer($obversion);
} else {
// The badge doen't exist or not accessible for the users.
header("HTTP/1.0 410 Gone");
Expand Down

0 comments on commit faf0029

Please sign in to comment.