Merge branch 'MDL-44822' of git://github.com/aolley/moodle
[moodle.git] / mod / assignment / index.php
blob990d6856fcad0f6a728d1d95032fa80ded9c375a
1 <?php
3 require_once("../../config.php");
4 require_once("lib.php");
5 require_once($CFG->libdir.'/gradelib.php');
7 $id = required_param('id', PARAM_INT); // course
9 if (!$course = $DB->get_record('course', array('id'=>$id))) {
10 print_error('invalidcourseid');
13 require_course_login($course);
14 $PAGE->set_pagelayout('incourse');
16 add_to_log($course->id, "assignment", "view all", "index.php?id=$course->id", "");
18 $strassignments = get_string("modulenameplural", "assignment");
19 $strassignment = get_string("modulename", "assignment");
20 $strassignmenttype = get_string("assignmenttype", "assignment");
21 $strname = get_string("name");
22 $strduedate = get_string("duedate", "assignment");
23 $strsubmitted = get_string("submitted", "assignment");
24 $strgrade = get_string("grade");
27 $PAGE->set_url('/mod/assignment/index.php', array('id'=>$course->id));
28 $PAGE->navbar->add($strassignments);
29 $PAGE->set_title($strassignments);
30 $PAGE->set_heading($course->fullname);
31 echo $OUTPUT->header();
33 if (!$cms = get_coursemodules_in_course('assignment', $course->id, 'cm.idnumber, m.assignmenttype, m.timedue')) {
34 notice(get_string('noassignments', 'assignment'), "../../course/view.php?id=$course->id");
35 die;
38 $usesections = course_format_uses_sections($course->format);
40 $timenow = time();
42 $table = new html_table();
44 if ($usesections) {
45 $strsectionname = get_string('sectionname', 'format_'.$course->format);
46 $table->head = array ($strsectionname, $strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
47 } else {
48 $table->head = array ($strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
51 $currentsection = "";
53 $types = assignment_types();
55 $modinfo = get_fast_modinfo($course);
56 foreach ($modinfo->instances['assignment'] as $cm) {
57 if (!$cm->uservisible) {
58 continue;
61 $assignmenttype = $cms[$cm->id]->assignmenttype;
63 //Show dimmed if the mod is hidden
64 $class = $cm->visible ? '' : 'class="dimmed"';
66 $link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";
68 $printsection = "";
69 if ($usesections) {
70 if ($cm->sectionnum !== $currentsection) {
71 if ($cm->sectionnum) {
72 $printsection = get_section_name($course, $cm->sectionnum);
74 if ($currentsection !== "") {
75 $table->data[] = 'hr';
77 $currentsection = $cm->sectionnum;
81 if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$assignmenttype.'/assignment.class.php')) {
82 continue;
85 require_once ($CFG->dirroot.'/mod/assignment/type/'.$assignmenttype.'/assignment.class.php');
86 $assignmentclass = 'assignment_'.$assignmenttype;
87 $assignmentinstance = new $assignmentclass($cm->id, NULL, $cm, $course);
89 $submitted = $assignmentinstance->submittedlink(true);
91 $grading_info = grade_get_grades($course->id, 'mod', 'assignment', $cm->instance, $USER->id);
92 if (isset($grading_info->items[0]) && !$grading_info->items[0]->grades[$USER->id]->hidden ) {
93 $grade = $grading_info->items[0]->grades[$USER->id]->str_grade;
95 else {
96 $grade = '-';
99 $type = $types[$assignmenttype];
101 // if type has an 'all.php' defined, make this a link
102 $pathtoall = "{$CFG->dirroot}/mod/assignment/type/{$assignmenttype}/all.php";
103 if (file_exists($pathtoall)) {
104 $type = "<a href=\"{$CFG->wwwroot}/mod/assignment/type/{$assignmenttype}/".
105 "all.php?id={$course->id}\">$type</a>";
108 $due = !empty($cms[$cm->id]->timedue) ? userdate($cms[$cm->id]->timedue) : '-';
110 if ($usesections) {
111 $table->data[] = array ($printsection, $link, $type, $due, $submitted, $grade);
112 } else {
113 $table->data[] = array ($link, $type, $due, $submitted, $grade);
117 echo "<br />";
119 echo html_writer::table($table);
121 echo $OUTPUT->footer();