diff --git a/mod/feedback/item/multichoice/lib.php b/mod/feedback/item/multichoice/lib.php index af444d4de55b7..6239b7240c10e 100644 --- a/mod/feedback/item/multichoice/lib.php +++ b/mod/feedback/item/multichoice/lib.php @@ -322,6 +322,16 @@ public function complete_form_element($item, $form) { $separator = !empty($info->horizontal) ? ' ' : \html_writer::div('', 'w-100'); $tmpvalue = $form->get_item_value($item) ?? 0; // Used for element defaults, so must be a valid value (not null). + // @brainite + foreach ($options as $k => $v) { + if ($v[0] === '*') { + $options[$k] = substr($v, 1); + if ($tmpvalue === 0) { + $tmpvalue = $k; + } + } + } + // Subtypes: // r = radio // c = checkbox diff --git a/mod/feedback/item/multichoice/multichoice_form.php b/mod/feedback/item/multichoice/multichoice_form.php index 9059ca380604f..073c66a6e7e9e 100644 --- a/mod/feedback/item/multichoice/multichoice_form.php +++ b/mod/feedback/item/multichoice/multichoice_form.php @@ -71,6 +71,9 @@ public function definition() { $mform->addElement('static', 'hint', '', get_string('use_one_line_for_each_value', 'feedback')); + // @brainite + $mform->addElement('static', 'hint', '', 'Mark default choice with * at the start of the line.'); + parent::definition(); $this->set_data($item); diff --git a/mod/quiz/classes/access_manager.php b/mod/quiz/classes/access_manager.php index b7f29824eee79..d62c16f870093 100644 --- a/mod/quiz/classes/access_manager.php +++ b/mod/quiz/classes/access_manager.php @@ -555,7 +555,8 @@ public function make_review_link(stdClass $attempt, $nolongerused, renderer $out $reviewoptions = display_options::make_from_quiz( $this->quizobj->get_quiz(), $when); - if (!$reviewoptions->attempt) { + // @brainite + if (!$reviewoptions->attempt || !$nolongerused->attempt) { return $output->no_review_message($this->quizobj->cannot_review_message($when, true, $attempt->timefinish)); } else { diff --git a/mod/quiz/classes/quiz_attempt.php b/mod/quiz/classes/quiz_attempt.php index 8aee1b09bd4fc..4f9fa0f26c071 100644 --- a/mod/quiz/classes/quiz_attempt.php +++ b/mod/quiz/classes/quiz_attempt.php @@ -768,7 +768,8 @@ public function get_display_options($reviewing) { if (is_null($this->reviewoptions)) { $this->reviewoptions = quiz_get_review_options($this->get_quiz(), $this->attempt, $this->quizobj->get_context()); - if ($this->is_own_preview()) { + // @brainite + if ($this->is_own_preview() && !($this->reviewoptions->never_preview ?? FALSE)) { // It should always be possible for a teacher to review their // own preview irrespective of the review options settings. $this->reviewoptions->attempt = true; diff --git a/mod/quiz/classes/quiz_settings.php b/mod/quiz/classes/quiz_settings.php index 7216ff69b2f77..0b7457e664a85 100644 --- a/mod/quiz/classes/quiz_settings.php +++ b/mod/quiz/classes/quiz_settings.php @@ -508,6 +508,12 @@ public function summary_url($attemptid) { * @return string an appropraite message. */ public function cannot_review_message($when, $short = false, ?int $attemptsubmittime = null) { + // @brainite + if ($short) { + return 'Review is currently unavailable.'; + } + return 'You cannot currently review this quiz. Complete the requirements and/or come back later.'; + if ($attemptsubmittime === null) { debugging('It is recommended that you pass $attemptsubmittime to cannot_review_message', DEBUG_DEVELOPER); diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 43c78fc757502..b5da40e6c0585 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1060,9 +1060,10 @@ function quiz_process_options($quiz) { if (empty($quiz->completionusegrade)) { $quiz->completionpassgrade = 0; } - if (empty($quiz->completionpassgrade)) { - $quiz->completionattemptsexhausted = 0; - } + // @brainite + // if (empty($quiz->completionpassgrade)) { + // $quiz->completionattemptsexhausted = 0; + // } if (empty($quiz->completionminattemptsenabled)) { $quiz->completionminattempts = 0; } @@ -2054,8 +2055,9 @@ function quiz_get_coursemodule_info($coursemodule) { if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) { if ($quiz->completionattemptsexhausted) { $result->customdata['customcompletionrules']['completionpassorattemptsexhausted'] = [ - 'completionpassgrade' => $coursemodule->completionpassgrade, - 'completionattemptsexhausted' => $quiz->completionattemptsexhausted, + // @brainite + 'completionpassgrade' => 1, // $coursemodule->completionpassgrade, + 'completionattemptsexhausted' => 1, // $quiz->completionattemptsexhausted, ]; } else { $result->customdata['customcompletionrules']['completionpassorattemptsexhausted'] = []; diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index d646465574247..0c3a3d7792740 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -1228,8 +1228,29 @@ function quiz_get_review_options($quiz, $attempt, $context) { $options->userinfoinhistory = $attempt->userid; } + else { + // @brainite + // + // If they are not complete, then disallow the preview. + if (!$quiz->timeclose || time() < $quiz->timeclose) { + global $CFG; + require_once($CFG->libdir . '/modinfolib.php'); + $cm = get_coursemodule_from_instance('quiz', $quiz->id); + $cm_info = \cm_info::create($cm); + if (isset($cm_info->customdata['customcompletionrules']) + && isset($cm_info->customdata['customcompletionrules']['completionpassorattemptsexhausted']) + && !empty($cm_info->customdata['customcompletionrules']['completionpassorattemptsexhausted'])) { + $completioninfo = new \completion_info($cm_info->get_course()); + $customcompletion = new \mod_quiz\completion\custom_completion($cm_info, $attempt->userid, $completioninfo->get_core_completion_state($cm_info, $attempt->userid)); + if ($customcompletion->get_state('completionpassorattemptsexhausted') === COMPLETION_INCOMPLETE) { + $options->attempt = question_display_options::HIDDEN; + $options->never_preview = TRUE; + } + } + } + } - return $options; + return $options; } /** diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php index 1829badd4ba1c..0a9570ef5e543 100644 --- a/mod/quiz/mod_form.php +++ b/mod/quiz/mod_form.php @@ -672,8 +672,9 @@ public function add_completiongrade_rules(): array { ['group' => 'cattempts', 'parentclass' => 'ms-4'] ); $completionpassgradeel = 'completionpassgrade' . $suffix; - $mform->hideIf($completionattemptsexhaustedel, $completionpassgradeel, 'notchecked'); - $mform->hideIf($completionattemptsexhaustedel, $completionpassgradeel, 'notchecked'); + // @brainite + // $mform->hideIf($completionattemptsexhaustedel, $completionpassgradeel, 'notchecked'); + // $mform->hideIf($completionattemptsexhaustedel, $completionpassgradeel, 'notchecked'); return [$completionattemptsexhaustedel]; }