MDL-29627 quiz old popup int column => new browsersecurity column.

The new column store more meaningful string constants.
This commit is contained in:
Tim Hunt 2011-10-06 20:15:01 +01:00
parent 0eafc98852
commit 4344c5d5d9
15 changed files with 170 additions and 46 deletions

View file

@ -116,7 +116,7 @@ class quiz_access_manager {
* @return array key => lang string. * @return array key => lang string.
*/ */
public static function get_browser_security_choices() { public static function get_browser_security_choices() {
$options = array(0 => get_string('none', 'quiz')); $options = array('-' => get_string('none', 'quiz'));
foreach (self::get_rule_classes() as $rule) { foreach (self::get_rule_classes() as $rule) {
$options += $rule::get_browser_security_choices(); $options += $rule::get_browser_security_choices();
} }

View file

@ -39,7 +39,7 @@ class quizaccess_safebrowser extends quiz_access_rule_base {
public static function make(quiz $quizobj, $timenow, $canignoretimelimits) { public static function make(quiz $quizobj, $timenow, $canignoretimelimits) {
if ($quizobj->get_quiz()->popup != 2) { if ($quizobj->get_quiz()->browsersecurity !== 'safebrowser') {
return null; return null;
} }
@ -83,6 +83,6 @@ class quizaccess_safebrowser extends quiz_access_rule_base {
return array(); return array();
} }
return array(2 => get_string('requiresafeexambrowser', 'quiz')); return array('safebrowser' => get_string('requiresafeexambrowser', 'quiz'));
} }
} }

View file

@ -41,7 +41,7 @@ class quizaccess_safebrowser_test extends UnitTestCase {
// Nothing very testable in this class, just test that it obeys the general access rule contact. // Nothing very testable in this class, just test that it obeys the general access rule contact.
public function test_safebrowser_access_rule() { public function test_safebrowser_access_rule() {
$quiz = new stdClass(); $quiz = new stdClass();
$quiz->popup = 1; $quiz->browsersecurity = 'safebrowser';
$quiz->questions = ''; $quiz->questions = '';
$cm = new stdClass(); $cm = new stdClass();
$cm->id = 0; $cm->id = 0;

View file

@ -54,7 +54,7 @@ class quizaccess_securewindow extends quiz_access_rule_base {
public static function make(quiz $quizobj, $timenow, $canignoretimelimits) { public static function make(quiz $quizobj, $timenow, $canignoretimelimits) {
if ($quizobj->get_quiz()->popup != 1) { if ($quizobj->get_quiz()->browsersecurity !== 'securewindow') {
return null; return null;
} }
@ -89,6 +89,6 @@ class quizaccess_securewindow extends quiz_access_rule_base {
* security settings menu. * security settings menu.
*/ */
public static function get_browser_security_choices() { public static function get_browser_security_choices() {
return array(1 => get_string('popupwithjavascriptsupport', 'quiz')); return array('securewindow' => get_string('popupwithjavascriptsupport', 'quiz'));
} }
} }

View file

@ -41,7 +41,7 @@ class quizaccess_securewindow_test extends UnitTestCase {
// Nothing very testable in this class, just test that it obeys the general access rule contact. // Nothing very testable in this class, just test that it obeys the general access rule contact.
public function test_securewindow_access_rule() { public function test_securewindow_access_rule() {
$quiz = new stdClass(); $quiz = new stdClass();
$quiz->popup = 1; $quiz->browsersecurity = 'securewindow';
$quiz->questions = ''; $quiz->questions = '';
$cm = new stdClass(); $cm = new stdClass();
$cm->id = 0; $cm->id = 0;

View file

@ -49,7 +49,7 @@ class backup_quiz_activity_structure_step extends backup_questions_activity_stru
'questionsperpage', 'shufflequestions', 'shuffleanswers', 'questionsperpage', 'shufflequestions', 'shuffleanswers',
'questions', 'sumgrades', 'grade', 'timecreated', 'questions', 'sumgrades', 'grade', 'timecreated',
'timemodified', 'timelimit', 'password', 'subnet', 'timemodified', 'timelimit', 'password', 'subnet',
'popup', 'delay1', 'delay2', 'showuserpicture', 'browsersecurity', 'delay1', 'delay2', 'showuserpicture',
'showblocks')); 'showblocks'));
$qinstances = new backup_nested_element('question_instances'); $qinstances = new backup_nested_element('question_instances');

View file

@ -195,6 +195,21 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
mod_quiz_display_options::AFTER_CLOSE : 0); mod_quiz_display_options::AFTER_CLOSE : 0);
} }
// The old popup column from from <= 2.1 need to be mapped to
// the new browsersecurity. MDL-29627
if (!isset($data->browsersecurity)) {
if (empty($data->popup)) {
$data->browsersecurity = '-';
} else if ($data->popup == 1) {
$data->browsersecurity = 'securewindow';
} else if ($data->popup == 2) {
$data->browsersecurity = 'safebrowser';
} else {
$data->preferredbehaviour = '-';
}
unset($data->popup);
}
// insert the quiz record // insert the quiz record
$newitemid = $DB->insert_record('quiz', $data); $newitemid = $DB->insert_record('quiz', $data);
// immediately after inserting "activity" record, call this // immediately after inserting "activity" record, call this

View file

@ -36,9 +36,9 @@
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated" NEXT="timelimit"/> <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated" NEXT="timelimit"/>
<FIELD NAME="timelimit" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timemodified" NEXT="password"/> <FIELD NAME="timelimit" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timemodified" NEXT="password"/>
<FIELD NAME="password" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="timelimit" NEXT="subnet"/> <FIELD NAME="password" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="timelimit" NEXT="subnet"/>
<FIELD NAME="subnet" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="password" NEXT="popup"/> <FIELD NAME="subnet" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="password" NEXT="browsersecurity"/>
<FIELD NAME="popup" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="subnet" NEXT="delay1"/> <FIELD NAME="browsersecurity" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" PREVIOUS="subnet" NEXT="delay1"/>
<FIELD NAME="delay1" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="popup" NEXT="delay2"/> <FIELD NAME="delay1" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="browsersecurity" NEXT="delay2"/>
<FIELD NAME="delay2" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="delay1" NEXT="showuserpicture"/> <FIELD NAME="delay2" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="delay1" NEXT="showuserpicture"/>
<FIELD NAME="showuserpicture" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Option to show the user's picture during the attempt and on the review page." PREVIOUS="delay2" NEXT="showblocks"/> <FIELD NAME="showuserpicture" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Option to show the user's picture during the attempt and on the review page." PREVIOUS="delay2" NEXT="showblocks"/>
<FIELD NAME="showblocks" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Whether blocks should be shown on the attempt.php and review.php pages." PREVIOUS="showuserpicture"/> <FIELD NAME="showblocks" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Whether blocks should be shown on the attempt.php and review.php pages." PREVIOUS="showuserpicture"/>

View file

@ -1121,6 +1121,76 @@ function xmldb_quiz_upgrade($oldversion) {
// Moodle v2.1.0 release upgrade line // Moodle v2.1.0 release upgrade line
// Put any upgrade step following this // Put any upgrade step following this
if ($oldversion < 2011100600) {
// Define field browsersecurity to be added to quiz
$table = new xmldb_table('quiz');
$field = new xmldb_field('browsersecurity', XMLDB_TYPE_CHAR, '32', null,
XMLDB_NOTNULL, null, '[unknownvalue]', 'subnet');
// Conditionally launch add field browsersecurity
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// quiz savepoint reached
upgrade_mod_savepoint(true, 2011100600, 'quiz');
}
if ($oldversion < 2011100601) {
$DB->set_field('quiz', 'browsersecurity', '-', array('popup' => 0));
$DB->set_field('quiz', 'browsersecurity', 'securewindow', array('popup' => 1));
$DB->set_field('quiz', 'browsersecurity', 'safebrowser', array('popup' => 2));
upgrade_mod_savepoint(true, 2011100601, 'quiz');
}
if ($oldversion < 2011100602) {
// Changing the default of field browsersecurity on table quiz to drop it
$table = new xmldb_table('quiz');
$field = new xmldb_field('browsersecurity', XMLDB_TYPE_CHAR, '32', null,
XMLDB_NOTNULL, null, null, 'subnet');
// Launch change of default for field browsersecurity
$dbman->change_field_default($table, $field);
// quiz savepoint reached
upgrade_mod_savepoint(true, 2011100602, 'quiz');
}
if ($oldversion < 2011100603) {
// Define field popup to be dropped from quiz
$table = new xmldb_table('quiz');
$field = new xmldb_field('popup');
// Conditionally launch drop field popup
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// quiz savepoint reached
upgrade_mod_savepoint(true, 2011100603, 'quiz');
}
if ($oldversion < 2011100604) {
switch (get_config('quiz', 'popup')) {
case 1:
set_config('browsersecurity', 'securewindow', 'quiz');
case 2:
set_config('browsersecurity', 'safebrowser', 'quiz');
default:
set_config('browsersecurity', '-', 'quiz');
}
unset_config('quiz', 'popup');
set_config('browsersecurity_adv', get_config('quiz', 'popup_adv'), 'quiz');
unset_config('quiz', 'popup_adv');
upgrade_mod_savepoint(true, 2011100604, 'quiz');
}
return true; return true;
} }

