From: tjhunt Date: Wed, 12 Dec 2007 17:23:55 +0000 (+0000) Subject: MDL-9459 - Provide information relating to groups in the summary message "Attemts... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2a13e454f95275c0f14625c7b61cf7c1865e824d;p=moodle.git MDL-9459 - Provide information relating to groups in the summary message "Attemts: 123". Now, depending on the situation, you see one of three messages: "Attempts: 123", "Attemtps 123 (45 from your groups)" or "Attemtps 123 (45 from this group)". I also took the opportunity to improve the layout of this message slightly, and clarify the message that tells you that you cannot add or remove questions from the quiz if there are attemts. Merged from MOODLE_19_STABLE. --- diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 5389bce0c1..95d67f06e4 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -61,6 +61,8 @@ $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['attemptsnumthisgroup'] = 'Attempts: $a->total ($a->group from this group)'; +$string['attemptsnumyourgroups'] = 'Attempts: $a->total ($a->group from your groups)'; $string['attemptsonly'] = 'Show only students with attempts'; $string['attemptsunlimited'] = 'Unlimited attempts'; $string['back'] = 'Back to preview question'; @@ -74,6 +76,7 @@ $string['bothattempts'] = 'Show students with and without attempts'; $string['calculated'] = 'Calculated'; $string['calculatedquestion'] = 'Calculated Question not supported at line $a. The question will be ignored'; $string['cannotcreatepath'] = 'Path cannot be created ($a)'; +$string['cannoteditafterattempts'] = 'You cannot add or remove questions because there are attempts.'; $string['cannotinsert'] = 'Cannot insert question'; $string['cannotopen'] = 'Cannot open export file ($a)'; $string['cannotread'] = 'Cannot read import file (or file is empty)'; diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 28e3e8f930..d50dd2fc3f 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -303,9 +303,11 @@ print_box_start(); - echo "
\n"; - echo "id\">".quiz_num_attempt_summary($quiz)."
".get_string("attemptsexist","quiz"); - echo "

\n"; + echo "
\n"; + echo '' . + quiz_num_attempt_summary($quiz, $cm) . '
' . + get_string('cannoteditafterattempts', 'quiz'); + echo "
\n"; $sumgrades = quiz_print_question_list($quiz, $thispageurl, false, $quiz_showbreaks, $quiz_reordertool); if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $quiz->instance)) { diff --git a/mod/quiz/index.php b/mod/quiz/index.php index caf2e748ee..074764c7e2 100644 --- a/mod/quiz/index.php +++ b/mod/quiz/index.php @@ -102,7 +102,9 @@ } if ($showing == 'stats') { - $data[] = quiz_num_attempt_summary($quiz); + // The $quiz objects returned by get_all_instances_in_course have the necessary $cm + // fields set to make the following call work. + $data[] = quiz_num_attempt_summary($quiz, $quiz); } else if ($showing = 'scores') { // Grade and feedback. diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index ad45148aa1..30be4d9d8a 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1036,7 +1036,7 @@ function quiz_print_overview($courses, &$htmlarray) { return array(); } - if (!$quizs = get_all_instances_in_courses('quiz', $courses)) { + if (!$quizzes = get_all_instances_in_courses('quiz', $courses)) { return; } @@ -1047,7 +1047,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 = time(); - foreach ($quizs as $quiz) { + foreach ($quizzes as $quiz) { if ($quiz->timeclose >= $now && $quiz->timeopen < $now) { /// Give a link to the quiz, and the deadline. $str = '
' . @@ -1060,6 +1060,8 @@ 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. + // The $quiz objects returned by get_all_instances_in_course have the necessary $cm + // fields set to make the following call work. $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. @@ -1089,12 +1091,34 @@ 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". + * @param object $cm the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment. + * @param boolean $returnzero if false (default), when no attempts have been made '' is returned instead of 'Attempts: 0'. + * @param int $currentgroup if there is a concept of current group where this method is being called + * (e.g. a report) pass it in here. Default 0 which means no current group. + * @return string a string like "Attempts: 123", "Attemtps 123 (45 from your groups)" or + * "Attemtps 123 (45 from this group)". */ -function quiz_num_attempt_summary($quiz, $returnzero = false) { +function quiz_num_attempt_summary($quiz, $cm, $returnzero = false, $currentgroup = 0) { + global $CFG, $USER; $numattempts = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0); if ($numattempts || $returnzero) { + if (groups_get_activity_groupmode($cm)) { + $a->total = $numattempts; + if ($currentgroup) { + $a->group = count_records_sql('SELECT count(1) FROM ' . + $CFG->prefix . 'quiz_attempts qa JOIN ' . + $CFG->prefix . 'groups_members gm ON qa.userid = gm.userid ' . + 'WHERE quiz = ' . $quiz->id . ' AND preview = 0 AND groupid = ' . $currentgroup); + return get_string('attemptsnumthisgroup', 'quiz', $a); + } else if ($groups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid)) { + $a->group = count_records_sql('SELECT count(1) FROM ' . + $CFG->prefix . 'quiz_attempts qa JOIN ' . + $CFG->prefix . 'groups_members gm ON qa.userid = gm.userid ' . + 'WHERE quiz = ' . $quiz->id . ' AND preview = 0 AND ' . + 'groupid IN (' . implode(',', array_keys($groups)) . ')'); + return get_string('attemptsnumyourgroups', 'quiz', $a); + } + } return get_string('attemptsnum', 'quiz', $numattempts); } return ''; diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 95cec6800c..bdc90c1696 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -72,13 +72,6 @@ class quiz_report extends quiz_default_report { $reporturlwithoptions = $reporturl . '&id=' . $cm->id . '&noattempts=' . $noattempts . '&detailedmarks=' . $detailedmarks . '&pagesize=' . $pagesize; - // Print information on the number of existing attempts - if (!$download) { //do not print notices when downloading - if ($strattemptnum = quiz_num_attempt_summary($quiz)) { - notify($strattemptnum); - } - } - /// find out current groups mode $currentgroup = groups_get_activity_group($cm, true); @@ -88,6 +81,13 @@ class quiz_report extends quiz_default_report { } } + // Print information on the number of existing attempts + if (!$download) { //do not print notices when downloading + if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, false, $currentgroup)) { + echo '
' . $strattemptnum . '
'; + } + } + // Now check if asked download of data if ($download) { $filename = clean_filename("$course->shortname ".format_string($quiz->name,true)); diff --git a/mod/quiz/view.php b/mod/quiz/view.php index e04808eae6..df3aff401b 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -126,8 +126,9 @@ // Show number of attempts summary to those who can view reports. if (has_capability('mod/quiz:viewreports', $context)) { - if ($strattemptnum = quiz_num_attempt_summary($quiz)) { - notify("id\">" . $strattemptnum . ''); + if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm)) { + echo ''; } } diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 90a47c3ee6..cd740a727a 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -3787,7 +3787,7 @@ table.quizreviewsummary td.cell { } #mod-quiz-edit #page .controls, -#mod-quiz-edit #page .attemptsnotice +#mod-quiz-edit #page .quizattemptcounts { text-align: center; } @@ -3923,6 +3923,10 @@ table.quizreviewsummary td.cell { .mod-quiz .gradingdetails { font-size: small; } +.quizattemptcounts { + text-align: center; + margin: 6px 0; +} /*** *** Modules: Resource ***/