MDL-35344 Ignore available updates info with invalid format
[moodle.git] / course / format / topics / lib.php
blob7c8408471808ab278944e2f6c6a91fe76a9bf997
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This file contains general functions for the course format Topic
20 * @since 2.0
21 * @package moodlecore
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 /**
28 * Indicates this format uses sections.
30 * @return bool Returns true
32 function callback_topics_uses_sections() {
33 return true;
36 /**
37 * Used to display the course structure for a course where format=topic
39 * This is called automatically by {@link load_course()} if the current course
40 * format = weeks.
42 * @param array $path An array of keys to the course node in the navigation
43 * @param stdClass $modinfo The mod info object for the current course
44 * @return bool Returns true
46 function callback_topics_load_content(&$navigation, $course, $coursenode) {
47 return $navigation->load_generic_course_sections($course, $coursenode, 'topics');
50 /**
51 * The string that is used to describe a section of the course
52 * e.g. Topic, Week...
54 * @return string
56 function callback_topics_definition() {
57 return get_string('topic');
60 function callback_topics_get_section_name($course, $section) {
61 // We can't add a node without any text
62 if ((string)$section->name !== '') {
63 return format_string($section->name, true, array('context' => context_course::instance($course->id)));
64 } else if ($section->section == 0) {
65 return get_string('section0name', 'format_topics');
66 } else {
67 return get_string('topic').' '.$section->section;
71 /**
72 * Declares support for course AJAX features
74 * @see course_format_ajax_support()
75 * @return stdClass
77 function callback_topics_ajax_support() {
78 $ajaxsupport = new stdClass();
79 $ajaxsupport->capable = true;
80 $ajaxsupport->testedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari' => 531, 'Chrome' => 6.0);
81 return $ajaxsupport;
84 /**
85 * Callback function to do some action after section move
87 * @param stdClass $course The course entry from DB
88 * @return array This will be passed in ajax respose.
90 function callback_topics_ajax_section_move($course) {
91 global $COURSE, $PAGE;
93 $titles = array();
94 rebuild_course_cache($course->id);
95 $modinfo = get_fast_modinfo($COURSE);
96 $renderer = $PAGE->get_renderer('format_topics');
97 if ($renderer && ($sections = $modinfo->get_section_info_all())) {
98 foreach ($sections as $number => $section) {
99 $titles[$number] = $renderer->section_title($section, $course);
102 return array('sectiontitles' => $titles, 'action' => 'move');