]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9459 - Provide information relating to groups in the summary message "Attemts...
authortjhunt <tjhunt>
Wed, 12 Dec 2007 17:23:55 +0000 (17:23 +0000)
committertjhunt <tjhunt>
Wed, 12 Dec 2007 17:23:55 +0000 (17:23 +0000)
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.

lang/en_utf8/quiz.php
mod/quiz/edit.php
mod/quiz/index.php
mod/quiz/lib.php
mod/quiz/report/overview/report.php
mod/quiz/view.php
theme/standard/styles_layout.css

index 5389bce0c18614a5daceb8b7a1d48b1f26aaf78a..95d67f06e4a76dcac8b7c500c14e77dcdc81ce39 100644 (file)
@@ -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)';
index 28e3e8f930b92183951378280ae6a3ad68fd4e1f..d50dd2fc3fdfd982b5b4b7831b15d468688a3982 100644 (file)
 
         print_box_start();
 
-        echo "<div class=\"attemptsnotice\">\n";
-        echo "<a href=\"report.php?mode=overview&amp;id=$cm->id\">".quiz_num_attempt_summary($quiz)."</a><br />".get_string("attemptsexist","quiz");
-        echo "</div><br />\n";
+        echo "<div class=\"quizattemptcounts\">\n";
+        echo '<a href="report.php?mode=overview&amp;id=' . $cm->id . '">' .
+                quiz_num_attempt_summary($quiz, $cm) . '</a><br />' .
+                get_string('cannoteditafterattempts', 'quiz');
+        echo "</div>\n";
 
         $sumgrades = quiz_print_question_list($quiz,  $thispageurl, false, $quiz_showbreaks, $quiz_reordertool);
         if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $quiz->instance)) {
index caf2e748eee8aa065bedbe61130903f7b8e54ec2..074764c7e2cefb832b6a6836e33d3246b86527f9 100644 (file)
         }
 
         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.
index ad45148aa1610cfeab9615450fb5a3f91f229b6d..30be4d9d8afcc3c656ce069b42e89cab722a5e2e 100644 (file)
@@ -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 = '<div class="quiz overview">' .
@@ -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 .= '<div class="info">' . quiz_num_attempt_summary($quiz, true) . '</div>';
             } 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 '';
index 95cec6800c9f37b34eebade780eb595d149240b2..bdc90c16968e13880dc9a227131d46d779b0a920 100644 (file)
@@ -72,13 +72,6 @@ class quiz_report extends quiz_default_report {
         $reporturlwithoptions = $reporturl . '&amp;id=' . $cm->id . '&amp;noattempts=' . $noattempts .
                 '&amp;detailedmarks=' . $detailedmarks . '&amp;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 '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
+            }
+        }
+
         // Now check if asked download of data
         if ($download) {
             $filename = clean_filename("$course->shortname ".format_string($quiz->name,true));
index e04808eae6cc626704663fc49eff8227eed89dc0..df3aff401b13e34c4c56d02fa1636183f814e7dd 100644 (file)
 
     // 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("<a href=\"report.php?mode=overview&amp;id=$cm->id\">" . $strattemptnum . '</a>');
+        if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm)) {
+            echo '<div class="quizattemptcounts"><a href="report.php?mode=overview&amp;id=' .
+                    $cm->id . '">' . $strattemptnum . '</a></div>';
         }
     }
 
index 90a47c3ee6b2402025692f60875d48c272888309..cd740a727a2ea6679cf4607c2ab9aa626d67ebf7 100644 (file)
@@ -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
  ***/