diff --git a/classes/observer.php b/classes/observer.php index 3869d86..b0ca5a9 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -79,4 +79,42 @@ public static function user_enrolment_deleted(\core\event\user_enrolment_deleted } } } + + /** + * Observer function to handle saving default settings on course creation. + * @param \core\event\course_created $event + */ + public static function course_created(\core\event\course_created $event) { + global $DB; + + $defaultsettings = get_config('local_recompletion'); + + if (!empty($defaultsettings->recompletiontype)) { + foreach ($defaultsettings as $key => $value) { + if (is_null($value) || $key === 'forcearchivecompletiondata') { + continue; + } + if ($key === 'recompletionemailbody' && !empty($value)) { + $DB->insert_record('local_recompletion_config', [ + 'course' => $event->courseid, + 'name' => 'recompletionemailbody_format', + 'value' => FORMAT_HTML]); + } + if ($key === 'recompletionschedule' && !empty($value)) { + $nextresttime = local_recompletion_calculate_schedule_time($value); + $DB->insert_record('local_recompletion_config', [ + 'course' => $event->courseid, + 'name' => 'nextresettime', + 'value' => $nextresttime]); + } + $setting = [ + 'name' => $key, + 'value' => $value, + 'course' => $event->courseid + ]; + + $DB->insert_record('local_recompletion_config', $setting); + } + } + } } diff --git a/classes/plugins/mod_assign.php b/classes/plugins/mod_assign.php index 61dd31e..b02522a 100644 --- a/classes/plugins/mod_assign.php +++ b/classes/plugins/mod_assign.php @@ -51,13 +51,15 @@ public static function editingform($mform): void { get_string('donothing', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING); $cba[] = $mform->createElement('radio', 'assign', '', get_string('extraattempt', 'local_recompletion'), LOCAL_RECOMPLETION_EXTRAATTEMPT); - $cba[] = $mform->createElement('checkbox', 'assignevent', '', get_string('assignevent', 'local_recompletion')); + $mform->addGroup($cba, 'assign', get_string('assignattempts', 'local_recompletion'), array(' '), false); $mform->addHelpButton('assign', 'assignattempts', 'local_recompletion'); + $mform->setDefault('assign', $config->assign); - $mform->setDefault('assign', $config->assignattempts); + $mform->addElement('checkbox', 'assignevent', '', get_string('assignevent', 'local_recompletion')); $mform->setDefault('assignevent', $config->assignevent); + $mform->disabledIf('assignevent', 'enable', 'notchecked'); $mform->disabledIf('assign', 'enable', 'notchecked'); } @@ -70,7 +72,7 @@ public static function settings($settings) { $choices = array(LOCAL_RECOMPLETION_NOTHING => new lang_string('donothing', 'local_recompletion'), LOCAL_RECOMPLETION_EXTRAATTEMPT => new lang_string('extraattempt', 'local_recompletion')); - $settings->add(new \admin_setting_configselect('local_recompletion/assignattempts', + $settings->add(new \admin_setting_configselect('local_recompletion/assign', new lang_string('assignattempts', 'local_recompletion'), new lang_string('assignattempts_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); diff --git a/classes/plugins/mod_choice.php b/classes/plugins/mod_choice.php index cc3c36f..221613e 100644 --- a/classes/plugins/mod_choice.php +++ b/classes/plugins/mod_choice.php @@ -54,7 +54,7 @@ public static function editingform($mform) : void { $mform->addGroup($cba, 'choice', get_string('choiceattempts', 'local_recompletion'), array(' '), false); $mform->addHelpButton('choice', 'choiceattempts', 'local_recompletion'); - $mform->setDefault('choice', $config->choiceattempts); + $mform->setDefault('choice', $config->choice); $mform->addElement('checkbox', 'archivechoice', get_string('archive', 'local_recompletion')); @@ -75,7 +75,7 @@ public static function settings($settings) { $choices = array(LOCAL_RECOMPLETION_NOTHING => new lang_string('donothing', 'local_recompletion'), LOCAL_RECOMPLETION_DELETE => new lang_string('delete', 'local_recompletion')); - $settings->add(new \admin_setting_configselect('local_recompletion/choiceattempts', + $settings->add(new \admin_setting_configselect('local_recompletion/choice', new lang_string('choiceattempts', 'local_recompletion'), new lang_string('choiceattempts_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); diff --git a/classes/plugins/mod_customcert.php b/classes/plugins/mod_customcert.php index 1a67560..edadbde 100644 --- a/classes/plugins/mod_customcert.php +++ b/classes/plugins/mod_customcert.php @@ -61,7 +61,7 @@ public static function editingform($mform): void { $mform->addGroup($cba, 'customcert', get_string('customcertcertificates', 'local_recompletion'), array(' '), false); $mform->addHelpButton('customcert', 'customcertcertificates', 'local_recompletion'); - $mform->setDefault('customcert', $config->customcertcertificates); + $mform->setDefault('customcert', $config->customcert); $mform->addElement('checkbox', 'archivecustomcert', get_string('archivecustomcertcertificates', 'local_recompletion')); @@ -94,7 +94,7 @@ public static function settings($settings) { $choices = array(LOCAL_RECOMPLETION_NOTHING => get_string('donothing', 'local_recompletion'), LOCAL_RECOMPLETION_DELETE => get_string('customcertresetcertificates', 'local_recompletion')); - $settings->add(new \admin_setting_configselect('local_recompletion/customcertcertificates', + $settings->add(new \admin_setting_configselect('local_recompletion/customcert', new lang_string('customcertcertificates', 'local_recompletion'), new lang_string('customcertcertificates_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); diff --git a/classes/plugins/mod_h5pactivity.php b/classes/plugins/mod_h5pactivity.php index c8cf831..6162acb 100644 --- a/classes/plugins/mod_h5pactivity.php +++ b/classes/plugins/mod_h5pactivity.php @@ -52,10 +52,10 @@ public static function editingform(MoodleQuickForm $mform): void { $mform->addGroup($cba, 'h5pactivity', get_string('h5pattempts', 'local_recompletion'), [' '], false); $mform->addHelpButton('h5pactivity', 'h5pattempts', 'local_recompletion'); - $mform->setDefault('h5pactivity', $config->h5pattempts); + $mform->setDefault('h5pactivity', $config->h5pactivity); $mform->addElement('checkbox', 'archiveh5pactivity', get_string('archive', 'local_recompletion')); - $mform->setDefault('archiveh5pactivity', $config->archiveh5p); + $mform->setDefault('archiveh5pactivity', $config->archiveh5pactivity); $mform->disabledIf('archiveh5pactivity', 'enable'); $mform->hideIf('archiveh5pactivity', 'h5pactivity'); @@ -73,11 +73,11 @@ public static function settings(admin_settingpage $settings): void { LOCAL_RECOMPLETION_DELETE => get_string('delete', 'local_recompletion') ]; - $settings->add(new admin_setting_configselect('local_recompletion/h5pattempts', + $settings->add(new admin_setting_configselect('local_recompletion/h5pactivity', new lang_string('h5pattempts', 'local_recompletion'), new lang_string('h5pattempts_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); - $settings->add(new admin_setting_configcheckbox('local_recompletion/archiveh5p', + $settings->add(new admin_setting_configcheckbox('local_recompletion/archiveh5pactivity', new lang_string('archiveh5p', 'local_recompletion'), '', 1)); } diff --git a/classes/plugins/mod_hotpot.php b/classes/plugins/mod_hotpot.php index d06355b..ec8cc6c 100644 --- a/classes/plugins/mod_hotpot.php +++ b/classes/plugins/mod_hotpot.php @@ -56,7 +56,7 @@ public static function editingform(MoodleQuickForm $mform): void { $mform->addGroup($cba, 'hotpot', get_string('hotpotattempts', 'local_recompletion'), [' '], false); $mform->addHelpButton('hotpot', 'hotpotattempts', 'local_recompletion'); - $mform->setDefault('hotpot', $config->hotpotattempts); + $mform->setDefault('hotpot', $config->hotpot); $mform->addElement('checkbox', 'archivehotpot', get_string('archive', 'local_recompletion')); $mform->setDefault('archivehhotpot', $config->archivehotpot); @@ -81,7 +81,7 @@ public static function settings(admin_settingpage $settings): void { LOCAL_RECOMPLETION_DELETE => get_string('delete', 'local_recompletion') ]; - $settings->add(new admin_setting_configselect('local_recompletion/hotpotattempts', + $settings->add(new admin_setting_configselect('local_recompletion/hotpot', new lang_string('hotpotattempts', 'local_recompletion'), new lang_string('hotpotattempts_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); diff --git a/classes/plugins/mod_hvp.php b/classes/plugins/mod_hvp.php index 982f5dd..c80d5f1 100644 --- a/classes/plugins/mod_hvp.php +++ b/classes/plugins/mod_hvp.php @@ -56,7 +56,7 @@ public static function editingform(MoodleQuickForm $mform): void { $mform->addGroup($cba, 'hvp', get_string('hvpattempts', 'local_recompletion'), [' '], false); $mform->addHelpButton('hvp', 'hvpattempts', 'local_recompletion'); - $mform->setDefault('hvp', $config->hvpattempts); + $mform->setDefault('hvp', $config->hvp); $mform->addElement('checkbox', 'archivehvp', get_string('archive', 'local_recompletion')); $mform->setDefault('archivehvp', $config->archivehvp); @@ -81,7 +81,7 @@ public static function settings(admin_settingpage $settings): void { LOCAL_RECOMPLETION_DELETE => get_string('delete', 'local_recompletion') ]; - $settings->add(new admin_setting_configselect('local_recompletion/hvpattempts', + $settings->add(new admin_setting_configselect('local_recompletion/hvp', new lang_string('hvpattempts', 'local_recompletion'), new lang_string('hvpattempts_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); diff --git a/classes/plugins/mod_lesson.php b/classes/plugins/mod_lesson.php index dfbf0dc..547fc5d 100644 --- a/classes/plugins/mod_lesson.php +++ b/classes/plugins/mod_lesson.php @@ -52,7 +52,7 @@ public static function editingform(MoodleQuickForm $mform): void { $mform->addGroup($cba, 'lesson', get_string('lessonattempts', 'local_recompletion'), [' '], false); $mform->addHelpButton('lesson', 'lessonattempts', 'local_recompletion'); - $mform->setDefault('lesson', $config->lessonattempts); + $mform->setDefault('lesson', $config->lesson); $mform->addElement('checkbox', 'archivelesson', get_string('archive', 'local_recompletion')); $mform->setDefault('archivelesson', $config->archivelesson); @@ -73,7 +73,7 @@ public static function settings(admin_settingpage $settings): void { LOCAL_RECOMPLETION_DELETE => get_string('delete', 'local_recompletion') ]; - $settings->add(new admin_setting_configselect('local_recompletion/lessonattempts', + $settings->add(new admin_setting_configselect('local_recompletion/lesson', new lang_string('lessonattempts', 'local_recompletion'), new lang_string('lessonattempts_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); diff --git a/classes/plugins/mod_pulse.php b/classes/plugins/mod_pulse.php index da3db3f..ba910f1 100644 --- a/classes/plugins/mod_pulse.php +++ b/classes/plugins/mod_pulse.php @@ -59,7 +59,7 @@ public static function editingform($mform): void { $mform->addGroup($cba, 'pulse', get_string('pulsenotifications', 'local_recompletion'), array(' '), false); $mform->addHelpButton('pulse', 'pulsenotifications', 'local_recompletion'); - $mform->setDefault('pulse', $config->pulsenotifications); + $mform->setDefault('pulse', $config->pulse); } /** @@ -73,7 +73,7 @@ public static function settings($settings) { } $choices = array(LOCAL_RECOMPLETION_NOTHING => get_string('donothing', 'local_recompletion'), LOCAL_RECOMPLETION_DELETE => get_string('pulseresetnotifications', 'local_recompletion')); - $settings->add(new \admin_setting_configselect('local_recompletion/pulsenotifications', + $settings->add(new \admin_setting_configselect('local_recompletion/pulse', new lang_string('pulsenotifications', 'local_recompletion'), new lang_string('pulsenotifications_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); } diff --git a/classes/plugins/mod_questionnaire.php b/classes/plugins/mod_questionnaire.php index 121cdc4..0d93f0c 100644 --- a/classes/plugins/mod_questionnaire.php +++ b/classes/plugins/mod_questionnaire.php @@ -57,7 +57,7 @@ public static function editingform($mform) : void { $mform->addGroup($cba, 'questionnaire', get_string('questionnaireattempts', 'local_recompletion'), array(' '), false); $mform->addHelpButton('questionnaire', 'questionnaireattempts', 'local_recompletion'); - $mform->setDefault('questionnaire', $config->questionnaireattempts); + $mform->setDefault('questionnaire', $config->questionnaire); $mform->addElement('checkbox', 'archivequestionnaire', get_string('archive', 'local_recompletion')); @@ -81,7 +81,7 @@ public static function settings($settings) { LOCAL_RECOMPLETION_DELETE => new lang_string('delete', 'local_recompletion'), LOCAL_RECOMPLETION_EXTRAATTEMPT => new lang_string('extraattempt', 'local_recompletion')); - $settings->add(new \admin_setting_configselect('local_recompletion/questionnaireattempts', + $settings->add(new \admin_setting_configselect('local_recompletion/questionnaire', new lang_string('questionnaireattempts', 'local_recompletion'), new lang_string('questionnaireattempts_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); diff --git a/classes/plugins/mod_quiz.php b/classes/plugins/mod_quiz.php index 78d14f5..2fce1a1 100644 --- a/classes/plugins/mod_quiz.php +++ b/classes/plugins/mod_quiz.php @@ -56,7 +56,7 @@ public static function editingform($mform) : void { $mform->addGroup($cba, 'quiz', get_string('quizattempts', 'local_recompletion'), array(' '), false); $mform->addHelpButton('quiz', 'quizattempts', 'local_recompletion'); - $mform->setDefault('quiz', $config->quizattempts); + $mform->setDefault('quiz', $config->quiz); $mform->addElement('checkbox', 'archivequiz', get_string('archive', 'local_recompletion')); @@ -83,7 +83,7 @@ public static function settings($settings) { LOCAL_RECOMPLETION_DELETE => new lang_string('delete', 'local_recompletion'), LOCAL_RECOMPLETION_EXTRAATTEMPT => new lang_string('extraattempt', 'local_recompletion')); - $settings->add(new \admin_setting_configselect('local_recompletion/quizattempts', + $settings->add(new \admin_setting_configselect('local_recompletion/quiz', new lang_string('quizattempts', 'local_recompletion'), new lang_string('quizattempts_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); diff --git a/classes/plugins/mod_scorm.php b/classes/plugins/mod_scorm.php index c60001d..6eb7a88 100644 --- a/classes/plugins/mod_scorm.php +++ b/classes/plugins/mod_scorm.php @@ -54,7 +54,7 @@ public static function editingform($mform) : void { $mform->addGroup($cba, 'scorm', get_string('scormattempts', 'local_recompletion'), array(' '), false); $mform->addHelpButton('scorm', 'scormattempts', 'local_recompletion'); - $mform->setDefault('scorm', $config->scormattempts); + $mform->setDefault('scorm', $config->scorm); $mform->addElement('checkbox', 'archivescorm', get_string('archive', 'local_recompletion')); @@ -74,7 +74,7 @@ public static function editingform($mform) : void { public static function settings($settings) { $choices = array(LOCAL_RECOMPLETION_NOTHING => get_string('donothing', 'local_recompletion'), LOCAL_RECOMPLETION_DELETE => get_string('delete', 'local_recompletion')); - $settings->add(new \admin_setting_configselect('local_recompletion/scormattempts', + $settings->add(new \admin_setting_configselect('local_recompletion/scorm', new lang_string('scormattempts', 'local_recompletion'), new lang_string('scormattempts_help', 'local_recompletion'), LOCAL_RECOMPLETION_NOTHING, $choices)); diff --git a/classes/recompletion_form.php b/classes/recompletion_form.php index 21743fd..25893ad 100644 --- a/classes/recompletion_form.php +++ b/classes/recompletion_form.php @@ -68,19 +68,19 @@ public function definition() { $mform->addHelpButton('recompletiontype', 'recompletiontype', 'local_recompletion'); $mform->addElement('checkbox', 'recompletionemailenable', get_string('recompletionemailenable', 'local_recompletion')); - $mform->setDefault('recompletionemailenable', $config->emailenable); + $mform->setDefault('recompletionemailenable', $config->recompletionemailenable); $mform->addHelpButton('recompletionemailenable', 'recompletionemailenable', 'local_recompletion'); $mform->hideIf('recompletionemailenable', 'recompletiontype', 'eq', ''); $mform->addElement('checkbox', 'recompletionunenrolenable', get_string('recompletionunenrolenable', 'local_recompletion')); - $mform->setDefault('recompletionunenrolenable', $config->unenrolenable); + $mform->setDefault('recompletionunenrolenable', $config->recompletionunenrolenable); $mform->addHelpButton('recompletionunenrolenable', 'recompletionunenrolenable', 'local_recompletion'); $mform->hideIf('recompletionunenrolenable', 'recompletiontype', 'eq', ''); $options = ['optional' => false, 'defaultunit' => 86400]; $mform->addElement('duration', 'recompletionduration', get_string('recompletionrange', 'local_recompletion'), $options); $mform->addHelpButton('recompletionduration', 'recompletionrange', 'local_recompletion'); - $mform->setDefault('recompletionduration', $config->duration); + $mform->setDefault('recompletionduration', $config->recompletionduration); $mform->hideif('recompletionduration', 'recompletiontype', 'neq', self::RECOMPLETION_TYPE_PERIOD); // Schedule / cron settings. @@ -105,11 +105,11 @@ public function definition() { $mform->addHelpButton('recompletionemailsubject', 'recompletionemailsubject', 'local_recompletion'); $mform->disabledIf('recompletionemailsubject', 'recompletiontype', 'eq', ''); $mform->disabledIf('recompletionemailsubject', 'recompletionemailenable', 'notchecked'); - $mform->setDefault('recompletionemailsubject', $config->emailsubject); + $mform->setDefault('recompletionemailsubject', $config->recompletionemailsubject); $mform->addElement('editor', 'recompletionemailbody', get_string('recompletionemailbody', 'local_recompletion'), $editoroptions); - $mform->setDefault('recompletionemailbody', ['text' => $config->emailbody, 'format' => FORMAT_HTML]); + $mform->setDefault('recompletionemailbody', ['text' => $config->recompletionemailbody, 'format' => FORMAT_HTML]); $mform->addHelpButton('recompletionemailbody', 'recompletionemailbody', 'local_recompletion'); $mform->disabledIf('recompletionemailbody', 'recompletiontype', 'eq', ''); $mform->disabledIf('recompletionemailbody', 'recompletionemailenable', 'notchecked'); diff --git a/db/events.php b/db/events.php index dc16cca..8f08b22 100644 --- a/db/events.php +++ b/db/events.php @@ -34,4 +34,8 @@ 'eventname' => '\core\event\user_enrolment_deleted', 'callback' => '\local_recompletion\observer::user_enrolment_deleted' ), + array( + 'eventname' => '\core\event\course_created', + 'callback' => '\local_recompletion\observer::course_created' + ), ); diff --git a/db/upgrade.php b/db/upgrade.php index 6f38cc1..17b673a 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -987,5 +987,39 @@ function xmldb_local_recompletion_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2023112600, 'local', 'recompletion'); } + if ($oldversion < 2023112704) { + // We renamed some site admin settings. + $update = [ + 'assignattempts' => 'assign', + 'choiceattempts' => 'choice', + 'customcertcertificates' => 'customcert', + 'h5pattempts' => 'h5pactivity', + 'archiveh5p' => 'archiveh5pactivity', + 'hotpotattempts' => 'hotpot', + 'hvpattempts' => 'hvp', + 'lessonattempts' => 'lesson', + 'pulsenotifications' => 'pulse', + 'questionnaireattempts' => 'questionnaire', + 'quizattempts' => 'quiz', + 'scormattempts' => 'scorm', + 'schedule' => 'recompletionschedule', + 'duration' => 'recompletionduration', + 'emailenable' => 'recompletionemailenable', + 'emailsubject' => 'recompletionemailsubject', + 'emailbody' => 'recompletionemailbody', + 'unenrolenable' => 'recompletionunenrolenable' + ]; + + foreach ($update as $old => $new) { + if ($DB->get_record('config_plugins', ['name' => $old, 'plugin' => 'local_recompletion']) != false) { + set_config($new, get_config('local_recompletion', $old), 'local_recompletion'); + unset_config($old, 'local_recompletion'); + } + } + + // Recompletion savepoint reached. + upgrade_plugin_savepoint(true, 2023112704, 'local', 'recompletion'); + } + return true; } diff --git a/settings.php b/settings.php index 83ccad1..3e25fd9 100644 --- a/settings.php +++ b/settings.php @@ -54,27 +54,27 @@ ), ])); - $settings->add(new admin_setting_configstrtotime('local_recompletion/schedule', + $settings->add(new admin_setting_configstrtotime('local_recompletion/recompletionschedule', new lang_string('recompletionschedule', 'local_recompletion'), new lang_string('recompletionschedule_help', 'local_recompletion'), 'Jan 1', PARAM_TEXT)); - $settings->add(new admin_setting_configduration('local_recompletion/duration', + $settings->add(new admin_setting_configduration('local_recompletion/recompletionduration', new lang_string('recompletionrange', 'local_recompletion'), new lang_string('recompletionrange_help', 'local_recompletion'), YEARSECS, PARAM_INT)); - $settings->add(new admin_setting_configcheckbox('local_recompletion/emailenable', + $settings->add(new admin_setting_configcheckbox('local_recompletion/recompletionemailenable', new lang_string('recompletionemailenable', 'local_recompletion'), new lang_string('recompletionemailenable_help', 'local_recompletion'), 1)); - $settings->add(new admin_setting_configtext('local_recompletion/emailsubject', + $settings->add(new admin_setting_configtext('local_recompletion/recompletionemailsubject', new lang_string('recompletionemailsubject', 'local_recompletion'), new lang_string('recompletionemailsubject_help', 'local_recompletion'), '', PARAM_TEXT)); - $settings->add(new admin_setting_confightmleditor('local_recompletion/emailbody', + $settings->add(new admin_setting_confightmleditor('local_recompletion/recompletionemailbody', new lang_string('recompletionemailbody', 'local_recompletion'), new lang_string('recompletionemailbody_help', 'local_recompletion'), '')); - $settings->add(new admin_setting_configcheckbox('local_recompletion/unenrolenable', + $settings->add(new admin_setting_configcheckbox('local_recompletion/recompletionunenrolenable', new lang_string('recompletionunenrolenable', 'local_recompletion'), new lang_string('recompletionunenrolenable_help', 'local_recompletion'), 0)); diff --git a/version.php b/version.php index dbf3dcc..0aeee1b 100644 --- a/version.php +++ b/version.php @@ -24,8 +24,8 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2023112703; -$plugin->release = 2023112703; +$plugin->version = 2023112705; +$plugin->release = 2023112705; $plugin->maturity = MATURITY_STABLE; $plugin->requires = 2022112805; // Requires 4.1. $plugin->component = 'local_recompletion';