public function print_criteria_actions(badge $badge) { $table = new html_table(); $table->attributes = array('class' => 'boxaligncenter', 'id' => 'badgeactions'); $table->colclasses = array('activatebadge'); $actions = array(); if (!$badge->is_active() && !$badge->is_locked()) { $accepted = $badge->get_accepted_criteria(); $potential = array_diff($accepted, array_keys($badge->criteria)); if (!empty($potential)) { foreach ($potential as $p) { if ($p != 0) { $select[$p] = get_string('criteria_' . $p, 'badges'); } } $actions[] = get_string('addbadgecriteria', 'badges'); $actions[] = $this->output->single_select(new moodle_url('/badges/criteria_settings.php', array('badgeid' => $badge->id, 'add' => true)), 'type', $select); } else { $actions[] = $this->output->box(get_string('nothingtoadd', 'badges'), 'clearfix'); } } $table->data[] = $actions; return html_writer::table($table); }
require_once dirname(dirname(__FILE__)) . '/config.php'; require_once $CFG->libdir . '/badgeslib.php'; $badgeid = optional_param('badgeid', 0, PARAM_INT); // Badge ID. $crit = optional_param('crit', 0, PARAM_INT); $type = optional_param('type', 0, PARAM_INT); // Criteria type. $delete = optional_param('delete', 0, PARAM_BOOL); $confirm = optional_param('confirm', 0, PARAM_BOOL); require_login(); $return = new moodle_url('/badges/criteria.php', array('id' => $badgeid)); $badge = new badge($badgeid); $context = $badge->get_context(); $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type)); // Make sure that no actions available for locked or active badges. if ($badge->is_active() || $badge->is_locked()) { redirect($return); } if ($badge->type == BADGE_TYPE_COURSE) { require_login($badge->courseid); $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid)); } $PAGE->set_context($context); $PAGE->set_url('/badges/criteria_action.php'); $PAGE->set_pagelayout('standard'); $PAGE->set_heading($badge->name); $PAGE->set_title($badge->name); navigation_node::override_active_url($navurl); if ($delete && has_capability('moodle/badges:configurecriteria', $context)) { if (!$confirm) { $optionsyes = array('confirm' => 1, 'sesskey' => sesskey(), 'badgeid' => $badgeid, 'delete' => true, 'type' => $type);
} require_login($badge->courseid); $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid)); } require_capability('moodle/badges:awardbadge', $context); $url = new moodle_url('/badges/award.php', array('id' => $badgeid, 'role' => $role)); $PAGE->set_url($url); $PAGE->set_context($context); // Set up navigation and breadcrumbs. $strrecipients = get_string('recipients', 'badges'); navigation_node::override_active_url($navurl); $PAGE->navbar->add($badge->name, new moodle_url('overview.php', array('id' => $badge->id)))->add($strrecipients); $PAGE->set_title($strrecipients); $PAGE->set_heading($badge->name); $PAGE->set_pagelayout('standard'); if (!$badge->is_active()) { echo $OUTPUT->header(); echo $OUTPUT->notification(get_string('donotaward', 'badges')); echo $OUTPUT->footer(); die; } $output = $PAGE->get_renderer('core', 'badges'); // Roles that can award this badge. $acceptedroles = array_keys($badge->criteria[BADGE_CRITERIA_TYPE_MANUAL]->params); if (count($acceptedroles) > 1) { // If there is more than one role that can award a badge, prompt user to make a selection. // If it is an admin, include all accepted roles, otherwise only the ones that current user has in this context. if ($isadmin) { $selection = $acceptedroles; } else { // Get all the roles that user has and use the ones required by this badge.
public function print_criteria_actions(badge $badge) { $output = ''; if (!$badge->is_active() && !$badge->is_locked()) { $accepted = $badge->get_accepted_criteria(); $potential = array_diff($accepted, array_keys($badge->criteria)); if (!empty($potential)) { foreach ($potential as $p) { if ($p != 0) { $select[$p] = get_string('criteria_' . $p, 'badges'); } } $output .= $this->output->single_select(new moodle_url('/badges/criteria_settings.php', array('badgeid' => $badge->id, 'add' => true)), 'type', $select, '', array('' => 'choosedots'), null, array('label' => get_string('addbadgecriteria', 'badges'))); } else { $output .= $this->output->box(get_string('nothingtoadd', 'badges'), 'clearfix'); } } return $output; }
/** * Triggered when badge is manually awarded. * * @param object $data * @return boolean */ function badges_award_handle_manual_criteria_review(stdClass $data) { $criteria = $data->crit; $userid = $data->userid; $badge = new badge($criteria->badgeid); if (!$badge->is_active() || $badge->is_issued($userid)) { return true; } if ($criteria->review($userid)) { $criteria->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } return true; }
/** * Triggered when 'user_updated' event happens. * * @param \core\event\user_updated $event event generated when user profile is updated. */ public static function profile_criteria_review(\core\event\user_updated $event) { global $DB, $CFG; if (!empty($CFG->enablebadges)) { require_once $CFG->dirroot . '/lib/badgeslib.php'; $userid = $event->objectid; if ($rs = $DB->get_records('badge_criteria', array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE))) { foreach ($rs as $r) { $badge = new badge($r->badgeid); if (!$badge->is_active() || $badge->is_issued($userid)) { continue; } if ($badge->criteria[BADGE_CRITERIA_TYPE_PROFILE]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_PROFILE]->mark_complete($userid); if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) { $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid); $badge->issue($userid); } } } } } }