Skip to content

Commit

Permalink
V2.5.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Aug 18, 2014
1 parent 285f866 commit 4a981a9
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 16 deletions.
5 changes: 4 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ can be really useful in visualising the issue along with any files you consider

Version Information
===================
18th August 2014 Version 2.5.3.9
1. Fixed CONTRIB-5211: Section 5 does not remain expanded when browsing away and back.

16th January 2014 Version 2.5.3.8
1. Fixed Essential theme overriding toggle text colour - see: https://moodle.org/mod/forum/discuss.php?d=251951.
2. Fixed bullet point styles - see: https://moodle.org/mod/forum/discuss.php?d=251944.
Expand Down Expand Up @@ -1082,6 +1085,6 @@ Desired Enhancements

Me
==
G J Barnard MSc. BSc(Hons)(Sndw). MBCS. CEng. CITP. PGCE. - 16th January 2014.
G J Barnard MSc. BSc(Hons)(Sndw). MBCS. CEng. CITP. PGCE. - 18th August 2014.
Moodle profile: http://moodle.org/user/profile.php?id=442195.
Web profile : http://about.me/gjbarnard
2 changes: 1 addition & 1 deletion db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function xmldb_format_topcoll_upgrade($oldversion = 0) {
}

// Automatic 'Purge all caches'....
if ($oldversion < 2013110502) {
if ($oldversion < 2114052000) {
purge_all_caches();
}

Expand Down
4 changes: 2 additions & 2 deletions format.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @copyright &copy; 2009-onwards G J Barnard in respect to modifications of standard topics format.
* @author G J Barnard - gjbarnard at gmail dot com and {@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 Public License
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
defined('MOODLE_INTERNAL') || die();
Expand Down Expand Up @@ -85,7 +85,7 @@
if (!empty($displaysection)) {
$renderer->print_single_section_page($course, null, null, null, null, $displaysection);
} else {
user_preference_allow_ajax_update('topcoll_toggle_' . $course->id, PARAM_TEXT);
user_preference_allow_ajax_update('topcoll_toggle_' . $course->id, PARAM_TOPCOLL);
$userpreference = get_user_preferences('topcoll_toggle_' . $course->id);
$renderer->set_user_preference($userpreference);

Expand Down
41 changes: 36 additions & 5 deletions module.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ M.format_topcoll.to2baseString = function(thirtysix) {
M.format_topcoll.save_toggles = function() {
"use strict";
if (this.togglePersistence == 1) { // Toggle persistence - 1 = on, 0 = off.
M.util.set_user_preference('topcoll_toggle_'+this.courseid , this.togglestate);
M.format_topcoll.set_user_preference('topcoll_toggle_' + this.courseid, this.togglestate);
}
};

Expand Down Expand Up @@ -249,7 +249,6 @@ M.format_topcoll.set_toggle_state = function(togglenum, state) {
value &= ~toggleflag;
}
var newchar = this.encode_value_to_character(value);
//this.togglestate[togglecharpos-1] = newchar;
var start = this.togglestate.substring(0,togglecharpos-1);
var end = this.togglestate.substring(togglecharpos);
this.togglestate = start + newchar + end;
Expand All @@ -267,12 +266,12 @@ M.format_topcoll.get_toggle_pos = function(togglenum) {

M.format_topcoll.get_min_digit = function() {
"use strict";
return ':';
return ':'; // 58 ':';
};

M.format_topcoll.get_max_digit = function() {
"use strict";
return 'y';
return 'y'; // 58 'y';
};

M.format_topcoll.get_toggle_flag = function(togglenum, togglecharpos) {
Expand Down Expand Up @@ -310,4 +309,36 @@ M.format_topcoll.decode_character_to_value = function(character) {
M.format_topcoll.encode_value_to_character = function(val) {
"use strict";
return String.fromCharCode(val + 58);
};
};

/**
* Makes a best effort to connect back to Moodle to update a user preference,
* however, there is no mechanism for finding out if the update succeeded.
*
* Before you can use this function in your JavsScript, you must have called
* user_preference_allow_ajax_update from moodlelib.php to tell Moodle that
* the update is allowed, and how to safely clean and submitted values.
*
* @param String name the name of the setting to update.
* @param String the value to set it to.
*/
M.format_topcoll.set_user_preference = function(name, value) {
YUI().use('io', function(Y) {
var url = M.cfg.wwwroot + '/course/format/topcoll/settopcollpref.php?sesskey=' +
M.cfg.sesskey + '&pref=' + encodeURI(name) + '&value=' + encodeURI(value);

// If we are a developer, ensure that failures are reported.
var cfg = {
method: 'get',
on: {}
};
if (M.cfg.developerdebug) {
cfg.on.failure = function(id, o, args) {
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: ");
}
}

// Make the request.
Y.io(url, cfg);
});
};
54 changes: 54 additions & 0 deletions settopcollpref.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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/>.

/**
* Code to update a user preference in response to an ajax call.
*
* You should not send requests to this script directly. Instead use the set_user_preference
* function in /course/format/topcol/module.js.
*
* @package course/format
* @subpackage topcoll
* @version See the value of '$plugin->version' in below.
* @copyright &copy; 2014-onwards G J Barnard based upon code originally written by Tim Hunt.
* @author G J Barnard - gjbarnard at gmail dot com and {@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
*/

require_once(dirname(__FILE__) . '/../../../config.php');
require_once($CFG->dirroot . '/course/format/topcoll/togglelib.php');

// Check access.
if (!confirm_sesskey()) {
print_error('invalidsesskey');
}

// Get the name of the preference to update, and check that it is allowed.
$name = required_param('pref', PARAM_RAW);
if (!isset($USER->ajax_updatable_user_prefs[$name])) {
print_error('notallowedtoupdateprefremotely');
}

// Get and set the value.
$value = required_topcoll_param('value', $USER->ajax_updatable_user_prefs[$name]);
error_log($name.' is before: '.$USER->ajax_updatable_user_prefs[$name].' after: '.$value);
// Update
if (!set_user_preference($name, $value)) {
print_error('errorsettinguserpref');
}

echo 'OK';
57 changes: 57 additions & 0 deletions test/format_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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 below.
* @copyright &copy; 2014-onwards G J Barnard in respect to modifications of standard topics format.
* @author G J Barnard - gjbarnard at gmail dot com and {@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->dirroot . '/course/format/topcoll/togglelib.php');

$run = false;
if ($run) {
// TEST CODE.
for ($i = 0; $i < 64; $i++) {
user_preference_allow_ajax_update('topcoll_toggle_a'.$i.'_' . $course->id, PARAM_TOPCOLL);
user_preference_allow_ajax_update('topcoll_toggle_b'.$i.'_' . $course->id, PARAM_TOPCOLL);
user_preference_allow_ajax_update('topcoll_toggle_c'.$i.'_' . $course->id, PARAM_TOPCOLL);
}
user_preference_allow_ajax_update('topcoll_toggle_bf_' . $course->id, PARAM_TOPCOLL);
user_preference_allow_ajax_update('topcoll_toggle_bf2_' . $course->id, PARAM_TOPCOLL);
user_preference_allow_ajax_update('topcoll_toggle_bf3_' . $course->id, PARAM_TOPCOLL);
user_preference_allow_ajax_update('topcoll_toggle_af_' . $course->id, PARAM_TOPCOLL);
user_preference_allow_ajax_update('topcoll_toggle_af2_' . $course->id, PARAM_TOPCOLL);
user_preference_allow_ajax_update('topcoll_toggle_af3_' . $course->id, PARAM_TOPCOLL);
// Test clean_param to see if it accepts '<' and '>' for PARAM_TEXT as stated in moodlelib.php.
echo '<h3>PARAM_TEXT < : '.clean_param('<',PARAM_TEXT).'</h3>';
echo '<h3>PARAM_TEXT > : '.clean_param('>',PARAM_TEXT).'</h3>';
echo '<h3>PARAM_RAW < : '.clean_param('<',PARAM_RAW).'</h3>';
echo '<h3>PARAM_RAW > : '.clean_param('>',PARAM_RAW).'</h3>';
}
62 changes: 62 additions & 0 deletions test/module_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* 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 &copy; 2014-onwards G J Barnard in respect to modifications of standard topics format.
* @author G J Barnard - gjbarnard at gmail dot com and {@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 Public License
*
* This program 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.
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/

M.format_topcoll.test_all_states = function() {
"use strict";
// Reset for this course.
console.log('test_all_states: togglestate:' + this.togglestate);
console.log('test_all_states: reset course.');
M.format_topcoll.resetState(M.format_topcoll.get_min_digit());
M.format_topcoll.save_toggles();
console.log('test_all_states: togglestate:' + this.togglestate);

// Loop through all possible states, this involves the first twelve toggles.
console.log('test_all_states: start loop.');
var state = 0;

for (state = 0; state < 64; state++) {
var newchar = this.encode_value_to_character(state);
console.log('test_all_states: newchar: ' + newchar + ' - togglestate:' + this.togglestate);

//M.util.set_user_preference('topcoll_toggle_' + state + '_' + this.courseid, this.togglestate);
M.format_topcoll.set_user_preference('topcoll_toggle_a' + state + '_' + this.courseid, newchar);
M.format_topcoll.set_user_preference('topcoll_toggle_b' + state + '_' + this.courseid, newchar + ':');
M.format_topcoll.set_user_preference('topcoll_toggle_c' + state + '_' + this.courseid, ':' + newchar);
}
console.log('test_all_states: end loop.');
console.log('test_all_states: start invalid data.');
M.format_topcoll.set_user_preference('topcoll_toggle_bf_' + this.courseid, '9');
M.format_topcoll.set_user_preference('topcoll_toggle_af_' + this.courseid, 'z');
M.format_topcoll.set_user_preference('topcoll_toggle_bf2_' + this.courseid, '9:');
M.format_topcoll.set_user_preference('topcoll_toggle_af2_' + this.courseid, 'z:');
M.format_topcoll.set_user_preference('topcoll_toggle_bf3_' + this.courseid, ':9');
M.format_topcoll.set_user_preference('topcoll_toggle_af3_' + this.courseid, ':z');
console.log('test_all_states: end invalid data.');
};
Loading

0 comments on commit 4a981a9

Please sign in to comment.