MDL-67451 badges: use the site OB version as default
authorSara Arjona <sara@moodle.com>
Wed, 4 Dec 2019 13:50:13 +0000 (14:50 +0100)
committerSara Arjona <sara@moodle.com>
Wed, 4 Dec 2019 20:01:09 +0000 (21:01 +0100)
badges/assertion.php
badges/classes/output/issued_badge.php
badges/renderer.php

index ec08d0f..0c41062 100644 (file)
@@ -36,7 +36,8 @@ if (empty($CFG->enablebadges)) {
 
 $hash = required_param('b', PARAM_ALPHANUM); // Issued badge unique hash for badge assertion.
 $action = optional_param('action', null, PARAM_BOOL); // Generates badge class if true.
-$obversion = optional_param('obversion', OPEN_BADGES_V1, PARAM_INT); // For control format OB specification version.
+// 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);
 
 $assertion = new core_badges_assertion($hash, $obversion);
 
index b669a19..bc70d3b 100644 (file)
@@ -54,6 +54,9 @@ class issued_badge implements renderable {
     /** @var badge class */
     public $badgeid = 0;
 
+    /** @var unique hash identifying the issued badge */
+    public $hash;
+
     /**
      * Initializes the badge to display
      *
@@ -62,7 +65,8 @@ class issued_badge implements renderable {
     public function __construct($hash) {
         global $DB;
 
-        $assertion = new \core_badges_assertion($hash);
+        $this->hash = $hash;
+        $assertion = new \core_badges_assertion($hash, badges_open_badges_backpack_api());
         $this->issued = $assertion->get_badge_assertion();
         $this->badgeclass = $assertion->get_badge_class();
 
index 74ce368..341ef6d 100644 (file)
@@ -337,13 +337,13 @@ class core_badges_renderer extends plugin_renderer_base {
 
         if ($USER->id == $userinfo->id && !empty($CFG->enablebadges)) {
             $output .= $this->output->single_button(
-                        new moodle_url('/badges/badge.php', array('hash' => $issued['uid'], 'bake' => true)),
+                        new moodle_url('/badges/badge.php', array('hash' => $ibadge->hash, 'bake' => true)),
                         get_string('download'),
                         'POST');
             if (!empty($CFG->badges_allowexternalbackpack) && ($expiration > $now) && badges_user_has_backpack($USER->id)) {
 
                 if (badges_open_badges_backpack_api() == OPEN_BADGES_V1) {
-                    $assertion = new moodle_url('/badges/assertion.php', array('b' => $issued['uid']));
+                    $assertion = new moodle_url('/badges/assertion.php', array('b' => $ibadge->hash));
                     $action = new component_action('click', 'addtobackpack', array('assertion' => $assertion->out(false)));
                     $attributes = array(
                             'type'  => 'button',
@@ -354,7 +354,7 @@ class core_badges_renderer extends plugin_renderer_base {
                     $this->output->add_action_handler($action, 'addbutton');
                     $output .= $tobackpack;
                 } else {
-                    $assertion = new moodle_url('/badges/backpack-add.php', array('hash' => $issued['uid']));
+                    $assertion = new moodle_url('/badges/backpack-add.php', array('hash' => $ibadge->hash));
                     $attributes = ['class' => 'btn btn-secondary m-1', 'role' => 'button'];
                     $tobackpack = html_writer::link($assertion, get_string('addtobackpack', 'badges'), $attributes);
                     $output .= $tobackpack;