Skip to content

Commit

Permalink
Merge branch 'MDL-38837_25' of https://github.com/totara/openbadges i…
Browse files Browse the repository at this point in the history
…nto MOODLE_25_STABLE
  • Loading branch information
danpoltawski committed Jul 22, 2013
2 parents 4896a0b + 2e64d85 commit 114b8be
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
15 changes: 14 additions & 1 deletion badges/backpack.js
Expand Up @@ -2,7 +2,20 @@
* Push badges to backpack.
*/
function addtobackpack(event, args) {
OpenBadges.issue([args.assertion], function(errors, successes) { });
var badgetable = Y.one('#issued-badge-table');
var errordiv = Y.one('#addtobackpack-error');
var errortext = M.util.get_string('error:backpackproblem', 'badges');
var errorhtml = '<div id="addtobackpack-error" class="box boxaligncenter notifyproblem">' + errortext + '</div>';

if (typeof OpenBadges !== 'undefined') {
OpenBadges.issue([args.assertion], function(errors, successes) { });
} else {
// Add error div if it doesn't exist yet.
if (!errordiv) {
var badgerror = Y.Node.create(errorhtml);
badgetable.insert(badgerror, 'before');
}
}
}

/**
Expand Down
6 changes: 2 additions & 4 deletions badges/badge.php
Expand Up @@ -56,10 +56,8 @@
navigation_node::override_active_url($url);
}

// TODO: Better way of pushing badges to Mozilla backpack?
if (!empty($CFG->badges_allowexternalbackpack)) {
$PAGE->requires->js(new moodle_url('http://backpack.openbadges.org/issuer.js'), true);
}
// Include JS files for backpack support.
badges_setup_backpack_js();

echo $OUTPUT->header();

Expand Down
7 changes: 2 additions & 5 deletions badges/mybadges.php
Expand Up @@ -90,11 +90,8 @@
$PAGE->set_heading($title);
$PAGE->set_pagelayout('mydashboard');

// TODO: Better way of pushing badges to Mozilla backpack?
if (!empty($CFG->badges_allowexternalbackpack)) {
$PAGE->requires->js(new moodle_url('http://backpack.openbadges.org/issuer.js'), true);
$PAGE->requires->js('/badges/backpack.js', true);
}
// Include JS files for backpack support.
badges_setup_backpack_js();

$output = $PAGE->get_renderer('core', 'badges');
$badges = badges_get_user_badges($USER->id);
Expand Down
11 changes: 7 additions & 4 deletions badges/renderer.php
Expand Up @@ -282,6 +282,7 @@ protected function render_issued_badge(issued_badge $ibadge) {
$today = strtotime($today_date);

$table = new html_table();
$table->id = 'issued-badge-table';

$imagetable = new html_table();
$imagetable->attributes = array('class' => 'clearfix badgeissuedimage');
Expand All @@ -294,11 +295,13 @@ protected function render_issued_badge(issued_badge $ibadge) {
$expiration = isset($issued['expires']) ? strtotime($issued['expires']) : $today + 1;
if (!empty($CFG->badges_allowexternalbackpack) && ($expiration > $today) && badges_user_has_backpack($USER->id)) {
$assertion = new moodle_url('/badges/assertion.php', array('b' => $ibadge->hash));
$action = new component_action('click', 'addtobackpack', array('assertion' => $assertion->out(false)));
$attributes = array(
'type' => 'button',
'value' => get_string('addtobackpack', 'badges'),
'onclick' => 'OpenBadges.issue(["' . $assertion->out(false) . '"], function(errors, successes) { })');
'type' => 'button',
'id' => 'addbutton',
'value' => get_string('addtobackpack', 'badges'));
$tobackpack = html_writer::tag('input', '', $attributes);
$this->output->add_action_handler($action, 'addbutton');
$imagetable->data[] = array($tobackpack);
}
}
Expand Down Expand Up @@ -459,7 +462,7 @@ protected function render_badge_user_collection(badge_user_collection $badges) {
get_string('downloadall'), 'POST', array('class' => 'activatebadge'));

// Local badges.
$localhtml = html_writer::start_tag('fieldset', array('class' => 'generalbox'));
$localhtml = html_writer::start_tag('fieldset', array('id' => 'issued-badge-table', 'class' => 'generalbox'));
$localhtml .= html_writer::tag('legend',
$this->output->heading_with_help(get_string('localbadges', 'badges', $SITE->fullname), 'localbadgesh', 'badges'));
if ($badges->badges) {
Expand Down
1 change: 1 addition & 0 deletions lang/en/badges.php
Expand Up @@ -198,6 +198,7 @@
$string['editsettings'] = 'Edit settings';
$string['enablebadges'] = 'Enable badges';
$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.';
$string['error:backpackproblem'] = 'There was a problem connecting to your backpack service provider. Please try again later.';
$string['error:cannotact'] = 'Cannot activate the badge. ';
$string['error:cannotawardbadge'] = 'Cannot award badge to a user.';
$string['error:clone'] = 'Cannot clone the badge.';
Expand Down
16 changes: 16 additions & 0 deletions lib/badgeslib.php
Expand Up @@ -1348,3 +1348,19 @@ function badges_handle_course_deletion($courseid) {
$DB->update_record('badge', $toupdate);
}
}

/**
* Loads JS files required for backpack support.
*
* @uses $CFG, $PAGE
* @return void
*/
function badges_setup_backpack_js() {
global $CFG, $PAGE;
if (!empty($CFG->badges_allowexternalbackpack)) {
$PAGE->requires->string_for_js('error:backpackproblem', 'badges');
$protocol = (strpos($CFG->wwwroot, 'https://') === 0) ? 'https://' : 'http://';
$PAGE->requires->js(new moodle_url($protocol . 'backpack.openbadges.org/issuer.js'), true);
$PAGE->requires->js('/badges/backpack.js', true);
}
}

0 comments on commit 114b8be

Please sign in to comment.