/**
  * This function creates the test data for the various tests below.  The file
  * setup is done on its own in the base class.
  *
  */
 private function create_section_icon_entries()
 {
     $courseid = $this->testcourseid;
     $sectionheaders = array();
     get_section_titles($courseid, $sectionheaders);
     // Section 1 - {master, then course-specific}.
     $si = new section_icon($courseid, $sectionheaders[0]);
     $si->update_icon_record(1, $this->fileids[self::SECTION1_GLOBAL_FILE_ID_INDEX]);
     $si->update_icon_record($courseid, $this->fileids[self::SECTION1_COURSE_FILE_ID_INDEX]);
     // Section 2 - {master, then course-specific}.
     $si = new section_icon($courseid, $sectionheaders[1]);
     $si->update_icon_record(1, $this->fileids[self::SECTION2_GLOBAL_FILE_ID_INDEX]);
     $si->update_icon_record($courseid, $this->fileids[self::SECTION2_COURSE_FILE_ID_INDEX]);
     $si->update_disableicon(false);
     // Section 3 - {master, then course-specific}.
     $si = new section_icon($courseid, $sectionheaders[2]);
     $si->update_icon_record(1, $this->fileids[self::SECTION3_GLOBAL_FILE_ID_INDEX]);
     $si->update_icon_record($courseid, $this->fileids[self::SECTION3_COURSE_FILE_ID_INDEX]);
     $si->update_disableicon(false);
     $si->update_label("This is a custom label");
     // Section 4 - {master only}.
     $si = new section_icon($courseid, $sectionheaders[3]);
     $si->update_icon_record(1, $this->fileids[self::SECTION4_GLOBAL_FILE_ID_INDEX]);
     // Section 5 - {master only}.
     $si = new section_icon($courseid, $sectionheaders[4]);
     $si->update_icon_record(1, $this->fileids[self::SECTION5_GLOBAL_FILE_ID_INDEX]);
     $si->update_disableicon(true);
     $si->update_label("Custom label, but section disabled");
     // Another entry not attached to a real section.
     $si = new section_icon($courseid, "Disabled Topic");
     $si->update_disableicon(true);
 }
 /**
  * This function draws the block on the screen.  Icons are retrieved from the database and displayed in
  * the block.  The link to edit the page is drawn only if the user has editing rights.
  *
  */
 public function get_content()
 {
     global $COURSE, $PAGE;
     $PAGE->requires->css('/blocks/nurs_navigation/fade.css');
     if ($this->content !== null) {
         return $this->content;
     }
     $courseid = $COURSE->id;
     $currentsection = $this->get_current_section($courseid);
     $sectionheaders = array();
     $numberofsections = get_section_titles($courseid, $sectionheaders);
     // Note: setting to new class here means that any changes above will be wiped.
     $this->content = new StdClass();
     $this->content->footer = '<ul style="text-align: center; width: 100%; margin: 0; padding: 0; list-style: none;">';
     $fontsize = $this->get_font_size();
     for ($i = 0; $i < $numberofsections; $i++) {
         $this->content->footer .= $this->get_block_icon_link($courseid, $i, $sectionheaders[$i], $currentsection, $fontsize);
     }
     $this->content->footer .= '</ul>';
     $context = context_course::instance($courseid);
     $canmanage = has_capability('block/nurs_navigation:caneditnursnavigation', $context);
     $url = new moodle_url('/course/view.php', array('id' => $COURSE->id, 'section' => 0));
     $this->content->footer .= "<center>" . html_writer::link($url, get_string('showallsections', BNN_LANG_TABLE)) . "</center>";
     if ($canmanage) {
         $url = new moodle_url('/blocks/nurs_navigation/edit_navigation.php', array('courseid' => $COURSE->id, 'blockid' => $this->instance->id));
         $this->content->footer .= "<center>" . html_writer::link($url, get_string('editsettings', BNN_LANG_TABLE)) . "</center>";
     }
     return $this->content;
 }
}
if (!isloggedin()) {
    echo get_string('loginrequired', BNN_LANG_TABLE);
    return;
}
if (!has_capability('block/nurs_navigation:caneditnursnavigation', context_course::instance($courseid))) {
    echo get_string('noaccess', BNN_LANG_TABLE);
    return;
}
$PAGE->set_url('/blocks/nurs_navigation/edit_navigation.php', array('id' => $courseid));
$PAGE->set_context(context_user::instance($USER->id));
$PAGE->set_title(get_string('editpagetitle', BNN_LANG_TABLE));
$PAGE->set_pagelayout('standard');
$PAGE->set_heading(get_string('editpagetitle', BNN_LANG_TABLE));
$sectionheaders = array();
$numberofsections = get_section_titles($courseid, $sectionheaders);
$naveditform = new edit_navigation_form($numberofsections, $sectionheaders, $courseid);
// Saving the blockid and courseid allows the page to continue upon post.
$toform['courseid'] = $courseid;
$toform['blockid'] = $blockid;
// And setup icon checkboxes.
for ($i = 0; $i < $numberofsections; $i++) {
    $si = new section_icon($courseid, $sectionheaders[$i]);
    $noiconname = 'noicon_' . "{$i}";
    $toform[$noiconname] = $si->get_icon_disable();
    $customlabelfield = 'customlabelfield_' . "{$i}";
    $customlabelcheckbox = 'customlbelcheckbox_' . "{$i}";
    if ($si->get_custom_label() != null) {
        $toform[$customlabelcheckbox] = true;
        $toform[$customlabelfield] = $si->get_custom_label();
    } else {
 /**
  * This method tests get_section_titles().  I check the first three section
  * titles for the course with an ID of 2.  Two of these are set, while the
  * third is set to NULL and is converted to "Topic X" by the function.  I also
  * ensure that no more than three entries are set, even though there are more
  * than three entries in the {course_sections} database.  That is, only the
  * active sections are returned.
  *
  */
 public function test_get_section_titles()
 {
     $courseid = $this->testcourseid;
     $sectionheaders = array();
     $count = get_section_titles($courseid, $sectionheaders);
     $this->assertEquals($count, self::DEFAULT_NUMBER_OF_SECTIONS);
     $this->assertEquals($sectionheaders[0], "Craig's Resources");
     $this->assertEquals($sectionheaders[1], "Some Other Section");
     $this->assertEquals($sectionheaders[2], "Topic 3");
     $this->assertFalse((bool) isset($sectionheaders[self::DEFAULT_NUMBER_OF_SECTIONS]));
 }