MDL-66357 core_badges: remove action=0 usage for issuer

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.
This commit is contained in:
Sara Arjona
2020-04-03 08:09:55 +02:00
parent 640628192a
commit faf0029eed
3 changed files with 26 additions and 16 deletions
+3 -6
View File
@@ -198,11 +198,8 @@ class core_badges_assertion {
$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);
@@ -223,7 +220,7 @@ class core_badges_assertion {
$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.
+20 -9
View File
@@ -925,17 +925,28 @@ class badge {
/**
* 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;
}
}
+3 -1
View File
@@ -30,6 +30,8 @@ require_once($CFG->libdir . '/badgeslib.php');
$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.
@@ -38,7 +40,7 @@ if (empty($id)) {
// 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");