}
}
-/**
- * Returns an array of sections for the requested course id
- *
- * This function stores the sections against the course id within a staticvar encase
- * of subsequent requests. This is used all over + in some standard libs and course
- * format callbacks so subsequent requests are a reality.
- *
- * Note: Since Moodle 2.3, it is more efficient to get this data by calling
- * get_fast_modinfo, then using $modinfo->get_section_info or get_section_info_all.
- *
- * @staticvar array $coursesections
- * @param int $courseid
- * @return array Array of sections
- */
-function get_all_sections($courseid) {
- global $DB;
- static $coursesections = array();
- if (!array_key_exists($courseid, $coursesections)) {
- $coursesections[$courseid] = $DB->get_records("course_sections", array("course"=>"$courseid"), "section",
- 'section, id, course, name, summary, summaryformat, sequence, visible, ' .
- 'availablefrom, availableuntil, showavailability, groupingid');
- }
- return $coursesections[$courseid];
-}
-
/**
* Set highlighted section. Only one section can be highlighted at the time.
*
}
/**
- * Returns course section - creates new if does not exist yet.
- * @param int $relative section number
+ * Returns course section - creates new if does not exist yet
+ *
+ * @param int $section relative section number (field course_sections.section)
* @param int $courseid
- * @return object $course_section object
+ * @return stdClass record from table {course_sections}
*/
function get_course_section($section, $courseid) {
global $DB;
debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
return get_string('sectionname', "format_$format") . ' ' . $section->section;
}
+
+/**
+ * Returns an array of sections for the requested course id
+ *
+ * It is usually not recommended to display the list of sections used
+ * in course because the course format may have it's own way to do it.
+ *
+ * If you need to just display the name of the section please call:
+ * get_section_name($course, $section)
+ * {@link get_section_name()}
+ * from 2.4 $section may also be just the field course_sections.section
+ *
+ * If you need the list of all sections it is more efficient to get this data by calling
+ * $modinfo = get_fast_modinfo($course);
+ * $sections = $modinfo->get_section_info_all()
+ * {@link get_fast_modinfo()}
+ * {@link course_modinfo::get_section_info_all()}
+ *
+ * Information about one section (instance of section_info):
+ * get_fast_modinfo($course)->get_sections_info($section)
+ * {@link course_modinfo::get_section_info()}
+ *
+ * @deprecated since 2.4
+ *
+ * @param int $courseid
+ * @return array Array of section_info objects
+ */
+function get_all_sections($courseid) {
+ global $DB;
+ debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
+ $course = $DB->get_record('course', array('id' => $courseid));
+ return get_fast_modinfo($course)->get_section_info_all();
+}
// Remove unnecessary data and add availability
foreach ($sections as $number => $section) {
- // Clone just in case it is reused elsewhere (get_all_sections cache)
+ // Clone just in case it is reused elsewhere
$compressedsections[$number] = clone($section);
section_info::convert_for_section_cache($compressedsections[$number]);
}