public function __construct($record) { global $DB; parent::__construct($record); $this->course = $DB->get_record_sql('SELECT c.id, c.enablecompletion, c.cacherev, c.startdate FROM {badge} b INNER JOIN {course} c ON b.courseid = c.id WHERE b.id = :badgeid ', array('badgeid' => $this->badgeid), MUST_EXIST); $this->courseid = $this->course->id; }
public function __construct($record) { global $DB; parent::__construct($record); $course = $DB->get_record_sql('SELECT b.courseid, c.startdate FROM {badge} b INNER JOIN {course} c ON b.courseid = c.id WHERE b.id = :badgeid ', array('badgeid' => $this->badgeid)); $this->courseid = $course->courseid; $this->coursestartdate = $course->startdate; }
/** * Test the badge criteria deleted event. * * There is no external API for this, so the unit test will simply * create and trigger the event and ensure data is returned as expected. */ public function test_badge_criteria_deleted() { $criteriaoverall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $this->badgeid)); $criteriaoverall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL)); $badge = new badge($this->badgeid); // Trigger and capture the event. $sink = $this->redirectEvents(); $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->delete(); $events = $sink->get_events(); $event = reset($events); // Check that the event data is valid. $this->assertCount(1, $events); $this->assertInstanceOf('\\core\\event\\badge_criteria_deleted', $event); $this->assertEquals($criteriaoverall->badgeid, $event->other['badgeid']); $this->assertDebuggingNotCalled(); $sink->close(); }
/** * Returns badge award criteria * * @return array An array of badge criteria */ public function get_criteria() { global $DB; $criteria = array(); if ($records = (array) $DB->get_records('badge_criteria', array('badgeid' => $this->id))) { foreach ($records as $record) { $criteria[$record->criteriatype] = award_criteria::build((array) $record); } } return $criteria; }
/** * Test badges assertion generated when a badge is issued. */ public function test_badges_assertion() { $this->preventResetByRollback(); // Messaging is not compatible with transactions. $badge = new badge($this->coursebadge); $this->assertFalse($badge->is_issued($this->user->id)); $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id)); $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY)); $criteria_overall1 = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE, 'badgeid' => $badge->id)); $criteria_overall1->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL, 'field_address' => 'address')); $this->user->address = 'Test address'; $sink = $this->redirectEmails(); user_update_user($this->user, false); $this->assertCount(1, $sink->get_messages()); $sink->close(); // Check if badge is awarded. $this->assertDebuggingCalled('Error baking badge image!'); $awards = $badge->get_awards(); $this->assertCount(1, $awards); // Get assertion. $award = reset($awards); $assertion = new core_badges_assertion($award->uniquehash); $testassertion = $this->assertion; // Make sure JSON strings have the same structure. $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())); }
/** * Delete this criterion * */ public function delete() { global $DB; // Remove any records of manual award. $DB->delete_records('badge_manual_award', array('badgeid' => $this->badgeid)); parent::delete(); }
$msg = 'criteriaupdated'; } else { $criteria = award_criteria::build($cparams); $msg = 'criteriacreated'; } $mform = new edit_criteria_form($FULLME, array('criteria' => $criteria, 'addcourse' => $addcourse, 'course' => $badge->courseid)); if (!empty($addcourse)) { if ($data = $mform->get_data()) { // If no criteria yet, add overall aggregation. if (count($badge->criteria) == 0) { $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id)); $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL)); } $id = $criteria->add_courses($data->courses); redirect(new moodle_url('/badges/criteria_settings.php', array('badgeid' => $badgeid, 'edit' => true, 'type' => BADGE_CRITERIA_TYPE_COURSESET, 'crit' => $id))); } } else { if ($data = $mform->get_data()) { // If no criteria yet, add overall aggregation. if (count($badge->criteria) == 0) { $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id)); $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL)); } $criteria->save($data); $return->param('msg', $msg); redirect($return); } } echo $OUTPUT->header(); $mform->display(); echo $OUTPUT->footer();
public function __construct($record) { parent::__construct($record); $this->courseid = self::get_course(); }
public function test_delete_badge_criteria() { $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $this->badgeid)); $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL)); $badge = new badge($this->badgeid); $this->assertInstanceOf('award_criteria_overall', $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]); $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->delete(); $this->assertEmpty($badge->get_criteria()); }