/** * This function determines the if user has locked in choice and updates database. * * @param int $courseid The ID of the course. * @param object $submittedform The object contains the results of the form when changes were saved. * @return string The url to redirect the user to. * */ function process_form($courseid, &$submittedform) { global $USER; if (isset($submittedform->lockchoice)) { if ($submittedform->lockchoice) { $student = new skills_group_student($courseid, $USER->id); $student->set_lock_choice(true); $url = new moodle_url('/course/view.php', array('id' => $courseid)); } } else { $url = new moodle_url('/course/view.php', array('id' => $courseid)); } return $url; }
/** * This function configures the skills_group_setting class for further testing. I do not call this * on the setUp() function here, but derived testing classes can do so as needed. * * @param integer $threshold low/high score threshold * @param integer $date date in unix epoch format * @param integer $allownaming whether students can name their groups (1) or not (0) */ protected function configure_settings($threshold = 1, $date = null, $allownaming = 1) { $sgs = new skills_group_setting($this->courseid); $settings = $this->get_skills_group_settings($threshold, $date, $allownaming); $sgs->update_record($settings); // Set last student to have choice locked. $student = new skills_group_student($this->courseid, $this->users[self::NUMBEROFUSERS - 1]->id); $student->set_lock_choice(true); }
/** * This function tests the flag that locks a student's choice. I'm testing * both the getter and the setter. Check to ensure that the record defaults * to false when no record exists. * */ public function test_lock_choice() { global $DB; $this->configure_settings(); $sgroup = new skills_group_student($this->courseid, $this->users[0]->id); $this->assertFalse($sgroup->get_lock_choice()); $sgroup->set_lock_choice(true); $lockchoice = $DB->get_field('skills_group_student', 'finalizegroup', array('userid' => $this->users[0]->id)); $this->assertEquals($lockchoice, 1); $this->assertTrue($sgroup->get_lock_choice()); $sgroup->set_lock_choice(false); $this->assertFalse($sgroup->get_lock_choice()); }