Assignment MDL-7206 - download all submissions as a zip - finally pushing this into...
[moodle.git] / mod / assignment / type / online / all.php
1 <?php
3 //===================================================
4 // all.php
5 //
6 // Displays a complete list of online assignments
7 // for the course. Rather like what happened in
8 // the old Journal activity.
9 // Howard Miller 2008
10 // See MDL-14045
11 //===================================================
13 require_once("../../../../config.php");
14 require_once("{$CFG->dirroot}/mod/assignment/lib.php");
15 require_once($CFG->libdir.'/gradelib.php');
16 require_once('assignment.class.php');
18 // get parameter
19 $id = required_param('id', PARAM_INT);   // course
21 if (!$course = $DB->get_record('course', array('id'=>$id))) {
22     print_error('invalidcourse');
23 }
25 $PAGE->set_url('/mod/assignment/type/online/all.php', array('id'=>$id));
27 require_course_login($course);
29 // check for view capability at course level
30 $context = get_context_instance(CONTEXT_COURSE,$course->id);
31 require_capability('mod/assignment:view',$context);
33 // various strings
34 $str = new stdClass;
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');
46 $PAGE->navbar->add($str->assignments, new moodle_url('/mod/assignment/index.php', array('id'=>$id)));
47 $PAGE->navbar->add($str->onlinetext);
49 // get all the assignments in the course
50 $assignments = get_all_instances_in_course('assignment',$course, $USER->id );
52 // get correct text for course type
53 if ($course->format=='weeks') {
54     $courseformat = $str->week;
56 } else if ($course->format=='topics') {
57     $courseformat = $str->topic;
59 } else {
60     $courseformat = '';
61 }
63 // array to hold display data
64 $views = array();
66 // loop over assignments finding online ones
67 foreach( $assignments as $assignment ) {
68     // only interested in online assignments
69     if ($assignment->assignmenttype != 'online') {
70         continue;
71     }
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     }
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();
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 );
91         } else {
92             $submissiondate = $str->duedateno;
93         }
95     } else {
96         $submissiontext = format_text( $submission->data1, $submission->data2 );
97         $submissiondate  = "{$str->submitted} ".userdate( $submission->timemodified );
98     }
100     // edit link
101     $editlink = "<a href=\"{$CFG->wwwroot}/mod/assignment/view.php?".
102         "id={$assignment->coursemodule}&amp;edit=1\">{$str->editmysubmission}</a>";
104     // format options for description
105     $formatoptions = new stdClass;
106     $formatoptions->noclean = true;
108     // object to hold display data for assignment
109     $view = new stdClass;
111     // start to build view object
112     if (!empty($courseformat)) {
113         $view->section = "$courseformat {$assignment->section}";
114     } else {
115         $view->section = '';
116     }
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;
126     $views[] = $view;
129 //===================
130 // DISPLAY
131 //===================
133 $PAGE->set_title($str->assignments);
134 echo $OUTPUT->header();
136 foreach ($views as $view) {
137     echo $OUTPUT->container_start('clearfix generalbox assignment');
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>';
143     }
145     // description part
146     echo '<div class="description">'.$view->description.'</div>';
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();
155     // feedback part
156     $onlineinstance = new assignment_online( $view->cm );
157     $onlineinstance->view_feedback();
159     echo $OUTPUT->container_end();
162 echo $OUTPUT->footer();