commit 985d383399e1b0f671888ebe87b70fbe0769507a Author: root Date: Mon Apr 8 08:44:15 2024 +0000 MDL-76665 mod_quiz: disable/enable seb templates when being used diff --git a/mod/quiz/accessrule/seb/classes/local/form/template.php b/mod/quiz/accessrule/seb/classes/local/form/template.php index f1a6c8e11d2..75280794138 100644 --- a/mod/quiz/accessrule/seb/classes/local/form/template.php +++ b/mod/quiz/accessrule/seb/classes/local/form/template.php @@ -62,12 +62,11 @@ class template extends \core\form\persistent { $mform->addElement('selectyesno', 'enabled', get_string('enabled', 'quizaccess_seb')); $mform->setType('enabled', PARAM_INT); - $this->add_action_buttons(); - if (!empty($this->get_persistent()) && !$this->get_persistent()->can_delete()) { - $mform->hardFreezeAllVisibleExcept([]); - $mform->addElement('cancel'); + $mform->hardFreezeAllVisibleExcept(['enabled']); } + + $this->add_action_buttons(); } /** diff --git a/mod/quiz/accessrule/seb/classes/settings_provider.php b/mod/quiz/accessrule/seb/classes/settings_provider.php index 40805bfab1a..86d3b064262 100644 --- a/mod/quiz/accessrule/seb/classes/settings_provider.php +++ b/mod/quiz/accessrule/seb/classes/settings_provider.php @@ -585,11 +585,21 @@ class settings_provider { * @return array */ protected static function get_template_options() : array { + global $PAGE, $DB; $templates = []; - $records = template::get_records(['enabled' => 1], 'name'); + $templates_t = template::TABLE; + $quiz_settings_t = quiz_settings::TABLE; + $cmid = $PAGE->cm->id ?? 'NULL'; + // get templates records and current's cm used template (even if it is disabled) + $records = $DB->get_records_sql( + "SELECT * + FROM {{$templates_t}} t + WHERE enabled = 1 OR EXISTS + (SELECT 1 FROM {{$quiz_settings_t}} WHERE templateid = t.id and cmid = $cmid)" + ); if ($records) { foreach ($records as $record) { - $templates[$record->get('id')] = $record->get('name'); + $templates[$record->id] = $record->name; } }