/**
 * This function draws the current section and sets up the collapsed labels.
 *
 * @param object $course This is the course object.
 * @param int $displaysection The numerical value of the section
 *
 */
function display_collapsed($course, $displaysection)
{
    global $PAGE;
    if (check_display($displaysection) && !$PAGE->user_is_editing()) {
        $cm = new collapsed_menu($course, $displaysection, true);
        $cm->render_menu();
        return $cm;
    }
}
 /**
  * This function tests the render_menu() method's ability to display
  * the menus properly and handle a number of special cases that should
  * arise.
  *
  * Note: for some reason (I think the cache gets flushed), all of the
  * section tests must go in here.
  *
  */
 public function test_renderarray()
 {
     global $DB;
     $courseid = $this->testcourseid;
     $course = $DB->get_record('course', array('id' => $courseid));
     rebuild_course_cache($courseid);
     $section = 1;
     $thissection = $DB->get_record('course_sections', array('course' => $courseid, 'section' => $section));
     $cm = new collapsed_menu($course, $section, false);
     $cm->render_menu();
     // Answers are below.
     $labelids = array($this->section1labelids[1], $this->section1labelids[2], $this->section1labelids[3], $this->section1labelids[0], $this->section1labelids[4]);
     $closeids = array("N" . $this->section1labelids[2], "N" . $this->section1labelids[3], "N" . $this->section1labelids[4], "N" . $this->section1labelids[4], "N" . $this->section1contentids[8]);
     $depthindices = array(2, 2, 2, 1, 1);
     $depthvalues = array(2, 2, 2, 0, 0);
     $numlabels = 5;
     // Test labelinfo values.
     $labelinfo = $cm->get_label_info();
     for ($i = 0; $i < $numlabels; $i++) {
         $this->assertEquals($labelinfo->labelid[$i], $labelids[$i]);
         $this->assertEquals($labelinfo->closeid[$i], $closeids[$i]);
         $this->assertEquals($labelinfo->depthindex[$i], $depthindices[$i]);
         $this->assertEquals($labelinfo->depthvalue[$i], $depthvalues[$i]);
     }
     // Now for mod depths: answers.
     $modids = array($this->section1contentids[0], $this->section1contentids[1], $this->section1contentids[2], $this->section1contentids[3], $this->section1contentids[4], $this->section1contentids[5], $this->section1contentids[6], $this->section1contentids[7], $this->section1contentids[8]);
     $depths = array(0, 0, 0, 1, 0, 0, 0, 0, 0);
     $nummods = 9;
     // Test the moddepth values.
     $moddepths = $cm->get_mod_depths();
     for ($i = 0; $i < $nummods; $i++) {
         $this->assertEquals($moddepths->modid[$i], $modids[$i]);
         $this->assertEquals($moddepths->moddepth[$i], $depths[$i]);
     }
     // Change section to 2, it tests the "inclusive" label end.
     $section = 2;
     $thissection = $DB->get_record('course_sections', array('course' => $courseid, 'section' => $section));
     $cm = new collapsed_menu($course, $section, false);
     $cm->render_menu();
     $labelinfo = $cm->get_label_info();
     $this->assertEquals($labelinfo->labelid[0], $this->section2labelids[0]);
     $this->assertEquals($labelinfo->closeid[0], "I" . $this->section2contentids[0]);
     // Go with section 3 next -> this section "reverses" the last entries.
     $section = 3;
     $thissection = $DB->get_record('course_sections', array('course' => $courseid, 'section' => $section));
     $cm = new collapsed_menu($course, $section, false);
     $cm->render_menu();
     $labelids = array($this->section3labelids[0], $this->section3labelids[2], $this->section3labelids[3], $this->section3labelids[1], $this->section3labelids[4], $this->section3labelids[6], $this->section3labelids[5], $this->section3labelids[7], $this->section3labelids[8]);
     $closeids = array("N" . $this->section3labelids[1], "N" . $this->section3labelids[3], "N" . $this->section3labelids[4], "N" . $this->section3labelids[4], "N" . $this->section3labelids[5], "N" . $this->section3labelids[7], "I" . $this->section3contentids[0], "I" . $this->section3contentids[0], "I" . $this->section3contentids[0]);
     $depthindices = array(1, 2, 2, 1, 1, 2, 1, 2, 3);
     $depthvalues = array(0, 1, 1, 0, 0, 1, 0, 1, 2);
     $numlabels = 9;
     $labelinfo = $cm->get_label_info();
     for ($i = 0; $i < $numlabels; $i++) {
         $this->assertEquals($labelinfo->labelid[$i], $labelids[$i]);
         $this->assertEquals($labelinfo->closeid[$i], $closeids[$i]);
         $this->assertEquals($labelinfo->depthindex[$i], $depthindices[$i]);
         $this->assertEquals($labelinfo->depthvalue[$i], $depthvalues[$i]);
     }
 }