Skip to content

Commit

Permalink
Merge branch 'MDL-67351-master_required_setting' of https://github.co…
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Jan 30, 2020
2 parents b5fc289 + 4a63a5b commit f494e9e
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 72 deletions.
6 changes: 5 additions & 1 deletion course/moodleform_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ protected function apply_admin_locked_flags() {
}

/**
* Get the list of admin settings for this module and apply any defaults/advanced/locked settings.
* Get the list of admin settings for this module and apply any defaults/advanced/locked/required settings.
*
* @param $datetimeoffsets array - If passed, this is an array of fieldnames => times that the
* default date/time value should be relative to. If not passed, all
Expand Down Expand Up @@ -1221,6 +1221,10 @@ public function apply_admin_defaults($datetimeoffsets = array()) {
if (!empty($settings->$advancedsetting)) {
$mform->setAdvanced($name);
}
$requiredsetting = $name . '_required';
if (!empty($settings->$requiredsetting)) {
$mform->addRule($name, null, 'required', null, 'client');
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@
$string['requiredentrieschanged'] = 'Note: After upgrading, the setting \'Required entries before viewing\' is now enforced in the following database activities:<br/>{$a->text}<br/>';
$string['requiremodintro'] = 'Require activity description';
$string['requiremodintro_desc'] = 'If enabled, users will be forced to enter a description for each activity.';
$string['required'] = 'Required';
$string['requires'] = 'Requires';
$string['purgecaches'] = 'Purge all caches';
$string['purgecachesconfirm'] = 'Moodle can cache themes, javascript, language strings, filtered text, rss feeds and many other pieces of calculated data. Purging these caches will delete that data from the server and force browsers to refetch data, so that you can be sure you are seeing the most up-to-date values produced by the current code. There is no danger in purging caches, but your site may appear slower for a while until the server and clients calculate new information and cache it.';
Expand Down
12 changes: 11 additions & 1 deletion lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,16 @@ public function set_locked_flag_options($enabled, $default) {
$this->set_flag_options($enabled, $default, 'locked', new lang_string('locked', 'core_admin'));
}

/**
* Set the required options flag on this admin setting.
*
* @param bool $enabled - One of self::OPTION_ENABLED or self::OPTION_DISABLED.
* @param bool $default - The default for the flag.
*/
public function set_required_flag_options($enabled, $default) {
$this->set_flag_options($enabled, $default, 'required', new lang_string('required', 'core_admin'));
}

