From: tjhunt <tjhunt> Date: Wed, 14 Jan 2009 07:08:02 +0000 (+0000) Subject: quiz: MDL-14926 New capability mod/quiz:reviewmyattempts, separate from mod/quiz... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=96c7d771df88fd0aa2514ba898c89f81053c6e93;p=moodle.git quiz: MDL-14926 New capability mod/quiz:reviewmyattempts, separate from mod/quiz:attempt. Merged from MOODLE_19_STABLE. --- diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index e2b693354d..1698881760 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -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'; diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index 821469da86..d56eb67407 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -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]; diff --git a/mod/quiz/db/access.php b/mod/quiz/db/access.php index 41c82d393f..724ee267ca 100644 --- a/mod/quiz/db/access.php +++ b/mod/quiz/db/access.php @@ -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, diff --git a/mod/quiz/index.php b/mod/quiz/index.php index 70174227c1..18bfef3274 100644 --- a/mod/quiz/index.php +++ b/mod/quiz/index.php @@ -53,15 +53,16 @@ } 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; diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 981454f1b1..07d9f7f6b1 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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); diff --git a/mod/quiz/report/grading/report.php b/mod/quiz/report/grading/report.php index 88932c05a4..6a1b2ba4c1 100644 --- a/mod/quiz/report/grading/report.php +++ b/mod/quiz/report/grading/report.php @@ -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])){ diff --git a/mod/quiz/report/overview/overviewgraph.php b/mod/quiz/report/overview/overviewgraph.php index 6989d35b90..61313c4654 100644 --- a/mod/quiz/report/overview/overviewgraph.php +++ b/mod/quiz/report/overview/overviewgraph.php @@ -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); diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 461fe566d0..f2a8c19fe3 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -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); diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php index ff106bdbed..46625ebb36 100644 --- a/mod/quiz/report/responses/report.php +++ b/mod/quiz/report/responses/report.php @@ -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); diff --git a/mod/quiz/report/statistics/report.php b/mod/quiz/report/statistics/report.php index 7d1ddfa58e..6089ac44fb 100644 --- a/mod/quiz/report/statistics/report.php +++ b/mod/quiz/report/statistics/report.php @@ -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; } diff --git a/mod/quiz/review.php b/mod/quiz/review.php index 9c48ac108f..4254bc7825 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -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()); diff --git a/mod/quiz/reviewquestion.php b/mod/quiz/reviewquestion.php index 7f0bdebfa5..e4750d90d1 100644 --- a/mod/quiz/reviewquestion.php +++ b/mod/quiz/reviewquestion.php @@ -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')) { diff --git a/mod/quiz/version.php b/mod/quiz/version.php index be12a4ee8d..5453ac40e4 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -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)? diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 388bdaebdb..31d5a02010 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -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. @@ -122,8 +123,8 @@ 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'); @@ -200,9 +201,11 @@ $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'; @@ -271,7 +274,9 @@ } } - $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) { @@ -341,23 +346,23 @@ 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'); } } @@ -365,7 +370,7 @@ if ($buttontext) { if (!$moreattempts) { $buttontext = ''; - } else if (!$canpreview && $messages = $accessmanager->prevent_access()) { + } else if ($canattempt && $messages = $accessmanager->prevent_access()) { $accessmanager->print_messages($messages); $buttontext = ''; }