mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-29627 quiz access plugins can add fields to mod_form and save the data.
This commit is contained in:
parent
ea38245cfb
commit
b83c32d39f
@ -90,6 +90,31 @@ class quiz_access_manager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any form fields that the access rules require to the settings form.
|
||||
* @param mod_quiz_mod_form $quizform the quiz settings form that is being built.
|
||||
* @param MoodleQuickForm $mform the wrapped MoodleQuickForm.
|
||||
*/
|
||||
public static function add_settings_form_fields(
|
||||
mod_quiz_mod_form $quizform, MoodleQuickForm $mform) {
|
||||
$rules = get_plugin_list_with_class('quizaccess', '', 'rule.php');
|
||||
foreach ($rules as $rule) {
|
||||
$rule::add_settings_form_fields($quizform, $mform);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save any submitted settings when the quiz settings form is submitted.
|
||||
* @param object $quiz the data from the quiz form, including $quiz->id
|
||||
* which is the is of the quiz being saved.
|
||||
*/
|
||||
public static function save_settings($quiz) {
|
||||
$rules = get_plugin_list_with_class('quizaccess', '', 'rule.php');
|
||||
foreach ($rules as $rule) {
|
||||
$rule::save_settings($quiz);
|
||||
}
|
||||
}
|
||||
|
||||
protected function accumulate_messages(&$messages, $new) {
|
||||
if (is_array($new)) {
|
||||
$messages = array_merge($messages, $new);
|
||||
|
@ -106,4 +106,26 @@ abstract class quiz_access_rule_base {
|
||||
public function time_left($attempt, $timenow) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any fields that this rule requires to the quiz settings form. This
|
||||
* method is called from {@link mod_quiz_mod_form::definition()}, while the
|
||||
* security seciton is being built.
|
||||
* @param mod_quiz_mod_form $quizform the quiz settings form that is being built.
|
||||
* @param MoodleQuickForm $mform the wrapped MoodleQuickForm.
|
||||
*/
|
||||
public static function add_settings_form_fields(
|
||||
mod_quiz_mod_form $quizform, MoodleQuickForm $mform) {
|
||||
// By default do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* Save any submitted settings when the quiz settings form is submitted. This
|
||||
* is called from {@link quiz_after_add_or_update()} in lib.php.
|
||||
* @param object $quiz the data from the quiz form, including $quiz->id
|
||||
* which is the is of the quiz being saved.
|
||||
*/
|
||||
public static function save_settings($quiz) {
|
||||
// By default do nothing.
|
||||
}
|
||||
}
|
||||
|
@ -1038,6 +1038,9 @@ function quiz_after_add_or_update($quiz) {
|
||||
array('id' => $feedback->id));
|
||||
}
|
||||
|
||||
// Store any settings belonging to the access rules.
|
||||
quiz_access_manager::save_settings($quiz);
|
||||
|
||||
// Update the events relating to this quiz.
|
||||
quiz_update_events($quiz);
|
||||
|
||||
|
@ -293,6 +293,9 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
$mform->setAdvanced('popup', $quizconfig->popup_adv);
|
||||
$mform->setDefault('popup', $quizconfig->popup);
|
||||
|
||||
// Any other rule plugins.
|
||||
quiz_access_manager::add_settings_form_fields($this, $mform);
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz'));
|
||||
$mform->addHelpButton('overallfeedbackhdr', 'overallfeedback', 'quiz');
|
||||
|
Loading…
x
Reference in New Issue
Block a user