This also cleans up the patch to prevent students from seeing the number of submissions for the assignment.
require_once("../../config.php");
require_once($CFG->dirroot.'/mod/assign/locallib.php');
-
-$id = required_param('id', PARAM_INT); // Course ID
+// For this type of page this is the course id.
+$id = required_param('id', PARAM_INT);
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
require_login($course);
// 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();
-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();
-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();
-$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) : '-';
+$context = context_course::instance($course->id);
- if ($usesections) {
- $row = array ($printsection, $link, $due, $submitted, $grade);
- } else {
- $row = array ($link, $due, $submitted, $grade);
- }
+require_capability('mod/assign:view', $context);
- $table->data[] = $row;
+$assign = new assign($context, null, $course);
-}
-echo html_writer::table($table);
-echo $OUTPUT->footer();
+// Get the assign to render the page.
+echo $assign->view('viewcourseindex');
$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. ';
$o .= $this->view_plugin_grading_batch_operation($mform);
} else if ($action == 'viewpluginpage') {
$o .= $this->view_plugin_page();
+ } else if ($action == 'viewcourseindex') {
+ $o .= $this->view_course_index();
} else {
$o .= $this->view_submission_page();
}
}
/**
- * View a page rendered by a plugin
+ * View a summary listing of all assignments in the current course.
+ *
+ * @return string
+ */
+ private function view_course_index() {
+ global $USER;
+
+ $o = '';
+
+ $course = $this->get_course();
+ $strplural = get_string('modulenameplural', 'assign');
+
+ if (!$cms = get_coursemodules_in_course('assign', $course->id, 'm.duedate')) {
+ $o .= $this->get_renderer()->notification(get_string('thereareno', 'moodle', $strplural));
+ $o .= $this->get_renderer()->continue_button(new moodle_url('/course/view.php', array('id' => $course->id)));
+ return $o;
+ }
+
+ $strsectionname = get_string('sectionname', 'format_'.$course->format);
+ $usesections = course_format_uses_sections($course->format);
+ $modinfo = get_fast_modinfo($course);
+
+ if ($usesections) {
+ $sections = $modinfo->get_section_info_all();
+ }
+ $courseindexsummary = new assign_course_index_summary($usesections, $strsectionname);
+
+ $timenow = time();
+
+ $currentsection = '';
+ foreach ($modinfo->instances['assign'] as $cm) {
+ if (!$cm->uservisible) {
+ continue;
+ }
+
+ $timedue = $cms[$cm->id]->duedate;
+
+ $sectionname = '';
+ if ($usesections && $cm->sectionnum) {
+ $sectionname = get_section_name($course, $sections[$cm->sectionnum]);
+ }
+
+ $submitted = '';
+ $context = context_module::instance($cm->id);
+
+ $assignment = new assign($context, $cm, $course);
+
+ if (has_capability('mod/assign:grade', $context)) {
+ $submitted = $assignment->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED);
+
+ } else if (has_capability('mod/assign:submit', $context)) {
+ $usersubmission = $assignment->get_user_submission($USER->id, false);
+
+ if (!empty($usersubmission->status)) {
+ $submitted = get_string('submissionstatus_' . $usersubmission->status, 'assign');
+ } else {
+ $submitted = get_string('submissionstatus_', 'assign');
+ }
+ }
+ $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 = '-';
+ }
+
+ $courseindexsummary->add_assign_info($cm->id, $cm->name, $sectionname, $timedue, $submitted, $grade);
+
+ }
+
+ $o .= $this->get_renderer()->render($courseindexsummary);
+ $o .= $this->view_footer();
+
+ return $o;
+ }
+
+ /**
+ * View a page rendered by a plugin.
*
* Uses url parameters 'pluginaction', 'pluginsubtype', 'plugin', and 'id'
*
}
+/**
+ * Renderable course index summary
+ * @package mod_assign
+ * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class assign_course_index_summary implements renderable {
+ /** @var array assignments - A list of course module info and submission counts or statuses */
+ public $assignments = array();
+ /** @var boolean usesections - Does this course format support sections? */
+ public $usesections = false;
+ /** @var string courseformat - The current course format name */
+ public $courseformatname = '';
+
+ /**
+ * constructor
+ *
+ * @param $usesections boolean - True if this course format uses sections
+ * @param $courseformatname string - The id of this course format
+ */
+ public function __construct($usesections, $courseformatname) {
+ $this->usesections = $usesections;
+ $this->courseformatname = $courseformatname;
+ }
+
+ /**
+ * Add a row of data to display on the course index page
+ *
+ * @param int $cmid - The course module id for generating a link
+ * @param string $cmname - The course module name for generating a link
+ * @param string $sectionname - The name of the course section (only if $usesections is true)
+ * @param int $timedue - The due date for the assignment - may be 0 if no duedate
+ * @param string $submissioninfo - A string with either the number of submitted assignments, or the
+ * status of the current users submission depending on capabilities.
+ * @param string $gradeinfo - The current users grade if they have been graded and it is not hidden.
+ */
+ public function add_assign_info($cmid, $cmname, $sectionname, $timedue, $submissioninfo, $gradeinfo) {
+ $this->assignments[] = array('cmid'=>$cmid,
+ 'cmname'=>$cmname,
+ 'sectionname'=>$sectionname,
+ 'timedue'=>$timedue,
+ 'submissioninfo'=>$submissioninfo,
+ 'gradeinfo'=>$gradeinfo);
+ }
+
+
+}
+
+
/**
* An assign file class that extends rendererable class and is used by the assign module.
*
return $o;
}
+ /**
+ * Render a course index summary
+ *
+ * @param assign_course_index_summary $indexsummary
+ * @return string
+ */
+ public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) {
+ $o = '';
+
+ $strplural = get_string('modulenameplural', 'assign');
+ $strsectionname = $indexsummary->courseformatname;
+ $strduedate = get_string('duedate', 'assign');
+ $strsubmission = get_string('submission', 'assign');
+ $strgrade = get_string('grade');
+
+ $table = new html_table();
+ if ($indexsummary->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');
+ }
+ $table->data = array();
+
+ $currentsection = '';
+ foreach ($indexsummary->assignments as $info) {
+ $params = array('id' => $info['cmid']);
+ $link = html_writer::link(new moodle_url('/mod/assign/view.php', $params),
+ $info['cmname']);
+ $due = $info['timedue'] ? userdate($info['timedue']) : '-';
+
+ $printsection = '';
+ if ($indexsummary->usesections) {
+ if ($info['sectionname'] !== $currentsection) {
+ if ($info['sectionname']) {
+ $printsection = $info['sectionname'];
+ }
+ if ($currentsection !== '') {
+ $table->data[] = 'hr';
+ }
+ $currentsection = $info['sectionname'];
+ }
+ }
+
+ if ($indexsummary->usesections) {
+ $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
+ } else {
+ $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
+ }
+ $table->data[] = $row;
+ }
+
+ $o .= html_writer::table($table);
+
+ return $o;
+ }
+
/**