Permalink
Browse files

MDL-35740 Assignment: Hide the number of assignment submissions for a…

…ll students that was visible to all students through the activities block
  • Loading branch information...
1 parent 7d3341b commit 901dd625f81ec71fb3eb6f3e0795ff9f2ad95a86 Raymond Wijaya committed with danpoltawski Oct 3, 2012
Showing with 86 additions and 13 deletions.
  1. +85 −13 mod/assign/index.php
  2. +1 −0 mod/assign/lang/en/assign.php
View
@@ -36,34 +36,106 @@
// Print the header
$strplural = get_string("modulenameplural", "assign");
+$strsectionname = get_string('sectionname', 'format_'.$course->format);
+$strduedate = get_string("duedate", "assign");
+$strsubmission = get_string("submission", "assign");
+$strgrade = get_string("grade");
$PAGE->navbar->add($strplural);
$PAGE->set_title($strplural);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
-// Get all the appropriate data
-if (!$assignments = get_all_instances_in_course("assign", $course)) {
+if (!$cms = get_coursemodules_in_course('assign', $course->id, 'cm.idnumber, m.duedate')) {
notice(get_string('thereareno', 'moodle', $strplural), new moodle_url('/course/view.php', array('id' => $course->id)));
die;
}
+$usesections = course_format_uses_sections($course->format);
+if ($usesections) {
+ $sections = get_all_sections($course->id);
+}
+
+$timenow = time();
+
// Check if we need the closing date header
$table = new html_table();
-$table->head = array ($strplural, get_string('duedate', 'assign'), get_string('submissions', 'assign'));
-$table->align = array ('left', 'left', 'center');
+if ($usesections) {
+ $table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
+ $table->align = array ('left', 'left', 'center', 'right', 'right');
+} else {
+ $table->head = array ($strplural, $strduedate, $strsubmission, $strgrade);
+ $table->align = array ('left', 'left', 'center', 'right');
+}
+
+$currentsection = "";
$table->data = array();
-foreach ($assignments as $assignment) {
- $cm = get_coursemodule_from_instance('assign', $assignment->id, 0, false, MUST_EXIST);
+$modinfo = get_fast_modinfo($course);
+foreach ($modinfo->instances['assign'] as $cm) {
+ if (!$cm->uservisible) {
+ continue;
+ }
+
+ $cm->timedue = $cms[$cm->id]->duedate;
+ $cm->idnumber = $cms[$cm->id]->idnumber;
+
+ $link = html_writer::link(new moodle_url('/mod/assign/view.php', array('id' => $cm->id)), $cm->name);
+
+ $printsection = "";
+ if ($usesections) {
+ if ($cm->sectionnum !== $currentsection) {
+ if ($cm->sectionnum) {
+ $printsection = get_section_name($course, $sections[$cm->sectionnum]);
+ }
+ if ($currentsection !== "") {
+ $table->data[] = 'hr';
+ }
+ $currentsection = $cm->sectionnum;
+ }
+ }
+
+ $submitted = "";
+ $cmod = get_coursemodule_from_instance('assign', $cm->instance, 0, false, MUST_EXIST);
+ $context = context_module::instance($cmod->id);
+ $assignment = new assign($context, $cmod, $course);
+ if (has_capability('mod/assign:grade', $context)) {
+ $params = array('assignment' => $cm->instance, 'status' => ASSIGN_SUBMISSION_STATUS_SUBMITTED);
+ $submissioncount = $DB->count_records('assign_submission', $params);
+ if ($submissioncount == 1) {
+ $submitted = html_writer::link(new moodle_url('/mod/assign/view.php', array('id' => $assignment->get_course_module()->id,
+ 'action' => 'grading')), $submissioncount . " " . get_string('submission', 'assign'));
+ } else if ($submissioncount > 1) {
+ $submitted = html_writer::link(new moodle_url('/mod/assign/view.php', array('id' => $assignment->get_course_module()->id,
+ 'action' => 'grading')), $submissioncount . " " . get_string('submissions', 'assign'));
+ } else {
+ $submitted = $submissioncount;
+ }
+ } else if(has_capability('mod/assign:submit', $context)) {
+ $submissionstatus = $assignment->get_user_submission($USER->id, false);
+ if (!empty($submissionstatus->status)) {
+ $submitted = get_string('submissionstatus_' . $submissionstatus->status, 'assign');
+ } else {
+ $submitted = get_string('submissionstatus_', 'assign');
+ }
+ } else {
+ $submitted = new html_table_cell(get_string('nopermission', 'assign'));
+ $submitted->attributes = array('class'=> 'submittedlate');
+ }
+ $grading_info = grade_get_grades($course->id, 'mod', 'assign', $cm->instance, $USER->id);
+ if (isset($grading_info->items[0]) && !$grading_info->items[0]->grades[$USER->id]->hidden ) {
+ $grade = $grading_info->items[0]->grades[$USER->id]->str_grade;
+ }
+ else {
+ $grade = '-';
+ }
+
+ $due = $cm->timedue ? userdate($cm->timedue) : '-';
- $link = html_writer::link(new moodle_url('/mod/assign/view.php', array('id' => $cm->id)), $assignment->name);
- $date = '-';
- if (!empty($assignment->duedate)) {
- $date = userdate($assignment->duedate);
+ if ($usesections) {
+ $row = array ($printsection, $link, $due, $submitted, $grade);
+ } else {
+ $row = array ($link, $due, $submitted, $grade);
}
- $params = array('assignment'=>$cm->instance, 'status'=>ASSIGN_SUBMISSION_STATUS_SUBMITTED);
- $submissions = $DB->count_records('assign_submission', $params);
- $row = array($link, $date, $submissions);
$table->data[] = $row;
}
@@ -190,6 +190,7 @@
$string['modulenameplural'] = 'Assignments';
$string['mysubmission'] = 'My submission: ';
$string['newsubmissions'] = 'Assignments submitted';
+$string['nopermission'] = 'No permission';
$string['nofiles'] = 'No files. ';
$string['nograde'] = 'No grade. ';
$string['nolatesubmissions'] = 'No late submissions accepted. ';

0 comments on commit 901dd62

Please sign in to comment.