Skip to content

Commit 6f3697c

Browse files
committed
V2.7.1.3 - CONTRIB-5211
1 parent 88f1cae commit 6f3697c

File tree

8 files changed

+305
-17
lines changed

8 files changed

+305
-17
lines changed

Readme.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Course Backup and Restore Instructions
166166
======================================
167167
1. Backup as you would any other course. The layout configuration will be stored with the course settings.
168168
2. Restore as you would any other course. If you are offered the option of 'Overwrite Course Configuration'
169-
you must say 'Yes' to have thelayout configuration restored otherwise the restored course will retain the
169+
you must say 'Yes' to have the layout configuration restored otherwise the restored course will retain the
170170
layout it previously had or the default in the 'config.php' file as mentioned in the 'Installation'
171171
instructions above depending on the situation.
172172
3. Note: I believe that if you restore a Collapsed Topic's course on an installation that does not have the
@@ -243,8 +243,9 @@ can be really useful in visualising the issue along with any files you consider
243243

244244
Version Information
245245
===================
246-
18th July 2014 Version 2.7.1.3
246+
18th August 2014 Version 2.7.1.3
247247
1. Fixed a few typos.
248+
2. Fixed CONTRIB-5211: Section 5 does not remain expanded when browsing away and back.
248249

249250
17th July 2014 Version 2.7.1.2
250251
1. Slight tweak to css to tidy things up when editing.
@@ -589,7 +590,7 @@ Change by G J Barnard
589590
Thanks to [Rick Jerz](https://moodle.org/user/profile.php?id=520965) for reporting this.
590591

591592
18th October 2012 - Version 2.3.9.1
592-
1. Fixed potenial issue when the course is first accessed and there is no user preference.
593+
1. Fixed potential issue when the course is first accessed and there is no user preference.
593594
2. Identified that sometimes when restoring a course, it is accessed for the first time and a toggle is clicked a 'Error
594595
updating user preference 'topcoll_toggle_x'' (where 'x' is the course id as shown in the URL 'id=x') can occur. I'm not
595596
completely sure why this is happening as the 'user_preference_allow_ajax_update' call in 'format.php' should establish that
@@ -1116,6 +1117,6 @@ Desired Enhancements
11161117

11171118
Me
11181119
==
1119-
G J Barnard MSc. BSc(Hons)(Sndw). MBCS. CEng. CITP. PGCE. - 18th July 2014.
1120+
G J Barnard MSc. BSc(Hons)(Sndw). MBCS. CEng. CITP. PGCE. - 18th August 2014.
11201121
Moodle profile: http://moodle.org/user/profile.php?id=442195.
11211122
Web profile : http://about.me/gjbarnard

format.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @copyright © 2009-onwards G J Barnard in respect to modifications of standard topics format.
2929
* @author G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195}
3030
* @link http://docs.moodle.org/en/Collapsed_Topics_course_format
31-
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
31+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3232
*
3333
*/
3434
defined('MOODLE_INTERNAL') || die();
@@ -85,7 +85,7 @@
8585
if (!empty($displaysection)) {
8686
$renderer->print_single_section_page($course, null, null, null, null, $displaysection);
8787
} else {
88-
user_preference_allow_ajax_update('topcoll_toggle_' . $course->id, PARAM_TEXT);
88+
user_preference_allow_ajax_update('topcoll_toggle_' . $course->id, PARAM_TOPCOLL);
8989
$userpreference = get_user_preferences('topcoll_toggle_' . $course->id);
9090
$renderer->set_user_preference($userpreference);
9191

module.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ M.format_topcoll.to2baseString = function(thirtysix) {
206206
M.format_topcoll.save_toggles = function() {
207207
"use strict";
208208
if (this.togglePersistence == 1) { // Toggle persistence - 1 = on, 0 = off.
209-
M.util.set_user_preference('topcoll_toggle_' + this.courseid, this.togglestate);
209+
M.format_topcoll.set_user_preference('topcoll_toggle_' + this.courseid, this.togglestate);
210210
}
211211
};
212212

@@ -260,7 +260,6 @@ M.format_topcoll.set_toggle_state = function(togglenum, state) {
260260
value &= ~toggleflag;
261261
}
262262
var newchar = this.encode_value_to_character(value);
263-
//this.togglestate[togglecharpos-1] = newchar;
264263
var start = this.togglestate.substring(0,togglecharpos - 1);
265264
var end = this.togglestate.substring(togglecharpos);
266265
this.togglestate = start + newchar + end;
@@ -278,12 +277,12 @@ M.format_topcoll.get_toggle_pos = function(togglenum) {
278277

279278
M.format_topcoll.get_min_digit = function() {
280279
"use strict";
281-
return ':';
280+
return ':'; // 58 ':';
282281
};
283282

284283
M.format_topcoll.get_max_digit = function() {
285284
"use strict";
286-
return 'y';
285+
return 'y'; // 58 'y';
287286
};
288287

289288
M.format_topcoll.get_toggle_flag = function(togglenum, togglecharpos) {
@@ -321,4 +320,36 @@ M.format_topcoll.decode_character_to_value = function(character) {
321320
M.format_topcoll.encode_value_to_character = function(val) {
322321
"use strict";
323322
return String.fromCharCode(val + 58);
324-
};
323+
};
324+
325+
/**
326+
* Makes a best effort to connect back to Moodle to update a user preference,
327+
* however, there is no mechanism for finding out if the update succeeded.
328+
*
329+
* Before you can use this function in your JavsScript, you must have called
330+
* user_preference_allow_ajax_update from moodlelib.php to tell Moodle that
331+
* the update is allowed, and how to safely clean and submitted values.
332+
*
333+
* @param String name the name of the setting to update.
334+
* @param String the value to set it to.
335+
*/
336+
M.format_topcoll.set_user_preference = function(name, value) {
337+
YUI().use('io', function(Y) {
338+
var url = M.cfg.wwwroot + '/course/format/topcoll/settopcollpref.php?sesskey=' +
339+
M.cfg.sesskey + '&pref=' + encodeURI(name) + '&value=' + encodeURI(value);
340+
341+
// If we are a developer, ensure that failures are reported.
342+
var cfg = {
343+
method: 'get',
344+
on: {}
345+
};
346+
if (M.cfg.developerdebug) {
347+
cfg.on.failure = function(id, o, args) {
348+
console.log("Error updating topcoll preference '" + name + "' using AJAX. Almost certainly your session has timed out. Clicking this link will repeat the AJAX call that failed so you can see the error: ");
349+
}
350+
}
351+
352+
// Make the request.
353+
Y.io(url, cfg);
354+
});
355+
};

settopcollpref.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
* Code to update a user preference in response to an ajax call.
19+
*
20+
* You should not send requests to this script directly. Instead use the set_user_preference
21+
* function in /course/format/topcol/module.js.
22+
*
23+
* @package course/format
24+
* @subpackage topcoll
25+
* @version See the value of '$plugin->version' in below.
26+
* @copyright &copy; 2014-onwards G J Barnard based upon code originally written by Tim Hunt.
27+
* @author G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195}
28+
* @link http://docs.moodle.org/en/Collapsed_Topics_course_format
29+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30+
*/
31+
32+
require_once(dirname(__FILE__) . '/../../../config.php');
33+
require_once($CFG->dirroot . '/course/format/topcoll/togglelib.php');
34+
35+
// Check access.
36+
if (!confirm_sesskey()) {
37+
print_error('invalidsesskey');
38+
}
39+
40+
// Get the name of the preference to update, and check that it is allowed.
41+
$name = required_param('pref', PARAM_RAW);
42+
if (!isset($USER->ajax_updatable_user_prefs[$name])) {
43+
print_error('notallowedtoupdateprefremotely');
44+
}
45+
46+
// Get and set the value.
47+
$value = required_topcoll_param('value', $USER->ajax_updatable_user_prefs[$name]);
48+
error_log($name.' is before: '.$USER->ajax_updatable_user_prefs[$name].' after: '.$value);
49+
// Update
50+
if (!set_user_preference($name, $value)) {
51+
print_error('errorsettinguserpref');
52+
}
53+
54+
echo 'OK';

test/format_test.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
* Collapsed Topics Information
19+
*
20+
* A topic based format that solves the issue of the 'Scroll of Death' when a course has many topics. All topics
21+
* except zero have a toggle that displays that topic. One or more topics can be displayed at any given time.
22+
* Toggles are persistent on a per browser session per course basis but can be made to persist longer by a small
23+
* code change. Full installation instructions, code adaptions and credits are included in the 'Readme.txt' file.
24+
*
25+
* @package course/format
26+
* @subpackage topcoll
27+
* @version See the value of '$plugin->version' in below.
28+
* @copyright &copy; 2014-onwards G J Barnard in respect to modifications of standard topics format.
29+
* @author G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195}
30+
* @link http://docs.moodle.org/en/Collapsed_Topics_course_format
31+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32+
*
33+
*/
34+
defined('MOODLE_INTERNAL') || die();
35+
36+
require_once($CFG->dirroot . '/course/format/topcoll/togglelib.php');
37+
38+
$run = false;
39+
if ($run) {
40+
// TEST CODE.
41+
for ($i = 0; $i < 64; $i++) {
42+
user_preference_allow_ajax_update('topcoll_toggle_a'.$i.'_' . $course->id, PARAM_TOPCOLL);
43+
user_preference_allow_ajax_update('topcoll_toggle_b'.$i.'_' . $course->id, PARAM_TOPCOLL);
44+
user_preference_allow_ajax_update('topcoll_toggle_c'.$i.'_' . $course->id, PARAM_TOPCOLL);
45+
}
46+
user_preference_allow_ajax_update('topcoll_toggle_bf_' . $course->id, PARAM_TOPCOLL);
47+
user_preference_allow_ajax_update('topcoll_toggle_bf2_' . $course->id, PARAM_TOPCOLL);
48+
user_preference_allow_ajax_update('topcoll_toggle_bf3_' . $course->id, PARAM_TOPCOLL);
49+
user_preference_allow_ajax_update('topcoll_toggle_af_' . $course->id, PARAM_TOPCOLL);
50+
user_preference_allow_ajax_update('topcoll_toggle_af2_' . $course->id, PARAM_TOPCOLL);
51+
user_preference_allow_ajax_update('topcoll_toggle_af3_' . $course->id, PARAM_TOPCOLL);
52+
// Test clean_param to see if it accepts '<' and '>' for PARAM_TEXT as stated in moodlelib.php.
53+
echo '<h3>PARAM_TEXT < : '.clean_param('<',PARAM_TEXT).'</h3>';
54+
echo '<h3>PARAM_TEXT > : '.clean_param('>',PARAM_TEXT).'</h3>';
55+
echo '<h3>PARAM_RAW < : '.clean_param('<',PARAM_RAW).'</h3>';
56+
echo '<h3>PARAM_RAW > : '.clean_param('>',PARAM_RAW).'</h3>';
57+
}

test/module_test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Collapsed Topics Information
3+
*
4+
* A topic based format that solves the issue of the 'Scroll of Death' when a course has many topics. All topics
5+
* except zero have a toggle that displays that topic. One or more topics can be displayed at any given time.
6+
* Toggles are persistent on a per browser session per course basis but can be made to persist longer by a small
7+
* code change. Full installation instructions, code adaptions and credits are included in the 'Readme.txt' file.
8+
*
9+
* @package course/format
10+
* @subpackage topcoll
11+
* @version See the value of '$plugin->version' in version.php.
12+
* @copyright &copy; 2014-onwards G J Barnard in respect to modifications of standard topics format.
13+
* @author G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195}
14+
* @link http://docs.moodle.org/en/Collapsed_Topics_course_format
15+
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
16+
*
17+
* This program is free software: you can redistribute it and/or modify
18+
* it under the terms of the GNU General Public License as published by
19+
* the Free Software Foundation, either version 3 of the License, or
20+
* (at your option) any later version.
21+
22+
* This program is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
29+
*/
30+
31+
M.format_topcoll.test_all_states = function() {
32+
"use strict";
33+
// Reset for this course.
34+
console.log('test_all_states: togglestate:' + this.togglestate);
35+
console.log('test_all_states: reset course.');
36+
M.format_topcoll.resetState(M.format_topcoll.get_min_digit());
37+
M.format_topcoll.save_toggles();
38+
console.log('test_all_states: togglestate:' + this.togglestate);
39+
40+
// Loop through all possible states, this involves the first twelve toggles.
41+
console.log('test_all_states: start loop.');
42+
var state = 0;
43+
44+
for (state = 0; state < 64; state++) {
45+
var newchar = this.encode_value_to_character(state);
46+
console.log('test_all_states: newchar: ' + newchar + ' - togglestate:' + this.togglestate);
47+
48+
//M.util.set_user_preference('topcoll_toggle_' + state + '_' + this.courseid, this.togglestate);
49+
M.format_topcoll.set_user_preference('topcoll_toggle_a' + state + '_' + this.courseid, newchar);
50+
M.format_topcoll.set_user_preference('topcoll_toggle_b' + state + '_' + this.courseid, newchar + ':');
51+
M.format_topcoll.set_user_preference('topcoll_toggle_c' + state + '_' + this.courseid, ':' + newchar);
52+
}
53+
console.log('test_all_states: end loop.');
54+
console.log('test_all_states: start invalid data.');
55+
M.format_topcoll.set_user_preference('topcoll_toggle_bf_' + this.courseid, '9');
56+
M.format_topcoll.set_user_preference('topcoll_toggle_af_' + this.courseid, 'z');
57+
M.format_topcoll.set_user_preference('topcoll_toggle_bf2_' + this.courseid, '9:');
58+
M.format_topcoll.set_user_preference('topcoll_toggle_af2_' + this.courseid, 'z:');
59+
M.format_topcoll.set_user_preference('topcoll_toggle_bf3_' + this.courseid, ':9');
60+
M.format_topcoll.set_user_preference('topcoll_toggle_af3_' + this.courseid, ':z');
61+
console.log('test_all_states: end invalid data.');
62+
};

0 commit comments

Comments
 (0)