View file

@ -42,6 +42,16 @@ define('QUIZ_MAX_DECIMAL_OPTION', 5);
define('QUIZ_MAX_Q_DECIMAL_OPTION', 7); define('QUIZ_MAX_Q_DECIMAL_OPTION', 7);
/**#@-*/ /**#@-*/
/**#@+
* Options determining how the grades from individual attempts are combined to give
* the overall grade for a user
*/
define('QUIZ_GRADEHIGHEST', '1');
define('QUIZ_GRADEAVERAGE', '2');
define('QUIZ_ATTEMPTFIRST', '3');
define('QUIZ_ATTEMPTLAST', '4');
/**#@-*/
/** /**
* If start and end date for the quiz are more than this many seconds apart * If start and end date for the quiz are more than this many seconds apart
* they will be represented by two separate events in the calendar * they will be represented by two separate events in the calendar

View file

@ -41,16 +41,6 @@ require_once($CFG->libdir . '/eventslib.php');
require_once($CFG->libdir . '/filelib.php'); require_once($CFG->libdir . '/filelib.php');
/**#@+
* Options determining how the grades from individual attempts are combined to give
* the overall grade for a user
*/
define('QUIZ_GRADEHIGHEST', '1');
define('QUIZ_GRADEAVERAGE', '2');
define('QUIZ_ATTEMPTFIRST', '3');
define('QUIZ_ATTEMPTLAST', '4');
/**#@-*/
/** /**
* We show the countdown timer if there is less than this amount of time left before the * We show the countdown timer if there is less than this amount of time left before the
* the quiz close date. (1 hour) * the quiz close date. (1 hour)

View file

@ -282,11 +282,11 @@ class mod_quiz_mod_form extends moodleform_mod {
$mform->disabledIf('delay2', 'attempts', 'eq', 2); $mform->disabledIf('delay2', 'attempts', 'eq', 2);
// 'Secure' window. // 'Secure' window.
$mform->addElement('select', 'popup', get_string('browsersecurity', 'quiz'), $mform->addElement('select', 'browsersecurity', get_string('browsersecurity', 'quiz'),
quiz_access_manager::get_browser_security_choices()); quiz_access_manager::get_browser_security_choices());
$mform->addHelpButton('popup', 'browsersecurity', 'quiz'); $mform->addHelpButton('browsersecurity', 'browsersecurity', 'quiz');
$mform->setAdvanced('popup', $quizconfig->popup_adv); $mform->setAdvanced('browsersecurity', $quizconfig->browsersecurity_adv);
$mform->setDefault('popup', $quizconfig->popup); $mform->setDefault('browsersecurity', $quizconfig->browsersecurity);
// Any other rule plugins. // Any other rule plugins.
quiz_access_manager::add_settings_form_fields($this, $mform); quiz_access_manager::add_settings_form_fields($this, $mform);

View file

@ -27,26 +27,17 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/quiz/lib.php'); require_once($CFG->dirroot . '/mod/quiz/lib.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
require_once($CFG->dirroot . '/mod/quiz/settingslib.php'); require_once($CFG->dirroot . '/mod/quiz/settingslib.php');
// First get a list of quiz reports with there own settings pages. If there none, // First get a list of quiz reports with there own settings pages. If there none,
// we use a simpler overall menu structure. // we use a simpler overall menu structure.
$reports = get_plugin_list_with_file('quiz', 'settings.php', false);
$reportsbyname = array(); $reportsbyname = array();
if ($reports = get_plugin_list('quiz')) { foreach ($reports as $report => $reportdir) {
foreach ($reports as $report => $reportdir) { $strreportname = get_string($report . 'report', 'quiz_'.$report);
if (file_exists("$reportdir/settings.php")) { $reportsbyname[$strreportname] = $report;
$strreportname = get_string($report . 'report', 'quiz_'.$report);
// Deal with reports which are lacking the language string
if ($strreportname[0] == '[') {
$textlib = textlib_get_instance();
$strreportname = $textlib->strtotitle($report . ' report');
}
$reportsbyname[$strreportname] = $report;
}
}
ksort($reportsbyname);
} }
ksort($reportsbyname);
// Create the quiz settings page. // Create the quiz settings page.
if (empty($reportsbyname)) { if (empty($reportsbyname)) {
@ -74,9 +65,9 @@ $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/attempts',
array('value' => 0, 'fix' => false), $options)); array('value' => 0, 'fix' => false), $options));
// Grading method. // Grading method.
$quizsettings->add(new admin_setting_configselect_with_advanced('quiz/grademethod', $quizsettings->add(new mod_quiz_admin_setting_grademethod('quiz/grademethod',
get_string('grademethod', 'quiz'), get_string('configgrademethod', 'quiz'), get_string('grademethod', 'quiz'), get_string('configgrademethod', 'quiz'),
array('value' => QUIZ_GRADEHIGHEST, 'fix' => false), quiz_get_grading_options())); array('value' => QUIZ_GRADEHIGHEST, 'fix' => false), null));
// Maximum grade // Maximum grade
$quizsettings->add(new admin_setting_configtext('quiz/maximumgrade', $quizsettings->add(new admin_setting_configtext('quiz/maximumgrade',
@ -178,9 +169,9 @@ $quizsettings->add(new admin_setting_configtext_with_advanced('quiz/delay2',
array('value' => 0, 'fix' => true), PARAM_INTEGER)); array('value' => 0, 'fix' => true), PARAM_INTEGER));
// 'Secure' window. // 'Secure' window.
$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/popup', $quizsettings->add(new mod_quiz_admin_setting_browsersecurity('quiz/browsersecurity',
get_string('showinsecurepopup', 'quiz'), get_string('configpopup', 'quiz'), get_string('showinsecurepopup', 'quiz'), get_string('configpopup', 'quiz'),
array('value' => 0, 'adv' => true))); array('value' => '-', 'adv' => true), null));
// Now, depending on whether any reports have their own settings page, add // Now, depending on whether any reports have their own settings page, add
// the quiz setting page to the appropriate place in the tree. // the quiz setting page to the appropriate place in the tree.
@ -198,7 +189,7 @@ if (empty($reportsbyname)) {
$settings = new admin_settingpage('modsettingsquizcat'.$reportname, $settings = new admin_settingpage('modsettingsquizcat'.$reportname,
$strreportname, 'moodle/site:config', !$module->visible); $strreportname, 'moodle/site:config', !$module->visible);
if ($ADMIN->fulltree) { if ($ADMIN->fulltree) {
include($CFG->dirroot."/mod/quiz/report/$reportname/settings.php"); include($CFG->dirroot . "/mod/quiz/report/$reportname/settings.php");
} }
$ADMIN->add('modsettingsquizcat', $settings); $ADMIN->add('modsettingsquizcat', $settings);
} }

View file

@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die();
/** /**
* Quiz specific admin settings class. * Admin settings class for the quiz review opitions.
* *
* @copyright 2008 Tim Hunt * @copyright 2008 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@ -147,3 +147,51 @@ class mod_quiz_admin_review_setting extends admin_setting {
$this->description, true, '', get_string('everythingon', 'quiz'), $query); $this->description, true, '', get_string('everythingon', 'quiz'), $query);
} }
} }
/**
* Admin settings class for the quiz grading method.
*
* Just so we can lazy-load the choices.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_quiz_admin_setting_grademethod extends admin_setting_configselect_with_advanced {
public function load_choices() {
global $CFG;
if (is_array($this->choices)) {
return true;
}
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
$this->choices = quiz_get_grading_options();
return true;
}
}
/**
* Admin settings class for the quiz browser security option.
*
* Just so we can lazy-load the choices.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_quiz_admin_setting_browsersecurity extends admin_setting_configselect_with_advanced {
public function load_choices() {
global $CFG;
if (is_array($this->choices)) {
return true;
}
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
$this->choices = quiz_access_manager::get_browser_security_choices();
return true;
}
}

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$module->version = 2011070100; $module->version = 2011100604;
$module->requires = 2011060313; $module->requires = 2011060313;
$module->cron = 0; $module->cron = 0;