MDL-29188 course_formats Fixed up formatting of section name within navigation
[moodle.git] / course / format / topics / lib.php
CommitLineData
7d2a0492 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.
13//
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/>.
16
17/**
18 * This file contains general functions for the course format Topic
19 *
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
24 */
25
7487c856
SH
26
27/**
28 * Indicates this format uses sections.
29 *
30 * @return bool Returns true
31 */
32function callback_topics_uses_sections() {
33 return true;
34}
35
7d2a0492 36/**
37 * Used to display the course structure for a course where format=topic
38 *
39 * This is called automatically by {@link load_course()} if the current course
40 * format = weeks.
41 *
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
45 */
3406acde 46function callback_topics_load_content(&$navigation, $course, $coursenode) {
0f4ab67d 47 return $navigation->load_generic_course_sections($course, $coursenode, 'topics');
7d2a0492 48}
49
50/**
51 * The string that is used to describe a section of the course
52 * e.g. Topic, Week...
53 *
54 * @return string
55 */
56function callback_topics_definition() {
57 return get_string('topic');
58}
59
60/**
61 * The GET argument variable that is used to identify the section being
62 * viewed by the user (if there is one)
63 *
64 * @return string
65 */
66function callback_topics_request_key() {
67 return 'topic';
68}
aa6c1ced 69
0f4ab67d
SH
70function callback_topics_get_section_name($course, $section) {
71 // We can't add a node without any text
b7676071 72 if (!empty($section->name)) {
113b970e 73 return format_string($section->name, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
0f4ab67d
SH
74 } else if ($section->section == 0) {
75 return get_string('section0name', 'format_topics');
76 } else {
77 return get_string('topic').' '.$section->section;
78 }
c0b5d925
DM
79}
80
81/**
82 * Declares support for course AJAX features
83 *
84 * @see course_format_ajax_support()
85 * @return stdClass
86 */
87function callback_topics_ajax_support() {
88 $ajaxsupport = new stdClass();
89 $ajaxsupport->capable = true;
90 $ajaxsupport->testedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari' => 531, 'Chrome' => 6.0);
91 return $ajaxsupport;
92}
ad470097
SH
93
94/**
95 * Returns a URL to arrive directly at a section
96 *
97 * @param int $courseid The id of the course to get the link for
98 * @param int $sectionnum The section number to jump to
99 * @return moodle_url
100 */
101function callback_topics_get_section_url($courseid, $sectionnum) {
102 return new moodle_url('/course/view.php', array('id' => $courseid, 'topic' => $sectionnum));
103}