forked from gjbarnard/moodle-format_topcoll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.php
219 lines (194 loc) · 9.52 KB
/
format.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Collapsed Topics Information
*
* A topic based format that solves the issue of the 'Scroll of Death' when a course has many topics. All topics
* except zero have a toggle that displays that topic. One or more topics can be displayed at any given time.
* Toggles are persistent on a per browser session per course basis but can be made to persist longer by a small
* code change. Full installation instructions, code adaptions and credits are included in the 'Readme.txt' file.
*
* @package course/format
* @subpackage topcoll
* @version See the value of '$plugin->version' in version.php.
* @copyright © 2009-onwards G J Barnard in respect to modifications of standard topics format.
* @author G J Barnard - {@link http://moodle.org/user/profile.php?id=442195}
* @link http://docs.moodle.org/en/Collapsed_Topics_course_format
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/filelib.php');
require_once($CFG->libdir . '/completionlib.php');
// Horrible backwards compatible parameter aliasing....
if ($ctopic = optional_param('ctopics', 0, PARAM_INT)) { // Collapsed Topics old section parameter.
$url = $PAGE->url;
$url->param('section', $ctopic);
debugging('Outdated collapsed topic param passed to course/view.php', DEBUG_DEVELOPER);
redirect($url);
}
if ($topic = optional_param('topic', 0, PARAM_INT)) { // Topics and Grid old section parameter.
$url = $PAGE->url;
$url->param('section', $topic);
debugging('Outdated topic / grid param passed to course/view.php', DEBUG_DEVELOPER);
redirect($url);
}
if ($week = optional_param('week', 0, PARAM_INT)) { // Weeks old section parameter.
$url = $PAGE->url;
$url->param('section', $week);
debugging('Outdated week param passed to course/view.php', DEBUG_DEVELOPER);
redirect($url);
}
// End backwards-compatible aliasing....
$context = context_course::instance($course->id);
// Retrieve course format option fields and add them to the $course object.
$courseformat = course_get_format($course);
$course = $courseformat->get_course();
if (($marker >= 0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
$course->marker = $marker;
course_set_marker($course->id, $marker);
}
// Make sure all sections are created.
course_create_sections_if_missing($course, range(0, $course->numsections));
$renderer = $PAGE->get_renderer('format_topcoll');
$devicetype = core_useragent::get_device_type(); // In /lib/classes/useragent.php.
if ($devicetype == "mobile") {
$portable = 1;
} else if ($devicetype == "tablet") {
$portable = 2;
} else {
$portable = 0;
}
$renderer->set_portable($portable);
if (!empty($displaysection)) {
$renderer->print_single_section_page($course, null, null, null, null, $displaysection);
} else {
$defaulttogglepersistence = clean_param(get_config('format_topcoll', 'defaulttogglepersistence'), PARAM_INT);
if ($defaulttogglepersistence == 1) {
user_preference_allow_ajax_update('topcoll_toggle_' . $course->id, PARAM_RAW);
$userpreference = get_user_preferences('topcoll_toggle_' . $course->id);
} else {
$userpreference = null;
}
$defaultuserpreference = clean_param(get_config('format_topcoll', 'defaultuserpreference'), PARAM_INT);
$renderer->set_user_preference($userpreference, $defaultuserpreference, $defaulttogglepersistence);
$tcsettings = $courseformat->get_settings();
echo '<style type="text/css" media="screen">';
echo '/* <![CDATA[ */';
echo '/* -- Toggle -- */';
echo '.course-content ul.ctopics li.section .content .toggle,';
echo '.course-content ul.ctopics li.section .content.sectionhidden {';
echo 'background-color: ';
echo \format_topcoll\toolbox::hex2rgba($tcsettings['togglebackgroundcolour'], $tcsettings['togglebackgroundopacity']);
echo ';';
echo '}';
echo '/* -- Toggle text -- */';
echo '.course-content ul.ctopics li.section .content .toggle span, ';
echo '.course-content ul.ctopics li.section .content.sectionhidden {';
echo 'color: ';
echo \format_topcoll\toolbox::hex2rgba($tcsettings['toggleforegroundcolour'], $tcsettings['toggleforegroundopacity']);
echo ';';
echo 'text-align: ';
switch ($tcsettings['togglealignment']) {
case 1:
echo 'left;';
break;
case 3:
echo 'right;';
break;
default:
echo 'center;';
}
echo '}';
echo '/* Toggle icon position. */';
echo '.course-content ul.ctopics li.section .content .toggle span, #toggle-all .content h4 span {';
echo 'background-position: ';
switch ($tcsettings['toggleiconposition']) {
case 2:
echo 'right';
break;
default:
echo 'left';
};
echo ' center;';
echo '}';
echo '/* -- What happens when a toggle is hovered over -- */';
echo '.course-content ul.ctopics li.section .content .toggle span:hover,';
echo '.course-content ul.ctopics li.section .content.sectionhidden .toggle span:hover {';
echo 'color: ';
echo \format_topcoll\toolbox::hex2rgba($tcsettings['toggleforegroundhovercolour'], $tcsettings['toggleforegroundhoveropacity']);
echo ';';
echo '}';
echo '.course-content ul.ctopics li.section .content div.toggle:hover {';
echo 'background-color: ';
echo \format_topcoll\toolbox::hex2rgba($tcsettings['togglebackgroundhovercolour'], $tcsettings['togglebackgroundhoveropacity']);
echo ';';
echo '}';
$topcollsidewidth = get_string('topcollsidewidthlang', 'format_topcoll');
$topcollsidewidthdelim = strpos($topcollsidewidth, '-');
$topcollsidewidthlang = strcmp(substr($topcollsidewidth, 0, $topcollsidewidthdelim), current_language());
$topcollsidewidthval = substr($topcollsidewidth, $topcollsidewidthdelim + 1);
// Dynamically changing widths with language.
if ((!$PAGE->user_is_editing()) && ($portable == 0) && ($topcollsidewidthlang == 0)) {
echo '.course-content ul.ctopics li.section.main .content, .course-content ul.ctopics li.tcsection .content {';
echo 'margin: 0 '.$topcollsidewidthval.';';
echo '}';
} else if ($PAGE->user_is_editing()) {
echo '.course-content ul.ctopics li.section.main .content, .course-content ul.ctopics li.tcsection .content {';
echo 'margin: 0 40px;';
echo '}';
}
// Make room for editing icons.
if ((!$PAGE->user_is_editing()) && ($topcollsidewidthlang == 0)) {
echo '.course-content ul.ctopics li.section.main .side, .course-content ul.ctopics li.tcsection .side {';
echo 'width: '.$topcollsidewidthval.';';
echo '}';
}
// Establish horizontal unordered list for horizontal columns.
if (($renderer->get_format_responsive()) && ($tcsettings['layoutcolumnorientation'] == 2)) {
echo '.course-content ul.ctopics li.section {';
echo 'display: inline-block;';
echo 'vertical-align: top;';
echo '}';
echo '.course-content ul.ctopics li.section.hidden {';
echo "display: inline-block !important; /* Only using '!important' because of Bootstrap 3. */";
echo '}';
}
// Site wide configuration Site Administration -> Plugins -> Course formats -> Collapsed Topics.
$tcborderradiustl = clean_param(get_config('format_topcoll', 'defaulttoggleborderradiustl'), PARAM_TEXT);
$tcborderradiustr = clean_param(get_config('format_topcoll', 'defaulttoggleborderradiustr'), PARAM_TEXT);
$tcborderradiusbr = clean_param(get_config('format_topcoll', 'defaulttoggleborderradiusbr'), PARAM_TEXT);
$tcborderradiusbl = clean_param(get_config('format_topcoll', 'defaulttoggleborderradiusbl'), PARAM_TEXT);
echo '.course-content ul.ctopics li.section .content .toggle, .course-content ul.ctopics li.section .content.sectionhidden {';
echo '-moz-border-top-left-radius: '.$tcborderradiustl.'em;';
echo '-webkit-border-top-left-radius: '.$tcborderradiustl.'em;';
echo 'border-top-left-radius: '.$tcborderradiustl.'em;';
echo '-moz-border-top-right-radius: '.$tcborderradiustr.'em;';
echo '-webkit-border-top-right-radius: '.$tcborderradiustr.'em;';
echo 'border-top-right-radius: '.$tcborderradiustr.'em;';
echo '-moz-border-bottom-right-radius: '.$tcborderradiusbr.'em;';
echo '-webkit-border-bottom-right-radius: '.$tcborderradiusbr.'em;';
echo 'border-bottom-right-radius: '.$tcborderradiusbr.'em;';
echo '-moz-border-bottom-left-radius: '.$tcborderradiusbl.'em;';
echo '-webkit-border-bottom-left-radius: '.$tcborderradiusbl.'em;';
echo 'border-bottom-left-radius: '.$tcborderradiusbl.'em;';
echo '}';
echo '/* ]]> */';
echo '</style>';
$renderer->print_multiple_section_page($course, null, null, null, null);
}
// Include course format js module.
$PAGE->requires->js('/course/format/topcoll/format.js');