/** * 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 color records that are needed * for testing. * */ private function create_color_information() { $courseid = 15; $colorrecord = new course_color_record($courseid); $colorrecord->set_foreground_color(''); $colorrecord->set_background_color(''); $courseid = 18; $colorrecord = new course_color_record($courseid); $colorrecord->set_foreground_color('#112233'); $colorrecord->set_background_color('#223344'); $courseid = 19; $colorrecord = new course_color_record($courseid); $colorrecord->set_foreground_color('#aabbcc'); $courseid = 20; $colorrecord = new course_color_record($courseid); $colorrecord->set_background_color('#667788'); }