mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Now Quiz Results can be set into anonymous mode, where performance is shown
but student and group names are not disclosed. See relevant discussion at http://moodle.org/mod/forum/discuss.php?d=29196 Version was also bumped up. Incidentally, prefixed all defined constant names with "B_QUIZRESULTS_" to avoid any conflicts with other things in the future.
This commit is contained in:
parent
9de855f52a
commit
85311ca8d6
@ -1,13 +1,16 @@
|
||||
<?php //$Id$
|
||||
|
||||
define('GRADE_FORMAT_PCT', 1);
|
||||
define('GRADE_FORMAT_FRA', 2);
|
||||
define('GRADE_FORMAT_ABS', 3);
|
||||
define('B_QUIZRESULTS_NAME_FORMAT_FULL', 1);
|
||||
define('B_QUIZRESULTS_NAME_FORMAT_ID', 2);
|
||||
define('B_QUIZRESULTS_NAME_FORMAT_ANON', 3);
|
||||
define('B_QUIZRESULTS_GRADE_FORMAT_PCT', 1);
|
||||
define('B_QUIZRESULTS_GRADE_FORMAT_FRA', 2);
|
||||
define('B_QUIZRESULTS_GRADE_FORMAT_ABS', 3);
|
||||
|
||||
class block_quiz_results extends block_base {
|
||||
function init() {
|
||||
$this->title = get_string('formaltitle', 'block_quiz_results');
|
||||
$this->version = 2005012600;
|
||||
$this->version = 2005082300;
|
||||
}
|
||||
|
||||
function applicable_formats() {
|
||||
@ -78,9 +81,16 @@ class block_quiz_results extends block_base {
|
||||
$best = array();
|
||||
$worst = array();
|
||||
|
||||
$nameformat = intval(empty($this->config->nameformat) ? B_QUIZRESULTS_NAME_FORMAT_FULL : $this->config->nameformat);
|
||||
|
||||
// If the block is configured to operate in group mode, or if the name display format
|
||||
// is other than "fullname", then we need to retrieve the full course record
|
||||
if(!empty($this->config->usegroups) || $nameformat != B_QUIZRESULTS_NAME_FORMAT_FULL) {
|
||||
$course = get_record_select('course', 'id = '.$courseid, 'groupmode, groupmodeforce, student');
|
||||
}
|
||||
|
||||
if(!empty($this->config->usegroups)) {
|
||||
// The block was configured to operate in group mode
|
||||
$course = get_record_select('course', 'id = '.$courseid, 'groupmode, groupmodeforce');
|
||||
if($course->groupmodeforce) {
|
||||
$groupmode = $course->groupmode;
|
||||
}
|
||||
@ -163,7 +173,7 @@ class block_quiz_results extends block_base {
|
||||
}
|
||||
|
||||
// Ready for output!
|
||||
$gradeformat = intval(empty($this->config->gradeformat) ? GRADE_FORMAT_PCT : $this->config->gradeformat);
|
||||
$gradeformat = intval(empty($this->config->gradeformat) ? B_QUIZRESULTS_GRADE_FORMAT_PCT : $this->config->gradeformat);
|
||||
|
||||
if($this->instance->pagetype != 'mod-quiz-view') {
|
||||
// Don't show header and link to the quiz if we ARE at the quiz...
|
||||
@ -176,16 +186,26 @@ class block_quiz_results extends block_base {
|
||||
$this->content->text .= ($numbest == 1?get_string('bestgroupgrade', 'block_quiz_results'):get_string('bestgroupgrades', 'block_quiz_results', $numbest));
|
||||
$this->content->text .= '</caption><colgroup class="number" /><colgroup class="name" /><colgroup class="grade" /><tbody>';
|
||||
foreach($best as $groupid => $averagegrade) {
|
||||
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td><a href="'.$CFG->wwwroot.'/course/group.php?group='.$groupid.'&id='.$courseid.'">'.$groupgrades[$groupid]['group'].'</a></td><td>';
|
||||
switch($nameformat) {
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ANON:
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ID:
|
||||
$thisname = get_string('group');
|
||||
break;
|
||||
default:
|
||||
case B_QUIZRESULTS_NAME_FORMAT_FULL:
|
||||
$thisname = '<a href="'.$CFG->wwwroot.'/course/group.php?group='.$groupid.'&id='.$courseid.'">'.$groupgrades[$groupid]['group'].'</a>';
|
||||
break;
|
||||
}
|
||||
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
|
||||
switch($gradeformat) {
|
||||
case GRADE_FORMAT_FRA:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_FRA:
|
||||
$this->content->text .= (format_float($averagegrade,$quiz->decimalpoints).'/'.$quiz->grade);
|
||||
break;
|
||||
case GRADE_FORMAT_ABS:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_ABS:
|
||||
$this->content->text .= format_float($averagegrade,$quiz->decimalpoints);
|
||||
break;
|
||||
default:
|
||||
case GRADE_FORMAT_PCT:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_PCT:
|
||||
$this->content->text .= round((float)$averagegrade / (float)$quiz->grade * 100).'%';
|
||||
break;
|
||||
}
|
||||
@ -201,16 +221,26 @@ class block_quiz_results extends block_base {
|
||||
$this->content->text .= ($numworst == 1?get_string('worstgroupgrade', 'block_quiz_results'):get_string('worstgroupgrades', 'block_quiz_results', $numworst));
|
||||
$this->content->text .= '</caption><colgroup class="number" /><colgroup class="name" /><colgroup class="grade" /><tbody>';
|
||||
foreach($worst as $groupid => $averagegrade) {
|
||||
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td><a href="'.$CFG->wwwroot.'/course/group.php?group='.$groupid.'&id='.$courseid.'">'.$groupgrades[$groupid]['group'].'</a></td><td>';
|
||||
switch($nameformat) {
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ANON:
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ID:
|
||||
$thisname = get_string('group');
|
||||
break;
|
||||
default:
|
||||
case B_QUIZRESULTS_NAME_FORMAT_FULL:
|
||||
$thisname = '<a href="'.$CFG->wwwroot.'/course/group.php?group='.$groupid.'&id='.$courseid.'">'.$groupgrades[$groupid]['group'].'</a>';
|
||||
break;
|
||||
}
|
||||
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
|
||||
switch($gradeformat) {
|
||||
case GRADE_FORMAT_FRA:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_FRA:
|
||||
$this->content->text .= (format_float($averagegrade,$quiz->decimalpoints).'/'.$quiz->grade);
|
||||
break;
|
||||
case GRADE_FORMAT_ABS:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_ABS:
|
||||
$this->content->text .= format_float($averagegrade,$quiz->decimalpoints);
|
||||
break;
|
||||
default:
|
||||
case GRADE_FORMAT_PCT:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_PCT:
|
||||
$this->content->text .= round((float)$averagegrade / (float)$quiz->grade * 100).'%';
|
||||
break;
|
||||
}
|
||||
@ -271,11 +301,11 @@ class block_quiz_results extends block_base {
|
||||
|
||||
// Now grab all the users from the database
|
||||
$userids = array_merge(array_keys($best), array_keys($worst));
|
||||
$users = get_records_list('user', 'id', implode(',',$userids), '', 'id, firstname, lastname');
|
||||
$users = get_records_list('user', 'id', implode(',',$userids), '', 'id, firstname, lastname, idnumber');
|
||||
|
||||
// Ready for output!
|
||||
|
||||
$gradeformat = intval(empty($this->config->gradeformat) ? GRADE_FORMAT_PCT : $this->config->gradeformat);
|
||||
$gradeformat = intval(empty($this->config->gradeformat) ? B_QUIZRESULTS_GRADE_FORMAT_PCT : $this->config->gradeformat);
|
||||
|
||||
if($this->instance->pagetype != 'mod-quiz-view') {
|
||||
// Don't show header and link to the quiz if we ARE at the quiz...
|
||||
@ -288,16 +318,28 @@ class block_quiz_results extends block_base {
|
||||
$this->content->text .= ($numbest == 1?get_string('bestgrade', 'block_quiz_results'):get_string('bestgrades', 'block_quiz_results', $numbest));
|
||||
$this->content->text .= '</caption><colgroup class="number" /><colgroup class="name" /><colgroup class="grade" /><tbody>';
|
||||
foreach($best as $userid => $gradeid) {
|
||||
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td><a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'&course='.$courseid.'">'.fullname($users[$userid]).'</a></td><td>';
|
||||
switch($nameformat) {
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ID:
|
||||
$thisname = $course->student.' '.intval($users[$userid]->idnumber);
|
||||
break;
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ANON:
|
||||
$thisname = $course->student;
|
||||
break;
|
||||
default:
|
||||
case B_QUIZRESULTS_NAME_FORMAT_FULL:
|
||||
$thisname = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'&course='.$courseid.'">'.fullname($users[$userid]).'</a>';
|
||||
break;
|
||||
}
|
||||
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
|
||||
switch($gradeformat) {
|
||||
case GRADE_FORMAT_FRA:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_FRA:
|
||||
$this->content->text .= (format_float($grades[$gradeid]->grade,$quiz->decimalpoints).'/'.$quiz->grade);
|
||||
break;
|
||||
case GRADE_FORMAT_ABS:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_ABS:
|
||||
$this->content->text .= format_float($grades[$gradeid]->grade,$quiz->decimalpoints);
|
||||
break;
|
||||
default:
|
||||
case GRADE_FORMAT_PCT:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_PCT:
|
||||
if ($quiz->grade) {
|
||||
$this->content->text .= round((float)$grades[$gradeid]->grade / (float)$quiz->grade * 100).'%';
|
||||
} else {
|
||||
@ -317,16 +359,28 @@ class block_quiz_results extends block_base {
|
||||
$this->content->text .= ($numworst == 1?get_string('worstgrade', 'block_quiz_results'):get_string('worstgrades', 'block_quiz_results', $numworst));
|
||||
$this->content->text .= '</caption><colgroup class="number" /><colgroup class="name" /><colgroup class="grade" /><tbody>';
|
||||
foreach($worst as $userid => $gradeid) {
|
||||
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td><a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'&course='.$courseid.'">'.fullname($users[$userid]).'</a></td><td>';
|
||||
switch($nameformat) {
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ID:
|
||||
$thisname = $course->student.' '.intval($users[$userid]->idnumber);
|
||||
break;
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ANON:
|
||||
$thisname = $course->student;
|
||||
break;
|
||||
default:
|
||||
case B_QUIZRESULTS_NAME_FORMAT_FULL:
|
||||
$thisname = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'&course='.$courseid.'">'.fullname($users[$userid]).'</a>';
|
||||
break;
|
||||
}
|
||||
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
|
||||
switch($gradeformat) {
|
||||
case GRADE_FORMAT_FRA:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_FRA:
|
||||
$this->content->text .= (format_float($grades[$gradeid]->grade,$quiz->decimalpoints).'/'.$quiz->grade);
|
||||
break;
|
||||
case GRADE_FORMAT_ABS:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_ABS:
|
||||
$this->content->text .= format_float($grades[$gradeid]->grade,$quiz->decimalpoints);
|
||||
break;
|
||||
default:
|
||||
case GRADE_FORMAT_PCT:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_PCT:
|
||||
$this->content->text .= round((float)$grades[$gradeid]->grade / (float)$quiz->grade * 100).'%';
|
||||
break;
|
||||
}
|
||||
|
@ -51,13 +51,24 @@
|
||||
<input name="usegroups" type="radio" id="usegroups_no" <?php if(empty($this->config->usegroups)) echo 'checked="checked"'; ?> value="0" /> <label for="usegroups_no"><?php print_string('no'); ?></label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<?php print_string('config_name_format', 'block_quiz_results') ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$usenames = array(B_QUIZRESULTS_NAME_FORMAT_FULL => get_string('config_names_full', 'block_quiz_results'), B_QUIZRESULTS_NAME_FORMAT_ID => get_string('config_names_id', 'block_quiz_results'), B_QUIZRESULTS_NAME_FORMAT_ANON => get_string('config_names_anon', 'block_quiz_results'));
|
||||
choose_from_menu($usenames, 'nameformat', empty($this->config->nameformat) ? B_QUIZRESULTS_NAME_FORMAT_FULL : $this->config->nameformat, '');
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
<?php print_string('config_grade_format', 'block_quiz_results') ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$formats = array(GRADE_FORMAT_PCT => get_string('config_format_percentage', 'block_quiz_results'), GRADE_FORMAT_FRA => get_string('config_format_fraction', 'block_quiz_results'), GRADE_FORMAT_ABS => get_string('config_format_absolute', 'block_quiz_results'));
|
||||
$formats = array(B_QUIZRESULTS_GRADE_FORMAT_PCT => get_string('config_format_percentage', 'block_quiz_results'), B_QUIZRESULTS_GRADE_FORMAT_FRA => get_string('config_format_fraction', 'block_quiz_results'), B_QUIZRESULTS_GRADE_FORMAT_ABS => get_string('config_format_absolute', 'block_quiz_results'));
|
||||
choose_from_menu($formats, 'gradeformat', empty($this->config->gradeformat) ? 0 : $this->config->gradeformat, '');
|
||||
?>
|
||||
</td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user