/**
 * This function just grabs any pre-existing values for the form settings and
 * adds them to an array.
 *
 * @param int $courseid This is the course ID.
 * @return array pre-existing form values (use ->set_data()) to set.
 *
 */
function set_values($courseid)
{
    $colorrecord = new course_color_record($courseid);
    // Saving the blockid and courseid allows the page to continue upon post.
    $toform['courseid'] = $courseid;
    $toform['backgroundcolor'] = $colorrecord->get_background_color();
    $toform['foregroundcolor'] = $colorrecord->get_foreground_color();
    $sectionheaders = array();
    $numberofsections = ctwcl_get_section_titles($courseid, $sectionheaders);
    $csr = new course_section_record($courseid);
    for ($i = 0; $i < $numberofsections; $i++) {
        $sectioncheckbox = 'sectioncheckbox_' . "{$i}";
        // Moodle sections count 1->N, section 0 is the summary area at the top.
        $toform[$sectioncheckbox] = $csr->get_section_status($i + 1);
    }
    return $toform;
}
/**
 * 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 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));
 }