예제 #1
0
        if ($badge->is_locked()) {
            $badge->set_status(BADGE_STATUS_ACTIVE_LOCKED);
            $msg = get_string('activatesuccess', 'badges');
        } else {
            require_sesskey();
            $badge->set_status(BADGE_STATUS_ACTIVE);
            $msg = get_string('activatesuccess', 'badges');
        }
        $returnurl->param('msg', $msg);
        redirect($returnurl);
    }
} else {
    if ($deactivate && has_capability('moodle/badges:configuredetails', $PAGE->context)) {
        $badge = new badge($deactivate);
        if ($badge->is_locked()) {
            $badge->set_status(BADGE_STATUS_INACTIVE_LOCKED);
            $msg = get_string('deactivatesuccess', 'badges');
        } else {
            require_sesskey();
            $badge->set_status(BADGE_STATUS_INACTIVE);
            $msg = get_string('deactivatesuccess', 'badges');
        }
        $returnurl->param('msg', $msg);
        redirect($returnurl);
    }
}
echo $OUTPUT->header();
if ($type == BADGE_TYPE_SITE) {
    echo $OUTPUT->heading_with_help($PAGE->heading, 'sitebadges', 'badges');
} else {
    echo $OUTPUT->heading($PAGE->heading);
예제 #2
0
 /**
  * Test the badge enabled event.
  *
  */
 public function test_badge_enabled()
 {
     $badge = new badge($this->badgeid);
     $sink = $this->redirectEvents();
     // Trigger and capture the event.
     $badge->set_status(BADGE_STATUS_ACTIVE);
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertCount(2, $events);
     $event = $events[1];
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\badge_enabled', $event);
     $this->assertEquals($badge->id, $event->objectid);
     $this->assertDebuggingNotCalled();
     $sink->close();
 }
예제 #3
0
    require_sesskey();
    require_capability('moodle/badges:createbadge', $context);
    $cloneid = $badge->make_clone();
    // If a user can edit badge details, they will be redirected to the edit page.
    if (has_capability('moodle/badges:configuredetails', $context)) {
        redirect(new moodle_url('/badges/edit.php', array('id' => $cloneid, 'action' => 'details')));
    }
    redirect(new moodle_url('/badges/overview.php', array('id' => $cloneid)));
}
if ($activate) {
    require_capability('moodle/badges:configurecriteria', $context);
    $PAGE->url->param('activate', 1);
    $status = $badge->status == BADGE_STATUS_INACTIVE ? BADGE_STATUS_ACTIVE : BADGE_STATUS_ACTIVE_LOCKED;
    if ($confirm == 1) {
        require_sesskey();
        $badge->set_status($status);
        $returnurl->param('msg', 'activatesuccess');
        if ($badge->type == BADGE_TYPE_SITE) {
            // Review on cron if there are more than 1000 users who can earn a site-level badge.
            $sql = 'SELECT COUNT(u.id) as num
                        FROM {user} u
                        LEFT JOIN {badge_issued} bi
                            ON u.id = bi.userid AND bi.badgeid = :badgeid
                        WHERE bi.badgeid IS NULL AND u.id != :guestid AND u.deleted = 0';
            $toearn = $DB->get_record_sql($sql, array('badgeid' => $badge->id, 'guestid' => $CFG->siteguest));
            if ($toearn->num < 1000) {
                $awards = $badge->review_all_criteria();
                $returnurl->param('awards', $awards);
            } else {
                $returnurl->param('awards', 'cron');
            }
예제 #4
0
 public function test_badge_status()
 {
     $badge = new badge($this->badgeid);
     $old_status = $badge->status;
     $badge->set_status(BADGE_STATUS_ACTIVE);
     $this->assertAttributeNotEquals($old_status, 'status', $badge);
     $this->assertAttributeEquals(BADGE_STATUS_ACTIVE, 'status', $badge);
 }