/** * Builds a list of information about sections on a course to be stored in * the course cache. (Does not include information that is already cached * in some other way.) * * @param stdClass $course Course object (must contain fields * @return array Information about sections, indexed by section number (not id) */ protected static function build_course_section_cache($course) { global $DB; // Get section data $sections = $DB->get_records('course_sections', array('course' => $course->id), 'section', 'section, id, course, name, summary, summaryformat, sequence, visible, ' . 'availablefrom, availableuntil, showavailability, groupingid'); $compressedsections = array(); $formatoptionsdef = course_get_format($course)->section_format_options(); // Remove unnecessary data and add availability foreach ($sections as $number => $section) { // Add cached options from course format to $section object foreach ($formatoptionsdef as $key => $option) { if (!empty($option['cache'])) { $formatoptions = course_get_format($course)->get_format_options($section); if (!array_key_exists('cachedefault', $option) || $option['cachedefault'] !== $formatoptions[$key]) { $section->$key = $formatoptions[$key]; } } } // Clone just in case it is reused elsewhere $compressedsections[$number] = clone($section); section_info::convert_for_section_cache($compressedsections[$number]); } return $compressedsections; }
/** * Builds a list of information about sections on a course to be stored in * the course cache. (Does not include information that is already cached * in some other way.) * * Used internally by rebuild_course_cache function; do not use otherwise. * @param int $courseid Course ID * @return array Information about sections, indexed by section number (not id) */ public static function build_section_cache($courseid) { global $DB; // Get section data $sections = $DB->get_records('course_sections', array('course' => $courseid), 'section', 'section, id, course, name, summary, summaryformat, sequence, visible, ' . 'availablefrom, availableuntil, showavailability, groupingid'); $compressedsections = array(); // Remove unnecessary data and add availability foreach ($sections as $number => $section) { // Clone just in case it is reused elsewhere (get_all_sections cache) $compressedsections[$number] = clone($section); section_info::convert_for_section_cache($compressedsections[$number]); } return $compressedsections; }