Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Merge branch 'MDL-66357-master' of git://github.com/sarjona/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Apr 8, 2020
2 parents 2c50e08 + faf0029 commit f1f1497
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 90 deletions.
3 changes: 2 additions & 1 deletion admin/settings/badges.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@
new lang_string('allowexternalbackpack', 'badges'),
new lang_string('allowexternalbackpack_desc', 'badges'), 1));

$bp = $DB->get_record('badge_external_backpack', ['backpackweburl' => BADGRIO_BACKPACKWEBURL]);
$backpacksettings->add(new admin_setting_configselect('badges_site_backpack',
new lang_string('sitebackpack', 'badges'),
new lang_string('sitebackpack_help', 'badges'),
1, $choices));
$bp->id, $choices));

$warning = badges_verify_site_backpack();
if (!empty($warning)) {
Expand Down
13 changes: 5 additions & 8 deletions badges/classes/assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class core_badges_assertion {
private $_url;

/** @var int $obversion to control version JSON-LD. */
private $_obversion = OPEN_BADGES_V1;
private $_obversion = OPEN_BADGES_V2;

/**
* Constructs with issued badge unique hash.
*
* @param string $hash Badge unique hash from badge_issued table.
* @param int $obversion to control version JSON-LD.
*/
public function __construct($hash, $obversion = OPEN_BADGES_V1) {
public function __construct($hash, $obversion = OPEN_BADGES_V2) {
global $DB;

$this->_data = $DB->get_record_sql('
Expand Down 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
6 changes: 5 additions & 1 deletion badges/tests/badgeslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ protected function setUp() {

$this->badgeid = $DB->insert_record('badge', $fordb, true);

// Set the default Issuer (because OBv2 needs them).
set_config('badges_defaultissuername', $fordb->issuername);
set_config('badges_defaultissuercontact', $fordb->issuercontact);

// Create a course with activity and auto completion tracking.
$this->course = $this->getDataGenerator()->create_course(array('enablecompletion' => true));
$this->user = $this->getDataGenerator()->create_user();
Expand Down Expand Up @@ -670,7 +674,7 @@ public function test_badges_assertion() {

// Get assertion.
$award = reset($awards);
$assertion = new core_badges_assertion($award->uniquehash);
$assertion = new core_badges_assertion($award->uniquehash, OPEN_BADGES_V1);
$testassertion = $this->assertion;

// Make sure JSON strings have the same structure.
Expand Down
17 changes: 3 additions & 14 deletions badges/tests/behat/add_badge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Feature: Add badges to the system
And I press "Save changes"
And I follow "Badges"
When I follow "Add a new badge"
Then the field "issuercontact" matches value "[email protected]"
And the field "issuername" matches value "Test Badge Site"
And I press "Issuer details"
Then I should see "[email protected]"
And I should see "Test Badge Site"

@javascript
Scenario: Accessing the badges
Expand All @@ -38,8 +39,6 @@ Feature: Add badges to the system
| Description | Test badge description |
| Image author | http://author.example.com |
| Image caption | Test caption image |
| issuername | Test Badge Site |
| issuercontact | testuser@example.com |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
When I press "Create badge"
Then I should see "Edit details"
Expand All @@ -62,8 +61,6 @@ Feature: Add badges to the system
| Description | Test badge related description |
| Image author | http://author.example.com |
| Image caption | Test caption image |
| issuername | Test Badge Site |
| issuercontact | testuser@example.com |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I wait until the page is ready
Expand All @@ -77,8 +74,6 @@ Feature: Add badges to the system
| Description | Test badge description |
| Image author | http://author.example.com |
| Image caption | Test caption image |
| issuername | Test Badge Site |
| issuercontact | testuser@example.com |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I follow "Related badges (0)"
Expand All @@ -101,8 +96,6 @@ Feature: Add badges to the system
| Description | Test badge description |
| Image author | http://author.example.com |
| Image caption | Test caption image |
| issuername | Test Badge Site |
| issuercontact | testuser@example.com |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
When I press "Create badge"
Then I should see "Edit details"
Expand All @@ -127,8 +120,6 @@ Feature: Add badges to the system
| Description | Test badge description |
| Image author | http://author.example.com |
| Image caption | Test caption image |
| issuername | Test Badge Site |
| issuercontact | testuser@example.com |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
When I press "Create badge"
Then I should see "Test Badge"
Expand Down Expand Up @@ -161,8 +152,6 @@ Feature: Add badges to the system
| Description | Test badge description |
| Image author | http://author.example.com |
| Image caption | Test caption image |
| issuername | Test Badge Site |
| issuercontact | testuser@example.com |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
Then I should see "Edit details"
Expand Down
11 changes: 0 additions & 11 deletions badges/tests/behat/award_badge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Feature: Award badges
And I set the following fields to these values:
| Name | Course Badge 1 |
| Description | Course badge 1 description |
| issuername | Tester of course badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Manual issue by role"
Expand All @@ -43,7 +42,6 @@ Feature: Award badges
And I set the following fields to these values:
| Name | Course Badge 2 |
| Description | Course badge 2 description |
| issuername | Tester of course badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
# Set "course badge 1" as criteria
Expand Down Expand Up @@ -102,8 +100,6 @@ Feature: Award badges
And I set the following fields to these values:
| Name | Profile Badge |
| Description | Test badge description |
| issuername | Test Badge Site |
| issuercontact | testuser@example.com |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Profile completion"
Expand Down Expand Up @@ -140,7 +136,6 @@ Feature: Award badges
And I set the following fields to these values:
| Name | Site Badge |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Manual issue by role"
Expand Down Expand Up @@ -183,7 +178,6 @@ Feature: Award badges
And I set the following fields to these values:
| Name | Course Badge |
| Description | Course badge description |
| issuername | Tester of course badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Manual issue by role"
Expand Down Expand Up @@ -235,7 +229,6 @@ Feature: Award badges
And I set the following fields to these values:
| Name | Course Badge |
| Description | Course badge description |
| issuername | Tester of course badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Activity completion"
Expand Down Expand Up @@ -290,7 +283,6 @@ Feature: Award badges
And I set the following fields to these values:
| Name | Course Badge |
| Description | Course badge description |
| issuername | Tester of course badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Course completion"
Expand Down Expand Up @@ -340,7 +332,6 @@ Feature: Award badges
And I set the following fields to these values:
| Name | Course Badge 1 |
| Description | Course badge description |
| issuername | Tester of course badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Manual issue by role"
Expand All @@ -366,7 +357,6 @@ Feature: Award badges
And I set the following fields to these values:
| Name | Course Badge 2 |
| Description | Course badge description |
| issuername | Tester of course badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Manual issue by role"
Expand Down Expand Up @@ -423,7 +413,6 @@ Feature: Award badges
And I set the following fields to these values:
| Name | Course Badge |
| Description | Course badge description |
| issuername | Tester of course badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Manual issue by role"
Expand Down
1 change: 0 additions & 1 deletion badges/tests/behat/award_badge_groups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Feature: Award badges with separate groups
And I set the following fields to these values:
| Name | Course Badge |
| Description | Course badge description |
| issuername | Tester of course badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Manual issue by role"
Expand Down
1 change: 0 additions & 1 deletion badges/tests/behat/criteria_activity.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Feature: Award badges based on activity completion
And I set the following fields to these values:
| Name | Course Badge |
| Description | Course badge description |
| issuername | Tester of course badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Activity completion"
Expand Down
11 changes: 0 additions & 11 deletions badges/tests/behat/criteria_cohort.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand Down Expand Up @@ -59,7 +58,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand Down Expand Up @@ -100,7 +98,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand Down Expand Up @@ -137,7 +134,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand Down Expand Up @@ -188,7 +184,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand Down Expand Up @@ -245,7 +240,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand Down Expand Up @@ -302,7 +296,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand Down Expand Up @@ -360,7 +353,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge 1 |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand All @@ -373,7 +365,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge 2 |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand Down Expand Up @@ -415,7 +406,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge 1 |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand All @@ -430,7 +420,6 @@ Feature: Award badges based on cohort
And I set the following fields to these values:
| Name | Site Badge 2 |
| Description | Site badge description |
| issuername | Tester of site badge |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Cohort membership"
Expand Down
Loading

0 comments on commit f1f1497

Please sign in to comment.