/**
* Get the currently saved value for a setting flag
*
Expand Down Expand Up @@ -2074,7 +2084,7 @@ public function get_dependent_on() {

/**
* An additional option that can be applied to an admin setting.
* The currently supported options are 'ADVANCED' and 'LOCKED'.
* The currently supported options are 'ADVANCED', 'LOCKED' and 'REQUIRED'.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down
6 changes: 6 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ information provided here is intended especially for developers.
incompatible takes a single int corresponding to the first incompatible branch. Any Moodle versions including and
above this will be prevented from installing the plugin, and a message will be given when attempting installation.
* Added the <component>_bulk_user_actions() callback which returns a list of custom action_links objects
* Add 'required' admin flag for mod forms allows elements to be toggled between being required or not in admin settings.
- In mod settings, along with lock, advanced flags, the required flag can now be set with $setting->set_required_flag_options().
The name of the admin setting must be exactly the same as the mod_form element.
- Currently supported by:
- mod_assign
- mod_quiz

=== 3.8 ===
* Add CLI option to notify all cron tasks to stop: admin/cli/cron.php --stop
Expand Down
40 changes: 1 addition & 39 deletions mod/quiz/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,11 @@ protected function definition() {
$mform->addElement('duration', 'timelimit', get_string('timelimit', 'quiz'),
array('optional' => true));
$mform->addHelpButton('timelimit', 'timelimit', 'quiz');
$mform->setAdvanced('timelimit', $quizconfig->timelimit_adv);
$mform->setDefault('timelimit', $quizconfig->timelimit);

// What to do with overdue attempts.
$mform->addElement('select', 'overduehandling', get_string('overduehandling', 'quiz'),
quiz_get_overdue_handling_options());
$mform->addHelpButton('overduehandling', 'overduehandling', 'quiz');
$mform->setAdvanced('overduehandling', $quizconfig->overduehandling_adv);
$mform->setDefault('overduehandling', $quizconfig->overduehandling);
// TODO Formslib does OR logic on disableif, and we need AND logic here.
// $mform->disabledIf('overduehandling', 'timelimit', 'eq', 0);
// $mform->disabledIf('overduehandling', 'timeclose', 'eq', 0);
Expand All @@ -111,8 +107,6 @@ protected function definition() {
$mform->addElement('duration', 'graceperiod', get_string('graceperiod', 'quiz'),
array('optional' => true));
$mform->addHelpButton('graceperiod', 'graceperiod', 'quiz');
$mform->setAdvanced('graceperiod', $quizconfig->graceperiod_adv);
$mform->setDefault('graceperiod', $quizconfig->graceperiod);
$mform->hideIf('graceperiod', 'overduehandling', 'neq', 'graceperiod');

// -------------------------------------------------------------------------------
Expand All @@ -135,15 +129,11 @@ protected function definition() {
}
$mform->addElement('select', 'attempts', get_string('attemptsallowed', 'quiz'),
$attemptoptions);
$mform->setAdvanced('attempts', $quizconfig->attempts_adv);
$mform->setDefault('attempts', $quizconfig->attempts);

// Grading method.
$mform->addElement('select', 'grademethod', get_string('grademethod', 'quiz'),
quiz_get_grading_options());
$mform->addHelpButton('grademethod', 'grademethod', 'quiz');
$mform->setAdvanced('grademethod', $quizconfig->grademethod_adv);
$mform->setDefault('grademethod', $quizconfig->grademethod);
if ($this->get_max_attempts_for_any_override() < 2) {
$mform->hideIf('grademethod', 'attempts', 'eq', 1);
}
Expand All @@ -154,7 +144,6 @@ protected function definition() {
$pagegroup = array();
$pagegroup[] = $mform->createElement('select', 'questionsperpage',
get_string('newpage', 'quiz'), quiz_questions_per_page_options(), array('id' => 'id_questionsperpage'));
$mform->setDefault('questionsperpage', $quizconfig->questionsperpage);

if (!empty($this->_cm)) {
$pagegroup[] = $mform->createElement('checkbox', 'repaginatenow', '',
Expand All @@ -164,23 +153,18 @@ protected function definition() {
$mform->addGroup($pagegroup, 'questionsperpagegrp',
get_string('newpage', 'quiz'), null, false);
$mform->addHelpButton('questionsperpagegrp', 'newpage', 'quiz');
$mform->setAdvanced('questionsperpagegrp', $quizconfig->questionsperpage_adv);

// Navigation method.
$mform->addElement('select', 'navmethod', get_string('navmethod', 'quiz'),
quiz_get_navigation_options());
$mform->addHelpButton('navmethod', 'navmethod', 'quiz');
$mform->setAdvanced('navmethod', $quizconfig->navmethod_adv);
$mform->setDefault('navmethod', $quizconfig->navmethod);

// -------------------------------------------------------------------------------
$mform->addElement('header', 'interactionhdr', get_string('questionbehaviour', 'quiz'));

// Shuffle within questions.
$mform->addElement('selectyesno', 'shuffleanswers', get_string('shufflewithin', 'quiz'));
$mform->addHelpButton('shuffleanswers', 'shufflewithin', 'quiz');
$mform->setAdvanced('shuffleanswers', $quizconfig->shuffleanswers_adv);
$mform->setDefault('shuffleanswers', $quizconfig->shuffleanswers);

// How questions behave (question behaviour).
if (!empty($this->current->preferredbehaviour)) {
Expand All @@ -192,14 +176,11 @@ protected function definition() {
$mform->addElement('select', 'preferredbehaviour',
get_string('howquestionsbehave', 'question'), $behaviours);
$mform->addHelpButton('preferredbehaviour', 'howquestionsbehave', 'question');
$mform->setDefault('preferredbehaviour', $quizconfig->preferredbehaviour);

// Can redo completed questions.
$redochoices = array(0 => get_string('no'), 1 => get_string('canredoquestionsyes', 'quiz'));
$mform->addElement('select', 'canredoquestions', get_string('canredoquestions', 'quiz'), $redochoices);
$mform->addHelpButton('canredoquestions', 'canredoquestions', 'quiz');
$mform->setAdvanced('canredoquestions', $quizconfig->canredoquestions_adv);
$mform->setDefault('canredoquestions', $quizconfig->canredoquestions);
foreach ($behaviours as $behaviour => $notused) {
if (!question_engine::can_questions_finish_during_the_attempt($behaviour)) {
$mform->hideIf('canredoquestions', 'preferredbehaviour', 'eq', $behaviour);
Expand All @@ -210,8 +191,6 @@ protected function definition() {
$mform->addElement('selectyesno', 'attemptonlast',
get_string('eachattemptbuildsonthelast', 'quiz'));
$mform->addHelpButton('attemptonlast', 'eachattemptbuildsonthelast', 'quiz');
$mform->setAdvanced('attemptonlast', $quizconfig->attemptonlast_adv);
$mform->setDefault('attemptonlast', $quizconfig->attemptonlast);
if ($this->get_max_attempts_for_any_override() < 2) {
$mform->hideIf('attemptonlast', 'attempts', 'eq', 1);
}
Expand Down Expand Up @@ -253,8 +232,6 @@ protected function definition() {
$mform->addElement('select', 'showuserpicture', get_string('showuserpicture', 'quiz'),
quiz_get_user_image_options());
$mform->addHelpButton('showuserpicture', 'showuserpicture', 'quiz');
$mform->setAdvanced('showuserpicture', $quizconfig->showuserpicture_adv);
$mform->setDefault('showuserpicture', $quizconfig->showuserpicture);

// Overall decimal points.
$options = array();
Expand All @@ -264,8 +241,6 @@ protected function definition() {
$mform->addElement('select', 'decimalpoints', get_string('decimalplaces', 'quiz'),
$options);
$mform->addHelpButton('decimalpoints', 'decimalplaces', 'quiz');
$mform->setAdvanced('decimalpoints', $quizconfig->decimalpoints_adv);
$mform->setDefault('decimalpoints', $quizconfig->decimalpoints);

// Question decimal points.
$options = array(-1 => get_string('sameasoverall', 'quiz'));
Expand All @@ -275,14 +250,10 @@ protected function definition() {
$mform->addElement('select', 'questiondecimalpoints',
get_string('decimalplacesquestion', 'quiz'), $options);
$mform->addHelpButton('questiondecimalpoints', 'decimalplacesquestion', 'quiz');
$mform->setAdvanced('questiondecimalpoints', $quizconfig->questiondecimalpoints_adv);
$mform->setDefault('questiondecimalpoints', $quizconfig->questiondecimalpoints);

// Show blocks during quiz attempt.
$mform->addElement('selectyesno', 'showblocks', get_string('showblocks', 'quiz'));
$mform->addHelpButton('showblocks', 'showblocks', 'quiz');
$mform->setAdvanced('showblocks', $quizconfig->showblocks_adv);
$mform->setDefault('showblocks', $quizconfig->showblocks);

// -------------------------------------------------------------------------------
$mform->addElement('header', 'security', get_string('extraattemptrestrictions', 'quiz'));
Expand All @@ -291,31 +262,23 @@ protected function definition() {
$mform->addElement('passwordunmask', 'quizpassword', get_string('requirepassword', 'quiz'));
$mform->setType('quizpassword', PARAM_TEXT);
$mform->addHelpButton('quizpassword', 'requirepassword', 'quiz');
$mform->setAdvanced('quizpassword', $quizconfig->password_adv);
$mform->setDefault('quizpassword', $quizconfig->password);

// IP address.
$mform->addElement('text', 'subnet', get_string('requiresubnet', 'quiz'));
$mform->setType('subnet', PARAM_TEXT);
$mform->addHelpButton('subnet', 'requiresubnet', 'quiz');
$mform->setAdvanced('subnet', $quizconfig->subnet_adv);
$mform->setDefault('subnet', $quizconfig->subnet);

// Enforced time delay between quiz attempts.
$mform->addElement('duration', 'delay1', get_string('delay1st2nd', 'quiz'),
array('optional' => true));
$mform->addHelpButton('delay1', 'delay1st2nd', 'quiz');
$mform->setAdvanced('delay1', $quizconfig->delay1_adv);
$mform->setDefault('delay1', $quizconfig->delay1);
if ($this->get_max_attempts_for_any_override() < 2) {
$mform->hideIf('delay1', 'attempts', 'eq', 1);
}

$mform->addElement('duration', 'delay2', get_string('delaylater', 'quiz'),
array('optional' => true));
$mform->addHelpButton('delay2', 'delaylater', 'quiz');
$mform->setAdvanced('delay2', $quizconfig->delay2_adv);
$mform->setDefault('delay2', $quizconfig->delay2);
if ($this->get_max_attempts_for_any_override() < 3) {
$mform->hideIf('delay2', 'attempts', 'eq', 1);
$mform->hideIf('delay2', 'attempts', 'eq', 2);
Expand All @@ -325,8 +288,6 @@ protected function definition() {
$mform->addElement('select', 'browsersecurity', get_string('browsersecurity', 'quiz'),
quiz_access_manager::get_browser_security_choices());
$mform->addHelpButton('browsersecurity', 'browsersecurity', 'quiz');
$mform->setAdvanced('browsersecurity', $quizconfig->browsersecurity_adv);
$mform->setDefault('browsersecurity', $quizconfig->browsersecurity);

// Any other rule plugins.
quiz_access_manager::add_settings_form_fields($this, $mform);
Expand Down Expand Up @@ -400,6 +361,7 @@ protected function definition() {
$mform->setDefault('grade', $quizconfig->maximumgrade);

// -------------------------------------------------------------------------------
$this->apply_admin_defaults();
$this->add_action_buttons();

$PAGE->requires->yui_module('moodle-mod_quiz-modform', 'M.mod_quiz.modform.init');
Expand Down
Loading

0 comments on commit f494e9e

Please sign in to comment.