]> git.mjollnir.org Git - moodle.git/commitdiff
quiz: MDL-14926 New capability mod/quiz:reviewmyattempts, separate from mod/quiz...
authortjhunt <tjhunt>
Wed, 14 Jan 2009 07:08:02 +0000 (07:08 +0000)
committertjhunt <tjhunt>
Wed, 14 Jan 2009 07:08:02 +0000 (07:08 +0000)
14 files changed:
lang/en_utf8/quiz.php
mod/quiz/attemptlib.php
mod/quiz/db/access.php
mod/quiz/index.php
mod/quiz/lib.php
mod/quiz/report/grading/report.php
mod/quiz/report/overview/overviewgraph.php
mod/quiz/report/overview/report.php
mod/quiz/report/responses/report.php
mod/quiz/report/statistics/report.php
mod/quiz/review.php
mod/quiz/reviewquestion.php
mod/quiz/version.php
mod/quiz/view.php

index e2b693354d9721f4bb3e3a21a663ba9e0eadbae6..1698881760b53e1fd956ff30e2d0f4a8a111f945 100644 (file)
@@ -134,10 +134,8 @@ $string['choosedatasetproperties'] = 'Choose dataset properties';
 $string['choosefile'] = 'Choose a file';
 $string['close'] = 'Close window';
 $string['closebeforeopen'] = 'Could not update the quiz. You have specified a close date before the open date.';
-$string['closedat'] = 'closed: $a';
 $string['closepreview'] = 'Close preview';
 $string['closereview'] = 'Close review';
-$string['closesat'] = 'closes: $a';
 $string['comment'] = 'Comment';
 $string['commentorgrade'] = 'Make comment or override grade';
 $string['comments'] = 'Comments';
@@ -459,8 +457,6 @@ $string['onlyteachersexport'] = 'Only teachers can export questions';
 $string['onlyteachersimport'] = 'Only teachers with editing rights can import questions';
 $string['open'] = 'Started';
 $string['openclosedatesupdated'] = 'Quiz open and close dates updated';
-$string['openedat'] = 'opened: $a';
-$string['opensat'] = 'opens: $a';
 $string['optional'] = 'optional';
 $string['orderandpaging'] = 'Order and paging';
 $string['orderingquiz'] = 'Order and paging';
@@ -527,6 +523,7 @@ $string['quiz:ignoretimelimits'] = 'Ignores time limit on quizzes';
 $string['quiz:manage'] = 'Manage quizzes';
 $string['quiz:preview'] = 'Preview quizzes';
 $string['quiz:regrade'] = 'Regrade quiz attempts';
+$string['quiz:reviewmyattempts'] = 'Review your own attempts';
 $string['quiz:view'] = 'View quiz information';
 $string['quiz:viewreports'] = 'View quiz reports';
 $string['quizavailable'] = 'The quiz is available until: $a';
@@ -534,8 +531,8 @@ $string['quizclose'] = 'Close the quiz';
 $string['quizclosed'] = 'This quiz closed on $a';
 $string['quizcloses'] = 'Quiz closes';
 $string['quizcloseson'] = 'This quiz will close at $a';
-$string['quizisclosed'] = 'This quiz is closed ($a)';
-$string['quizisopen'] = 'This quiz is open ($a)';
+$string['quizisclosed'] = 'This quiz is closed';
+$string['quizisopen'] = 'This quiz is open';
 $string['quiznavigation'] = 'Quiz navigation';
 $string['quiznotavailable'] = 'The quiz will not be available until $a';
 $string['quizopen'] = 'Open the quiz';
index 821469da865920e44e0500d1afc23f2945d23f13..d56eb67407138d76496ce872db8d75eb1dd5ad29 100644 (file)
@@ -493,6 +493,20 @@ class quiz_attempt extends quiz {
                 (!$this->is_preview_user() || $this->attempt->preview);
     }
 
