-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummary_student.php
More file actions
executable file
·297 lines (288 loc) · 11.7 KB
/
summary_student.php
File metadata and controls
executable file
·297 lines (288 loc) · 11.7 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
global $DB;
$base_url = str_replace('blocks/progress/summary_student.php', '', $_SERVER['SCRIPT_FILENAME']);
require_once($base_url.'config.php');
$student = $DB->get_record_select('user', 'id='.$_GET['student']);
$courses = enrol_get_users_courses($student->id, 'sortorder');
$user = $DB->get_record_select('user', 'id='.$_GET['user']);
$now = time();
// require valid moodle login. Will redirect to login page if not logged in.
require_login();
//Checks session userid matches url id.
//function CheckRole() {
// global $USER;
// if ($_GET['student']==$USER->id) { } else exit("Authentication missmatch, access denied.");
// }
// get the context
//$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
// If user does not have editing rights call the check role function.
//if (has_capability('moodle/course:update', $context)) { } else CheckRole();
?>
<?php
function uses_outcomes($prefix, $courseid) {
$grades = get_possible($prefix, $courseid);
if ($grades['P']) return true;
return false;
}
?>
<?php
function get_possible($prefix, $course) {
$letters = array('P', 'M', 'D'); # needs to be based on bands
foreach($letters as $letter) {
$temp = array();
$sql = 'select a.shortname
from '.$prefix.'grade_outcomes a, '.$prefix.'grade_outcomes_courses b
where a.id = b.outcomeid
and b.courseid='.$course.
' and a.shortname like "'.$letter.'%";';
include '/protected/dbcred.php';
mysql_connect($host, $user, $pass);
mysql_select_db($db);
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$possible[$letter] = $count;
}
return $possible;
}
?>
<?php // MJT NEEDS FIXING!
function get_achieved($prefix, $student, $course) {
$sql = 'SELECT b.itemname
FROM '.$prefix.'grade_grades a, '.$prefix.'grade_items b, '.$prefix.'grade_outcomes c
WHERE a.itemid = b.id
AND b.itemname = c.fullname
AND a.userid = '.$student.'
AND a.finalgrade >1
AND b.courseid = '.$course.';';
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$c = 'g'.$row['itemname'];
$outcome[$c] = 1;
}
$achieved = array('P'=>0, 'M'=>0, 'D'=>0);
//print_r($outcome);
if ( isset($outcome) ) {
foreach ($outcome as $c=>$d) {
if (strpos($c, 'P')) $achieved['P']++;
if (strpos($c, 'M')) $achieved['M']++;
if (strpos($c, 'D')) $achieved['D']++;
}
return $achieved;
}
return null;
}
?>
<?php
function outcome_achieved($prefix, $course, $student, $outcome) {
//$quiz = quiz_outcome_achieved($prefix, $course, $student, $outcome);
if (isset($quiz))
if ($quiz) return true;
$sql = 'SELECT b.itemname
FROM '.$prefix.'grade_grades a, '.$prefix.'grade_items b, '.$prefix.'grade_outcomes c
WHERE a.itemid = b.id
AND b.itemname = c.fullname
AND a.userid = '.$student.'
AND a.finalgrade >1
AND c.shortname = "'.$outcome.'"
AND b.courseid = '.$course.';';
$result = mysql_query($sql);
if (mysql_num_rows($result)) return true;
return false;
}
?>
<?php
// returns true if the user has achieved a specific outcome through a quiz //
function quiz_outcome_achieved($prefix, $course, $student, $outcome) {
global $DB;
$quizzes = $DB->get_records_select('quiz', 'course='.$course, array('id'));
foreach($quizzes as $q) {
//$threshold = $DB->get_field_select('quiz_feedback', 'mingrade', 'feedbacktext="PASS"');
$grade = $DB->get_field_select('quiz_grades', 'grade', 'quiz='.$q->id.' and userid='.$student);
if (isset($threshold))
if ($grade >= $threshold) { // they have passed the quiz!
// which criteria have they passed?
$sql = 'select count(b.id) as id from mdl_grade_items a, mdl_grade_outcomes b
where a.outcomeid = b.id
and a.courseid = '.$course.'
and a.itemmodule = "quiz"
and b.shortname = "'.$outcome.'";';
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if ($row['id']) return true;
}
}
return false;
}
?>
<?php
function get_possible_criteria($prefix, $course) {
$letters = array('P', 'M', 'D'); # needs to be based on bands
foreach($letters as $letter) {
$sql = 'select a.shortname
from '.$prefix.'grade_outcomes a, '.$prefix.'grade_outcomes_courses b
where a.id = b.outcomeid
and b.courseid='.$course.
' and a.shortname like "'.$letter.'%";';
$result = mysql_query($sql);
$temp = array();
while ($row = mysql_fetch_assoc($result)) {
array_push($temp, str_replace($letter, '', $row['shortname']));
}
$possible[$letter] = $temp;
}
return $possible;
}
?>
<?php
function get_description($prefix, $course, $outcome) {
$sql = 'SELECT description from '.$prefix.'grade_outcomes WHERE courseid='.$course.' and shortname="'.$outcome.'";';
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$desc = str_replace('<p>', "\n", $row['description']);
$desc = strip_tags($desc);
return $desc;
}
?>
<?php
function get_points($course) {
global $DB;
$idnumber = $DB->get_field_select('course', 'idnumber', 'id='.$course['course']->id);
$values = explode('/', $idnumber);
if (count($values) == 3 && is_numeric($values[0]) && is_numeric($values[1]) && is_numeric($values[2])) {
$points = 0;
if ($course['achieved']['summary']['P'] >= $course['possible']['summary']['P']) $points = $values[0];
if ($course['achieved']['summary']['M'] >= $course['possible']['summary']['M']) $points = $values[1];
if ($course['achieved']['summary']['D'] >= $course['possible']['summary']['D']) $points = $values[2];
return $points;
}
return 0;
}
?>
<?php
$all_courses = array();
$max = array('P'=>0, 'M'=>0, 'D'=>0);
foreach ($courses as $course) {
if (uses_outcomes($CFG->prefix, $course->id)) { // only a valid course if uses PMD outcomes
$poss = array();
$all_courses[$course->sortorder]['course'] = $course;
$all_courses[$course->sortorder]['possible']['summary'] = get_possible($CFG->prefix, $course->id);
$all_courses[$course->sortorder]['possible']['detail'] = get_possible_criteria($CFG->prefix, $course->id);
$poss = get_possible($CFG->prefix, $course->id);
if ($poss['P'] > $max['P']) $max['P'] = $poss['P'];
if ($poss['M'] > $max['M']) $max['M'] = $poss['M'];
if ($poss['D'] > $max['D']) $max['D'] = $poss['D'];
$all_courses[$course->sortorder]['achieved']['summary'] = get_achieved($CFG->prefix, $student->id, $course->id);
//$grades = get_grade_data($CFG->prefix, $student->id, $course->id);
}
}
//echo '<pre>';
//print_r($all_courses);
//echo '</pre>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Summary</title>
<?php
if (file_exists('screen.css')) echo '<link rel="stylesheet" href="screen.css" type="text/css" media="screen">';
if (file_exists('print.css')) echo '<link rel="stylesheet" href="print.css" type="text/css" media="print">';
?>
</head>
<body>
<h1><?php echo get_string('summaryforstudent', 'block_progress').' '.$student->firstname.' '.$student->lastname ?></h1>
<p class="printonly">printed by <?php echo $user->firstname.' '.$user->lastname ?></p>
<p class="printonly"><?php echo date('jS F Y', $now) ?></p>
<?php
if ( array_key_exists('home', $_GET) && $_GET['home'] != 'true' && $_GET['student'] != $_GET['user']) {
echo '<a href="javascript:history.go(-1)">'.get_string('back', 'block_progress').'</a>';
}
?>
<table border="1">
<tr>
<th colspan="3"> </th>
<?php
// FOR DEBUG
if ( array_key_exists('debug', $_GET) ) echo '<th class="centre">P</th><th class="centre">M</th><th class="centre">D</th>';
echo '<th class="left" colspan="'.($max['P']+1).'">'.get_string('pass', 'block_progress').'</th>';
echo '<th class="left" colspan="'.($max['M']+1).'">'.get_string('merit', 'block_progress').'</th>';
echo '<th class="left" colspan="'.($max['D']+6).'">'.get_string('distinction', 'block_progress').'</th>';
?>
</tr>
<?php
$points_total = 0;
foreach ($all_courses as $course) {
$points = get_points($course);
$points_total += $points;
if ($points==0) $points = ' ';
//echo '<pre>';
//print_r($course);
//echo '</pre>';
$unit_num = '';
if ( array_key_exists('prefix', $_GET) ) $unit_num = '<strong>'.str_replace(strtoupper($_GET['prefix']), '', $course['course']->shortname).'</strong> ';
echo '<tr>';
echo '<td class="right">'.$unit_num.$course['course']->fullname.'</td>';
$url = 'summary_student_course.php?course='.$course['course']->id.'&user='.$_GET['user'].'&student='.$user->id;
if ( array_key_exists('prefix', $_GET) ) $url .= '&prefix='.$_GET['prefix'];
//echo '<td class="noprint"><a href="'.$url.'">'.get_string('show', 'block_progress').'</a></td>';
echo '<td class="noprint"> </td>';
echo '<td class="right">'.$points.'</td>';
// FOR DEBUG
if ( array_key_exists('debug', $_GET) ) {
echo '<td class="partial">'.$course['achieved']['summary']['P'].'/'.$course['possible']['summary']['P'].'</td>';
echo '<td class="partial">'.$course['achieved']['summary']['M'].'/'.$course['possible']['summary']['M'].'</td>';
echo '<td class="partial">'.$course['achieved']['summary']['D'].'/'.$course['possible']['summary']['D'].'</td>';
}
// PASS
echo '<td class="divider"> </td>';
//for ($i=0; $i<$course['possible']['summary']['P']; $i++ ) echo '<td class="nograde"> </td>';
//print_r($courses['possible']['detail']['P']);
foreach($course['possible']['detail']['P'] as $c) {
$class = 'partial nobox';
$title = '';
$desc = get_description($CFG->prefix, $course['course']->id, 'P'.$c);
if ($desc) $title = ' title="'.$desc.'"';
if (outcome_achieved($CFG->prefix, $course['course']->id, $student->id, 'P'.$c)) $class = 'achieved';
if (quiz_outcome_achieved($CFG->prefix, $course['course']->id, $student->id, 'P'.$c)) $class = 'achieved';
echo "\n".'<td'.$title.' class="'.$class.'">'.$c.'</td>';
}
$padding_p = $max['P']-$course['possible']['summary']['P'];
for ($i=0; $i<$padding_p; $i++) echo "\n".'<td class="notenrolled"> </td>';
// MERIT
echo "\n".'<td class="divider"> </td>';
foreach($course['possible']['detail']['M'] as $c) {
$class = 'partial nobox';
$title = '';
$desc = get_description($CFG->prefix, $course['course']->id, 'M'.$c);
if ($desc) $title = ' title="'.$desc.'"';
if (outcome_achieved($CFG->prefix, $course['course']->id, $student->id, 'M'.$c)) $class = 'achieved';
if (quiz_outcome_achieved($CFG->prefix, $course['course']->id, $student->id, 'M'.$c)) $class = 'achieved';
//echo "\n".'<td class="'.$class.'">'.$c.'</td>';
echo "\n".'<td'.$title.' class="'.$class.'">'.$c.'</td>';
}
$padding_p = $max['M']-$course['possible']['summary']['M'];
for ($i=0; $i<$padding_p; $i++) echo "\n".'<td class="notenrolled"> </td>';
// DISTINCTION
echo "\n".'<td class="divider"> </td>';
foreach($course['possible']['detail']['D'] as $c) {
$class = 'partial nobox';
$title = '';
$desc = get_description($CFG->prefix, $course['course']->id, 'D'.$c);
if ($desc) $title = ' title="'.$desc.'"';
if (outcome_achieved($CFG->prefix, $course['course']->id, $student->id, 'D'.$c)) $class = 'achieved';
// if (quiz_outcome_achieved($CFG->prefix, $course['course']->id, $student->id, 'D'.$c)) $class = 'achieved';
//echo "\n".'<td class="'.$class.'">'.$c.'</td>';
echo "\n".'<td'.$title.' class="'.$class.'">'.$c.'</td>';
}
$padding_p = $max['D']-$course['possible']['summary']['D'];
for ($i=0; $i<$padding_p; $i++) echo "\n".'<td class="notenrolled"> </td>';
echo "\n".'</tr>';
}
if ($points_total > 0 ) echo '<tr><td class="right"><em>'.get_string('pointstotal', 'block_progress').'</em></td><td class="total right"><strong>'.$points_total.'</strong></td></tr>';
?>
</table>
<p class="noprint footer"><a href="#" onClick="window.print();return false"><?php print_string('print', 'block_progress');
?></a></p>
</body>
</html>