$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', 1, PARAM_INT); // For control format OB specification version.
+$obversion = optional_param('obversion', OPEN_BADGES_V1, PARAM_INT); // For control format OB specification version.
$assertion = new core_badges_assertion($hash, $obversion);
} else { // Revoked badge.
header("HTTP/1.0 410 Gone");
$assertion = array();
- if ($obversion == 2) {
+ if ($obversion == OPEN_BADGES_V2) {
$assertionurl = new moodle_url('/badges/assertion.php', array('b' => $hash));
$assertion['id'] = $assertionurl->out();
}
private $_url;
/** @var int $obversion to control version JSON-LD. */
- private $_obversion = 1;
+ private $_obversion = OPEN_BADGES_V1;
/**
* 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 = 1) {
+ public function __construct($hash, $obversion = OPEN_BADGES_V1) {
global $DB;
$this->_data = $DB->get_record_sql('
*/
protected function embed_data_badge_version2 (&$json, $type = OPEN_BADGES_V2_TYPE_ASSERTION) {
// Specification Version 2.0.
- if ($this->_obversion == 2) {
+ if ($this->_obversion == OPEN_BADGES_V2) {
$badge = new badge($this->_data->id);
if (empty($this->_data->courseid)) {
$context = context_system::instance();
}
$hash = $this->_data->uniquehash;
- $assertionsurl = new moodle_url('/badges/assertion.php', array('b' => $hash, 'obversion' => 2));
- $classurl = new moodle_url('/badges/assertion.php', array('b' => $hash, 'action' => 1, 'obversion' => 2));
+ $assertionsurl = new moodle_url('/badges/assertion.php', array('b' => $hash, 'obversion' => $this->_obversion));
+ $classurl = new moodle_url(
+ '/badges/assertion.php',
+ array('b' => $hash, 'action' => 1, 'obversion' => $this->_obversion)
+ );
$issuerurl = new moodle_url('/badges/assertion.php', array('b' => $this->_data->uniquehash, 'action' => 0,
- 'obversion' => 2));
+ 'obversion' => $this->_obversion));
// For assertion.
if ($type == OPEN_BADGES_V2_TYPE_ASSERTION) {
$json['@context'] = OPEN_BADGES_V2_CONTEXT;
require_login();
$return = new moodle_url('/badges/competency.php', array('id' => $badgeid));
$badge = new badge($badgeid);
+$context = $badge->get_context();
+require_capability('moodle/badges:configuredetails', $context);
+
if ($action == 'remove') {
$badge->delete_alignment($alignmentid);
}
$badge = new badge($badgeid);
$context = $badge->get_context();
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
+require_capability('moodle/badges:configuredetails', $context);
if ($badge->type == BADGE_TYPE_COURSE) {
if (empty($CFG->badges_allowcoursebadges)) {
require_login();
$return = new moodle_url('/badges/related.php', array('id' => $badgeid));
$badge = new badge($badgeid);
+$context = $badge->get_context();
+require_capability('moodle/badges:configuredetails', $context);
+
if ($action == 'remove') {
$badge->delete_related_badge($relatedid);
}
*/
public function get_badges_option($badge) {
global $DB;
- $sql = "SELECT b.id, b.name, b.version, b.language, b.type
+ $sql = "SELECT b.id, b.name, b.version, b.language, b.type
FROM {badge} b
WHERE b.id <> :badgeid
- AND b.id NOT IN (SELECT br.relatedbadgeid
+ AND b.id NOT IN (SELECT br.relatedbadgeid
FROM {badge_related} br WHERE br.badgeid = :badgeid1)";
$params = array('badgeid' => $badge->id, 'badgeid1' => $badge->id);
if ($badge->type == BADGE_TYPE_COURSE) {
public function test_clone_badge() {
$badge = new badge($this->badgeid);
$newid = $badge->make_clone();
- $cloned_badge = new badge($newid);
-
- $this->assertEquals($badge->description, $cloned_badge->description);
- $this->assertEquals($badge->issuercontact, $cloned_badge->issuercontact);
- $this->assertEquals($badge->issuername, $cloned_badge->issuername);
- $this->assertEquals($badge->issuercontact, $cloned_badge->issuercontact);
- $this->assertEquals($badge->issuerurl, $cloned_badge->issuerurl);
- $this->assertEquals($badge->expiredate, $cloned_badge->expiredate);
- $this->assertEquals($badge->expireperiod, $cloned_badge->expireperiod);
- $this->assertEquals($badge->type, $cloned_badge->type);
- $this->assertEquals($badge->courseid, $cloned_badge->courseid);
- $this->assertEquals($badge->message, $cloned_badge->message);
- $this->assertEquals($badge->messagesubject, $cloned_badge->messagesubject);
- $this->assertEquals($badge->attachment, $cloned_badge->attachment);
- $this->assertEquals($badge->notification, $cloned_badge->notification);
- $this->assertEquals($badge->version, $cloned_badge->version);
- $this->assertEquals($badge->language, $cloned_badge->language);
- $this->assertEquals($badge->imagecaption, $cloned_badge->imagecaption);
- $this->assertEquals($badge->imageauthorname, $cloned_badge->imageauthorname);
- $this->assertEquals($badge->imageauthoremail, $cloned_badge->imageauthoremail);
- $this->assertEquals($badge->imageauthorurl, $cloned_badge->imageauthorurl);
-
+ $clonedbadge = new badge($newid);
+
+ $this->assertEquals($badge->description, $clonedbadge->description);
+ $this->assertEquals($badge->issuercontact, $clonedbadge->issuercontact);
+ $this->assertEquals($badge->issuername, $clonedbadge->issuername);
+ $this->assertEquals($badge->issuercontact, $clonedbadge->issuercontact);
+ $this->assertEquals($badge->issuerurl, $clonedbadge->issuerurl);
+ $this->assertEquals($badge->expiredate, $clonedbadge->expiredate);
+ $this->assertEquals($badge->expireperiod, $clonedbadge->expireperiod);
+ $this->assertEquals($badge->type, $clonedbadge->type);
+ $this->assertEquals($badge->courseid, $clonedbadge->courseid);
+ $this->assertEquals($badge->message, $clonedbadge->message);
+ $this->assertEquals($badge->messagesubject, $clonedbadge->messagesubject);
+ $this->assertEquals($badge->attachment, $clonedbadge->attachment);
+ $this->assertEquals($badge->notification, $clonedbadge->notification);
+ $this->assertEquals($badge->version, $clonedbadge->version);
+ $this->assertEquals($badge->language, $clonedbadge->language);
+ $this->assertEquals($badge->imagecaption, $clonedbadge->imagecaption);
+ $this->assertEquals($badge->imageauthorname, $clonedbadge->imageauthorname);
+ $this->assertEquals($badge->imageauthoremail, $clonedbadge->imageauthoremail);
+ $this->assertEquals($badge->imageauthorurl, $clonedbadge->imageauthorurl);
}
public function test_badge_status() {
// Test Openbadge specification version 2.
// Get assertion version 2.
$award = reset($awards);
- $assertion2 = new core_badges_assertion($award->uniquehash, 2);
+ $assertion2 = new core_badges_assertion($award->uniquehash, OPEN_BADGES_V2);
$testassertion2 = $this->assertion2;
// Make sure JSON strings have the same structure.
// Insert an related badge.
$badge->add_related_badges([$newid1, $newid2, $newid3]);
$this->assertCount(3, $badge->get_related_badges());
-
+
// Only get related is active.
$clonedbage1 = new badge($newid1);
$clonedbage1->status = BADGE_STATUS_ACTIVE;
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I follow "Related badges (0)"
- And I should see "This badge does not have an related badge."
+ And I should see "This badge does not have related badges."
And I press "Add related badge"
And I follow "Related badges"
And I wait until the page is ready
*/
define('BADGE_BACKPACKURL', 'https://backpack.openbadges.org');
+/*
+ * Open Badges specifications.
+ */
+define('OPEN_BADGES_V1', 1);
+define('OPEN_BADGES_V2', 2);
+
/*
* Only use for Open Badges 2.0 specification
*/
$badgecontext = $this->get_context();
$fs->delete_area_files($badgecontext->id, 'badges', 'badgeimage', $this->id);
+ // Delete endorsements, competencies and related badges.
+ $DB->delete_records('badge_endorsement', array('badgeid' => $this->id));
+ $DB->delete_records('badge_related', array('badgeid' => $this->id));
+ $DB->delete_records('badge_competencies', array('badgeid' => $this->id));
+
// Finally, remove badge itself.
$DB->delete_records('badge', array('id' => $this->id));
* @param int $alignmentid ID competency alignment.
* @return bool A status for delete a competency alignment.
*/
- public function delete_alignment($alignmentid = 0) {
+ public function delete_alignment($alignmentid) {
global $DB;
- return $DB->delete_records('badge_competencies', array('id' => $alignmentid));
+ return $DB->delete_records('badge_competencies', array('badgeid' => $this->id, 'id' => $alignmentid));
}
/**
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20181030" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20181105" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
- <KEY NAME="relatedbadge" TYPE="foreign" FIELDS="badgeid" REFTABLE="badge" REFFIELDS="id"/>
+ <KEY NAME="badgeid" TYPE="foreign" FIELDS="badgeid" REFTABLE="badge" REFFIELDS="id"/>
+ <KEY NAME="relatedbadgeid" TYPE="foreign" FIELDS="relatedbadgeid" REFTABLE="badge" REFFIELDS="id"/>
+ <KEY NAME="badgeid-relatedbadgeid" TYPE="unique" FIELDS="badgeid, relatedbadgeid"/>
</KEYS>
</TABLE>
<TABLE NAME="user_devices" COMMENT="This table stores user's mobile devices information in order to send PUSH notifications">
</INDEXES>
</TABLE>
</TABLES>
-</XMLDB>
+</XMLDB>
\ No newline at end of file
$dbman->add_index($table, $index);
}
- // Main savepoint reached.
upgrade_main_savepoint(true, 2018102300.02);
}
$fieldversion = new xmldb_field('version', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'nextcron');
$fieldlanguage = new xmldb_field('language', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'version');
$fieldimageauthorname = new xmldb_field('imageauthorname', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'language');
- $fieldimageauthoremail = new xmldb_field('imageauthoremail', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'imageauthorname');
- $fieldimageauthorurl = new xmldb_field('imageauthorurl', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'imageauthoremail');
+ $fieldimageauthoremail = new xmldb_field('imageauthoremail', XMLDB_TYPE_CHAR, '255', null, null,
+ null, null, 'imageauthorname');
+ $fieldimageauthorurl = new xmldb_field('imageauthorurl', XMLDB_TYPE_CHAR, '255', null, null,
+ null, null, 'imageauthoremail');
$fieldimagecaption = new xmldb_field('imagecaption', XMLDB_TYPE_TEXT, null, null, null, null, null, 'imageauthorurl');
if (!$dbman->field_exists($tablebadge, $fieldversion)) {
// Adding keys to table badge_related.
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
- $table->add_key('relatedbadge', XMLDB_KEY_FOREIGN, ['badgeid'], 'badge', ['id']);
+ $table->add_key('badgeid', XMLDB_KEY_FOREIGN, ['badgeid'], 'badge', ['id']);
+ $table->add_key('relatedbadgeid', XMLDB_KEY_FOREIGN, ['relatedbadgeid'], 'badge', ['id']);
+ $table->add_key('badgeid-relatedbadgeid', XMLDB_KEY_UNIQUE, ['badgeid', 'relatedbadgeid']);
// Conditionally launch create table for badge_related.
if (!$dbman->table_exists($table)) {