Skip to content

Commit

Permalink
MDL-38997 badges: Add checks to fix notices if badge settings not yet…
Browse files Browse the repository at this point in the history
… configured
  • Loading branch information
simoncoggins committed Apr 6, 2013
1 parent 369496c commit 60d72ef
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion admin/settings/top.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$ADMIN->add('root', new admin_category('users', new lang_string('users','admin')));
$ADMIN->add('root', new admin_category('courses', new lang_string('courses','admin')));
$ADMIN->add('root', new admin_category('grades', new lang_string('grades')));
$ADMIN->add('root', new admin_category('badges', new lang_string('badges'), (isset($CFG->enablebadges) && $CFG->enablebadges == 0)));
$ADMIN->add('root', new admin_category('badges', new lang_string('badges'), empty($CFG->enablebadges)));
$ADMIN->add('root', new admin_category('location', new lang_string('location','admin')));
$ADMIN->add('root', new admin_category('language', new lang_string('language')));
$ADMIN->add('root', new admin_category('modules', new lang_string('plugins', 'admin')));
Expand Down
2 changes: 1 addition & 1 deletion badges/badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}

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

Expand Down
4 changes: 2 additions & 2 deletions badges/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
function badge_cron() {
global $CFG;

if ($CFG->enablebadges) {
if (!empty($CFG->enablebadges)) {
badge_review_cron();
badge_message_cron();
}
Expand Down Expand Up @@ -159,4 +159,4 @@ function badge_assemble_notification(stdClass $badge) {

message_send($eventdata);
}
}
}
10 changes: 7 additions & 3 deletions badges/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ public function definition() {
$mform->addElement('text', 'issuername', get_string('name'), array('size' => '70'));
$mform->setType('issuername', PARAM_NOTAGS);
$mform->addRule('issuername', null, 'required');
$mform->setDefault('issuername', $CFG->badges_defaultissuername);
if (isset($CFG->badges_defaultissuername)) {
$mform->setDefault('issuername', $CFG->badges_defaultissuername);
}
$mform->addHelpButton('issuername', 'issuername', 'badges');

$mform->addElement('text', 'issuercontact', get_string('contact', 'badges'), array('size' => '70'));
$mform->setDefault('issuercontact', $CFG->badges_defaultissuercontact);
if (isset($CFG->badges_defaultissuercontact)) {
$mform->setDefault('issuercontact', $CFG->badges_defaultissuercontact);
}
$mform->setType('issuercontact', PARAM_EMAIL);
$mform->addRule('issuercontact', get_string('invalidemail', 'moodle'), 'email', null, 'client', true);
$mform->addHelpButton('issuercontact', 'contact', 'badges');
Expand Down Expand Up @@ -238,4 +242,4 @@ public function validation($data, $files) {

return $errors;
}
}
}
4 changes: 2 additions & 2 deletions badges/mybackpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

$clear = optional_param('clear', false, PARAM_BOOL);

if (!$CFG->badges_allowexternalbackpack) {
if (empty($CFG->badges_allowexternalbackpack)) {
redirect($CFG->wwwroot);
}

Expand Down Expand Up @@ -161,4 +161,4 @@
echo $OUTPUT->header();
$form->display();
echo $OUTPUT->footer();
}
}
4 changes: 2 additions & 2 deletions badges/mybadges.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
$PAGE->set_pagelayout('mydashboard');

// TODO: Better way of pushing badges to Mozilla backpack?
if ($CFG->badges_allowexternalbackpack) {
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);
}
Expand All @@ -113,4 +113,4 @@

echo $output->render($userbadges);

