diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 690ad9aaa50..c996ac785ae 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -60,6 +60,7 @@ $string['attemptsallowed'] = 'Attempts allowed'; $string['attemptsdeleted'] = 'Quiz attempts deleted'; $string['attemptselection'] = 'Select which attempts to analyze per user:'; $string['attemptsexist'] = 'You can no longer add or remove questions.'; +$string['attemptsnum'] = 'Attempts: $a'; $string['attemptsonly'] = 'Show only students with attempts'; $string['attemptsunlimited'] = 'Unlimited attempts'; $string['back'] = 'Back to preview question'; diff --git a/lib/questionlib.php b/lib/questionlib.php index 20d649857f6..60eb2029228 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1891,8 +1891,7 @@ function default_export_filename($course,$category) { $export_name .= moodle_strtolower($export_categoryname)."-"; //The date format $export_name .= userdate(time(),$export_date_format,99,false); - //The extension - no extension, supplied by format - // $export_name .= ".txt"; + //Extension is supplied by format later. return $export_name; } diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 03112733b3e..04aacad65b9 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -304,12 +304,8 @@ print_box_start(); - $a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0); - $a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)'); - $a->studentstring = $course->students; - echo "
\n"; - echo "id\">".get_string('numattempts', 'quiz', $a)."
".get_string("attemptsexist","quiz"); + echo "id\">".quiz_num_attempt_summary($quiz)."
".get_string("attemptsexist","quiz"); echo "

\n"; $sumgrades = quiz_print_question_list($quiz, $thispageurl, false, $quiz_showbreaks, $quiz_reordertool); diff --git a/mod/quiz/index.php b/mod/quiz/index.php index 3de177a3d2f..54d19c73606 100644 --- a/mod/quiz/index.php +++ b/mod/quiz/index.php @@ -112,17 +112,7 @@ } if ($showing == 'stats') { - - // Number of students who have attempted this quiz. - if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) { - $a->studentnum = count_records_select('quiz_attempts', - "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)'); - $a->studentstring = $course->students; - $data[] = "id\">" . - get_string('numattempts', 'quiz', $a) . ''; - } else { - $data[] = ''; - } + $data[] = quiz_num_attempt_summary($quiz); } else if ($showing = 'scores') { // Grade and feedback. diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 588c9bbe9bb..2d49d5ec125 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1022,7 +1022,7 @@ function quiz_print_overview($courses, &$htmlarray) { /// We want to list quizzes that are currently available, and which have a close date. /// This is the same as what the lesson does, and the dabate is in MDL-10568. - $now = date(); + $now = time(); foreach ($quizs as $quiz) { if ($quiz->timeclose >= $now && $quiz->timeopen < $now) { /// Give a link to the quiz, and the deadline. @@ -1036,15 +1036,7 @@ function quiz_print_overview($courses, &$htmlarray) { $context = get_context_instance(CONTEXT_MODULE, $quiz->coursemodule); if (has_capability('mod/quiz:viewreports', $context)) { /// For teacher-like people, show a summary of the number of student attempts. - $a = new stdClass; - if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) { - $a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)'); - } else { - $a->studentnum = 0; - $a->attemptnum = 0; - } - $a->studentstring = $course->students; - $str .= '
' . get_string('numattempts', 'quiz', $a) . '
'; + $str .= '
' . quiz_num_attempt_summary($quiz, true) . '
'; } else if (has_capability('mod/quiz:attempt', $context)){ // Student /// For student-like people, tell them how many attempts they have made. if (isset($USER->id) && ($attempts = quiz_get_user_attempts($quiz->id, $USER->id))) { @@ -1068,4 +1060,19 @@ function quiz_print_overview($courses, &$htmlarray) { } } } + +/** + * Return a textual summary of the number of attemtps that have been made at a particular quiz, + * returns '' if no attemtps have been made yet, unless $returnzero is passed as true. + * @param object $quiz the quiz object. Only $quiz->id is used at the moment. + * @param boolean $returnzero if false (default), when no attempts have been made '' is returned instead of 'Attempts: 0'. + * @return string a string like "Attempts: 123". + */ +function quiz_num_attempt_summary($quiz, $returnzero = false) { + $numattempts = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0); + if ($numattempts || $returnzero) { + return get_string('attemptsnum', 'quiz', $numattempts); + } + return ''; +} ?> diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 13bfde6f77d..cadfcf18e17 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -74,14 +74,8 @@ class quiz_report extends quiz_default_report { // Print information on the number of existing attempts if (!$download) { //do not print notices when downloading - if ($attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) { - $a = new stdClass; - $a->attemptnum = $attemptnum; - $a->studentnum = count_records_select('quiz_attempts', - "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)'); - $a->studentstring = $course->students; - - notify(get_string('numattempts', 'quiz', $a)); + if ($strattemptnum = quiz_num_attempt_summary($quiz)) { + notify($strattemptnum); } } diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 906971a6a48..e77ad5552b7 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -125,11 +125,8 @@ // Show number of attempts summary to those who can view reports. if (has_capability('mod/quiz:viewreports', $context)) { - if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) { - $a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)'); - $a->studentstring = $course->students; - - notify("id\">".get_string('numattempts', 'quiz', $a).''); + if ($strattemptnum = quiz_num_attempt_summary($quiz)) { + notify("id\">" . $strattemptnum . ''); } }