-
Notifications
You must be signed in to change notification settings - Fork 1
/
report.php
214 lines (192 loc) · 7.53 KB
/
report.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?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/>.
/**
*
* @package moodle-mod
* @subpackage strathpa
* @copyright 2012 University of Strathclyde
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
require('../../config.php');
require_once("lib.php");
require_once($CFG->dirroot."/lib/tablelib.php");
$id = optional_param('id', false, PARAM_INT);//course module id;
$groupid = optional_param('selectedgroup', false, PARAM_INT);
$startreportperiod = optional_param('startperiod', false, PARAM_INT);
$p = optional_param('peerassessment', 0, PARAM_INT);
$params = array();
if ($id) {
$params['id']=$id;
}
if ($groupid) {
$params['selectedgroup'] = $groupid;
}
if ($startreportperiod) {
$params['startReportPeriod'] = $startreportperiod;
}
if ($p != 0) {
$params['peerassessment'] = $p;
}
if ($id) {
if (!$cm = get_coursemodule_from_id('strathpa', $id)) {
error("Course Module ID was incorrect (1)");
}
if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
error("Course is misconfigured");
}
if (!$peerassessment = $DB->get_record(PA_TABLE, array('id' => $cm->instance))) {
error("Course module is incorrect");
}
} else {
if (! $peerassessment = $DB->get_record('strathpa', array('id' => $p))) {
error('Course module is incorrect');
}
if (! $course = $DB->get_record('course', array('id'=>$peerassessment->course))) {
error('Course is misconfigured');
}
if (! $cm = get_coursemodule_from_instance('strathpa', $peerassessment->id, $course->id)) {
error('Course Module ID was incorrect (2)');
}
$id=$cm->id;
}
require_course_login($course, true, $cm);
$PAGE->set_url('/mod/strathpa/report.php', $params);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/strathpa:viewreport', $context);
$ratings = $DB->get_records('strathpa_ratings', array('peerassessment' => $peerassessment->id));
$group = false;
$groupmode = false;
$group_context=false;
if ($peerassessment->assignment) {
if (!$assignment_cm = get_coursemodule_from_id('assignment', $peerassessment->assignment)) {
die('Couldn\'t get cm for assignment');
}
} else {
$assignment_cm = $cm;
}
$data = data_submitted();
if ($data) {
if (!empty($data->delete)) {
//add_to_log('requested deletion of rating')
//echo "deleting a rating\n";
//if ($rating = $DB->get_records('strathpa_ratings', array('id' => $data->ratingid))) {
if ($rating = $DB->get_records('strathpa_ratings', array('id' => $data->ratingid))) {
if (!$DB->delete_records('strathpa_ratings', array('id' => $rating->id))) {
notice("Could not delete rating");
}
} else {
if ($rating = $DB->get_records_select('strathpa_ratings',
"peerassessment={$data->peerassessment} AND timemodified={$data->ratingtime} AND ratedby={$data->userid} ")
) {
if (!$DB->delete_records_select('strathpa_ratings',
"peerassessment={$data->peerassessment}
AND timemodified={$data->ratingtime}
AND ratedby={$data->userid} ")
) {
notice("Could not delete rating");
}
} else {
notice("Couldn't locate a rating for specified user");
}
}
if (!($DB->delete_records('strathpa_comments', array(
'peerassessment'=> $data->peerassessment,
'userid' => $data->userid)
))) {
notice("Could not delete comment");
}
strathpa_update_grades($peerassessment); //update the grade book since we've deleted some entries
redirect($CFG->wwwroot."/mod/strathpa/report.php?selectedgroup={$groupid}&id={$id}");
}
}
$displaygroups= array();
//display a list of groups to display
$groups = groups_get_activity_allowed_groups($assignment_cm);
foreach ($groups as $g) {
$displaygroups[$g->id] =$g->name;
}
ksort($displaygroups, SORT_STRING); /* This is a hack based on the fact that
groups are created in numeric/
alphabetical order.
*/
$members = groups_get_members($groupid);
$group = groups_get_group($groupid);
/*
if ($strathpa->frequency > PA_FREQ_ONCE) {
// TODO (future) we have to display a list of dates
}
*/
$str_title_details = new stdClass();
$str_title_details->peerassessmentname = $peerassessment->name;
$str_title_details->groupname = '';
if ($groupid) {
$str_title_details->groupname = $group->name;
$str_title = get_string('peerassessmentactivityheadingforgroup','strathpa',$str_title_details);
}
$PAGE->set_title($str_title);
echo $OUTPUT->header();
$navigation = build_navigation('', $cm);
//print_header_simple(format_string($peerassessment->name), '', $navigation,
//'', '', true, '', navmenu($course, $cm));
echo $OUTPUT->heading($str_title);
$OUTPUT->heading($str_title);//get_string('peerassessmentreportheading', 'strathpa', $peerassessment));
echo '<div class="reportlink">';
print_string('displaygroup', 'strathpa');
print_report_select_form($id, $groups, $groupid);
echo '</div>';
if ($groupid) {
switch ($peerassessment->frequency) {
case PA_FREQ_ONCE:
$table = strathpa_get_table_single_frequency($peerassessment, $group);
break;
case PA_FREQ_WEEKLY:
$overview_table = new Stdclass;
$overview_table->head[] = '';
$a = array(); // average rating
$b = array(); //average given rating
$a[] = get_string('averageratingreceived', 'strathpa');
$b[] = get_string('averageratinggiven', 'strathpa');
foreach ($members as $m) {
$overview_table->head[] = $m->lastname . ', '.$m->firstname;
$a[] = get_average_rating_for_student($peerassessment, $m->id);
$b[] = get_average_rating_by_student($peerassessment, $m->id);
}
$overview_table->data[] = $a;
$overview_table->data[] = $b;
print_heading(get_string('overview', 'strathpa'));
print_table($overview_table);
$table = strathpa_get_table_weekly_frequency($peerassessment, $group);
print_heading(get_string('details', 'strathpa'));
break;
case PA_FREQ_UNLIMITED:
$table = strathpa_get_table_unlimited_frequency($peerassessment, $group);
break;
break;
}
echo html_writer::table($table);
} else {
echo $OUTPUT->box_start();
echo("Please choose a group to display.");
echo $OUTPUT->single_select(
$CFG->wwwroot."/mod/strathpa/report.php?id={$id}&selectedgroup=",
'reportgroupjump',
$displaygroups,
$groupid
);
echo $OUTPUT->box_end();
}
echo $OUTPUT->footer();