-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·151 lines (131 loc) · 5.46 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This script lists all the instances of questionnaire in a particular course
*
* @package mod
* @subpackage questionnaire
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once($CFG->dirroot.'/mod/questionnaire/locallib.php');
$id = required_param('id', PARAM_INT);
$PAGE->set_url('/mod/questionnaire/index.php', array('id' => $id));
if (! $course = $DB->get_record('course', array('id' => $id))) {
print_error('incorrectcourseid', 'questionnaire');
}
$coursecontext = context_course::instance($id);
require_login($course->id);
$PAGE->set_pagelayout('incourse');
add_to_log($course->id, "questionnaire", "view all", "index.php?id=$course->id", "");
// Print the header.
$strquestionnaires = get_string("modulenameplural", "questionnaire");
$PAGE->navbar->add($strquestionnaires);
$PAGE->set_title("$course->shortname: $strquestionnaires");
$PAGE->set_heading(format_string($course->fullname));
echo $OUTPUT->header();
// Get all the appropriate data.
if (!$questionnaires = get_all_instances_in_course("questionnaire", $course)) {
notice(get_string('thereareno', 'moodle', $strquestionnaires), "../../course/view.php?id=$course->id");
die;
}
// Check if we need the closing date header.
$showclosingheader = false;
foreach ($questionnaires as $questionnaire) {
if ($questionnaire->closedate != 0) {
$showclosingheader = true;
}
if ($showclosingheader) {
break;
}
}
// Configure table for displaying the list of instances.
$headings = array(get_string('name'));
$align = array('left');
if ($showclosingheader) {
array_push($headings, get_string('questionnairecloses', 'questionnaire'));
array_push($align, 'left');
}
array_unshift($headings, get_string('sectionname', 'format_'.$course->format));
array_unshift($align, 'left');
$showing = '';
// Current user role == admin or teacher.
if (has_capability('mod/questionnaire:viewsingleresponse', $coursecontext)) {
array_push($headings, get_string('responses', 'questionnaire'));
array_push($align, 'center');
$showing = 'stats';
array_push($headings, get_string('realm', 'questionnaire'));
array_push($align, 'left');
// Current user role == student.
} else if (has_capability('mod/questionnaire:submit', $coursecontext)) {
array_push($headings, get_string('status'));
array_push($align, 'left');
$showing = 'responses';
}
$table = new html_table();
$table->head = $headings;
$table->align = $align;
// Populate the table with the list of instances.
$currentsection = '';
foreach ($questionnaires as $questionnaire) {
$cmid = $questionnaire->coursemodule;
$data = array();
$realm = $DB->get_field('questionnaire_survey', 'realm', array('id' => $questionnaire->sid));
// Template surveys should NOT be displayed as an activity to students.
if (!($realm == 'template' && !has_capability('mod/questionnaire:manage', context_module::instance($cmid)))) {
// Section number if necessary.
$strsection = '';
if ($questionnaire->section != $currentsection) {
$strsection = get_section_name($course, $questionnaire->section);
$currentsection = $questionnaire->section;
}
$data[] = $strsection;
// Show normal if the mod is visible.
$class = '';
if (!$questionnaire->visible) {
$class = ' class="dimmed"';
}
$data[] = "<a$class href=\"view.php?id=$cmid\">$questionnaire->name</a>";
// Close date.
if ($questionnaire->closedate) {
$data[] = userdate($questionnaire->closedate);
} else if ($showclosingheader) {
$data[] = '';
}
if ($showing == 'responses') {
$status = '';
if ($responses = questionnaire_get_user_responses($questionnaire->sid, $USER->id, $complete = false)) {
foreach ($responses as $response) {
if ($response->complete == 'y') {
$status .= get_string('submitted', 'questionnaire').' '.userdate($response->submitted).'<br />';
} else {
$status .= get_string('attemptstillinprogress', 'questionnaire').' '.
userdate($response->submitted).'<br />';
}
}
}
$data[] = $status;
} else if ($showing == 'stats') {
$data[] = $DB->count_records('questionnaire_response', array('survey_id' => $questionnaire->sid, 'complete' => 'y'));
$data[] = get_string($realm, 'questionnaire');
}
}
$table->data[] = $data;
} // End of loop over questionnaire instances.
echo html_writer::table($table);
// Finish the page.
echo $OUTPUT->footer();