/** * This method tests the update_section_record() method by using the * get_section_status() member that was tested in the previous test. * I do a bit of value toggling and just test to make sure the status * flag gets properly updated. * */ public function test_update_section_record() { $courseid = 2; $csr = new course_section_record($courseid); $sectionid = 3; // This should delete the record. $csr->update_section_record($sectionid, true); $this->assertTrue((bool) $csr->get_section_status($sectionid)); // This should re-create the record, but with false. $csr->update_section_record($sectionid, false); $this->assertFalse((bool) $csr->get_section_status($sectionid)); $sectionid = 4; // Toggle existing record to false. $csr->update_section_record($sectionid, false); $this->assertFalse((bool) $csr->get_section_status($sectionid)); }
/** * This function checks the course table for this section and determines whether * collapsed labels should be used. * * @param int $sectionid This is the section number. * @returns bool T/F indicating whether the nested menus should be used (T) * or should not be used (F). * */ function check_display($sectionid) { global $COURSE; $csr = new course_section_record($COURSE->id); return $csr->get_section_status($sectionid); }
/** * This function processes the submitted form for the two requested colors. Earlier * in this file, the default values are placed into the form, so I only handle updates * if the values have changed from the default. * */ function process_form($courseid, &$submittedform) { global $DB; if (isset($submittedform->returndefault)) { $colorrecord = new course_color_record($courseid); $colorrecord->delete_record(); return; } /* NOTE: I've written these as separate cases to try to only write new colors and preserve * the code falling back to the defaults as best as I can. */ if ($submittedform->foregroundcolor != DEFAULT_FOREGROUND) { $colorrecord = new course_color_record($courseid); $colorrecord->set_foreground_color($submittedform->foregroundcolor); } if ($submittedform->backgroundcolor != DEFAULT_BACKGROUND) { $colorrecord = new course_color_record($courseid); $colorrecord->set_background_color($submittedform->backgroundcolor); } // Now check each of the sections. $sectionheaders = array(); $numberofsections = ctwcl_get_section_titles($courseid, $sectionheaders); $csr = new course_section_record($courseid); for ($i = 0; $i < $numberofsections; $i++) { $sectionfield = 'sectionfield_' . "{$i}"; $sectioncheckbox = 'sectioncheckbox_' . "{$i}"; // Moodle sections count 1->N, section 0 is the summary area at the top. $csr->update_section_record($i + 1, $submittedform->{$sectioncheckbox}); } }
/** * This function creates the various section records that are needed * for testing. * */ private function create_section_toggles() { $courseid = $this->testcourseid; $csr = new course_section_record($courseid); $csr->update_section_record(3, false); // This statement does not create an entry, but I've left it in. $csr->update_section_record(4, true); $courseid = 3; $csr = new course_section_record($courseid); $csr->update_section_record(7, false); $courseid = 10; $csr = new course_section_record($courseid); $csr->update_section_record(15, false); }