mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
Merge branch 'MDL-58454-master' of git://github.com/junpataleta/moodle
This commit is contained in:
commit
2bdc254cd2
@ -35,8 +35,9 @@ 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.
|
||||
|
||||
$assertion = new core_badges_assertion($hash);
|
||||
$assertion = new core_badges_assertion($hash, $obversion);
|
||||
|
||||
if (!is_null($action)) {
|
||||
// Get badge class or issuer information depending on $action.
|
||||
@ -48,11 +49,16 @@ if (!is_null($action)) {
|
||||
$json = $assertion->get_badge_assertion();
|
||||
} else { // Revoked badge.
|
||||
header("HTTP/1.0 410 Gone");
|
||||
echo json_encode(array("revoked" => true));
|
||||
$assertion = array();
|
||||
if ($obversion == OPEN_BADGES_V2) {
|
||||
$assertionurl = new moodle_url('/badges/assertion.php', array('b' => $hash));
|
||||
$assertion['id'] = $assertionurl->out();
|
||||
}
|
||||
$assertion['revoked'] = true;
|
||||
echo json_encode($assertion);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo json_encode($json);
|
||||
|
126
badges/badge_json.php
Normal file
126
badges/badge_json.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Serve BadgeClass JSON for related badge.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
define('AJAX_SCRIPT', true);
|
||||
define('NO_MOODLE_COOKIES', true); // No need for a session here.
|
||||
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$action = optional_param('action', null, PARAM_INT); // Generates badge class if true.
|
||||
$json = array();
|
||||
$badge = new badge($id);
|
||||
if ($badge->status != BADGE_STATUS_INACTIVE) {
|
||||
if (is_null($action)) {
|
||||
// Get the content of badge class.
|
||||
if (empty($badge->courseid)) {
|
||||
$context = context_system::instance();
|
||||
} else {
|
||||
$context = context_course::instance($badge->courseid);
|
||||
}
|
||||
$urlimage = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f1')->out(false);
|
||||
|
||||
$url = new moodle_url('/badges/badge_json.php', array('id' => $badge->id));
|
||||
|
||||
$json['name'] = $badge->name;
|
||||
$json['description'] = $badge->description;
|
||||
if ($badge->imageauthorname ||
|
||||
$badge->imageauthoremail ||
|
||||
$badge->imageauthorurl ||
|
||||
$badge->imagecaption) {
|
||||
$urlimage = moodle_url::make_pluginfile_url($context->id,
|
||||
'badges', 'badgeimage', $badge->id, '/', 'f1')->out(false);
|
||||
$json['image'] = array();
|
||||
$json['image']['id'] = $urlimage;
|
||||
if ($badge->imageauthorname || $badge->imageauthoremail || $badge->imageauthorurl) {
|
||||
$authorimage = new moodle_url('/badges/image_author_json.php', array('id' => $badge->id));
|
||||
$json['image']['author'] = $authorimage->out(false);
|
||||
}
|
||||
if ($badge->imagecaption) {
|
||||
$json['image']['caption'] = $badge->imagecaption;
|
||||
}
|
||||
} else {
|
||||
$json['image'] = $urlimage;
|
||||
}
|
||||
|
||||
$json['criteria']['id'] = $url->out(false);
|
||||
$json['criteria']['narrative'] = $badge->markdown_badge_criteria();
|
||||
$json['issuer'] = $badge->get_badge_issuer();
|
||||
$json['@context'] = OPEN_BADGES_V2_CONTEXT;
|
||||
$json['id'] = $url->out();
|
||||
$json['type'] = OPEN_BADGES_V2_TYPE_BADGE;
|
||||
if (!empty($badge->version)) {
|
||||
$json['version'] = $badge->version;
|
||||
}
|
||||
if (!empty($badge->language)) {
|
||||
$json['@language'] = $badge->language;
|
||||
}
|
||||
|
||||
$relatedbadges = $badge->get_related_badges(true);
|
||||
if (!empty($relatedbadges)) {
|
||||
foreach ($relatedbadges as $related) {
|
||||
$relatedurl = new moodle_url('/badges/badge_json.php', array('id' => $related->id));
|
||||
$relateds[] = array('id' => $relatedurl->out(false),
|
||||
'version' => $related->version, '@language' => $related->language);
|
||||
}
|
||||
$json['related'] = $relateds;
|
||||
}
|
||||
|
||||
$endorsement = $badge->get_endorsement();
|
||||
if (!empty($endorsement)) {
|
||||
$endorsementurl = new moodle_url('/badges/endorsement_json.php', array('id' => $badge->id));
|
||||
$json['endorsement'] = $endorsementurl->out(false);
|
||||
}
|
||||
|
||||
$competencies = $badge->get_alignment();
|
||||
if (!empty($competencies)) {
|
||||
foreach ($competencies as $item) {
|
||||
$alignment = array('targetName' => $item->targetname, 'targetUrl' => $item->targeturl);
|
||||
if ($item->targetdescription) {
|
||||
$alignment['targetDescription'] = $item->targetdescription;
|
||||
}
|
||||
if ($item->targetframework) {
|
||||
$alignment['targetFramework'] = $item->targetframework;
|
||||
}
|
||||
if ($item->targetcode) {
|
||||
$alignment['targetCode'] = $item->targetcode;
|
||||
}
|
||||
$json['alignment'][] = $alignment;
|
||||
}
|
||||
}
|
||||
} else if ($action == 0) {
|
||||
// Get the content for issuer.
|
||||
$json = $badge->get_json_issuer_related_badge();
|
||||
}
|
||||
} else {
|
||||
// The badge doen't exist or not accessible for the users.
|
||||
header("HTTP/1.0 410 Gone");
|
||||
$badgeurl = new moodle_url('/badges/badge_json.php', array('id' => $id));
|
||||
$json['id'] = $badgeurl->out();
|
||||
$json['error'] = get_string('error:relatedbadgedoesntexist', 'badges');
|
||||
}
|
||||
echo $OUTPUT->header();
|
||||
echo json_encode($json);
|
@ -34,6 +34,8 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* - Badge Class (general information about a badge and what it is intended to represent)
|
||||
* - Issuer Class (general information of an issuing organisation)
|
||||
*/
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
require_once($CFG->dirroot . '/badges/renderer.php');
|
||||
|
||||
/**
|
||||
* Class that represents badge assertion.
|
||||
@ -46,12 +48,16 @@ class core_badges_assertion {
|
||||
/** @var moodle_url Issued badge url */
|
||||
private $_url;
|
||||
|
||||
/** @var int $obversion to control version JSON-LD. */
|
||||
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) {
|
||||
public function __construct($hash, $obversion = OPEN_BADGES_V1) {
|
||||
global $DB;
|
||||
|
||||
$this->_data = $DB->get_record_sql('
|
||||
@ -78,6 +84,7 @@ class core_badges_assertion {
|
||||
} else {
|
||||
$this->_url = new moodle_url('/badges/badge.php');
|
||||
}
|
||||
$this->_obversion = $obversion;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,6 +118,7 @@ class core_badges_assertion {
|
||||
if (!empty($this->_data->dateexpire)) {
|
||||
$assertion['expires'] = $this->_data->dateexpire;
|
||||
}
|
||||
$this->embed_data_badge_version2($assertion, OPEN_BADGES_V2_TYPE_ASSERTION);
|
||||
}
|
||||
return $assertion;
|
||||
}
|
||||
@ -136,6 +144,7 @@ class core_badges_assertion {
|
||||
$class['image'] = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $this->_data->id, '/', 'f1')->out(false);
|
||||
$class['criteria'] = $this->_url->out(false); // Currently issued badge URL.
|
||||
$class['issuer'] = $issuerurl->out(false);
|
||||
$this->embed_data_badge_version2($class, OPEN_BADGES_V2_TYPE_BADGE);
|
||||
}
|
||||
return $class;
|
||||
}
|
||||
@ -156,7 +165,169 @@ class core_badges_assertion {
|
||||
$issuer['email'] = $this->_data->issuercontact;
|
||||
}
|
||||
}
|
||||
$this->embed_data_badge_version2($issuer, OPEN_BADGES_V2_TYPE_ISSUER);
|
||||
return $issuer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related badges of the badge.
|
||||
*
|
||||
* @param badge $badge Badge object.
|
||||
* @return array|bool List related badges.
|
||||
*/
|
||||
public function get_related_badges(badge $badge) {
|
||||
global $DB;
|
||||
$arraybadges = array();
|
||||
$relatedbadges = $badge->get_related_badges(true);
|
||||
if ($relatedbadges) {
|
||||
foreach ($relatedbadges as $rb) {
|
||||
$url = new moodle_url('/badges/badge_json.php', array('id' => $rb->id));
|
||||
$arraybadges[] = array(
|
||||
'id' => $url->out(false),
|
||||
'version' => $rb->version,
|
||||
'@language' => $rb->language
|
||||
);
|
||||
}
|
||||
}
|
||||
return $arraybadges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get endorsement of the badge.
|
||||
*
|
||||
* @return false|stdClass Endorsement information.
|
||||
*/
|
||||
public function get_endorsement() {
|
||||
global $DB;
|
||||
$endorsement = array();
|
||||
$record = $DB->get_record_select('badge_endorsement', 'badgeid = ?', array($this->_data->id));
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get criteria of badge class.
|
||||
*
|
||||
* @return array|string Criteria information.
|
||||
*/
|
||||
public function get_criteria_badge_class() {
|
||||
$badge = new badge($this->_data->id);
|
||||
$narrative = $badge->markdown_badge_criteria();
|
||||
if (!empty($narrative)) {
|
||||
$criteria = array();
|
||||
$criteria['id'] = $this->_url->out(false);
|
||||
$criteria['narrative'] = $narrative;
|
||||
return $criteria;
|
||||
} else {
|
||||
return $this->_url->out(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get competencies alignment of the badge.
|
||||
*
|
||||
* @return array competencies information.
|
||||
*/
|
||||
public function get_competencies_alignment() {
|
||||
global $DB;
|
||||
$badgeid = $this->_data->id;
|
||||
$alignments = array();
|
||||
$items = $DB->get_records_select('badge_competencies', 'badgeid = ?', array($badgeid));
|
||||
foreach ($items as $item) {
|
||||
$alignment = array('targetName' => $item->targetname, 'targetUrl' => $item->targeturl);
|
||||
if ($item->targetdescription) {
|
||||
$alignment['targetDescription'] = $item->targetdescription;
|
||||
}
|
||||
if ($item->targetframework) {
|
||||
$alignment['targetFramework'] = $item->targetframework;
|
||||
}
|
||||
if ($item->targetcode) {
|
||||
$alignment['targetCode'] = $item->targetcode;
|
||||
}
|
||||
$alignments[] = $alignment;
|
||||
}
|
||||
return $alignments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Embed data of Open Badges Specification Version 2.0 to json.
|
||||
*
|
||||
* @param array $json for assertion, badges, issuer.
|
||||
* @param string $type Content type.
|
||||
*/
|
||||
protected function embed_data_badge_version2 (&$json, $type = OPEN_BADGES_V2_TYPE_ASSERTION) {
|
||||
// Specification Version 2.0.
|
||||
if ($this->_obversion == OPEN_BADGES_V2) {
|
||||
$badge = new badge($this->_data->id);
|
||||
if (empty($this->_data->courseid)) {
|
||||
$context = context_system::instance();
|
||||
} else {
|
||||
$context = context_course::instance($this->_data->courseid);
|
||||
}
|
||||
|
||||
$hash = $this->_data->uniquehash;
|
||||
$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' => $this->_obversion));
|
||||
// For assertion.
|
||||
if ($type == OPEN_BADGES_V2_TYPE_ASSERTION) {
|
||||
$json['@context'] = OPEN_BADGES_V2_CONTEXT;
|
||||
$json['type'] = OPEN_BADGES_V2_TYPE_ASSERTION;
|
||||
$json['id'] = $assertionsurl->out(false);
|
||||
$json['badge'] = $this->get_badge_class();
|
||||
$json['issuedOn'] = date('c', $this->_data->dateissued);
|
||||
if (!empty($this->_data->dateexpire)) {
|
||||
$json['expires'] = date('c', $this->_data->dateexpire);
|
||||
}
|
||||
unset($json['uid']);
|
||||
}
|
||||
|
||||
// For Badge.
|
||||
if ($type == OPEN_BADGES_V2_TYPE_BADGE) {
|
||||
$json['@context'] = OPEN_BADGES_V2_CONTEXT;
|
||||
$json['id'] = $classurl->out(false);
|
||||
$json['type'] = OPEN_BADGES_V2_TYPE_BADGE;
|
||||
$json['version'] = $this->_data->version;
|
||||
$json['criteria'] = $this->get_criteria_badge_class();
|
||||
$json['issuer'] = $this->get_issuer();
|
||||
$json['@language'] = $this->_data->language;
|
||||
if (!empty($relatedbadges = $this->get_related_badges($badge))) {
|
||||
$json['related'] = $relatedbadges;
|
||||
}
|
||||
if ($endorsement = $this->get_endorsement()) {
|
||||
$endorsementurl = new moodle_url('/badges/endorsement_json.php', array('id' => $this->_data->id));
|
||||
$json['endorsement'] = $endorsementurl->out(false);
|
||||
}
|
||||
if ($competencies = $this->get_competencies_alignment()) {
|
||||
$json['alignment'] = $competencies;
|
||||
}
|
||||
if ($this->_data->imageauthorname ||
|
||||
$this->_data->imageauthoremail ||
|
||||
$this->_data->imageauthorurl ||
|
||||
$this->_data->imagecaption) {
|
||||
$urlimage = moodle_url::make_pluginfile_url($context->id,
|
||||
'badges', 'badgeimage', $this->_data->id, '/', 'f1')->out(false);
|
||||
$json['image'] = array();
|
||||
$json['image']['id'] = $urlimage;
|
||||
if ($this->_data->imageauthorname || $this->_data->imageauthoremail || $this->_data->imageauthorurl) {
|
||||
$authorimage = new moodle_url('/badges/image_author_json.php', array('id' => $this->_data->id));
|
||||
$json['image']['author'] = $authorimage->out(false);
|
||||
}
|
||||
if ($this->_data->imagecaption) {
|
||||
$json['image']['caption'] = $this->_data->imagecaption;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For issuer.
|
||||
if ($type == OPEN_BADGES_V2_TYPE_ISSUER) {
|
||||
$json['@context'] = OPEN_BADGES_V2_CONTEXT;
|
||||
$json['id'] = $issuerurl->out(false);
|
||||
$json['type'] = OPEN_BADGES_V2_TYPE_ISSUER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
109
badges/competency.php
Normal file
109
badges/competency.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* List competencies, skills, or standards are targeted by a BadgeClass.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
require_once($CFG->dirroot . '/badges/competency_form.php');
|
||||
|
||||
$badgeid = required_param('id', PARAM_INT);
|
||||
$alignmentid = optional_param('alignmentid', 0, PARAM_INT);
|
||||
$action = optional_param('action', '', PARAM_TEXT);
|
||||
$lang = current_language();
|
||||
|
||||
require_login();
|
||||
if (empty($CFG->enablebadges)) {
|
||||
print_error('badgesdisabled', 'badges');
|
||||
}
|
||||
$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)) {
|
||||
print_error('coursebadgesdisabled', 'badges');
|
||||
}
|
||||
require_login($badge->courseid);
|
||||
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
|
||||
$PAGE->set_pagelayout('standard');
|
||||
navigation_node::override_active_url($navurl);
|
||||
} else {
|
||||
$PAGE->set_pagelayout('admin');
|
||||
navigation_node::override_active_url($navurl, true);
|
||||
}
|
||||
|
||||
$currenturl = new moodle_url('/badges/competency.php', array('id' => $badge->id));
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url($currenturl);
|
||||
$PAGE->set_heading($badge->name);
|
||||
$PAGE->set_title($badge->name);
|
||||
$PAGE->navbar->add($badge->name);
|
||||
|
||||
$output = $PAGE->get_renderer('core', 'badges');
|
||||
$msg = optional_param('msg', '', PARAM_TEXT);
|
||||
$emsg = optional_param('emsg', '', PARAM_TEXT);
|
||||
$url = new moodle_url('/badges/competency.php', array('id' => $badge->id, 'action' => $action, 'alignmentid' => $alignmentid));
|
||||
$mform = new competency_alignment_form($url, array('badge' => $badge, 'action' => $action, 'alignmentid' => $alignmentid));
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($currenturl);
|
||||
} else if ($mform->is_submitted() && $mform->is_validated() && ($data = $mform->get_data())) {
|
||||
$alignment = new stdClass();
|
||||
$alignment->badgeid = $badgeid;
|
||||
$alignment->targetname = $data->targetname;
|
||||
$alignment->targeturl = $data->targeturl;
|
||||
$alignment->targetframework = $data->targetframework;
|
||||
$alignment->targetcode = $data->targetcode;
|
||||
$alignment->targetdescription = trim($data->targetdescription);
|
||||
$badge->save_alignment($alignment, $alignmentid);
|
||||
redirect($currenturl);
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
|
||||
echo $output->print_badge_status_box($badge);
|
||||
$output->print_badge_tabs($badgeid, $context, 'alignment');
|
||||
if ($emsg !== '') {
|
||||
echo $OUTPUT->notification($emsg);
|
||||
} else if ($msg !== '') {
|
||||
echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
|
||||
}
|
||||
echo $output->notification(get_string('notealignment', 'badges'), 'info');
|
||||
|
||||
if ($alignmentid || $action == 'add' || $action == 'edit') {
|
||||
$mform->display();
|
||||
} else if (empty($action)) {
|
||||
if (!$badge->is_active() && !$badge->is_locked()) {
|
||||
$urlbutton = new moodle_url('/badges/competency.php', array('id' => $badge->id, 'action' => 'add'));
|
||||
echo $OUTPUT->box($OUTPUT->single_button($urlbutton, get_string('addalignment', 'badges')), 'clearfix mdl-align');
|
||||
}
|
||||
$alignment = $badge->get_alignment();
|
||||
if (count($alignment) > 0) {
|
||||
$renderrelated = new badge_competencies_alignment($alignment, $badgeid);
|
||||
echo $output->render($renderrelated);
|
||||
} else {
|
||||
echo $output->notification(get_string('noalignment', 'badges'));
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
41
badges/competency_action.php
Normal file
41
badges/competency_action.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Processing actions with competencies alignment.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
$alignmentid = required_param('alignmentid', PARAM_INT); // Related badge ID.
|
||||
$badgeid = required_param('id', PARAM_INT); // Badge ID.
|
||||
$action = optional_param('action', 'remove', PARAM_TEXT); // Remove.
|
||||
|
||||
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);
|
||||
}
|
||||
redirect($return);
|
79
badges/competency_form.php
Normal file
79
badges/competency_form.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Form competency for editing.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
/**
|
||||
* Form to edit competency alignment.
|
||||
*
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
class competency_alignment_form extends moodleform {
|
||||
|
||||
/**
|
||||
* Defines the form.
|
||||
*/
|
||||
public function definition() {
|
||||
global $DB;
|
||||
$mform = $this->_form;
|
||||
$badge = $this->_customdata['badge'];
|
||||
$action = $this->_customdata['action'];
|
||||
$alignmentid = $this->_customdata['alignmentid'];
|
||||
$mform->addElement('header', 'alignment', get_string('alignment', 'badges'));
|
||||
$mform->addElement('text', 'targetname', get_string('targetname', 'badges'), array('size' => '70'));
|
||||
$mform->setType('targetname', PARAM_TEXT);
|
||||
$mform->addRule('targetname', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
||||
$mform->addRule('targetname', null, 'required');
|
||||
$mform->addHelpButton('targetname', 'targetname', 'badges');
|
||||
$mform->addElement('text', 'targeturl', get_string('targeturl', 'badges'), array('size' => '70'));
|
||||
$mform->setType('targeturl', PARAM_URL);
|
||||
$mform->addRule('targeturl', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
||||
$mform->addRule('targeturl', null, 'required');
|
||||
$mform->addHelpButton('targeturl', 'targeturl', 'badges');
|
||||
$mform->addElement('text', 'targetframework', get_string('targetframework', 'badges'), array('size' => '70'));
|
||||
$mform->setType('targetframework', PARAM_TEXT);
|
||||
$mform->addRule('targetframework', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
||||
$mform->addHelpButton('targetframework', 'targetframework', 'badges');
|
||||
$mform->addElement('text', 'targetcode', get_string('targetcode', 'badges'), array('size' => '70'));
|
||||
$mform->setType('targetcode', PARAM_TEXT);
|
||||
$mform->addRule('targetcode', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
||||
$mform->addHelpButton('targetcode', 'targetcode', 'badges');
|
||||
$mform->addElement('textarea', 'targetdescription', get_string('targetdescription', 'badges'),
|
||||
'wrap="virtual" rows="8" cols="70"');
|
||||
$this->add_action_buttons();
|
||||
if ($action == 'edit' || $alignmentid) {
|
||||
$alignment = new stdClass();
|
||||
$alignment = $DB->get_record_select('badge_competencies', 'id = ?', array($alignmentid));
|
||||
$this->set_data($alignment);
|
||||
// Freeze all elements if badge is active or locked.
|
||||
if ($badge->is_active() || $badge->is_locked()) {
|
||||
$mform->hardFreezeAllVisibleExcept(array());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -84,15 +84,21 @@ $editoroptions = array(
|
||||
);
|
||||
$badge = file_prepare_standard_editor($badge, 'message', $editoroptions, $context);
|
||||
|
||||
$form_class = 'edit_' . $action . '_form';
|
||||
$form = new $form_class($currenturl, array('badge' => $badge, 'action' => $action, 'editoroptions' => $editoroptions));
|
||||
$formclass = 'edit_' . $action . '_form';
|
||||
$form = new $formclass($currenturl, array('badge' => $badge, 'action' => $action, 'editoroptions' => $editoroptions));
|
||||
|
||||
if ($form->is_cancelled()) {
|
||||
redirect(new moodle_url('/badges/overview.php', array('id' => $badgeid)));
|
||||
} else if ($form->is_submitted() && $form->is_validated() && ($data = $form->get_data())) {
|
||||
if ($action == 'details') {
|
||||
$badge->name = $data->name;
|
||||
$badge->version = trim($data->version);
|
||||
$badge->language = $data->language;
|
||||
$badge->description = $data->description;
|
||||
$badge->imageauthorname = $data->imageauthorname;
|
||||
$badge->imageauthoremail = $data->imageauthoremail;
|
||||
$badge->imageauthorurl = $data->imageauthorurl;
|
||||
$badge->imagecaption = $data->imagecaption;
|
||||
$badge->usermodified = $USER->id;
|
||||
$badge->issuername = $data->issuername;
|
||||
$badge->issuerurl = $data->issuerurl;
|
||||
|
@ -45,6 +45,7 @@ class edit_details_form extends moodleform {
|
||||
$mform = $this->_form;
|
||||
$badge = (isset($this->_customdata['badge'])) ? $this->_customdata['badge'] : false;
|
||||
$action = $this->_customdata['action'];
|
||||
$languages = get_string_manager()->get_list_of_languages();
|
||||
|
||||
$mform->addElement('header', 'badgedetails', get_string('badgedetails', 'badges'));
|
||||
$mform->addElement('text', 'name', get_string('name'), array('size' => '70'));
|
||||
@ -53,6 +54,12 @@ class edit_details_form extends moodleform {
|
||||
$mform->addRule('name', null, 'required');
|
||||
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
||||
|
||||
$mform->addElement('text', 'version', get_string('version', 'badges'), array('size' => '70'));
|
||||
$mform->setType('version', PARAM_TEXT);
|
||||
$mform->addHelpButton('version', 'version', 'badges');
|
||||
$mform->addElement('select', 'language', get_string('language'), $languages);
|
||||
$mform->addHelpButton('language', 'language', 'badges');
|
||||
|
||||
$mform->addElement('textarea', 'description', get_string('description', 'badges'), 'wrap="virtual" rows="8" cols="70"');
|
||||
$mform->setType('description', PARAM_NOTAGS);
|
||||
$mform->addRule('description', null, 'required');
|
||||
@ -68,6 +75,18 @@ class edit_details_form extends moodleform {
|
||||
$mform->insertElementBefore($currentimage, 'image');
|
||||
}
|
||||
$mform->addHelpButton('image', 'badgeimage', 'badges');
|
||||
$mform->addElement('text', 'imageauthorname', get_string('imageauthorname', 'badges'), array('size' => '70'));
|
||||
$mform->setType('imageauthorname', PARAM_TEXT);
|
||||
$mform->addHelpButton('imageauthorname', 'imageauthorname', 'badges');
|
||||
$mform->addElement('text', 'imageauthoremail', get_string('imageauthoremail', 'badges'), array('size' => '70'));
|
||||
$mform->setType('imageauthoremail', PARAM_TEXT);
|
||||
$mform->addHelpButton('imageauthoremail', 'imageauthoremail', 'badges');
|
||||
$mform->addElement('text', 'imageauthorurl', get_string('imageauthorurl', 'badges'), array('size' => '70'));
|
||||
$mform->setType('imageauthorurl', PARAM_URL);
|
||||
$mform->addHelpButton('imageauthorurl', 'imageauthorurl', 'badges');
|
||||
$mform->addElement('text', 'imagecaption', get_string('imagecaption', 'badges'), array('size' => '70'));
|
||||
$mform->setType('imagecaption', PARAM_TEXT);
|
||||
$mform->addHelpButton('imagecaption', 'imagecaption', 'badges');
|
||||
|
||||
$mform->addElement('header', 'issuerdetails', get_string('issuerdetails', 'badges'));
|
||||
|
||||
@ -118,6 +137,7 @@ class edit_details_form extends moodleform {
|
||||
$mform->setType('action', PARAM_TEXT);
|
||||
|
||||
if ($action == 'new') {
|
||||
$mform->setDefault('language', $CFG->lang);
|
||||
$this->add_action_buttons(true, get_string('createbutton', 'badges'));
|
||||
} else {
|
||||
// Add hidden fields.
|
||||
@ -174,6 +194,10 @@ class edit_details_form extends moodleform {
|
||||
$errors['expirydategr'] = get_string('error:invalidexpiredate', 'badges');
|
||||
}
|
||||
|
||||
if ($data['imageauthoremail'] && !validate_email($data['imageauthoremail'])) {
|
||||
$errors['imageauthoremail'] = get_string('invalidemail');
|
||||
}
|
||||
|
||||
// Check for duplicate badge names.
|
||||
if ($data['action'] == 'new') {
|
||||
$duplicate = $DB->record_exists_select('badge', 'name = :name AND status != :deleted',
|
||||
|
100
badges/endorsement.php
Normal file
100
badges/endorsement.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Endorsement information
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
require_once($CFG->dirroot . '/badges/endorsement_form.php');
|
||||
|
||||
$badgeid = required_param('id', PARAM_INT);
|
||||
|
||||
require_login();
|
||||
|
||||
if (empty($CFG->enablebadges)) {
|
||||
print_error('badgesdisabled', 'badges');
|
||||
}
|
||||
|
||||
$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)) {
|
||||
print_error('coursebadgesdisabled', 'badges');
|
||||
}
|
||||
require_login($badge->courseid);
|
||||
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
|
||||
$PAGE->set_pagelayout('standard');
|
||||
navigation_node::override_active_url($navurl);
|
||||
} else {
|
||||
$PAGE->set_pagelayout('admin');
|
||||
navigation_node::override_active_url($navurl, true);
|
||||
}
|
||||
|
||||
$currenturl = new moodle_url('/badges/endorsement.php', array('id' => $badgeid));
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url($currenturl);
|
||||
$PAGE->set_heading($badge->name);
|
||||
$PAGE->set_title($badge->name);
|
||||
$PAGE->navbar->add($badge->name);
|
||||
|
||||
$output = $PAGE->get_renderer('core', 'badges');
|
||||
$msg = optional_param('msg', '', PARAM_TEXT);
|
||||
$emsg = optional_param('emsg', '', PARAM_TEXT);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
|
||||
|
||||
echo $output->print_badge_status_box($badge);
|
||||
$output->print_badge_tabs($badgeid, $context, 'bendorsement');
|
||||
|
||||
$form = new endorsement_form($currenturl, array('badge' => $badge));
|
||||
if ($form->is_cancelled()) {
|
||||
redirect(new moodle_url('/badges/overview.php', array('id' => $badgeid)));
|
||||
} else if ($form->is_submitted() && $form->is_validated() && ($data = $form->get_data())) {
|
||||
$endorsement = new stdClass();
|
||||
$endorsement->badgeid = $badgeid;
|
||||
$endorsement->issuername = $data->issuername;
|
||||
$endorsement->issueremail = $data->issueremail;
|
||||
$endorsement->issuerurl = $data->issuerurl;
|
||||
$endorsement->claimid = $data->claimid;
|
||||
$endorsement->claimcomment = strip_tags($data->claimcomment);
|
||||
$endorsement->dateissued = $data->dateissued;
|
||||
|
||||
if ($badge->save_endorsement($endorsement)) {
|
||||
$msg = get_string('changessaved');
|
||||
} else {
|
||||
$emsg = get_string('error:save', 'badges');
|
||||
}
|
||||
}
|
||||
|
||||
if ($emsg !== '') {
|
||||
echo $OUTPUT->notification($emsg);
|
||||
|
||||
} else if ($msg !== '') {
|
||||
echo $OUTPUT->notification($msg, 'notifysuccess');
|
||||
}
|
||||
echo $output->notification(get_string('noteendorsement', 'badges'), 'info');
|
||||
$form->display();
|
||||
echo $OUTPUT->footer();
|
91
badges/endorsement_form.php
Normal file
91
badges/endorsement_form.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Form endorsement for editing.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
/**
|
||||
* Form to edit endorsement.
|
||||
*
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai
|
||||
*/
|
||||
class endorsement_form extends moodleform {
|
||||
|
||||
/**
|
||||
* Defines the form.
|
||||
*/
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$badge = $this->_customdata['badge'];
|
||||
$mform->addElement('header', 'endorsement', get_string('issuerdetails', 'badges'));
|
||||
$mform->addElement('text', 'issuername', get_string('issuername_endorsement', 'badges'), array('size' => '70'));
|
||||
$mform->setType('issuername', PARAM_TEXT);
|
||||
$mform->addRule('issuername', null, 'required');
|
||||
$mform->addHelpButton('issuername', 'issuername_endorsement', 'badges');
|
||||
$mform->addElement('text', 'issueremail', get_string('issueremail', 'badges'), array('size' => '70'));
|
||||
$mform->addRule('issueremail', null, 'required');
|
||||
$mform->setType('issueremail', PARAM_RAW);
|
||||
$mform->addHelpButton('issueremail', 'issueremail', 'badges');
|
||||
$mform->addElement('text', 'issuerurl', get_string('issuerurl', 'badges'), array('size' => '70'));
|
||||
$mform->setType('issuerurl', PARAM_URL);
|
||||
$mform->addRule('issuerurl', null, 'required');
|
||||
$mform->addHelpButton('issuerurl', 'issuerurl', 'badges');
|
||||
$mform->addElement('date_time_selector', 'dateissued',
|
||||
get_string('dateawarded', 'badges'));
|
||||
$mform->addElement('header', 'claim', get_string('claim', 'badges'));
|
||||
$mform->addElement('text', 'claimid', get_string('claimid', 'badges'), array('size' => '70'));
|
||||
$mform->setType('claimid', PARAM_URL);
|
||||
$mform->addRule('claimid', null, 'required');
|
||||
$mform->addElement('textarea', 'claimcomment', get_string('claimcomment', 'badges'), 'wrap="virtual" rows="8" cols="70"');
|
||||
$mform->setType('claimcomment', PARAM_NOTAGS);
|
||||
$endorsement = new stdClass();
|
||||
$endorsement = $badge->get_endorsement();
|
||||
if ($endorsement) {
|
||||
$mform->setDefault('dateissued', $endorsement->dateissued);
|
||||
$this->set_data($endorsement);
|
||||
}
|
||||
$this->add_action_buttons();
|
||||
// Freeze all elements if badge is active or locked.
|
||||
if ($badge->is_active() || $badge->is_locked()) {
|
||||
$mform->hardFreezeAllVisibleExcept(array());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates form data.
|
||||
*
|
||||
* @param array $data submitted data.
|
||||
* @param array $files submitted files.
|
||||
* @return array $errors An array of errors.
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
if ($data['issueremail'] && !validate_email($data['issueremail'])) {
|
||||
$errors['issueremail'] = get_string('invalidemail');
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
}
|
69
badges/endorsement_json.php
Normal file
69
badges/endorsement_json.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Serve endorsement JSON for assertion.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
define('AJAX_SCRIPT', true);
|
||||
define('NO_MOODLE_COOKIES', true); // No need for a session here.
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
if (empty($CFG->enablebadges)) {
|
||||
print_error('badgesdisabled', 'badges');
|
||||
}
|
||||
|
||||
global $DB;
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$action = optional_param('action', null, PARAM_BOOL); // Generates endorsement issuer class if true.
|
||||
$badge = new badge($id);
|
||||
|
||||
$json = array();
|
||||
$endorsement = $badge->get_endorsement();
|
||||
$endorsementurl = new moodle_url('/badges/endorsement_json.php', array('id' => $id));
|
||||
|
||||
if ($endorsement) {
|
||||
$issuer = array();
|
||||
$issuerurl = new moodle_url('/badges/endorsement_json.php', array('id' => $id, 'action' => 1));
|
||||
$issuer['id'] = $issuerurl->out(false);
|
||||
$issuer['name'] = $endorsement->issuername;
|
||||
$issuer['email'] = $endorsement->issueremail;
|
||||
$issuer['url'] = $endorsement->issuerurl;
|
||||
if ($action) {
|
||||
$json = $issuer;
|
||||
} else {
|
||||
$json['@context'] = OPEN_BADGES_V2_CONTEXT;
|
||||
$json['type'] = OPEN_BADGES_V2_TYPE_ENDORSEMENT;
|
||||
$json['id'] = $endorsementurl->out(false);
|
||||
$json['issuer'] = $issuer;
|
||||
if (!empty($endorsement->claimcomment)) {
|
||||
$json['claim']['id'] = $endorsement->claimid;
|
||||
$json['claim']['endorsementComment'] = $endorsement->claimcomment;
|
||||
} else {
|
||||
$json['claim'] = $endorsement->claimid;
|
||||
}
|
||||
$json['issuedOn'] = date('c', $endorsement->dateissued);
|
||||
$json['verification'] = array('type' => 'hosted');
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo json_encode($json);
|
52
badges/image_author_json.php
Normal file
52
badges/image_author_json.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Serve profile image author JSON for assertion.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
|
||||
define('AJAX_SCRIPT', true);
|
||||
define('NO_MOODLE_COOKIES', true); // No need for a session here.
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
if (empty($CFG->enablebadges)) {
|
||||
print_error('badgesdisabled', 'badges');
|
||||
}
|
||||
|
||||
$id = required_param('id', PARAM_INT); // Unique hash of badge assertion.
|
||||
$badge = new badge($id);
|
||||
|
||||
$json = array();
|
||||
$authorimage = new moodle_url('/badges/image_author_json.php', array('id' => $badge->id));
|
||||
$json['id'] = $authorimage->out(false);
|
||||
$json['type'] = OPEN_BADGES_V2_TYPE_AUTHOR;
|
||||
if (!empty($badge->imageauthorname)) {
|
||||
$json['name'] = $badge->imageauthorname;
|
||||
}
|
||||
if (!empty($badge->imageauthoremail)) {
|
||||
$json['email'] = $badge->imageauthoremail;
|
||||
}
|
||||
if (!empty($badge->imageauthorurl)) {
|
||||
$json['url'] = $badge->imageauthorurl;
|
||||
}
|
||||
echo $OUTPUT->header();
|
||||
echo json_encode($json);
|
@ -77,7 +77,13 @@ if ($form->is_cancelled()) {
|
||||
$now = time();
|
||||
|
||||
$fordb->name = $data->name;
|
||||
$fordb->version = $data->version;
|
||||
$fordb->language = $data->language;
|
||||
$fordb->description = $data->description;
|
||||
$fordb->imageauthorname = $data->imageauthorname;
|
||||
$fordb->imageauthoremail = $data->imageauthoremail;
|
||||
$fordb->imageauthorurl = $data->imageauthorurl;
|
||||
$fordb->imagecaption = $data->imagecaption;
|
||||
$fordb->timecreated = $now;
|
||||
$fordb->timemodified = $now;
|
||||
$fordb->usercreated = $USER->id;
|
||||
|
106
badges/related.php
Normal file
106
badges/related.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Related badges information
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
require_once($CFG->dirroot . '/badges/related_form.php');
|
||||
|
||||
$badgeid = required_param('id', PARAM_INT);
|
||||
$action = optional_param('action', null, PARAM_TEXT);
|
||||
$lang = current_language();
|
||||
|
||||
require_login();
|
||||
|
||||
if (empty($CFG->enablebadges)) {
|
||||
print_error('badgesdisabled', 'badges');
|
||||
}
|
||||
|
||||
$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)) {
|
||||
print_error('coursebadgesdisabled', 'badges');
|
||||
}
|
||||
require_login($badge->courseid);
|
||||
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
|
||||
$PAGE->set_pagelayout('standard');
|
||||
navigation_node::override_active_url($navurl);
|
||||
} else {
|
||||
$PAGE->set_pagelayout('admin');
|
||||
navigation_node::override_active_url($navurl, true);
|
||||
}
|
||||
|
||||
$currenturl = new moodle_url('/badges/related.php', array('id' => $badge->id));
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url($currenturl);
|
||||
$PAGE->set_heading($badge->name);
|
||||
$PAGE->set_title($badge->name);
|
||||
$PAGE->navbar->add($badge->name);
|
||||
$output = $PAGE->get_renderer('core', 'badges');
|
||||
$msg = optional_param('msg', '', PARAM_TEXT);
|
||||
$emsg = optional_param('emsg', '', PARAM_TEXT);
|
||||
$url = new moodle_url('/badges/related.php', array('id' => $badge->id, 'action' => 'add'));
|
||||
|
||||
$mform = new edit_relatedbadge_form($url, array('badge' => $badge));
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($currenturl);
|
||||
} else if ($mform->is_submitted() && $mform->is_validated() && ($data = $mform->get_data())) {
|
||||
|
||||
if (isset($data->relatedbadgeids)) {
|
||||
$badge->add_related_badges($data->relatedbadgeids);
|
||||
}
|
||||
redirect($currenturl);
|
||||
}
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
|
||||
echo $output->print_badge_status_box($badge);
|
||||
|
||||
$output->print_badge_tabs($badgeid, $context, 'brelated');
|
||||
if ($emsg !== '') {
|
||||
echo $OUTPUT->notification($emsg);
|
||||
} else if ($msg !== '') {
|
||||
echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
|
||||
}
|
||||
|
||||
echo $output->notification(get_string('noterelated', 'badges'), 'info');
|
||||
if (is_null($action)) {
|
||||
if (!$badge->is_active() && !$badge->is_locked()) {
|
||||
echo $OUTPUT->box($OUTPUT->single_button($url, get_string('addrelated', 'badges')), 'clearfix mdl-align');
|
||||
}
|
||||
if ($badge->has_related()) {
|
||||
$badgerelated = $badge->get_related_badges();
|
||||
$renderrelated = new badge_related($badgerelated, $badgeid);
|
||||
echo $output->render($renderrelated);
|
||||
} else {
|
||||
echo $output->notification(get_string('norelated', 'badges'));
|
||||
}
|
||||
} else if ($action == 'add') {
|
||||
$mform->display();
|
||||
}
|
||||
echo $OUTPUT->footer();
|
42
badges/related_action.php
Normal file
42
badges/related_action.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Action related badges.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
$relatedid = optional_param('relatedid', 0, PARAM_INT); // Related badge ID.
|
||||
$badgeid = optional_param('badgeid', 0, PARAM_INT); // Badge ID.
|
||||
$action = optional_param('action', 'remove', PARAM_TEXT); // Add, remove option.
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
redirect($return);
|
107
badges/related_form.php
Normal file
107
badges/related_form.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Form related badges.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage badges
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
/**
|
||||
* Form to edit badge details.
|
||||
*
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
class edit_relatedbadge_form extends moodleform {
|
||||
|
||||
/**
|
||||
* Defines the form.
|
||||
*/
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$badge = $this->_customdata['badge'];
|
||||
$badgesarray = $this->get_badges_option($badge);
|
||||
$mform->addElement('header', 'alignment', get_string('relatedbages', 'badges'));
|
||||
if (!$badgesarray) {
|
||||
$badgesarray = array(get_string('none'));
|
||||
$attributes = array('size' => '3', 'disabled' => true, 'style' => 'min-width: 200px');
|
||||
} else {
|
||||
$attributes = array('size' => '10');
|
||||
}
|
||||
$mform->addElement('select', 'relatedbadgeids', get_string('relatedbages', 'badges'), $badgesarray, $attributes);
|
||||
$mform->getElement('relatedbadgeids')->setMultiple(true);
|
||||
$this->add_action_buttons();
|
||||
|
||||
// Freeze all elements if badge is active or locked.
|
||||
if ($badge->is_active() || $badge->is_locked()) {
|
||||
$mform->hardFreezeAllVisibleExcept(array());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates form data.
|
||||
*
|
||||
* @param array $data submitted data.
|
||||
* @param array $files submitted files.
|
||||
* @return array $errors An array of errors.
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list badge of a course or list badge site.
|
||||
*
|
||||
* @param object $badge Badge object.
|
||||
* @return array $options An array the badges.
|
||||
*/
|
||||
public function get_badges_option($badge) {
|
||||
global $DB;
|
||||
$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
|
||||
FROM {badge_related} br WHERE br.badgeid = :badgeid1)";
|
||||
$params = array('badgeid' => $badge->id, 'badgeid1' => $badge->id);
|
||||
if ($badge->type == BADGE_TYPE_COURSE) {
|
||||
$sql .= " AND (b.courseid = :courseid OR b.type = :badgetype)";
|
||||
$params['courseid'] = $badge->courseid;
|
||||
$params['badgetype'] = BADGE_TYPE_SITE;
|
||||
}
|
||||
|
||||
$records = $DB->get_records_sql($sql, $params);
|
||||
$languages = get_string_manager()->get_list_of_languages();
|
||||
$options = array();
|
||||
foreach ($records as $record) {
|
||||
$language = isset($languages[$record->language]) ? $languages[$record->language] : '';
|
||||
$options[$record->id] = $record->name .
|
||||
' (version: ' . $record->version . ', language: ' . $language . ', ' .
|
||||
($record->type == BADGE_TYPE_COURSE ? get_string('badgesview', 'badges') : get_string('sitebadges', 'badges')) .
|
||||
')';
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
@ -139,15 +139,24 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
// Prints a badge overview infomation.
|
||||
public function print_badge_overview($badge, $context) {
|
||||
$display = "";
|
||||
$languages = get_string_manager()->get_list_of_languages();
|
||||
|
||||
// Badge details.
|
||||
|
||||
$display .= $this->heading(get_string('badgedetails', 'badges'), 3);
|
||||
$dl = array();
|
||||
$dl[get_string('name')] = $badge->name;
|
||||
$dl[get_string('version', 'badges')] = $badge->version;
|
||||
$dl[get_string('language')] = $languages[$badge->language];
|
||||
$dl[get_string('description', 'badges')] = $badge->description;
|
||||
$dl[get_string('createdon', 'search')] = userdate($badge->timecreated);
|
||||
$dl[get_string('badgeimage', 'badges')] = print_badge_image($badge, $context, 'large');
|
||||
$dl[get_string('imageauthorname', 'badges')] =
|
||||
html_writer::link($badge->imageauthorname, $badge->imageauthorname, array('target' => '_blank'));
|
||||
$dl[get_string('imageauthoremail', 'badges')] =
|
||||
html_writer::tag('a', $badge->imageauthoremail, array('href' => 'mailto:' . $badge->imageauthoremail));
|
||||
$dl[get_string('imageauthorurl', 'badges')] =
|
||||
html_writer::link($badge->imageauthorurl, $badge->imageauthorurl, array('target' => '_blank'));
|
||||
$dl[get_string('imagecaption', 'badges')] = $badge->imagecaption;
|
||||
$display .= $this->definition_list($dl);
|
||||
|
||||
// Issuer details.
|
||||
@ -212,6 +221,10 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
}
|
||||
}
|
||||
|
||||
$display .= self::print_badge_endorsement($badge);
|
||||
$display .= self::print_badge_related($badge);
|
||||
$display .= self::print_badge_competencies($badge);
|
||||
|
||||
return html_writer::div($display, null, array('id' => 'badge-overview'));
|
||||
}
|
||||
|
||||
@ -277,11 +290,13 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
$badge = new badge($ibadge->badgeid);
|
||||
$now = time();
|
||||
$expiration = isset($issued['expires']) ? $issued['expires'] : $now + 86400;
|
||||
$badgeimage = is_array($badgeclass['image']) ? $badgeclass['image']['id'] : $badgeclass['image'];
|
||||
$languages = get_string_manager()->get_list_of_languages();
|
||||
|
||||
$output = '';
|
||||
$output .= html_writer::start_tag('div', array('id' => 'badge'));
|
||||
$output .= html_writer::start_tag('div', array('id' => 'badge-image'));
|
||||
$output .= html_writer::empty_tag('img', array('src' => $badgeclass['image'], 'alt' => $badge->name));
|
||||
$output .= html_writer::empty_tag('img', array('src' => $badgeimage, 'alt' => $badge->name));
|
||||
if ($expiration < $now) {
|
||||
$output .= $this->output->pix_icon('i/expired',
|
||||
get_string('expireddate', 'badges', userdate($issued['expires'])),
|
||||
@ -334,7 +349,16 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
$output .= $this->output->heading(get_string('badgedetails', 'badges'), 3);
|
||||
$dl = array();
|
||||
$dl[get_string('name')] = $badge->name;
|
||||
$dl[get_string('version', 'badges')] = $badge->version;
|
||||
$dl[get_string('language')] = $languages[$badge->language];
|
||||
$dl[get_string('description', 'badges')] = $badge->description;
|
||||
$dl[get_string('imageauthorname', 'badges')] =
|
||||
html_writer::link($badge->imageauthorname, $badge->imageauthorname, array('target' => '_blank'));
|
||||
$dl[get_string('imageauthoremail', 'badges')] =
|
||||
html_writer::tag('a', $badge->imageauthoremail, array('href' => 'mailto:' . $badge->imageauthoremail));
|
||||
$dl[get_string('imageauthorurl', 'badges')] =
|
||||
html_writer::link($badge->imageauthorurl, $badge->imageauthorurl, array('target' => '_blank'));
|
||||
$dl[get_string('imagecaption', 'badges')] = $badge->imagecaption;
|
||||
|
||||
if ($badge->type == BADGE_TYPE_COURSE && isset($badge->courseid)) {
|
||||
$coursename = $DB->get_field('course', 'fullname', array('id' => $badge->courseid));
|
||||
@ -345,8 +369,12 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
|
||||
$output .= $this->output->heading(get_string('issuancedetails', 'badges'), 3);
|
||||
$dl = array();
|
||||
$issued['issuedOn'] = !preg_match( '~^[1-9][0-9]*$~', $issued['issuedOn'] ) ?
|
||||
strtotime($issued['issuedOn']) : $issued['issuedOn'];
|
||||
$dl[get_string('dateawarded', 'badges')] = userdate($issued['issuedOn']);
|
||||
if (isset($issued['expires'])) {
|
||||
$issued['expires'] = !preg_match( '~^[1-9][0-9]*$~', $issued['expires'] ) ?
|
||||
strtotime($issued['expires']) : $issued['expires'];
|
||||
if ($issued['expires'] < $now) {
|
||||
$dl[get_string('expirydate', 'badges')] = userdate($issued['expires']) . get_string('warnexpired', 'badges');
|
||||
|
||||
@ -377,6 +405,29 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
|
||||
$dl[get_string('evidence', 'badges')] = get_string('completioninfo', 'badges') . html_writer::alist($items, array(), 'ul');
|
||||
$output .= $this->definition_list($dl);
|
||||
$output .= self::print_badge_endorsement($badge);
|
||||
$relatedbadges = $badge->get_related_badges();
|
||||
$output .= $this->heading(get_string('relatedbages', 'badges'), 3);
|
||||
if (!empty($relatedbadges)) {
|
||||
$items = array();
|
||||
foreach ($relatedbadges as $related) {
|
||||
$items[] = $related->name;
|
||||
}
|
||||
$output .= html_writer::alist($items, array(), 'ul');
|
||||
} else {
|
||||
$output .= get_string('norelated', 'badges');
|
||||
}
|
||||
$output .= $this->heading(get_string('alignment', 'badges'), 3);
|
||||
$competencies = $badge->get_alignment();
|
||||
if (!empty($competencies)) {
|
||||
$items = array();
|
||||
foreach ($competencies as $competency) {
|
||||
$items[] = html_writer::link($competency->targeturl, $competency->targetname, array('target' => '_blank'));
|
||||
}
|
||||
$output .= html_writer::alist($items, array(), 'ul');
|
||||
} else {
|
||||
$output .= get_string('noalignment', 'badges');
|
||||
}
|
||||
$output .= html_writer::end_tag('div');
|
||||
|
||||
return $output;
|
||||
@ -627,6 +678,7 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
public function print_badge_tabs($badgeid, $context, $current = 'overview') {
|
||||
global $DB;
|
||||
|
||||
$badge = new badge($badgeid);
|
||||
$row = array();
|
||||
|
||||
$row[] = new tabobject('overview',
|
||||
@ -665,6 +717,31 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
);
|
||||
}
|
||||
|
||||
if (has_capability('moodle/badges:configuredetails', $context)) {
|
||||
$row[] = new tabobject('bendorsement',
|
||||
new moodle_url('/badges/endorsement.php', array('id' => $badgeid)),
|
||||
get_string('bendorsement', 'badges')
|
||||
);
|
||||
}
|
||||
|
||||
if (has_capability('moodle/badges:configuredetails', $context)) {
|
||||
$related = $DB->count_records_sql("SELECT COUNT(br.badgeid)
|
||||
FROM {badge_related} br WHERE br.badgeid = :badgeid", array('badgeid' => $badgeid));
|
||||
$row[] = new tabobject('brelated',
|
||||
new moodle_url('/badges/related.php', array('id' => $badgeid)),
|
||||
get_string('brelated', 'badges', $related)
|
||||
);
|
||||
}
|
||||
|
||||
if (has_capability('moodle/badges:configuredetails', $context)) {
|
||||
$competencies = $DB->count_records_sql("SELECT COUNT(bc.id)
|
||||
FROM {badge_competencies} bc WHERE bc.badgeid = :badgeid", array('badgeid' => $badgeid));
|
||||
$row[] = new tabobject('balignment',
|
||||
new moodle_url('/badges/competency.php', array('id' => $badgeid)),
|
||||
get_string('balignment', 'badges', $competencies)
|
||||
);
|
||||
}
|
||||
|
||||
echo $this->tabtree($row, $current);
|
||||
}
|
||||
|
||||
@ -957,6 +1034,193 @@ class core_badges_renderer extends plugin_renderer_base {
|
||||
$output .= html_writer::end_tag('dl');
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs list en badges.
|
||||
*
|
||||
* @param badge $badge Badge object.
|
||||
* @return string $output content endorsement to output.
|
||||
*/
|
||||
protected function print_badge_endorsement(badge $badge) {
|
||||
$output = '';
|
||||
$endorsement = $badge->get_endorsement();
|
||||
$dl = array();
|
||||
$output .= $this->heading(get_string('endorsement', 'badges'), 3);
|
||||
if (!empty($endorsement)) {
|
||||
$dl[get_string('issuername', 'badges')] = $endorsement->issuername;
|
||||
$dl[get_string('issueremail', 'badges')] = $endorsement->issueremail;
|
||||
$dl[get_string('issuerurl', 'badges')] = html_writer::link($endorsement->issuerurl, $endorsement->issuerurl,
|
||||
array('target' => '_blank'));
|
||||
$dl[get_string('dateawarded', 'badges')] = date('c', $endorsement->dateissued);
|
||||
$dl[get_string('claimid', 'badges')] = html_writer::link($endorsement->claimid, $endorsement->claimid,
|
||||
array('target' => '_blank'));
|
||||
$dl[get_string('claimcomment', 'badges')] = $endorsement->claimcomment;
|
||||
$output .= $this->definition_list($dl);
|
||||
} else {
|
||||
$output .= get_string('noendorsement', 'badges');
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print list badges related.
|
||||
*
|
||||
* @param badge $badge Badge objects.
|
||||
* @return string $output List related badges to output.
|
||||
*/
|
||||
protected function print_badge_related(badge $badge) {
|
||||
$output = '';
|
||||
$relatedbadges = $badge->get_related_badges();
|
||||
$output .= $this->heading(get_string('relatedbages', 'badges'), 3);
|
||||
if (!empty($relatedbadges)) {
|
||||
$items = array();
|
||||
foreach ($relatedbadges as $related) {
|
||||
$relatedurl = new moodle_url('/badges/overview.php', array('id' => $related->id));
|
||||
$items[] = html_writer::link($relatedurl->out(), $related->name, array('target' => '_blank'));
|
||||
}
|
||||
$output .= html_writer::alist($items, array(), 'ul');
|
||||
} else {
|
||||
$output .= get_string('norelated', 'badges');
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print list badge competencies.
|
||||
*
|
||||
* @param badge $badge Badge objects.
|
||||
* @return string $output List competencies to output.
|
||||
*/
|
||||
protected function print_badge_competencies(badge $badge) {
|
||||
$output = '';
|
||||
$output .= $this->heading(get_string('alignment', 'badges'), 3);
|
||||
$competencies = $badge->get_alignment();
|
||||
if (!empty($competencies)) {
|
||||
$items = array();
|
||||
foreach ($competencies as $competency) {
|
||||
$urlaligment = new moodle_url('competency.php',
|
||||
array('id' => $badge->id, 'alignmentid' => $competency->id)
|
||||
);
|
||||
$items[] = html_writer::link($urlaligment, $competency->targetname, array('target' => '_blank'));
|
||||
}
|
||||
$output .= html_writer::alist($items, array(), 'ul');
|
||||
} else {
|
||||
$output .= get_string('noalignment', 'badges');
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a table for related badges.
|
||||
*
|
||||
* @param badge_related $related list related badges.
|
||||
* @return string list related badges to output.
|
||||
*/
|
||||
protected function render_badge_related(badge_related $related) {
|
||||
$currentbadge = new badge($related->currentbadgeid);
|
||||
$languages = get_string_manager()->get_list_of_languages();
|
||||
$paging = new paging_bar($related->totalcount, $related->page, $related->perpage, $this->page->url, 'page');
|
||||
$htmlpagingbar = $this->render($paging);
|
||||
$table = new html_table();
|
||||
$table->attributes['class'] = 'generaltable boxaligncenter boxwidthwide';
|
||||
$table->head = array(
|
||||
get_string('name'),
|
||||
get_string('version', 'badges'),
|
||||
get_string('language', 'badges'),
|
||||
get_string('type', 'badges')
|
||||
);
|
||||
if (!$currentbadge->is_active() && !$currentbadge->is_locked()) {
|
||||
array_push($table->head, '');
|
||||
}
|
||||
|
||||
foreach ($related->badges as $badge) {
|
||||
$badgeobject = new badge($badge->id);
|
||||
$style = array('title' => $badgeobject->name);
|
||||
if (!$badgeobject->is_active()) {
|
||||
$style['class'] = 'dimmed';
|
||||
}
|
||||
$context = ($badgeobject->type == BADGE_TYPE_SITE) ?
|
||||
context_system::instance() : context_course::instance($badgeobject->courseid);
|
||||
$forlink = print_badge_image($badgeobject, $context) . ' ' .
|
||||
html_writer::start_tag('span') . $badgeobject->name . html_writer::end_tag('span');
|
||||
$name = html_writer::link(new moodle_url('/badges/overview.php', array('id' => $badgeobject->id)), $forlink, $style);
|
||||
|
||||
$row = array(
|
||||
$name,
|
||||
$badge->version,
|
||||
$badge->language ? $languages[$badge->language] : '',
|
||||
$badge->type == BADGE_TYPE_COURSE ? get_string('badgesview', 'badges') : get_string('sitebadges', 'badges')
|
||||
);
|
||||
if (!$currentbadge->is_active() && !$currentbadge->is_locked()) {
|
||||
$action = $this->output->action_icon(
|
||||
new moodle_url('related_action.php',
|
||||
array(
|
||||
'badgeid' => $related->currentbadgeid,
|
||||
'relatedid' => $badge->id,
|
||||
'action' => 'remove'
|
||||
)
|
||||
), new pix_icon('t/delete', get_string('delete')));
|
||||
$actions = html_writer::tag('div', $action, array('class' => 'badge-actions'));
|
||||
array_push($row, $actions);
|
||||
}
|
||||
$table->data[] = $row;
|
||||
}
|
||||
$htmltable = html_writer::table($table);
|
||||
|
||||
return $htmlpagingbar . $htmltable . $htmlpagingbar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a table with competencies alignment.
|
||||
*
|
||||
* @param badge_competencies_alignment $alignment List competencies alignment.
|
||||
* @return string List competencies aligment to output.
|
||||
*/
|
||||
protected function render_badge_competencies_alignment(badge_competencies_alignment $alignment) {
|
||||
$currentbadge = new badge($alignment->currentbadgeid);
|
||||
$paging = new paging_bar($alignment->totalcount, $alignment->page, $alignment->perpage, $this->page->url, 'page');
|
||||
$htmlpagingbar = $this->render($paging);
|
||||
$table = new html_table();
|
||||
$table->attributes['class'] = 'generaltable boxaligncenter boxwidthwide';
|
||||
$table->head = array('Name', 'URL', '');
|
||||
|
||||
foreach ($alignment->alignments as $item) {
|
||||
$urlaligment = new moodle_url('competency.php',
|
||||
array(
|
||||
'id' => $currentbadge->id,
|
||||
'alignmentid' => $item->id,
|
||||
)
|
||||
);
|
||||
$row = array(
|
||||
html_writer::link($urlaligment, $item->targetname),
|
||||
html_writer::link($item->targeturl, $item->targeturl, array('target' => '_blank'))
|
||||
);
|
||||
if (!$currentbadge->is_active() && !$currentbadge->is_locked()) {
|
||||
$delete = $this->output->action_icon(
|
||||
new moodle_url('competency_action.php',
|
||||
array(
|
||||
'id' => $currentbadge->id,
|
||||
'alignmentid' => $item->id,
|
||||
'action' => 'remove'
|
||||
)
|
||||
), new pix_icon('t/delete', get_string('delete')));
|
||||
$edit = $this->output->action_icon(
|
||||
new moodle_url('competency.php',
|
||||
array(
|
||||
'id' => $currentbadge->id,
|
||||
'alignmentid' => $item->id,
|
||||
'action' => 'edit'
|
||||
)
|
||||
), new pix_icon('t/edit', get_string('edit')));
|
||||
$actions = html_writer::tag('div', $edit . $delete, array('class' => 'badge-actions'));
|
||||
array_push($row, $actions);
|
||||
}
|
||||
$table->data[] = $row;
|
||||
}
|
||||
$htmltable = html_writer::table($table);
|
||||
|
||||
return $htmlpagingbar . $htmltable . $htmlpagingbar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1157,3 +1421,87 @@ class badge_user_collection extends badge_collection implements renderable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection of all related badges.
|
||||
*
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
class badge_related implements renderable {
|
||||
|
||||
/** @var string how are the data sorted. */
|
||||
public $sort = 'name';
|
||||
|
||||
/** @var string how are the data sorted. */
|
||||
public $dir = 'ASC';
|
||||
|
||||
/** @var int page number to display. */
|
||||
public $page = 0;
|
||||
|
||||
/** @var int number of badges to display per page. */
|
||||
public $perpage = BADGE_PERPAGE;
|
||||
|
||||
/** @var int the total number of badges to display. */
|
||||
public $totalcount = null;
|
||||
|
||||
/** @var int the current badge. */
|
||||
public $currentbadgeid = 0;
|
||||
|
||||
/** @var array list of badges. */
|
||||
public $badges = array();
|
||||
|
||||
/**
|
||||
* Initializes the list of badges to display.
|
||||
*
|
||||
* @param array $badges related badges to render.
|
||||
* @param int $currentbadgeid ID current badge.
|
||||
*/
|
||||
public function __construct($badges, $currentbadgeid) {
|
||||
$this->badges = $badges;
|
||||
$this->currentbadgeid = $currentbadgeid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection of all competencies.
|
||||
*
|
||||
* @copyright 2018 Tung Thai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
|
||||
*/
|
||||
class badge_competencies_alignment implements renderable
|
||||
{
|
||||
/** @var string how are the data sorted. */
|
||||
public $sort = 'name';
|
||||
|
||||
/** @var string how are the data sorted. */
|
||||
public $dir = 'ASC';
|
||||
|
||||
/** @var int page number to display. */
|
||||
public $page = 0;
|
||||
|
||||
/** @var int number of badges to display per page. */
|
||||
public $perpage = BADGE_PERPAGE;
|
||||
|
||||
/** @var int the total number of badges to display. */
|
||||
public $totalcount = null;
|
||||
|
||||
/** @var array list of badges. */
|
||||
public $alignments = array();
|
||||
|
||||
/** @var array list of badges. */
|
||||
public $currentbadgeid = 0;
|
||||
|
||||
/**
|
||||
* Initializes the list of competencies to display.
|
||||
*
|
||||
* @param array $alignments List competencies alignment to render.
|
||||
* @param int $currentbadgeid ID current badge.
|
||||
*/
|
||||
public function __construct($alignments, $currentbadgeid) {
|
||||
$this->alignments = $alignments;
|
||||
$this->currentbadgeid = $currentbadgeid;
|
||||
}
|
||||
}
|
@ -38,14 +38,14 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
protected $coursebadge;
|
||||
protected $assertion;
|
||||
|
||||
/** @var $assertion2 to define json format for Open badge version 2 */
|
||||
protected $assertion2;
|
||||
|
||||
protected function setUp() {
|
||||
global $DB, $CFG;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$CFG->enablecompletion = true;
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
|
||||
$fordb = new stdClass();
|
||||
$fordb->id = null;
|
||||
$fordb->name = "Test badge with 'apostrophe' and other friends (<>&@#)";
|
||||
@ -60,11 +60,17 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
$fordb->expiredate = null;
|
||||
$fordb->expireperiod = null;
|
||||
$fordb->type = BADGE_TYPE_SITE;
|
||||
$fordb->version = 1;
|
||||
$fordb->language = 'en';
|
||||
$fordb->courseid = null;
|
||||
$fordb->messagesubject = "Test message subject";
|
||||
$fordb->message = "Test message body";
|
||||
$fordb->attachment = 1;
|
||||
$fordb->notification = 0;
|
||||
$fordb->imageauthorname = "Image Author 1";
|
||||
$fordb->imageauthoremail = "author@example.com";
|
||||
$fordb->imageauthorurl = "http://author-url.example.com";
|
||||
$fordb->imagecaption = "Test caption image";
|
||||
$fordb->status = BADGE_STATUS_INACTIVE;
|
||||
|
||||
$this->badgeid = $DB->insert_record('badge', $fordb, true);
|
||||
@ -81,7 +87,6 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
$maninstance = $DB->get_record('enrol', array('courseid' => $this->course->id, 'enrol' => 'manual'), '*', MUST_EXIST);
|
||||
$manplugin->enrol_user($maninstance, $this->user->id, $studentrole->id);
|
||||
$this->assertEquals(1, $DB->count_records('user_enrolments'));
|
||||
|
||||
$completionauto = array('completion' => COMPLETION_TRACKING_AUTOMATIC);
|
||||
$this->module = $this->getDataGenerator()->create_module('forum', array('course' => $this->course->id), $completionauto);
|
||||
|
||||
@ -89,12 +94,65 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
$fordb->type = BADGE_TYPE_COURSE;
|
||||
$fordb->courseid = $this->course->id;
|
||||
$fordb->status = BADGE_STATUS_ACTIVE;
|
||||
|
||||
$this->coursebadge = $DB->insert_record('badge', $fordb, true);
|
||||
|
||||
// Insert Endorsement.
|
||||
$endorsement = new stdClass();
|
||||
$endorsement->badgeid = $this->coursebadge;
|
||||
$endorsement->issuername = "Issuer 123";
|
||||
$endorsement->issueremail = "issuer123@email.com";
|
||||
$endorsement->issuerurl = "https://example.org/issuer-123";
|
||||
$endorsement->dateissued = 1524567747;
|
||||
$endorsement->claimid = "https://example.org/robotics-badge.json";
|
||||
$endorsement->claimcomment = "Test endorser comment";
|
||||
$DB->insert_record('badge_endorsement', $endorsement, true);
|
||||
|
||||
// Insert related badges.
|
||||
$badge = new badge($this->coursebadge);
|
||||
$clonedid = $badge->make_clone();
|
||||
$badgeclone = new badge($clonedid);
|
||||
$badgeclone->status = BADGE_STATUS_ACTIVE;
|
||||
$badgeclone->save();
|
||||
|
||||
$relatebadge = new stdClass();
|
||||
$relatebadge->badgeid = $this->coursebadge;
|
||||
$relatebadge->relatedbadgeid = $clonedid;
|
||||
$relatebadge->relatedid = $DB->insert_record('badge_related', $relatebadge, true);
|
||||
|
||||
// Insert a competency aligment.
|
||||
$competency = new stdClass();
|
||||
$competency->badgeid = $this->coursebadge;
|
||||
$competency->targetname = 'CCSS.ELA-Literacy.RST.11-12.3';
|
||||
$competency->targeturl = 'http://www.corestandards.org/ELA-Literacy/RST/11-12/3';
|
||||
$competency->targetdescription = 'Test target description';
|
||||
$competency->targetframework = 'CCSS.RST.11-12.3';
|
||||
$competency->targetcode = 'CCSS.RST.11-12.3';
|
||||
$DB->insert_record('badge_competencies', $competency, true);
|
||||
|
||||
$this->assertion = new stdClass();
|
||||
$this->assertion->badge = '{"uid":"%s","recipient":{"identity":"%s","type":"email","hashed":true,"salt":"%s"},"badge":"%s","verify":{"type":"hosted","url":"%s"},"issuedOn":"%d","evidence":"%s"}';
|
||||
$this->assertion->class = '{"name":"%s","description":"%s","image":"%s","criteria":"%s","issuer":"%s"}';
|
||||
$this->assertion->issuer = '{"name":"%s","url":"%s","email":"%s"}';
|
||||
// Format JSON-LD for Openbadge specification version 2.0.
|
||||
$this->assertion2 = new stdClass();
|
||||
$this->assertion2->badge = '{"recipient":{"identity":"%s","type":"email","hashed":true,"salt":"%s"},' .
|
||||
'"badge":{"name":"%s","description":"%s","image":{"id":"%s","author":"%s","caption":"%s"},' .
|
||||
'"criteria":{"id":"%s","narrative":"%s"},"issuer":{"name":"%s","url":"%s","email":"%s",' .
|
||||
'"@context":"https:\/\/w3id.org\/openbadges\/v2","id":"%s","type":"Issuer"},' .
|
||||
'"@context":"https:\/\/w3id.org\/openbadges\/v2","id":"%s","type":"BadgeClass","version":"%s",' .
|
||||
'"@language":"%s","related":[{"id":"%s","version":"%s","@language":"%s"}],"endorsement":"%s",' .
|
||||
'"alignment":[{"targetName":"%s","targetUrl":"%s","targetDescription":"%s","targetFramework":"%s",' .
|
||||
'"targetCode":"%s"}]},"verify":{"type":"hosted","url":"%s"},"issuedOn":"%s","evidence":"%s",' .
|
||||
'"@context":"https:\/\/w3id.org\/openbadges\/v2","type":"Assertion","id":"%s"}';
|
||||
$this->assertion2->class = '{"name":"%s","description":"%s","image":{"id":"%s","author":"%s","caption":"%s"},' .
|
||||
'"criteria":{"id":"%s","narrative":"%s"},"issuer":{"name":"%s","url":"%s","email":"%s",' .
|
||||
'"@context":"https:\/\/w3id.org\/openbadges\/v2","id":"%s","type":"Issuer"},' .
|
||||
'"@context":"https:\/\/w3id.org\/openbadges\/v2","id":"%s","type":"BadgeClass","version":"%s",' .
|
||||
'"@language":"%s","related":[{"id":"%s","version":"%s","@language":"%s"}],"endorsement":"%s",' .
|
||||
'"alignment":[{"targetName":"%s","targetUrl":"%s","targetDescription":"%s","targetFramework":"%s",' .
|
||||
'"targetCode":"%s"}]}';
|
||||
$this->assertion2->issuer = '{"name":"%s","url":"%s","email":"%s",' .
|
||||
'"@context":"https:\/\/w3id.org\/openbadges\/v2","id":"%s","type":"Issuer"}';
|
||||
}
|
||||
|
||||
public function test_create_badge() {
|
||||
@ -107,21 +165,27 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
public function test_clone_badge() {
|
||||
$badge = new badge($this->badgeid);
|
||||
$newid = $badge->make_clone();
|
||||
$cloned_badge = new badge($newid);
|
||||
$clonedbadge = 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->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() {
|
||||
@ -139,6 +203,45 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
$this->assertAttributeEquals(BADGE_STATUS_ARCHIVED, 'status', $badge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Really delete the badge.
|
||||
*/
|
||||
public function test_delete_badge_for_real() {
|
||||
global $DB;
|
||||
|
||||
$badge = new badge($this->badgeid);
|
||||
|
||||
$newid1 = $badge->make_clone();
|
||||
$newid2 = $badge->make_clone();
|
||||
$newid3 = $badge->make_clone();
|
||||
|
||||
// Insert related badges to badge 1.
|
||||
$badge->add_related_badges([$newid1, $newid2, $newid3]);
|
||||
|
||||
// Another badge.
|
||||
$badge2 = new badge($newid2);
|
||||
// Make badge 1 related for badge 2.
|
||||
$badge2->add_related_badges([$this->badgeid]);
|
||||
|
||||
// Confirm that the records about this badge about its relations have been removed as well.
|
||||
$relatedsql = 'badgeid = :badgeid OR relatedbadgeid = :relatedbadgeid';
|
||||
$relatedparams = array(
|
||||
'badgeid' => $this->badgeid,
|
||||
'relatedbadgeid' => $this->badgeid
|
||||
);
|
||||
// Badge 1 has 4 related records. 3 where it's the badgeid, 1 where it's the relatedbadgeid.
|
||||
$this->assertEquals(4, $DB->count_records_select('badge_related', $relatedsql, $relatedparams));
|
||||
|
||||
// Delete the badge for real.
|
||||
$badge->delete(false);
|
||||
|
||||
// Confirm that the badge itself has been removed.
|
||||
$this->assertFalse($DB->record_exists('badge', ['id' => $this->badgeid]));
|
||||
|
||||
// Confirm that the records about this badge about its relations have been removed as well.
|
||||
$this->assertFalse($DB->record_exists_select('badge_related', $relatedsql, $relatedparams));
|
||||
}
|
||||
|
||||
public function test_create_badge_criteria() {
|
||||
$badge = new badge($this->badgeid);
|
||||
$criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
|
||||
@ -239,6 +342,12 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
$badge->attachment = 1;
|
||||
$badge->notification = 0;
|
||||
$badge->status = BADGE_STATUS_INACTIVE;
|
||||
$badge->version = "Version $i";
|
||||
$badge->language = "en";
|
||||
$badge->imagecaption = "Image caption $i";
|
||||
$badge->imageauthorname = "Image author's name $i";
|
||||
$badge->imageauthoremail = "author$i@example.com";
|
||||
$badge->imageauthorname = "Image author's name $i";
|
||||
|
||||
$badgeid = $DB->insert_record('badge', $badge, true);
|
||||
$badges[$badgeid] = new badge($badgeid);
|
||||
@ -314,6 +423,12 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
$badge->attachment = 1;
|
||||
$badge->notification = 0;
|
||||
$badge->status = BADGE_STATUS_ACTIVE;
|
||||
$badge->version = "Version $i";
|
||||
$badge->language = "en";
|
||||
$badge->imagecaption = "Image caption";
|
||||
$badge->imageauthorname = "Image author's name";
|
||||
$badge->imageauthoremail = "author@example.com";
|
||||
$badge->imageauthorname = "Image author's name";
|
||||
|
||||
$badgeid = $DB->insert_record('badge', $badge, true);
|
||||
$badges[$badgeid] = new badge($badgeid);
|
||||
@ -545,6 +660,17 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
$this->assertStringMatchesFormat($testassertion->badge, json_encode($assertion->get_badge_assertion()));
|
||||
$this->assertStringMatchesFormat($testassertion->class, json_encode($assertion->get_badge_class()));
|
||||
$this->assertStringMatchesFormat($testassertion->issuer, json_encode($assertion->get_issuer()));
|
||||
|
||||
// Test Openbadge specification version 2.
|
||||
// Get assertion version 2.
|
||||
$award = reset($awards);
|
||||
$assertion2 = new core_badges_assertion($award->uniquehash, OPEN_BADGES_V2);
|
||||
$testassertion2 = $this->assertion2;
|
||||
|
||||
// Make sure JSON strings have the same structure.
|
||||
$this->assertStringMatchesFormat($testassertion2->badge, json_encode($assertion2->get_badge_assertion()));
|
||||
$this->assertStringMatchesFormat($testassertion2->class, json_encode($assertion2->get_badge_class()));
|
||||
$this->assertStringMatchesFormat($testassertion2->issuer, json_encode($assertion2->get_issuer()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -611,4 +737,101 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
$nodes->setAccessible(true);
|
||||
$this->assertArrayHasKey('localbadges', $nodes->getValue($tree));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test insert and update endorsement with a site badge.
|
||||
*/
|
||||
public function test_badge_endorsement() {
|
||||
$badge = new badge($this->badgeid);
|
||||
|
||||
// Insert Endorsement.
|
||||
$endorsement = new stdClass();
|
||||
$endorsement->badgeid = $this->badgeid;
|
||||
$endorsement->issuername = "Issuer 123";
|
||||
$endorsement->issueremail = "issuer123@email.com";
|
||||
$endorsement->issuerurl = "https://example.org/issuer-123";
|
||||
$endorsement->dateissued = 1524567747;
|
||||
$endorsement->claimid = "https://example.org/robotics-badge.json";
|
||||
$endorsement->claimcomment = "Test endorser comment";
|
||||
|
||||
$badge->save_endorsement($endorsement);
|
||||
$endorsement1 = $badge->get_endorsement();
|
||||
$this->assertEquals($endorsement->badgeid, $endorsement1->badgeid);
|
||||
$this->assertEquals($endorsement->issuername, $endorsement1->issuername);
|
||||
$this->assertEquals($endorsement->issueremail, $endorsement1->issueremail);
|
||||
$this->assertEquals($endorsement->issuerurl, $endorsement1->issuerurl);
|
||||
$this->assertEquals($endorsement->dateissued, $endorsement1->dateissued);
|
||||
$this->assertEquals($endorsement->claimid, $endorsement1->claimid);
|
||||
$this->assertEquals($endorsement->claimcomment, $endorsement1->claimcomment);
|
||||
|
||||
// Update Endorsement.
|
||||
$endorsement1->issuername = "Issuer update";
|
||||
$badge->save_endorsement($endorsement1);
|
||||
$endorsement2 = $badge->get_endorsement();
|
||||
$this->assertEquals($endorsement1->id, $endorsement2->id);
|
||||
$this->assertEquals($endorsement1->issuername, $endorsement2->issuername);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test insert and delete related badge with a site badge.
|
||||
*/
|
||||
public function test_badge_related() {
|
||||
$badge = new badge($this->badgeid);
|
||||
$newid1 = $badge->make_clone();
|
||||
$newid2 = $badge->make_clone();
|
||||
$newid3 = $badge->make_clone();
|
||||
|
||||
// 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;
|
||||
$clonedbage1->save();
|
||||
$this->assertCount(1, $badge->get_related_badges(true));
|
||||
|
||||
// Delete an related badge.
|
||||
$badge->delete_related_badge($newid2);
|
||||
$this->assertCount(2, $badge->get_related_badges());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test insert, update, delete competencies alignment with a site badge.
|
||||
*/
|
||||
public function test_competencies_alignment() {
|
||||
$badge = new badge($this->badgeid);
|
||||
|
||||
// Insert a competency alignment.
|
||||
$competency1 = new stdClass();
|
||||
$competency1->badgeid = $this->badgeid;
|
||||
$competency1->targetname = 'CCSS.ELA-Literacy.RST.11-12.3';
|
||||
$competency1->targeturl = 'http://www.corestandards.org/ELA-Literacy/RST/11-12/3';
|
||||
$competency1->targetdescription = 'Test target description';
|
||||
$competency1->targetframework = 'CCSS.RST.11-12.3';
|
||||
$competency1->targetcode = 'CCSS.RST.11-12.3';
|
||||
$competency2 = clone $competency1;
|
||||
$newid1 = $badge->save_alignment($competency1);
|
||||
$newid2 = $badge->save_alignment($competency2);
|
||||
$competencies1 = $badge->get_alignment();
|
||||
$this->assertCount(2, $competencies1);
|
||||
|
||||
$this->assertEquals($competency1->badgeid, $competencies1[$newid1]->badgeid);
|
||||
$this->assertEquals($competency1->targetname, $competencies1[$newid1]->targetname);
|
||||
$this->assertEquals($competency1->targeturl, $competencies1[$newid1]->targeturl);
|
||||
$this->assertEquals($competency1->targetdescription, $competencies1[$newid1]->targetdescription);
|
||||
$this->assertEquals($competency1->targetframework, $competencies1[$newid1]->targetframework);
|
||||
$this->assertEquals($competency1->targetcode, $competencies1[$newid1]->targetcode);
|
||||
|
||||
// Update competency aligment.
|
||||
$competencies1[$newid1]->targetname = 'CCSS.ELA-Literacy.RST.11-12.3 update';
|
||||
$badge->save_alignment($competencies1[$newid1], $competencies1[$newid1]->id);
|
||||
$competencies2 = $badge->get_alignment();
|
||||
$this->assertEquals($competencies1[$newid1]->id, $competencies2[$newid1]->id);
|
||||
$this->assertEquals($competencies1[$newid1]->targetname, $competencies2[$newid1]->targetname);
|
||||
|
||||
// Delete competency alignment.
|
||||
$badge->delete_alignment($competencies1[$newid2]->id);
|
||||
$this->assertCount(1, $badge->get_alignment());
|
||||
}
|
||||
}
|
||||
|
@ -33,14 +33,115 @@ Feature: Add badges to the system
|
||||
Given I navigate to "Badges > Add a new badge" in site administration
|
||||
And I set the following fields to these values:
|
||||
| Name | Test badge with 'apostrophe' and other friends (<>&@#) |
|
||||
| Version | v1 |
|
||||
| Language | English |
|
||||
| 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"
|
||||
And I should see "Test badge with 'apostrophe' and other friends (&@#)"
|
||||
And I should see "Endorsement"
|
||||
And I should see "Related badges (0)"
|
||||
And I should see "Competencies (0)"
|
||||
And I should not see "Create badge"
|
||||
And I follow "Manage badges"
|
||||
And I should see "Number of badges available: 1"
|
||||
And I should not see "There are no badges available."
|
||||
|
||||
@javascript @_file_upload
|
||||
Scenario: Add a badge related
|
||||
Given I navigate to "Badges > Add a new badge" in site administration
|
||||
And I set the following fields to these values:
|
||||
| Name | Test Badge 1 |
|
||||
| Version | v1 |
|
||||
| Language | French |
|
||||
| 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
|
||||
And I follow "Manage badges"
|
||||
And I should see "Number of badges available: 1"
|
||||
And I press "Add a new badge"
|
||||
And I set the following fields to these values:
|
||||
| Name | Test Badge 2 |
|
||||
| Version | v2 |
|
||||
| Language | English |
|
||||
| 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)"
|
||||
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
|
||||
And I follow "Related badges"
|
||||
And I set the field "relatedbadgeids[]" to "Test Badge 1 (version: v1, language: French, Site badges)"
|
||||
When I press "Save changes"
|
||||
Then I should see "Related badges (1)"
|
||||
|
||||
@javascript @_file_upload
|
||||
Scenario: Endorsement for Badge
|
||||
Given I navigate to "Badges > Add a new badge" in site administration
|
||||
And I set the following fields to these values:
|
||||
| Name | Test Badge Enrolment |
|
||||
| Version | v1 |
|
||||
| Language | English |
|
||||
| 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"
|
||||
And I should see "Endorsement"
|
||||
And I follow "Endorsement"
|
||||
And I set the following fields to these values:
|
||||
| Name | Endorser |
|
||||
| Email | endorsement@example.com |
|
||||
| Issuer URL | http://example.com |
|
||||
| Claim URL | http://claimurl.example.com |
|
||||
| Endorsement Comment | Test Endorsement Comment |
|
||||
And I press "Save changes"
|
||||
Then I should see "Changes saved"
|
||||
|
||||
@javascript @_file_upload
|
||||
Scenario: Competencies alignment for Badge
|
||||
Given I navigate to "Badges > Add a new badge" in site administration
|
||||
And I set the following fields to these values:
|
||||
| Name | Test Badge |
|
||||
| Version | v1 |
|
||||
| Language | English |
|
||||
| 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"
|
||||
And I should see "Endorsement"
|
||||
And I follow "Competencies (0)"
|
||||
And I should see "This badge does not have a competencies alignment."
|
||||
And I press "Add competency alignment"
|
||||
And I follow "Competencies alignment"
|
||||
And I wait until the page is ready
|
||||
And I follow "Competencies alignment"
|
||||
And I set the following fields to these values:
|
||||
| Name | Test Badge Competencies |
|
||||
| URL | https://competencies.example.com |
|
||||
| Description | Test Badge Competencies description |
|
||||
When I press "Save changes"
|
||||
And I should see "Competencies (1)"
|
||||
|
@ -27,6 +27,7 @@
|
||||
$string['actions'] = 'Actions';
|
||||
$string['activate'] = 'Enable access';
|
||||
$string['activatesuccess'] = 'Access to the badges was successfully enabled.';
|
||||
$string['addalignment'] = 'Add competency alignment';
|
||||
$string['addbadge'] = 'Add badges';
|
||||
$string['addbadge_help'] = 'Select all badges that should be added to this badge requirement. Hold CTRL key to select multiple items.';
|
||||
$string['addbadgecriteria'] = 'Add badge criteria';
|
||||
@ -36,10 +37,12 @@ $string['addcohort'] = 'Add cohort';
|
||||
$string['addcohort_help'] = 'Select all cohorts that should be added to this badge requirement. Hold CTRL key to select multiple items.';
|
||||
$string['addcourse'] = 'Add courses';
|
||||
$string['addcourse_help'] = 'Select all courses that should be added to this badge requirement. Hold CTRL key to select multiple items.';
|
||||
$string['addrelated'] = 'Add related badge';
|
||||
$string['addtobackpack'] = 'Add to backpack';
|
||||
$string['adminonly'] = 'This page is restricted to site administrators only.';
|
||||
$string['after'] = 'after the date of issue.';
|
||||
$string['aggregationmethod'] = 'Aggregation method';
|
||||
$string['alignment'] = 'Competencies alignment';
|
||||
$string['all'] = 'All';
|
||||
$string['allmethod'] = 'All of the selected conditions are met';
|
||||
$string['allmethodactivity'] = 'All of the selected activities are complete';
|
||||
@ -68,6 +71,8 @@ $string['archivehelp'] = '<p>This option means that the badge will be marked as
|
||||
<p>If you would like your users to retain access to the earned badges it is important to select this option instead of fully deleting badges.</p>';
|
||||
$string['attachment'] = 'Attach badge to message';
|
||||
$string['attachment_help'] = 'If enabled, an issued badge file will be attached to the recipient\'s email for download. (Attachments must be enabled in Site administration > Plugins > Message outputs > Email to use this option.)';
|
||||
$string['authorimage'] = 'Image author';
|
||||
$string['authorimage_help'] = 'Author of the image, must be an URL.';
|
||||
$string['award'] = 'Award badge';
|
||||
$string['awardedtoyou'] = 'Issued to me';
|
||||
$string['awardoncron'] = 'Access to the badges was successfully enabled. Too many users can instantly earn this badge. To ensure site performance, this action will take some time to process.';
|
||||
@ -150,9 +155,17 @@ $string['badgeurl'] = 'Issued badge link';
|
||||
$string['bawards'] = 'Recipients ({$a})';
|
||||
$string['bcriteria'] = 'Criteria';
|
||||
$string['bdetails'] = 'Edit details';
|
||||
$string['bendorsement'] = 'Endorsement';
|
||||
$string['bmessage'] = 'Message';
|
||||
$string['boverview'] = 'Overview';
|
||||
$string['brelated'] = 'Related badges ({$a})';
|
||||
$string['balignment'] = 'Competencies ({$a})';
|
||||
$string['bydate'] = ' complete by';
|
||||
$string['imagecaption'] = 'Image caption';
|
||||
$string['imagecaption_help'] = 'Caption for the image.';
|
||||
$string['claim'] = 'Claim';
|
||||
$string['claimcomment'] = 'Endorsement Comment';
|
||||
$string['claimid'] = 'Claim URL';
|
||||
$string['clearsettings'] = 'Clear settings';
|
||||
$string['completionnotenabled'] = 'Course completion is not enabled for this course, so it cannot be included in badge criteria. Course completion may be enabled in the course settings.';
|
||||
$string['completioninfo'] = 'This badge was issued for completing: ';
|
||||
@ -249,6 +262,7 @@ $string['disconnect'] = 'Disconnect';
|
||||
$string['donotaward'] = 'Currently, this badge is not active, so it cannot be awarded to users. If you would like to award this badge, please set its status to active.';
|
||||
$string['editsettings'] = 'Edit settings';
|
||||
$string['enablebadges'] = 'Enable badges';
|
||||
$string['endorsement'] = 'Endorsement';
|
||||
$string['error:backpackdatainvalid'] = 'The data return from the backpack was invalid.';
|
||||
$string['error:backpackemailnotfound'] = 'The email \'{$a}\' is not associated with a backpack. You need to <a href="http://backpack.openbadges.org">create a backpack</a> for that account or sign in with another email address.';
|
||||
$string['error:backpacknotavailable'] = 'Your site is not accessible from the Internet, so any badges issued from this site cannot be verified by external backpack services.';
|
||||
@ -289,6 +303,7 @@ $string['error:notifycoursedate'] = 'Warning: Badges associated with course and
|
||||
$string['error:parameter'] = 'Warning: At least one parameter should be selected to ensure correct badge issuing workflow.';
|
||||
$string['error:requesttimeout'] = 'The connection request timed out before it could complete.';
|
||||
$string['error:requesterror'] = 'The connection request failed (error code {$a}).';
|
||||
$string['error:relatedbadgedoesntexist'] = 'There is no public badge with this identifier';
|
||||
$string['error:save'] = 'Cannot save the badge.';
|
||||
$string['error:userdeleted'] = '{$a->user} (This user no longer exists in {$a->site})';
|
||||
$string['eventbadgearchived'] = 'Badge archived';
|
||||
@ -322,12 +337,26 @@ $string['externalbadgesp'] = 'Badges from other web sites:';
|
||||
$string['externalbadges_help'] = 'This area displays badges from your external backpack.';
|
||||
$string['fixed'] = 'Fixed date';
|
||||
$string['hiddenbadge'] = 'Unfortunately, the badge owner has not made this information available.';
|
||||
$string['imageauthoremail'] = 'Image author\'s email';
|
||||
$string['imageauthoremail_help'] = 'An email address associated with author of the image.';
|
||||
$string['imageauthorname'] = 'Image author\'s name';
|
||||
$string['imageauthorname_help'] = 'The name of the badge image\'s author';
|
||||
$string['imageauthorurl'] = 'Image author\'s URL';
|
||||
$string['imageauthorurl_help'] = 'The URL of the image\'s author';
|
||||
$string['invalidurl'] = 'Invalid URL';
|
||||
$string['issuedbadge'] = 'Issued badge information';
|
||||
$string['issuancedetails'] = 'Badge expiry';
|
||||
$string['issuerdetails'] = 'Issuer details';
|
||||
$string['issueremail'] = 'Email';
|
||||
$string['issueremail_help'] = 'Endorser\'s contact address';
|
||||
$string['issuername'] = 'Issuer name';
|
||||
$string['issuername_help'] = 'Name of the issuing agent or authority.';
|
||||
$string['issuername_endorsement'] = 'Name';
|
||||
$string['issuername_endorsement_help'] = 'The name of the endorser.';
|
||||
$string['issuerurl'] = 'Issuer URL';
|
||||
$string['issuerurl_help'] = 'The homepage or social media profile of the endorser. Should be a URL/URI Accessible via HTTP.';
|
||||
$string['language'] = 'Language';
|
||||
$string['language_help'] = 'Identify which language your badge expressed in.';
|
||||
$string['localconnectto'] = 'To share these badges outside this web site you need to <a href="{$a}">connect to a backpack</a>.';
|
||||
$string['localbadges'] = 'My badges from {$a} web site';
|
||||
$string['localbadgesh'] = 'My badges from this web site';
|
||||
@ -353,17 +382,30 @@ $string['mybackpack'] = 'My backpack settings';
|
||||
$string['never'] = 'Never';
|
||||
$string['newbadge'] = 'Add a new badge';
|
||||
$string['newimage'] = 'New image';
|
||||
$string['noalignment'] = 'This badge does not have a competencies alignment.';
|
||||
$string['noawards'] = 'This badge has not been earned yet.';
|
||||
$string['nobackpack'] = 'There is no backpack service connected to this account.<br/>';
|
||||
$string['nobackpackbadges'] = 'There are no badges in the collections you have selected. <a href="mybackpack.php">Add more collections</a>.';
|
||||
$string['nobackpackcollections'] = 'No badge collections have been selected. <a href="mybackpack.php">Add collections</a>.';
|
||||
$string['nobadges'] = 'There are no badges available.';
|
||||
$string['nocriteria'] = 'Criteria for this badge have not been set up yet.';
|
||||
$string['noendorsement'] = 'This badge does not have an endorsement.';
|
||||
$string['noexpiry'] = 'This badge does not have an expiry date.';
|
||||
$string['noparamstoadd'] = 'There are no additional parameters available to add to this badge requirement.';
|
||||
$string['norelated'] = 'This badge does not have related badges.';
|
||||
$string['notacceptedrole'] = 'Your current role assignment is not among the roles that can manually issue this badge.<br/>
|
||||
If you would like to see users who have already earned this badge, you can visit {$a} page. ';
|
||||
$string['notconnected'] = 'Not connected';
|
||||
$string['notealignment'] = '<p>Identify Competencies, Skills or Standards that this badge aligns to so that earners and consumers can understand how the badge may stack and build upon one another.</p>
|
||||
<p>Example:</p>
|
||||
<ul>
|
||||
<li>Name: CCSS.ELA-Literacy.RST.11-12.3</li>
|
||||
<li>URL: http://www.corestandards.org/ELA-Literacy/RST/11-12/3</li>
|
||||
<li>Description: Follow precisely a complex multistep procedure when carrying out experiments, taking measurements, or performing technical tasks; analyze the specific results based on explanations in the text.</li>
|
||||
<li>Code: CCSS.ELA-Literacy.RST.11-12.3</li>
|
||||
</ul>';
|
||||
$string['noteendorsement'] = 'Endorsement is used to provide a comment expressing approval of a Badge from a third party, that it is a good representation of the achievement it describes.';
|
||||
$string['noterelated'] = 'When you have multiple badges, you may want to keep track of the history behind their developements, choose \'Add related badge\' button then specify the badges relating to this one and their version.';
|
||||
$string['nothingtoadd'] = 'There are no available criteria to add.';
|
||||
$string['notification'] = 'Notify badge creator';
|
||||
$string['notification_help'] = 'This setting manages notifications sent to a badge creator to let them know that the badge has been issued.
|
||||
@ -421,6 +463,7 @@ $string['recipientdetails'] = 'Recipient details';
|
||||
$string['recipientidentificationproblem'] = 'Cannot find a recipient of this badge among the existing users.';
|
||||
$string['recipientvalidationproblem'] = 'Current user cannot be verified as a recipient of this badge.';
|
||||
$string['relative'] = 'Relative date';
|
||||
$string['relatedbages'] = 'Related badges';
|
||||
$string['revoke'] = 'Revoke badge';
|
||||
$string['requiredcohort'] = 'At least one cohort should be added to the cohort criterion.';
|
||||
$string['requiredcourse'] = 'At least one course should be added to the courseset criterion.';
|
||||
@ -462,6 +505,17 @@ Once a badge has been issued to at least one user, it automatically becomes **LO
|
||||
|
||||
We want to make sure that all users complete the same requirements to earn a badge. Currently, it is not possible to revoke badges. If we allowed badges requirements to be modified all the time, we would most likely end up with users having the same badge for meeting completely different requirements.';
|
||||
$string['subject'] = 'Message subject';
|
||||
$string['targetname'] = 'Name';
|
||||
$string['targetname_help'] = 'Competency, Skill or Standard the badge aligns to';
|
||||
$string['targeturl'] = 'URL';
|
||||
$string['targeturl_help'] = 'URL linking to the official description of the alignment target, for example an individual standard within an educational framework.';
|
||||
$string['targetdescription'] = 'Description';
|
||||
$string['targetdescription_help'] = 'Short description of the alignment target.';
|
||||
$string['targetframework'] = 'Framework';
|
||||
$string['targetframework_help'] = 'Name of the framework the alignment target.';
|
||||
$string['targetcode'] = 'Code';
|
||||
$string['targetcode_help'] = 'A locally unique string identifier that identifies the alignment target within its framework.';
|
||||
$string['type'] = 'Type';
|
||||
$string['variablesubstitution'] = 'Variable substitution in messages.';
|
||||
$string['variablesubstitution_help'] = 'In a badge message, certain variables can be inserted into the subject and/or body of a message so that they will be replaced with real values when the message is sent. The variables should be inserted into the text exactly as they are shown below. The following variables can be used:
|
||||
|
||||
@ -475,6 +529,8 @@ $string['variablesubstitution_help'] = 'In a badge message, certain variables ca
|
||||
: This will be replaced by the public URL with information about the issued badge.';
|
||||
$string['viewbadge'] = 'View issued badge';
|
||||
$string['visible'] = 'Visible';
|
||||
$string['version'] = 'Version';
|
||||
$string['version_help'] = 'When you have multiple related badges and want to keep track of the history behind the badge\'s developements, use this field to version each badge. You can add all related badges on Related badge page.';
|
||||
$string['warnexpired'] = ' (This badge has expired!)';
|
||||
$string['year'] = 'Year(s)';
|
||||
|
||||
|
@ -98,6 +98,22 @@ define('BADGE_MESSAGE_MONTHLY', 4);
|
||||
*/
|
||||
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
|
||||
*/
|
||||
define('OPEN_BADGES_V2_CONTEXT', 'https://w3id.org/openbadges/v2');
|
||||
define('OPEN_BADGES_V2_TYPE_ASSERTION', 'Assertion');
|
||||
define('OPEN_BADGES_V2_TYPE_BADGE', 'BadgeClass');
|
||||
define('OPEN_BADGES_V2_TYPE_ISSUER', 'Issuer');
|
||||
define('OPEN_BADGES_V2_TYPE_ENDORSEMENT', 'Endorsement');
|
||||
define('OPEN_BADGES_V2_TYPE_AUTHOR', 'Author');
|
||||
|
||||
/**
|
||||
* Class that represents badge.
|
||||
*
|
||||
@ -127,6 +143,24 @@ class badge {
|
||||
public $status = 0;
|
||||
public $nextcron;
|
||||
|
||||
/** @var string control version of badge */
|
||||
public $version;
|
||||
|
||||
/** @var string language code */
|
||||
public $language;
|
||||
|
||||
/** @var string name image author */
|
||||
public $imageauthorname;
|
||||
|
||||
/** @var string email image author */
|
||||
public $imageauthoremail;
|
||||
|
||||
/** @var string url image author */
|
||||
public $imageauthorurl;
|
||||
|
||||
/** @var string image caption */
|
||||
public $imagecaption;
|
||||
|
||||
/** @var array Badge criteria */
|
||||
public $criteria = array();
|
||||
|
||||
@ -680,6 +714,16 @@ class badge {
|
||||
$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));
|
||||
$relatedsql = 'badgeid = :badgeid OR relatedbadgeid = :relatedbadgeid';
|
||||
$relatedparams = array(
|
||||
'badgeid' => $this->id,
|
||||
'relatedbadgeid' => $this->id
|
||||
);
|
||||
$DB->delete_records_select('badge_related', $relatedsql, $relatedparams);
|
||||
$DB->delete_records('badge_competencies', array('badgeid' => $this->id));
|
||||
|
||||
// Finally, remove badge itself.
|
||||
$DB->delete_records('badge', array('id' => $this->id));
|
||||
|
||||
@ -691,6 +735,208 @@ class badge {
|
||||
$event = \core\event\badge_deleted::create($eventparams);
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add multiple related badges.
|
||||
*
|
||||
* @param array $relatedids Id of badges.
|
||||
*/
|
||||
public function add_related_badges($relatedids) {
|
||||
global $DB;
|
||||
$relatedbadges = array();
|
||||
foreach ($relatedids as $relatedid) {
|
||||
$relatedbadge = new stdClass();
|
||||
$relatedbadge->badgeid = $this->id;
|
||||
$relatedbadge->relatedbadgeid = $relatedid;
|
||||
$relatedbadges[] = $relatedbadge;
|
||||
}
|
||||
$DB->insert_records('badge_related', $relatedbadges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an related badge.
|
||||
*
|
||||
* @param int $relatedid Id related badge.
|
||||
* @return bool A status for delete an related badge.
|
||||
*/
|
||||
public function delete_related_badge($relatedid) {
|
||||
global $DB;
|
||||
return $DB->delete_records('badge_related', array('badgeid' => $this->id, 'relatedbadgeid' => $relatedid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if badge has related badges.
|
||||
*
|
||||
* @return bool A status related badge.
|
||||
*/
|
||||
public function has_related() {
|
||||
global $DB;
|
||||
return $DB->record_exists('badge_related', array('badgeid' => $this->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related badges of badge.
|
||||
*
|
||||
* @param bool $activeonly Do not get the inactive badges when is true.
|
||||
* @return array Related badges information.
|
||||
*/
|
||||
public function get_related_badges(bool $activeonly = false) {
|
||||
global $DB;
|
||||
|
||||
$params = array('badgeid' => $this->id);
|
||||
$query = "SELECT b.id, b.name, b.version, b.language, b.type
|
||||
FROM {badge_related} br
|
||||
JOIN {badge} b ON b.id = br.relatedbadgeid
|
||||
WHERE br.badgeid = :badgeid";
|
||||
if ($activeonly) {
|
||||
$query .= " AND b.status <> :status";
|
||||
$params['status'] = BADGE_STATUS_INACTIVE;
|
||||
}
|
||||
$relatedbadges = $DB->get_records_sql($query, $params);
|
||||
return $relatedbadges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert/update competency alignment information of badge.
|
||||
*
|
||||
* @param stdClass $alignment Data of a competency alignment.
|
||||
* @param int $alignmentid ID competency alignment.
|
||||
* @return bool|int A status/ID when insert or update data.
|
||||
*/
|
||||
public function save_alignment($alignment, $alignmentid = 0) {
|
||||
global $DB;
|
||||
|
||||
$record = $DB->record_exists('badge_competencies', array('id' => $alignmentid));
|
||||
if ($record) {
|
||||
$alignment->id = $alignmentid;
|
||||
return $DB->update_record('badge_competencies', $alignment);
|
||||
} else {
|
||||
return $DB->insert_record('badge_competencies', $alignment, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a competency alignment of badge.
|
||||
*
|
||||
* @param int $alignmentid ID competency alignment.
|
||||
* @return bool A status for delete a competency alignment.
|
||||
*/
|
||||
public function delete_alignment($alignmentid) {
|
||||
global $DB;
|
||||
return $DB->delete_records('badge_competencies', array('badgeid' => $this->id, 'id' => $alignmentid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get competencies of badge.
|
||||
*
|
||||
* @return array List content competencies.
|
||||
*/
|
||||
public function get_alignment() {
|
||||
global $DB;
|
||||
return $DB->get_records('badge_competencies', array('badgeid' => $this->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert/update Endorsement information of badge.
|
||||
*
|
||||
* @param stdClass $endorsement Data of an endorsement.
|
||||
* @return bool|int A status/ID when insert or update data.
|
||||
*/
|
||||
public function save_endorsement($endorsement) {
|
||||
global $DB;
|
||||
$record = $DB->get_record('badge_endorsement', array('badgeid' => $this->id));
|
||||
if ($record) {
|
||||
$endorsement->id = $record->id;
|
||||
return $DB->update_record('badge_endorsement', $endorsement);
|
||||
} else {
|
||||
return $DB->insert_record('badge_endorsement', $endorsement, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get endorsement of badge.
|
||||
*
|
||||
* @return array|stdClass Endorsement information.
|
||||
*/
|
||||
public function get_endorsement() {
|
||||
global $DB;
|
||||
return $DB->get_record('badge_endorsement', array('badgeid' => $this->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Markdown language support for criteria.
|
||||
*
|
||||
* @return string $output Markdown content to output.
|
||||
*/
|
||||
public function markdown_badge_criteria() {
|
||||
$agg = $this->get_aggregation_methods();
|
||||
if (empty($this->criteria)) {
|
||||
return get_string('nocriteria', 'badges');
|
||||
}
|
||||
$overalldescr = '';
|
||||
$overall = $this->criteria[BADGE_CRITERIA_TYPE_OVERALL];
|
||||
if (!empty($overall->description)) {
|
||||
$overalldescr = format_text($overall->description, $overall->descriptionformat,
|
||||
array('context' => $this->get_context())) . '\n';
|
||||
}
|
||||
// Get the condition string.
|
||||
if (count($this->criteria) == 2) {
|
||||
$condition = get_string('criteria_descr', 'badges');
|
||||
} else {
|
||||
$condition = get_string('criteria_descr_' . BADGE_CRITERIA_TYPE_OVERALL, 'badges',
|
||||
core_text::strtoupper($agg[$this->get_aggregation_method()]));
|
||||
}
|
||||
unset($this->criteria[BADGE_CRITERIA_TYPE_OVERALL]);
|
||||
$items = array();
|
||||
// If only one criterion left, make sure its description goe to the top.
|
||||
if (count($this->criteria) == 1) {
|
||||
$c = reset($this->criteria);
|
||||
if (!empty($c->description)) {
|
||||
$overalldescr = $c->description . '\n';
|
||||
}
|
||||
if (count($c->params) == 1) {
|
||||
$items[] = ' * ' . get_string('criteria_descr_single_' . $c->criteriatype, 'badges') .
|
||||
$c->get_details();
|
||||
} else {
|
||||
$items[] = '* ' . get_string('criteria_descr_' . $c->criteriatype, 'badges',
|
||||
core_text::strtoupper($agg[$this->get_aggregation_method($c->criteriatype)])) .
|
||||
$c->get_details();
|
||||
}
|
||||
} else {
|
||||
foreach ($this->criteria as $type => $c) {
|
||||
$criteriadescr = '';
|
||||
if (!empty($c->description)) {
|
||||
$criteriadescr = $c->description;
|
||||
}
|
||||
if (count($c->params) == 1) {
|
||||
$items[] = ' * ' . get_string('criteria_descr_single_' . $type, 'badges') .
|
||||
$c->get_details() . $criteriadescr;
|
||||
} else {
|
||||
$items[] = '* ' . get_string('criteria_descr_' . $type, 'badges',
|
||||
core_text::strtoupper($agg[$this->get_aggregation_method($type)])) .
|
||||
$c->get_details() . $criteriadescr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return strip_tags($overalldescr . $condition . html_writer::alist($items, array(), 'ul'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define issuer information by format Open Badges specification version 2.
|
||||
*
|
||||
* @return array Issuer informations of the badge.
|
||||
*/
|
||||
public function get_badge_issuer() {
|
||||
$issuer = array();
|
||||
$issuerurl = new moodle_url('/badges/badge_json.php', array('id' => $this->id, 'action' => 0));
|
||||
$issuer['name'] = $this->issuername;
|
||||
$issuer['url'] = $this->issuerurl;
|
||||
$issuer['email'] = $this->issuercontact;
|
||||
$issuer['@context'] = OPEN_BADGES_V2_CONTEXT;
|
||||
$issuer['id'] = $issuerurl->out(false);
|
||||
$issuer['type'] = OPEN_BADGES_V2_TYPE_ISSUER;
|
||||
return $issuer;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20181022" 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"
|
||||
>
|
||||
@ -3039,6 +3039,12 @@
|
||||
<FIELD NAME="notification" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Message when badge is awarded"/>
|
||||
<FIELD NAME="status" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Badge status: 0 = inactive, 1 = active, 2 = active+locked, 3 = inactive+locked, 4 = archived"/>
|
||||
<FIELD NAME="nextcron" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="version" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="language" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="imageauthorname" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="imageauthoremail" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="imageauthorurl" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="imagecaption" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
@ -3115,6 +3121,22 @@
|
||||
<KEY NAME="fk_issuedid" TYPE="foreign" FIELDS="issuedid" REFTABLE="badge_issued" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="badge_endorsement" COMMENT="Defines endorsement for badge">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="badgeid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="issuername" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="issuerurl" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="issueremail" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="claimid" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="claimcomment" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="dateissued" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="endorsementbadge" TYPE="foreign" FIELDS="badgeid" REFTABLE="badge" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="badge_manual_award" COMMENT="Track manual award criteria for badges">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
@ -3158,6 +3180,34 @@
|
||||
<KEY NAME="fk_backpackid" TYPE="foreign" FIELDS="backpackid" REFTABLE="badge_backpack" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="badge_competencies" COMMENT="Defines competencies alignment for badges">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="badgeid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="targetname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="targeturl" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="targetdescription" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="targetframework" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="targetcode" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="competenciesbadge" TYPE="foreign" FIELDS="badgeid" REFTABLE="badge" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="badge_related" COMMENT="Defines badge related for badges">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="badgeid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="relatedbadgeid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="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">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
@ -3932,4 +3982,4 @@
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
||||
</XMLDB>
|
@ -2672,5 +2672,102 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2018102900.01);
|
||||
}
|
||||
|
||||
if ($oldversion < 2018110300.01) {
|
||||
// Define fields to be added to the 'badge' table.
|
||||
$tablebadge = new xmldb_table('badge');
|
||||
$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');
|
||||
$fieldimagecaption = new xmldb_field('imagecaption', XMLDB_TYPE_TEXT, null, null, null, null, null, 'imageauthorurl');
|
||||
|
||||
if (!$dbman->field_exists($tablebadge, $fieldversion)) {
|
||||
$dbman->add_field($tablebadge, $fieldversion);
|
||||
}
|
||||
if (!$dbman->field_exists($tablebadge, $fieldlanguage)) {
|
||||
$dbman->add_field($tablebadge, $fieldlanguage);
|
||||
}
|
||||
if (!$dbman->field_exists($tablebadge, $fieldimageauthorname)) {
|
||||
$dbman->add_field($tablebadge, $fieldimageauthorname);
|
||||
}
|
||||
if (!$dbman->field_exists($tablebadge, $fieldimageauthoremail)) {
|
||||
$dbman->add_field($tablebadge, $fieldimageauthoremail);
|
||||
}
|
||||
if (!$dbman->field_exists($tablebadge, $fieldimageauthorurl)) {
|
||||
$dbman->add_field($tablebadge, $fieldimageauthorurl);
|
||||
}
|
||||
if (!$dbman->field_exists($tablebadge, $fieldimagecaption)) {
|
||||
$dbman->add_field($tablebadge, $fieldimagecaption);
|
||||
}
|
||||
|
||||
// Define table badge_endorsement to be created.
|
||||
$table = new xmldb_table('badge_endorsement');
|
||||
|
||||
// Adding fields to table badge_endorsement.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('issuername', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('issuerurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('issueremail', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('claimid', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||||
$table->add_field('claimcomment', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('dateissued', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
// Adding keys to table badge_endorsement.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
$table->add_key('endorsementbadge', XMLDB_KEY_FOREIGN, ['badgeid'], 'badge', ['id']);
|
||||
|
||||
// Conditionally launch create table for badge_endorsement.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Define table badge_related to be created.
|
||||
$table = new xmldb_table('badge_related');
|
||||
|
||||
// Adding fields to table badge_related.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('relatedbadgeid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
|
||||
|
||||
// Adding keys to table badge_related.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['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)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Define table badge_competencies to be created.
|
||||
$table = new xmldb_table('badge_competencies');
|
||||
|
||||
// Adding fields to table badge_competencies.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('targetname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('targeturl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('targetdescription', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('targetframework', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||||
$table->add_field('targetcode', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||||
|
||||
// Adding keys to table badge_competencies.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
$table->add_key('competenciesbadge', XMLDB_KEY_FOREIGN, ['badgeid'], 'badge', ['id']);
|
||||
|
||||
// Conditionally launch create table for badge_competencies.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2018110300.01);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2018110500.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2018110500.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user