quiz: MDL-14926 New capability mod/quiz:reviewmyattempts, separate from mod/quiz:attempt. Merged from MOODLE_19_STABLE.

This commit is contained in:
tjhunt 2009-01-14 07:08:02 +00:00
parent 894687e8a3
commit 96c7d771df
14 changed files with 64 additions and 34 deletions

View 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];

View 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,

View file

@ -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;

View 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);

View 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])){

View 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);

View 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);

View 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);

View 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;
}

View 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());

View 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')) {

View 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)?

View 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.
@ -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 = '';
}