From 98ad7484c819c4b794ae88606f0e71e645313158 Mon Sep 17 00:00:00 2001 From: defacer Date: Tue, 25 Jan 2005 23:49:36 +0000 Subject: [PATCH] First commit of the requested quiz_results block. --- blocks/quiz_results/block_quiz_results.php | 159 +++++++++++++++++++++ blocks/quiz_results/config_instance.html | 70 +++++++++ 2 files changed, 229 insertions(+) create mode 100644 blocks/quiz_results/block_quiz_results.php create mode 100644 blocks/quiz_results/config_instance.html diff --git a/blocks/quiz_results/block_quiz_results.php b/blocks/quiz_results/block_quiz_results.php new file mode 100644 index 0000000000..b4081ad1c8 --- /dev/null +++ b/blocks/quiz_results/block_quiz_results.php @@ -0,0 +1,159 @@ +title = get_string('formaltitle', 'block_quiz_results'); + $this->content_type = BLOCK_TYPE_TEXT; + $this->version = 2005012500; + } + + function get_content() { + global $USER, $CFG; + + if ($this->content !== NULL) { + return $this->content; + } + if (empty($this->instance)) { + $this->content = ''; + return $this->content; + } + + $this->content = new stdClass; + $this->content->text = ''; + $this->content->footer = ''; + + if($this->instance->pagetype == MOODLE_PAGE_COURSE) { + // We need to see if we are monitoring a quiz + $quizid = empty($this->config->quizid) ? 0 : $this->config->quizid; + $courseid = $this->instance->pageid; + } + else { + // Assuming we are displayed in the quiz view page + // TODO + $quizid = 0; + $courseid = 0; + } + + if(empty($quizid)) { + return $this->content; + } + + // Get the quiz record + $quiz = get_record('quiz', 'id', $quizid); + if(empty($quiz)) { + return $this->content; + } + + // Get the grades for this quiz + $grades = get_records('quiz_grades', 'quiz', $quizid, 'grade, timemodified DESC'); + + if(empty($grades)) { + // No grades, sorry + // TODO + } + + $numbest = empty($this->config->showbest) ? 0 : min($this->config->showbest, count($grades)); + $numworst = empty($this->config->showworst) ? 0 : min($this->config->showworst, count($grades) - $numbest); + $best = array(); + $worst = array(); + + if(!empty($this->config->usegroups)) { + // Group mode activated, what about it? + // TODO + } + else { + // Single user mode + + // Collect all the usernames we are going to need + $remaining = $numbest; + $grade = end($grades); + while($remaining--) { + $best[$grade->userid] = $grade->id; + $grade = prev($grades); + } + + $remaining = $numworst; + $grade = reset($grades); + while($remaining--) { + $worst[$grade->userid] = $grade->id; + $grade = next($grades); + } + + if(empty($best) && empty($worst)) { + // Nothing to show, for some reason... + return $this->content; + } + + // 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'); + + // Ready for output! + + $gradeformat = intval(empty($this->config->gradeformat) ? GRADE_FORMAT_PCT : $this->config->gradeformat); + + $this->content->text .= '

'.$quiz->name.'

'; + + $rank = 0; + if(!empty($best)) { + $this->content->text .= '

'.get_string('bestgrades', 'block_quiz_results', $numbest).'

'; + $this->content->text .= ''; + foreach($best as $userid => $gradeid) { + $this->content->text .= ''; + } + $this->content->text .= '
'.(++$rank).'.'.fullname($users[$userid]).''; + switch($gradeformat) { + case GRADE_FORMAT_FRA: + $this->content->text .= ($grades[$gradeid]->grade.'/'.$quiz->grade); + break; + case GRADE_FORMAT_ABS: + $this->content->text .= $grades[$gradeid]->grade; + break; + default: + case GRADE_FORMAT_PCT: + $this->content->text .= round(intval($grades[$gradeid]->grade) / intval($quiz->grade) * 100).'%'; + break; + } + $this->content->text .= '
'; + } + + $rank = 0; + if(!empty($worst)) { + $worst = array_reverse($worst, true); + $this->content->text .= '

'.get_string('worstgrades', 'block_quiz_results', $numworst).'

'; + $this->content->text .= ''; + foreach($worst as $userid => $gradeid) { + $this->content->text .= ''; + } + $this->content->text .= '
'.(++$rank).'.'.fullname($users[$userid]).''; + switch($gradeformat) { + case GRADE_FORMAT_FRA: + $this->content->text .= ($grades[$gradeid]->grade.'/'.$quiz->grade); + break; + case GRADE_FORMAT_ABS: + $this->content->text .= $grades[$gradeid]->grade; + break; + default: + case GRADE_FORMAT_PCT: + $this->content->text .= round(intval($grades[$gradeid]->grade) / intval($quiz->grade) * 100).'%'; + break; + } + $this->content->text .= '
'; + } + + } + + + return $this->content; + } + + function instance_allow_config() { + return true; + } +} + +?> diff --git a/blocks/quiz_results/config_instance.html b/blocks/quiz_results/config_instance.html new file mode 100644 index 0000000000..95aedb7146 --- /dev/null +++ b/blocks/quiz_results/config_instance.html @@ -0,0 +1,70 @@ + +instance->pagetype == MOODLE_PAGE_COURSE) { ?> + + + + +instance->pagetype == MOODLE_PAGE_COURSE) ?> + + + + + + + + + + + + + + + + + + + +
+ + + instance->pageid, '', 'id, name'); + if(empty($quizzes)) { + print_string('config_no_quizzes_in_course', 'block_quiz_results'); + echo '

'; + } + else { + $options = array(); + foreach($quizzes as $quiz) { + $options[$quiz->id] = $quiz->name; + } + choose_from_menu($options, 'quizid', empty($this->config->quizid) ? 0 : $this->config->quizid); + } + ?> +
+ + + +
+ + + +
+ + + config->usegroups)) echo 'checked="checked"'; ?> value="1" /> + config->usegroups)) echo 'checked="checked"'; ?> value="0" /> +
+ + + 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')); + choose_from_menu($formats, 'gradeformat', empty($this->config->gradeformat) ? 0 : $this->config->gradeformat, ''); + ?> +
+ +
\ No newline at end of file -- 2.39.5