$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';
$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';
$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';
$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';
(!$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];
// Ability to do the quiz as a 'student'.
'mod/quiz:attempt' => array(
+ 'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'legacy' => 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,
}
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;
// 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);
}
$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])){
$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);
/// 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);
$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);
$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);
$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);
$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;
}
/// 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());
/// 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')) {
// 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)?
/// 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 = '';
}