echo $OUTPUT->footer();
echo $OUTPUT->footer();
6 changes: 3 additions & 3 deletions badges/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function print_badges_list($badges, $userid, $profile = false, $external
$download = $status = $push = '';
if (($userid == $USER->id) && !$profile) {
$url = new moodle_url('mybadges.php', array('download' => $badge->id, 'hash' => $badge->uniquehash, 'sesskey' => sesskey()));
if ($CFG->badges_allowexternalbackpack && (empty($badge->dateexpire) || $badge->dateexpire > time())) {
if (!empty($CFG->badges_allowexternalbackpack) && (empty($badge->dateexpire) || $badge->dateexpire > time())) {
$assertion = new moodle_url('/badges/assertion.php', array('b' => $badge->uniquehash));
$action = new component_action('click', 'addtobackpack', array('assertion' => $assertion->out(false)));
$push = $this->output->action_icon(new moodle_url('#'), new pix_icon('t/backpack', get_string('addtobackpack', 'badges')), $action);
Expand Down Expand Up @@ -292,7 +292,7 @@ protected function render_issued_badge(issued_badge $ibadge) {
get_string('download'),
'POST'));
$expiration = isset($issued['expires']) ? strtotime($issued['expires']) : $today + 1;
if ($CFG->badges_allowexternalbackpack && ($expiration > $today)) {
if (!empty($CFG->badges_allowexternalbackpack) && ($expiration > $today)) {
$assertion = new moodle_url('/badges/assertion.php', array('b' => $ibadge->hash));
$attributes = array(
'type' => 'button',
Expand Down Expand Up @@ -473,7 +473,7 @@ protected function render_badge_user_collection(badge_user_collection $badges) {
// External badges.
$backpack = $badges->backpack;
$externalhtml = "";
if ($CFG->badges_allowexternalbackpack) {
if (!empty($CFG->badges_allowexternalbackpack)) {
$externalhtml .= html_writer::start_tag('fieldset', array('class' => 'generalbox'));
$externalhtml .= html_writer::tag('legend', $this->output->heading_with_help(get_string('externalbadges', 'badges'), 'externalbadges', 'badges'));
if (!is_null($backpack)) {
Expand Down
9 changes: 5 additions & 4 deletions lib/badgeslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,9 @@ function badges_get_issued_badge_info($hash) {
$url = new moodle_url('/badges/badge.php', array('hash' => $hash));

// Recipient's email is hashed: <algorithm>$<hash(email + salt)>.
$a['recipient'] = 'sha256$' . hash('sha256', $record->email . $CFG->badges_badgesalt);
$a['salt'] = $CFG->badges_badgesalt;
$badgesalt = isset($CFG->badgesalt) ? $CFG->badgesalt : '';
$a['recipient'] = 'sha256$' . hash('sha256', $record->email . $badgesalt);
$a['salt'] = $badgesalt;

if ($record->dateexpire) {
$a['expires'] = date('Y-m-d', $record->dateexpire);
Expand Down Expand Up @@ -891,7 +892,7 @@ function badges_add_course_navigation(navigation_node $coursenode, stdClass $cou
$coursecontext = context_course::instance($course->id);
$isfrontpage = (!$coursecontext || $course->id == $SITE->id);

if ($CFG->enablebadges && $CFG->badges_allowcoursebadges && !$isfrontpage) {
if (!empty($CFG->enablebadges) && !empty($CFG->badges_allowcoursebadges) && !$isfrontpage) {
if (has_capability('moodle/badges:configuredetails', $coursecontext)) {
$coursenode->add(get_string('coursebadges', 'badges'), null,
navigation_node::TYPE_CONTAINER, null, 'coursebadges',
Expand Down Expand Up @@ -1228,7 +1229,7 @@ function profile_display_badges($userid, $courseid = 0) {
}

// Print external badges.
if ($courseid == 0 && $CFG->badges_allowexternalbackpack) {
if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) {
$backpack = get_backpack_settings($userid);
if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) {
$left = get_string('externalbadgesp', 'badges');
Expand Down
2 changes: 1 addition & 1 deletion lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ public function add_course_essentials($coursenode, stdClass $course) {
}

// Badges.
if ($CFG->enablebadges && has_capability('moodle/badges:viewbadges', $this->page->context)) {
if (!empty($CFG->enablebadges) && has_capability('moodle/badges:viewbadges', $this->page->context)) {
$url = new moodle_url($CFG->wwwroot . '/badges/view.php',
array('type' => 2, 'id' => $course->id));

Expand Down

0 comments on commit 60d72ef

Please sign in to comment.