Assignment MDL-7206 - download all submissions as a zip - finally pushing this into...
[moodle.git] / mod / assignment / type / online / all.php
CommitLineData
81625028 1<?php
3b0d5ca3 2
3//===================================================
4// all.php
5//
6// Displays a complete list of online assignments
e7521559 7// for the course. Rather like what happened in
3b0d5ca3 8// the old Journal activity.
9// Howard Miller 2008
10// See MDL-14045
11//===================================================
12
81625028 13require_once("../../../../config.php");
14require_once("{$CFG->dirroot}/mod/assignment/lib.php");
15require_once($CFG->libdir.'/gradelib.php');
16require_once('assignment.class.php');
3b0d5ca3 17
81625028 18// get parameter
19$id = required_param('id', PARAM_INT); // course
3b0d5ca3 20
81625028 21if (!$course = $DB->get_record('course', array('id'=>$id))) {
22 print_error('invalidcourse');
23}
3b0d5ca3 24
a6855934 25$PAGE->set_url('/mod/assignment/type/online/all.php', array('id'=>$id));
3b0d5ca3 26
81625028 27require_course_login($course);
6d2d4228 28
81625028 29// check for view capability at course level
30$context = get_context_instance(CONTEXT_COURSE,$course->id);
31require_capability('mod/assignment:view',$context);
3b0d5ca3 32
81625028 33// various strings
e7521559 34$str = new stdClass;
81625028 35$str->assignments = get_string("modulenameplural", "assignment");
36$str->duedate = get_string('duedate','assignment');
37$str->duedateno = get_string('duedateno','assignment');
38$str->editmysubmission = get_string('editmysubmission','assignment');
39$str->emptysubmission = get_string('emptysubmission','assignment');
40$str->noassignments = get_string('noassignments','assignment');
41$str->onlinetext = get_string('typeonline','assignment');
42$str->submitted = get_string('submitted','assignment');
43$str->topic = get_string('topic');
44$str->week = get_string('week');
3b0d5ca3 45
a6855934 46$PAGE->navbar->add($str->assignments, new moodle_url('/mod/assignment/index.php', array('id'=>$id)));
81625028 47$PAGE->navbar->add($str->onlinetext);
3b0d5ca3 48
81625028 49// get all the assignments in the course
50$assignments = get_all_instances_in_course('assignment',$course, $USER->id );
cadf3652 51
81625028 52// get correct text for course type
53if ($course->format=='weeks') {
54 $courseformat = $str->week;
cadf3652 55
81625028 56} else if ($course->format=='topics') {
57 $courseformat = $str->topic;
3b0d5ca3 58
81625028 59} else {
60 $courseformat = '';
61}
3b0d5ca3 62
81625028 63// array to hold display data
64$views = array();
3b0d5ca3 65
81625028 66// loop over assignments finding online ones
67foreach( $assignments as $assignment ) {
68 // only interested in online assignments
69 if ($assignment->assignmenttype != 'online') {
70 continue;
71 }
6d2d4228 72
81625028 73 // check we are allowed to view this
74 $context = get_context_instance(CONTEXT_MODULE, $assignment->coursemodule);
75 if (!has_capability('mod/assignment:view',$context)) {
76 continue;
77 }
3b0d5ca3 78
81625028 79 // create instance of assignment class to get
80 // submitted assignments
81 $onlineinstance = new assignment_online( $assignment->coursemodule );
82 $submitted = $onlineinstance->submittedlink(true);
83 $submission = $onlineinstance->get_submission();
cadf3652 84
81625028 85 // submission (if there is one)
86 if (empty($submission)) {
87 $submissiontext = $str->emptysubmission;
88 if (!empty($assignment->timedue)) {
89 $submissiondate = "{$str->duedate} ".userdate( $assignment->timedue );
cadf3652 90
91 } else {
81625028 92 $submissiondate = $str->duedateno;
3b0d5ca3 93 }
94
81625028 95 } else {
96 $submissiontext = format_text( $submission->data1, $submission->data2 );
97 $submissiondate = "{$str->submitted} ".userdate( $submission->timemodified );
98 }
3b0d5ca3 99
81625028 100 // edit link
101 $editlink = "<a href=\"{$CFG->wwwroot}/mod/assignment/view.php?".
102 "id={$assignment->coursemodule}&amp;edit=1\">{$str->editmysubmission}</a>";
3b0d5ca3 103
81625028 104 // format options for description
105 $formatoptions = new stdClass;
106 $formatoptions->noclean = true;
3b0d5ca3 107
81625028 108 // object to hold display data for assignment
109 $view = new stdClass;
3b0d5ca3 110
81625028 111 // start to build view object
112 if (!empty($courseformat)) {
113 $view->section = "$courseformat {$assignment->section}";
114 } else {
115 $view->section = '';
3b0d5ca3 116 }
117
81625028 118 $view->name = $assignment->name;
119 $view->submitted = $submitted;
120 $view->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
121 $view->editlink = $editlink;
122 $view->submissiontext = $submissiontext;
123 $view->submissiondate = $submissiondate;
124 $view->cm = $assignment->coursemodule;
125
126 $views[] = $view;
127}
128
3b0d5ca3 129//===================
130// DISPLAY
131//===================
132
81625028 133$PAGE->set_title($str->assignments);
134echo $OUTPUT->header();
3b0d5ca3 135
81625028 136foreach ($views as $view) {
137 echo $OUTPUT->container_start('clearfix generalbox assignment');
3b0d5ca3 138
81625028 139 // info bit
140 echo $OUTPUT->heading("$view->section - $view->name", 3, 'mdl-left');
141 if (!empty($view->submitted)) {
142 echo '<div class="reportlink">'.$view->submitted.'</div>';
3b0d5ca3 143 }
7a3f8bf4 144
81625028 145 // description part
146 echo '<div class="description">'.$view->description.'</div>';
147
148 //submission part
149 echo $OUTPUT->container_start('generalbox submission');
150 echo '<div class="submissiondate">'.$view->submissiondate.'</div>';
151 echo "<p>$view->submissiontext</p>\n";
152 echo "<p>$view->editlink</p>\n";
153 echo $OUTPUT->container_end();
154
155 // feedback part
156 $onlineinstance = new assignment_online( $view->cm );
157 $onlineinstance->view_feedback();
158
159 echo $OUTPUT->container_end();
160}
161
162echo $OUTPUT->footer();