コード例 #1
0
 /**
  * This method tests get_number_of_sections().  I check both a valid
  * course ID and an invalid course ID.
  *
  */
 public function test_get_number_of_sections()
 {
     $courseid = $this->testcourseid;
     $count = get_number_of_sections($courseid);
     $this->assertEquals($count, 5);
     $courseid = 15;
     // Temporarily removed -> will fire an exception, need to figure out how to do this with phpunit.
     // Must look like comment: $count = get_number_of_sections($courseid);.
     // Must look like comment: $this->assertEquals($count, 0);.
 }
コード例 #2
0
/**
 * This is method returns the section titles for all active sections within a course.  The data
 * is appened to the passed second parameter.
 *
 * @param int $courseid This is the course ID of the course to check.
 * @param array $sectionheaders The section headers will be appended here.
 * @return int Total number of active sections.
 *
 */
function get_section_titles($courseid, &$sectionheaders)
{
    global $DB;
    $numberofsections = get_number_of_sections($courseid);
    // TODO: there's probably a better way to access this information as well -> look it up.
    $params = array($courseid);
    $query = "SELECT * FROM {course_sections} WHERE course = ? ORDER BY section";
    $sections = $DB->get_records_sql($query, $params);
    foreach ($sections as $section) {
        // Skip topic 0.
        if ($section->section != 0 && $section->section <= $numberofsections) {
            // If name is set, use that name, otherwise default to "Topic X".
            $sectionheaders[] = isset($section->name) ? $section->name : 'Topic ' . $section->section;
        }
    }
    return $numberofsections;
}