Permalink
Browse files

mod-assignment MDL-23848 Users can now view previously submit assignm…

…ents if they no longer have the submit capability
  • Loading branch information...
1 parent 0fab420 commit a3f2fa69b01051b125cc4c64b580274e48ff6a69 Sam Hemelryk committed Sep 16, 2010
@@ -135,6 +135,7 @@
$string['uploadnofilefound'] = 'No file was found - are you sure you selected one to upload?';
$string['uploadnotregistered'] = '\'$a\' was uploaded OK but submission did not register!';
$string['uploadsuccess'] = 'Uploaded \'$a\' successfully';
+$string['usernosubmit'] = 'Sorry, you are not allowed to submit an assignment.';
$string['viewfeedback'] = 'View assignment grades and feedback';
$string['viewsubmissions'] = 'View $a submitted assignments';
$string['yoursubmission'] = 'Your submission';
View
@@ -209,13 +209,18 @@ function view_feedback($submission=NULL) {
global $USER, $CFG;
require_once($CFG->libdir.'/gradelib.php');
- if (!has_capability('mod/assignment:submit', $this->context, $USER->id, false)) {
- // can not submit assignments -> no feedback
- return;
+ if (!$submission) { /// Get submission for this assignment
+ $submission = $this->get_submission($USER->id, false);
}
- if (!$submission) { /// Get submission for this assignment
- $submission = $this->get_submission($USER->id);
+ // Check the user can submit
+ $cansubmit = has_capability('mod/assignment:submit', $this->context, $USER->id, false);
+ // If not then check if ther user still has the view cap and has a previous submission
+ $cansubmit = $cansubmit || (!empty($submission) && has_capability('mod/assignment:view', $this->context, $USER->id, false));
+
+ if (!$cansubmit) {
+ // can not submit assignments -> no feedback
+ return;
}
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $USER->id);
@@ -809,14 +814,16 @@ function display_submission($extra_javascript = '') {
/// Get all ppl that can submit assignments
$currentgroup = groups_get_activity_group($cm);
- if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
- $users = array_keys($users);
- }
- // if groupmembersonly used, remove users who are not in any group
- if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
- if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
- $users = array_intersect($users, array_keys($groupingusers));
+ $gradebookroles = explode(",", $CFG->gradebookroles);
+ $users = get_role_users($gradebookroles, $context, true);
+ if ($users) {
+ $users = array_keys($users);
+ // if groupmembersonly used, remove users who are not in any group
+ if (!empty($CFG->enablegroupings) and $cm->groupmembersonly) {
+ if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
+ $users = array_intersect($users, array_keys($groupingusers));
+ }
}
}
@@ -1067,15 +1074,15 @@ function display_submissions($message='') {
$currentgroup = groups_get_activity_group($cm, true);
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id);
- /// Get all ppl that are allowed to submit assignments
- if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
+ $gradebookroles = explode(",", $CFG->gradebookroles);
+ $users = get_role_users($gradebookroles, $context, true);
+ if ($users) {
$users = array_keys($users);
- }
-
- // if groupmembersonly used, remove users who are not in any group
- if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
- if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
- $users = array_intersect($users, array_keys($groupingusers));
+ if (!empty($CFG->enablegroupings) and $cm->groupmembersonly) {
+ $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id');
+ if ($groupingusers) {
+ $users = array_intersect($users, array_keys($groupingusers));
+ }
}
}
@@ -2776,18 +2783,19 @@ function assignment_count_real_submissions($cm, $groupid=0) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
- // this is all the users with this capability set, in this context or higher
- if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $groupid, '', false)) {
+ $gradebookroles = explode(",", $CFG->gradebookroles);
+ $users = get_role_users($gradebookroles, $context, true);
+ if ($users) {
$users = array_keys($users);
- }
-
- // if groupmembersonly used, remove users who are not in any group
- if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
- if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
- $users = array_intersect($users, array_keys($groupingusers));
+ // if groupmembersonly used, remove users who are not in any group
+ if (!empty($CFG->enablegroupings) and $cm->groupmembersonly) {
+ $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id');
+ if ($groupingusers) {
+ $users = array_intersect($users, array_keys($groupingusers));
+ }
}
}
-
+
if (empty($users)) {
return 0;
}
@@ -3005,7 +3013,9 @@ function assignment_print_overview($courses, &$htmlarray) {
// count how many people can submit
$submissions = 0; // init
- if ($students = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', 0, '', false)) {
+ $gradebookroles = explode(",", $CFG->gradebookroles);
+ $students = get_role_users($gradebookroles, $context, true);
+ if ($students) {
foreach($students as $student){
if(isset($unmarkedsubmissions[$assignment->id][$student->id])){
$submissions++;
@@ -84,7 +84,7 @@ function view() {
if ($editmode) {
$this->view_header(get_string('editmysubmission', 'assignment'));
} else {
- $this->view_header();
+ $this->view_header(get_string('viewsubmissions', 'assignment'));
}
$this->view_intro();
@@ -95,28 +95,30 @@ function view() {
notify(get_string('submissionsaved', 'assignment'), 'notifysuccess');
}
- if (has_capability('mod/assignment:submit', $context)) {
- if ($editmode) {
- print_box_start('generalbox', 'online');
- $mform->display();
- } else {
- print_box_start('generalbox boxwidthwide boxaligncenter', 'online');
- if ($submission) {
- echo format_text($submission->data1, $submission->data2);
- } else if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604
+ if ($editmode) {
+ print_box_start('generalbox', 'online');
+ $mform->display();
+ print_box_end();
+ } else {
+ print_box_start('generalbox boxwidthwide boxaligncenter', 'online');
+ if ($submission) {
+ echo format_text($submission->data1, $submission->data2);
+ } else if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604
+ if (isguest()) {
echo '<div style="text-align:center">'. get_string('guestnosubmit', 'assignment').'</div>';
- } else if ($this->isopen()){ //fix for #4206
- echo '<div style="text-align:center">'.get_string('emptysubmission', 'assignment').'</div>';
+ } else {
+ echo '<div style="text-align:center">'. get_string('usernosubmit', 'assignment').'</div>';
}
+ } else if ($this->isopen()){ //fix for #4206
+ echo '<div style="text-align:center">'.get_string('emptysubmission', 'assignment').'</div>';
}
print_box_end();
- if (!$editmode && $editable) {
+ if ($editable) {
echo "<div style='text-align:center'>";
print_single_button('view.php', array('id'=>$this->cm->id,'edit'=>'1'),
get_string('editmysubmission', 'assignment'));
echo "</div>";
}
-
}
$this->view_feedback();
@@ -36,37 +36,37 @@ function view() {
$this->view_dates();
- if (has_capability('mod/assignment:submit', $this->context)) {
- $filecount = $this->count_user_files($USER->id);
- $submission = $this->get_submission($USER->id);
+ $filecount = $this->count_user_files($USER->id);
+ $submission = $this->get_submission($USER->id);
- $this->view_feedback();
+ $this->view_feedback();
- if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) {
- print_heading(get_string('submission', 'assignment'), '', 3);
- } else {
- print_heading(get_string('submissiondraft', 'assignment'), '', 3);
- }
+ if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) {
+ print_heading(get_string('submission', 'assignment'), '', 3);
+ } else {
+ print_heading(get_string('submissiondraft', 'assignment'), '', 3);
+ }
- if ($filecount and $submission) {
- print_simple_box($this->print_user_files($USER->id, true), 'center');
+ if ($filecount and $submission) {
+ print_simple_box($this->print_user_files($USER->id, true), 'center');
+ } else {
+ if (!$this->isopen() or $this->is_finalized($submission)) {
+ print_simple_box(get_string('nofiles', 'assignment'), 'center');
} else {
- if (!$this->isopen() or $this->is_finalized($submission)) {
- print_simple_box(get_string('nofiles', 'assignment'), 'center');
- } else {
- print_simple_box(get_string('nofilesyet', 'assignment'), 'center');
- }
+ print_simple_box(get_string('nofilesyet', 'assignment'), 'center');
}
+ }
+ if (has_capability('mod/assignment:submit', $this->context)) {
$this->view_upload_form();
+ }
- if ($this->notes_allowed()) {
- print_heading(get_string('notes', 'assignment'), '', 3);
- $this->view_notes();
- }
-
- $this->view_final_submission();
+ if ($this->notes_allowed()) {
+ print_heading(get_string('notes', 'assignment'), '', 3);
+ $this->view_notes();
}
+
+ $this->view_final_submission();
$this->view_footer();
}

0 comments on commit a3f2fa6

Please sign in to comment.