Skip to content

Commit

Permalink
MDL-83905 core_badges: Replace manual JSON with exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Jan 23, 2025
1 parent c67762d commit 08a0e1e
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions badges/classes/assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
require_once($CFG->libdir . '/badgeslib.php');
require_once($CFG->dirroot . '/badges/renderer.php');

use core_badges\local\backpack\ob\exporter_base;

/**
* Class that represents badge assertion.
*
Expand Down Expand Up @@ -116,6 +118,13 @@ public function get_assertion_hash() {
* @return array Badge assertion.
*/
public function get_badge_assertion($issued = true, $usesalt = true) {
$assertionexporter = exporter_base::create_assertion_exporter_from_hash(
$this->_data->uniquehash,
exporter_base::convert_apiversion(OPEN_BADGES_V2),
);
return $assertionexporter->export();

/*
global $CFG;
$assertion = array();
if ($this->_data) {
Expand Down Expand Up @@ -163,6 +172,7 @@ public function get_badge_assertion($issued = true, $usesalt = true) {
$this->embed_data_badge_version2($assertion, OPEN_BADGES_V2_TYPE_ASSERTION);
}
return $assertion;
*/
}

/**
Expand All @@ -172,6 +182,14 @@ public function get_badge_assertion($issued = true, $usesalt = true) {
* @return array Badge Class information.
*/
public function get_badge_class($issued = true) {
// TODO: Should the image be added with the data:image/png;base64, prefix?
$badgeexporter = exporter_base::create_badge_exporter_from_id(
$this->get_badge_id(),
exporter_base::convert_apiversion(OPEN_BADGES_V2),
);
return $badgeexporter->export();
/*
// TODO: This badge contains less information, for instance, version or language are not present).
$class = [];
if ($this->_data) {
if (empty($this->_data->courseid)) {
Expand Down Expand Up @@ -214,6 +232,7 @@ public function get_badge_class($issued = true) {
}
}
return $class;
*/
}

/**
Expand All @@ -222,11 +241,11 @@ public function get_badge_class($issued = true) {
* @return array Issuer information.
*/
public function get_issuer() {
$badge = new badge($this->get_badge_id());
$issuer = $badge->get_badge_issuer();

$this->embed_data_badge_version2($issuer, OPEN_BADGES_V2_TYPE_ISSUER);
return $issuer;
$issuerexporter = exporter_base::create_issuer_exporter_from_id(
$this->get_badge_id(),
exporter_base::convert_apiversion(OPEN_BADGES_V2),
);
return $issuerexporter->export();
}

/**
Expand Down

0 comments on commit 08a0e1e

Please sign in to comment.