+    /**
+     * Check the appropriate capability to see whether this user may review their own attempt.
+     * If not, prints an error.
+     */
+    public function check_review_capability() {
+        if (!$this->has_capability('mod/quiz:viewreports')) {
+            if ($this->get_review_options()->quizstate == QUIZ_STATE_IMMEDIATELY) {
+                $this->require_capability('mod/quiz:attempt');
+            } else {
+                $this->require_capability('mod/quiz:reviewmyattempts');
+            }
+        }
+    }
+
     public function get_question_state($questionid) {
         $this->ensure_state_loaded($questionid);
         return $this->states[$questionid];
index 41c82d393fd32ea2d492045381c840868cf1646b..724ee267ca84cbafd613453d5805df7c0c78f720 100644 (file)
@@ -22,6 +22,7 @@ $mod_quiz_capabilities = array(
 
     // Ability to do the quiz as a 'student'.
     'mod/quiz:attempt' => array(
+        'riskbitmask' => RISK_SPAM,
         'captype' => 'write',
         'contextlevel' => CONTEXT_MODULE,
         'legacy' => array(
@@ -29,6 +30,17 @@ $mod_quiz_capabilities = array(
         )
     ),
 
+    // Ability for a 'Student' to review their previous attempts. Review by
+    // 'Teachers' is controlled by mod/quiz:viewreports.
+    'mod/quiz:reviewmyattempts' => array(
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_MODULE,
+        'legacy' => array(
+            'student' => CAP_ALLOW
+        ),
+        'clonepermissionsfrom' => 'moodle/quiz:attempt'
+    ),
+
     // Edit the quiz settings, add and remove questions.
     'mod/quiz:manage' => array(
         'riskbitmask' => RISK_SPAM,
index 70174227c173b71181166b9dfb7cf1ab64c8b6d0..18bfef3274c8afd67b68e728b8daaa9e72910211 100644 (file)
     }
     array_unshift($align, 'center');
 
-    $showing = 'scores';  // default
+    $showing = '';  // default
 
     if (has_capability('mod/quiz:viewreports', $coursecontext)) {
         array_push($headings, get_string('attempts', 'quiz'));
         array_push($align, 'left');
         $showing = 'stats';
-    } else if (has_capability('mod/quiz:attempt', $coursecontext)) {
+    } else if (has_any_capability(array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $coursecontext)) {
         array_push($headings, get_string('bestgrade', 'quiz'), get_string('feedback', 'quiz'));
         array_push($align, 'left', 'left');
+        $showing = 'scores';  // default
     }
 
     $table->head = $headings;
index 981454f1b1e562d37a52a198a4d17831891eba34..07d9f7f6b1f860353a6cfb0bf3fddbaa19513067 100644 (file)
@@ -1186,7 +1186,7 @@ function quiz_print_overview($courses, &$htmlarray) {
                 // 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, $quiz, true) . '</div>';
-            } else if (has_capability('mod/quiz:attempt', $context)){ // Student
+            } else if (has_any_capability(array('mod/quiz:reviewmyattempts', '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))) {
                     $numattempts = count($attempts);
index 88932c05a42dfef47a1ed084e8abc1a4a04ec7fd..6a1b2ba4c175e735e991fbf52ce1e7995ab45c2a 100644 (file)
@@ -83,8 +83,7 @@ class quiz_grading_report extends quiz_default_report {
         }
 
         $currentgroup = groups_get_activity_group($this->cm, true);
-        $this->users     = get_users_by_capability($this->context, 'mod/quiz:attempt','','','','',$currentgroup,'',false);
-
+        $this->users = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'','','','',$currentgroup,'',false);
 
         if (!empty($questionid)) {
             if (!isset($gradeableqs[$questionid])){
index 6989d35b90c1870d6c756c5d220bdd2a88d3a245..61313c4654c9acbf98c6b7446d1e1028f21598bb 100644 (file)
@@ -14,7 +14,7 @@ if ($groupid && $groupmode = groups_get_activity_groupmode($cm)) {   // Groups a
     $groups = groups_get_activity_allowed_groups($cm);
     if (array_key_exists($groupid, $groups)){
         $group = $groups[$groupid];
-        if (!$groupusers = get_users_by_capability($modcontext, 'mod/quiz:attempt','','','','',$group->id,'',false)){
+        if (!$groupusers = get_users_by_capability($modcontext, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'','','','',$group->id,'',false)){
             print_error('nostudentsingroup');
         } else {
             $groupusers = array_keys($groupusers);
index 461fe566d091c57dab6d8ddfffe553f96be0f086..f2a8c19fe3a3c5b09493fb33924815bd0488823a 100644 (file)
@@ -35,7 +35,7 @@ class quiz_overview_report extends quiz_default_report {
         
         /// find out current groups mode
         $currentgroup = groups_get_activity_group($cm, true);
-        if (!$students = get_users_by_capability($this->context, 'mod/quiz:attempt','','','','','','',false)){
+        if (!$students = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'','','','','','',false)){
             $students = array();
         } else {
             $students = array_keys($students);
@@ -47,7 +47,7 @@ class quiz_overview_report extends quiz_default_report {
             $groupstudents = array();
         } else {
             // all users who can attempt quizzes and who are in the currently selected group
-            if (!$groupstudents = get_users_by_capability($this->context, 'mod/quiz:attempt','','','','',$currentgroup,'',false)){
+            if (!$groupstudents = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'','','','',$currentgroup,'',false)){
                 $groupstudents = array();
             } else {
                 $groupstudents = array_keys($groupstudents);
index ff106bdbed911b2f65307c341d2f75e95e367c42..46625ebb3664d5ac1ab46e6a968636e5e16ba6c5 100644 (file)
@@ -104,7 +104,7 @@ class quiz_responses_report extends quiz_default_report {
         $displayoptions['qmfilter'] = $qmfilter;
 
         //work out the sql for this table.
-        if (!$students = get_users_by_capability($context, 'mod/quiz:attempt','','','','','','',false)){
+        if (!$students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'','','','','','',false)){
             $students = array();
         } else {
             $students = array_keys($students);
@@ -116,7 +116,7 @@ class quiz_responses_report extends quiz_default_report {
             $groupstudents = array();
         } else {
             // all users who can attempt quizzes and who are in the currently selected group
-            if (!$groupstudents = get_users_by_capability($context, 'mod/quiz:attempt','','','','',$currentgroup,'',false)){
+            if (!$groupstudents = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'','','','',$currentgroup,'',false)){
                 $groupstudents = array();
             } else {
                 $groupstudents = array_keys($groupstudents);
index 7d1ddfa58e3a5b519e604c2c7ee25928721d9a54..6089ac44fb6da43ce54bbe98a46a45864b389713 100644 (file)
@@ -65,7 +65,7 @@ class quiz_statistics_report extends quiz_default_report {
         $nostudentsingroup = false;//true if a group is selected and their is noeone in it.
         if (!empty($currentgroup)) {
             // all users who can attempt quizzes and who are in the currently selected group
-            $groupstudents = get_users_by_capability($context, 'mod/quiz:attempt','','','','',$currentgroup,'',false);
+            $groupstudents = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'','','','',$currentgroup,'',false);
             if (!$groupstudents){
                 $nostudentsingroup = true;
             }
index 9c48ac108fee9b5c7f12a86aa2c4bdc1a3ea5c32..4254bc782587bf23dfb81623177ac208087ae448 100644 (file)
@@ -19,6 +19,7 @@
 
 /// Check login.
     require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
+    $attemptobj->check_review_capability();
 
 /// Create an object to manage all the other (non-roles) access rules.
     $accessmanager = $attemptobj->get_access_manager(time());
index 7f0bdebfa586727d95bb334110ccc21a69fbfe9f..e4750d90d1d9c6983d1972c11c041cb7f0047078 100644 (file)
@@ -19,6 +19,7 @@
 
 /// Check login.
     require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
+    $attemptobj->check_review_capability();
 
 /// Permissions checks for normal users who do not have quiz:viewreports capability.
     if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
index be12a4ee8d68e1b1981b60780144ddd0b1134b6d..5453ac40e4d812be3b65a51378bf2561a338a997 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2009010700;   // The (date) version of this module
+$module->version  = 2009011400;   // The (date) version of this module
 $module->requires = 2008072401;   // Requires this Moodle version
 $module->cron     = 0;            // How often should cron check this module (seconds)?
 
index 388bdaebdb716be2ae4599050704bf538116bacd..31d5a020100f3f47dd55ceb97aea5aba31647d48 100644 (file)
@@ -40,6 +40,7 @@
 
 /// Cache some other capabilites we use several times.
     $canattempt = has_capability('mod/quiz:attempt', $context);
+    $canreviewmine = has_capability('mod/quiz:reviewmyattempts', $context);
     $canpreview = has_capability('mod/quiz:preview', $context);
 
 /// Create an object to manage all the other (non-roles) access rules.
         finish_page($course);
     }
 
-/// If they are not using guest access, and they can't do the quiz, tell them that.
-    if (!($canattempt || $canpreview)) {
+/// If they are not enrolled in this course in a good enough role, tell them to enrol.
+    if (!($canattempt || $canpreview || $canreviewmine)) {
         print_box('<p>' . get_string('youneedtoenrol', 'quiz') . "</p>\n\n<p>" .
                 print_continue($CFG->wwwroot . '/course/view.php?id=' . $course->id, true) .
                 "</p>\n", 'generalbox', 'notice');
             $table->align[] = 'center';
             $table->size[] = '';
         }
-        $table->head[] = get_string('review', 'quiz');
-        $table->align[] = 'center';
-        $table->size[] = '';
+        if ($canreviewmine) {
+            $table->head[] = get_string('review', 'quiz');
+            $table->align[] = 'center';
+            $table->size[] = '';
+        }
         if ($feedbackcolumn) {
             $table->head[] = get_string('feedback', 'quiz');
             $table->align[] = 'left';
                 }
             }
 
-            $row[] = $accessmanager->make_review_link($attempt, $canpreview, $attemptoptions);
+            if ($canreviewmine) {
+                $row[] = $accessmanager->make_review_link($attempt, $canpreview, $attemptoptions);
+            }
 
             if ($feedbackcolumn && $attempt->timefinish > 0) {
                 if ($attemptoptions->overallfeedback) {
         print_heading(get_string("noquestions", "quiz"));
     } else {
         if ($unfinished) {
-            if ($canpreview) {
-                $buttontext = get_string('continuepreview', 'quiz');
-            } else {
+            if ($canattempt) {
                 $buttontext = get_string('continueattemptquiz', 'quiz');
+            } else if ($canpreview) {
+                $buttontext = get_string('continuepreview', 'quiz');
             }
         } else {
-            $messages = $accessmanager->prevent_new_attempt($numattempts, $lastfinishedattempt);
-            if (!$canpreview && $messages) {
-                $accessmanager->print_messages($messages);
-            } else {
-                if ($canpreview) {
-                    $buttontext = get_string('previewquiznow', 'quiz');
+            if ($canattempt) {
+                $messages = $accessmanager->prevent_new_attempt($numattempts, $lastfinishedattempt);
+                if ($messages) {
+                    $accessmanager->print_messages($messages);
                 } else if ($numattempts == 0) {
                     $buttontext = get_string('attemptquiznow', 'quiz');
                 } else {
                     $buttontext = get_string('reattemptquiz', 'quiz');
                 }
+            } else if ($canpreview) {
+                $buttontext = get_string('previewquiznow', 'quiz');
             }
         }
 
         if ($buttontext) {
             if (!$moreattempts) {
                 $buttontext = '';
-            } else if (!$canpreview && $messages = $accessmanager->prevent_access()) {
+            } else if ($canattempt && $messages = $accessmanager->prevent_access()) {
                 $accessmanager->print_messages($messages);
                 $buttontext = '';
             }