b746dac2c4b7c6140e8418ef4fe54195657de2e8
[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');
44 $PAGE->navbar->add($str->assignments, new moodle_url('/mod/assignment/index.php', array('id'=>$id)));
45 $PAGE->navbar->add($str->onlinetext);
47 // get all the assignments in the course
48 $assignments = get_all_instances_in_course('assignment',$course, $USER->id );
50 $sections = get_all_sections($course->id);
52 // array to hold display data
53 $views = array();
55 // loop over assignments finding online ones
56 foreach( $assignments as $assignment ) {
57     // only interested in online assignments
58     if ($assignment->assignmenttype != 'online') {
59         continue;
60     }
62     // check we are allowed to view this
63     $context = get_context_instance(CONTEXT_MODULE, $assignment->coursemodule);
64     if (!has_capability('mod/assignment:view',$context)) {
65         continue;
66     }
68     // create instance of assignment class to get
69     // submitted assignments
70     $onlineinstance = new assignment_online( $assignment->coursemodule );
71     $submitted = $onlineinstance->submittedlink(true);
72     $submission = $onlineinstance->get_submission();
74     // submission (if there is one)
75     if (empty($submission)) {
76         $submissiontext = $str->emptysubmission;
77         if (!empty($assignment->timedue)) {
78             $submissiondate = "{$str->duedate} ".userdate( $assignment->timedue );
80         } else {
81             $submissiondate = $str->duedateno;
82         }
84     } else {
85         $submissiontext = format_text( $submission->data1, $submission->data2 );
86         $submissiondate  = "{$str->submitted} ".userdate( $submission->timemodified );
87     }
89     // edit link
90     $editlink = "<a href=\"{$CFG->wwwroot}/mod/assignment/view.php?".
91         "id={$assignment->coursemodule}&amp;edit=1\">{$str->editmysubmission}</a>";
93     // format options for description
94     $formatoptions = new stdClass;
95     $formatoptions->noclean = true;
97     // object to hold display data for assignment
98     $view = new stdClass;
100     // start to build view object
101     $view->section = get_section_name($course, $sections[$assignment->section]);
103     $view->name = $assignment->name;
104     $view->submitted = $submitted;
105     $view->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
106     $view->editlink = $editlink;
107     $view->submissiontext = $submissiontext;
108     $view->submissiondate = $submissiondate;
109     $view->cm = $assignment->coursemodule;
111     $views[] = $view;
114 //===================
115 // DISPLAY
116 //===================
118 $PAGE->set_title($str->assignments);
119 echo $OUTPUT->header();
121 foreach ($views as $view) {
122     echo $OUTPUT->container_start('clearfix generalbox assignment');
124     // info bit
125     echo $OUTPUT->heading("$view->section - $view->name", 3, 'mdl-left');
126     if (!empty($view->submitted)) {
127         echo '<div class="reportlink">'.$view->submitted.'</div>';
128     }
130     // description part
131     echo '<div class="description">'.$view->description.'</div>';
133     //submission part
134     echo $OUTPUT->container_start('generalbox submission');
135     echo '<div class="submissiondate">'.$view->submissiondate.'</div>';
136     echo "<p class='no-overflow'>$view->submissiontext</p>\n";
137     echo "<p>$view->editlink</p>\n";
138     echo $OUTPUT->container_end();
140     // feedback part
141     $onlineinstance = new assignment_online( $view->cm );
142     $onlineinstance->view_feedback();
144     echo $OUTPUT->container_end();
147 echo $OUTPUT->footer();