mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-48969 Block: Disable and migrate quiz_results block
This commit is contained in:
parent
d6383f6afe
commit
846f6dc712
@ -57,18 +57,36 @@ class restore_quiz_results_block_task extends restore_block_task {
|
||||
public function after_restore() {
|
||||
global $DB;
|
||||
|
||||
// Get the blockid
|
||||
// Get the blockid.
|
||||
$blockid = $this->get_blockid();
|
||||
|
||||
// Extract block configdata and update it to point to the new quiz
|
||||
// Extract block configdata and update it to point to the new quiz.
|
||||
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
|
||||
$config = unserialize(base64_decode($configdata));
|
||||
if (!empty($config->quizid)) {
|
||||
// Get quiz mapping and replace it in config
|
||||
// Get quiz mapping and replace it in config.
|
||||
if ($quizmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'quiz', $config->quizid)) {
|
||||
$config->quizid = $quizmap->newitemid;
|
||||
$configdata = base64_encode(serialize($config));
|
||||
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
|
||||
$config->activityparent = 'quiz';
|
||||
$config->activityparentid = $quizmap->newitemid;
|
||||
|
||||
// Set the decimal valuue as appropriate.
|
||||
if ($config->gradeformat == 1) {
|
||||
// This block is using percentages, do not display any decimal places.
|
||||
$config->decimalpoints = 0;
|
||||
} else {
|
||||
// Get the decimal value from the corresponding quiz.
|
||||
$config->decimalpoints = $DB->get_field('quiz', 'decimalpoints', array('id' => $config->activityparentid));
|
||||
}
|
||||
|
||||
// Get the grade_items record to set the activitygradeitemid.
|
||||
$info = $DB->get_record('grade_items',
|
||||
array('iteminstance' => $config->activityparentid, 'itemmodule' => $config->activityparent));
|
||||
$config->activitygradeitemid = $info->id;
|
||||
unset($config->quizid);
|
||||
|
||||
// Save the new configuration and update the record.
|
||||
$DB->set_field('block_instances', 'configdata', base64_encode(serialize($config)), array('id' => $blockid));
|
||||
$DB->set_field('block_instances', 'blockname', 'activity_results', array('id' => $blockid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,12 +22,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/lib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Block quiz_results class definition.
|
||||
*
|
||||
@ -38,441 +36,25 @@ require_once($CFG->dirroot . '/mod/quiz/lib.php');
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
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('pluginname', 'block_quiz_results');
|
||||
}
|
||||
|
||||
function applicable_formats() {
|
||||
return array('course' => true, 'mod-quiz' => true);
|
||||
}
|
||||
|
||||
/**
|
||||
* If this block belongs to a quiz context, then return that quiz's id.
|
||||
* Otherwise, return 0.
|
||||
* @return integer the quiz id.
|
||||
*/
|
||||
public function get_owning_quiz() {
|
||||
if (empty($this->instance->parentcontextid)) {
|
||||
return 0;
|
||||
}
|
||||
$parentcontext = context::instance_by_id($this->instance->parentcontextid);
|
||||
if ($parentcontext->contextlevel != CONTEXT_MODULE) {
|
||||
return 0;
|
||||
}
|
||||
$cm = get_coursemodule_from_id('quiz', $parentcontext->instanceid);
|
||||
if (!$cm) {
|
||||
return 0;
|
||||
}
|
||||
return $cm->instance;
|
||||
return array('mod-quiz' => true);
|
||||
}
|
||||
|
||||
function instance_config_save($data, $nolongerused = false) {
|
||||
if (empty($data->quizid)) {
|
||||
$data->quizid = $this->get_owning_quiz();
|
||||
}
|
||||
parent::instance_config_save($data);
|
||||
}
|
||||
|
||||
function get_content() {
|
||||
global $USER, $CFG, $DB;
|
||||
|
||||
if ($this->content !== NULL) {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
$this->content = new stdClass;
|
||||
$this->content->text = '';
|
||||
$this->content->footer = '';
|
||||
|
||||
if (empty($this->instance)) {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
if ($this->page->activityname == 'quiz' && $this->page->context->id == $this->instance->parentcontextid) {
|
||||
$quiz = $this->page->activityrecord;
|
||||
$quizid = $quiz->id;
|
||||
$courseid = $this->page->course->id;
|
||||
$inquiz = true;
|
||||
} else if (!empty($this->config->quizid)) {
|
||||
$quizid = $this->config->quizid;
|
||||
$quiz = $DB->get_record('quiz', array('id' => $quizid));
|
||||
if (empty($quiz)) {
|
||||
$this->content->text = get_string('error_emptyquizrecord', 'block_quiz_results');
|
||||
return $this->content;
|
||||
}
|
||||
$courseid = $quiz->course;
|
||||
$inquiz = false;
|
||||
} else {
|
||||
$quizid = 0;
|
||||
}
|
||||
|
||||
if (empty($quizid)) {
|
||||
$this->content->text = get_string('error_emptyquizid', 'block_quiz_results');
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
if (empty($this->config->showbest) && empty($this->config->showworst)) {
|
||||
$this->content->text = get_string('configuredtoshownothing', 'block_quiz_results');
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
// Get the grades for this quiz
|
||||
$grades = $DB->get_records('quiz_grades', array('quiz' => $quizid), 'grade, timemodified DESC');
|
||||
|
||||
if (empty($grades)) {
|
||||
// No grades, sorry
|
||||
// The block will hide itself in this case
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
$groupmode = NOGROUPS;
|
||||
$best = array();
|
||||
$worst = array();
|
||||
|
||||
if (!empty($this->config->nameformat)) {
|
||||
$nameformat = $this->config->nameformat;
|
||||
} else {
|
||||
$nameformat = B_QUIZRESULTS_NAME_FORMAT_FULL;
|
||||
}
|
||||
|
||||
if (!empty($this->config->usegroups)) {
|
||||
if ($inquiz) {
|
||||
$cm = $this->page->cm;
|
||||
$context = $this->page->context;
|
||||
} else {
|
||||
$cm = get_coursemodule_from_instance('quiz', $quizid, $courseid);
|
||||
$context = context_module::instance($cm->id);
|
||||
}
|
||||
$groupmode = groups_get_activity_groupmode($cm);
|
||||
|
||||
if ($groupmode == SEPARATEGROUPS && has_capability('moodle/site:accessallgroups', $context)) {
|
||||
// We 'll make an exception in this case
|
||||
$groupmode = VISIBLEGROUPS;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($groupmode) {
|
||||
case VISIBLEGROUPS:
|
||||
// Display group-mode results
|
||||
$groups = groups_get_all_groups($courseid);
|
||||
|
||||
if(empty($groups)) {
|
||||
// No groups exist, sorry
|
||||
$this->content->text = get_string('error_nogroupsexist', 'block_quiz_results');
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
// Find out all the userids which have a submitted grade
|
||||
$userids = array();
|
||||
$gradeforuser = array();
|
||||
foreach ($grades as $grade) {
|
||||
$userids[] = $grade->userid;
|
||||
$gradeforuser[$grade->userid] = (float)$grade->grade;
|
||||
}
|
||||
|
||||
// Now find which groups these users belong in
|
||||
list($usertest, $params) = $DB->get_in_or_equal($userids);
|
||||
$params[] = $courseid;
|
||||
$usergroups = $DB->get_records_sql('
|
||||
SELECT gm.id, gm.userid, gm.groupid, g.name
|
||||
FROM {groups} g
|
||||
LEFT JOIN {groups_members} gm ON g.id = gm.groupid
|
||||
WHERE gm.userid ' . $usertest . ' AND g.courseid = ?', $params);
|
||||
|
||||
// Now, iterate the grades again and sum them up for each group
|
||||
$groupgrades = array();
|
||||
foreach ($usergroups as $usergroup) {
|
||||
if (!isset($groupgrades[$usergroup->groupid])) {
|
||||
$groupgrades[$usergroup->groupid] = array(
|
||||
'sum' => (float)$gradeforuser[$usergroup->userid],
|
||||
'number' => 1,
|
||||
'group' => $usergroup->name);
|
||||
} else {
|
||||
$groupgrades[$usergroup->groupid]['sum'] += $gradeforuser[$usergroup->userid];
|
||||
$groupgrades[$usergroup->groupid]['number'] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($groupgrades as $groupid => $groupgrade) {
|
||||
$groupgrades[$groupid]['average'] = $groupgrades[$groupid]['sum'] / $groupgrades[$groupid]['number'];
|
||||
}
|
||||
|
||||
// Sort groupgrades according to average grade, ascending
|
||||
uasort($groupgrades, create_function('$a, $b', 'if($a["average"] == $b["average"]) return 0; return ($a["average"] > $b["average"] ? 1 : -1);'));
|
||||
|
||||
// How many groups do we have with graded member submissions to show?
|
||||
$numbest = empty($this->config->showbest) ? 0 : min($this->config->showbest, count($groupgrades));
|
||||
$numworst = empty($this->config->showworst) ? 0 : min($this->config->showworst, count($groupgrades) - $numbest);
|
||||
|
||||
// Collect all the group results we are going to use in $best and $worst
|
||||
$remaining = $numbest;
|
||||
$groupgrade = end($groupgrades);
|
||||
while ($remaining--) {
|
||||
$best[key($groupgrades)] = $groupgrade['average'];
|
||||
$groupgrade = prev($groupgrades);
|
||||
}
|
||||
|
||||
$remaining = $numworst;
|
||||
$groupgrade = reset($groupgrades);
|
||||
while ($remaining--) {
|
||||
$worst[key($groupgrades)] = $groupgrade['average'];
|
||||
$groupgrade = next($groupgrades);
|
||||
}
|
||||
|
||||
// Ready for output!
|
||||
$gradeformat = intval(empty($this->config->gradeformat) ? B_QUIZRESULTS_GRADE_FORMAT_PCT : $this->config->gradeformat);
|
||||
|
||||
if (!$inquiz) {
|
||||
// Don't show header and link to the quiz if we ARE at the quiz...
|
||||
$this->content->text .= '<h1><a href="'.$CFG->wwwroot.'/mod/quiz/view.php?q='.$quizid.'">'.$quiz->name.'</a></h1>';
|
||||
}
|
||||
|
||||
if ($nameformat = B_QUIZRESULTS_NAME_FORMAT_FULL) {
|
||||
if (has_capability('moodle/course:managegroups', $context)) {
|
||||
$grouplink = $CFG->wwwroot.'/group/overview.php?id='.$courseid.'&group=';
|
||||
} else if (has_capability('moodle/course:viewparticipants', $context)) {
|
||||
$grouplink = $CFG->wwwroot.'/user/index.php?id='.$courseid.'&group=';
|
||||
} else {
|
||||
$grouplink = '';
|
||||
}
|
||||
}
|
||||
|
||||
$rank = 0;
|
||||
if(!empty($best)) {
|
||||
$this->content->text .= '<table class="grades"><caption>';
|
||||
$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) {
|
||||
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:
|
||||
if ($grouplink) {
|
||||
$thisname = '<a href="'.$grouplink.$groupid.'">'.$groupgrades[$groupid]['group'].'</a>';
|
||||
} else {
|
||||
$thisname = $groupgrades[$groupid]['group'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
|
||||
switch($gradeformat) {
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_FRA:
|
||||
$this->content->text .= quiz_format_grade($quiz, $averagegrade).'/'.$quiz->grade;
|
||||
break;
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_ABS:
|
||||
$this->content->text .= quiz_format_grade($quiz, $averagegrade);
|
||||
break;
|
||||
default:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_PCT:
|
||||
$this->content->text .= round((float)$averagegrade / (float)$quiz->grade * 100).'%';
|
||||
break;
|
||||
}
|
||||
$this->content->text .= '</td></tr>';
|
||||
}
|
||||
$this->content->text .= '</tbody></table>';
|
||||
}
|
||||
|
||||
$rank = 0;
|
||||
if(!empty($worst)) {
|
||||
$worst = array_reverse($worst, true);
|
||||
$this->content->text .= '<table class="grades"><caption>';
|
||||
$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) {
|
||||
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 B_QUIZRESULTS_GRADE_FORMAT_FRA:
|
||||
$this->content->text .= quiz_format_grade($quiz, $averagegrade).'/'.$quiz->grade;
|
||||
break;
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_ABS:
|
||||
$this->content->text .= quiz_format_grade($quiz, $averagegrade);
|
||||
break;
|
||||
default:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_PCT:
|
||||
$this->content->text .= round((float)$averagegrade / (float)$quiz->grade * 100).'%';
|
||||
break;
|
||||
}
|
||||
$this->content->text .= '</td></tr>';
|
||||
}
|
||||
$this->content->text .= '</tbody></table>';
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case SEPARATEGROUPS:
|
||||
// This is going to be just like no-groups mode, only we 'll filter
|
||||
// out the grades from people not in our group.
|
||||
if (!isloggedin()) {
|
||||
// Not logged in, so show nothing
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
$mygroups = groups_get_all_groups($courseid, $USER->id);
|
||||
if(empty($mygroups)) {
|
||||
// Not member of a group, show nothing
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
// Get users from the same groups as me.
|
||||
list($grouptest, $params) = $DB->get_in_or_equal(array_keys($mygroups));
|
||||
$mygroupsusers = $DB->get_records_sql_menu(
|
||||
'SELECT DISTINCT userid, 1 FROM {groups_members} WHERE groupid ' . $grouptest,
|
||||
$params);
|
||||
|
||||
// Filter out the grades belonging to other users, and proceed as if there were no groups
|
||||
foreach ($grades as $key => $grade) {
|
||||
if (!isset($mygroupsusers[$grade->userid])) {
|
||||
unset($grades[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// No break, fall through to the default case now we have filtered the $grades array.
|
||||
default:
|
||||
case NOGROUPS:
|
||||
// Single user mode
|
||||
$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);
|
||||
|
||||
// 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));
|
||||
$fields = array_merge(array('id', 'idnumber'), get_all_user_name_fields());
|
||||
$fields = implode(',', $fields);
|
||||
$users = $DB->get_records_list('user', 'id', $userids, '', $fields);
|
||||
|
||||
// Ready for output!
|
||||
|
||||
$gradeformat = intval(empty($this->config->gradeformat) ? B_QUIZRESULTS_GRADE_FORMAT_PCT : $this->config->gradeformat);
|
||||
|
||||
if(!$inquiz) {
|
||||
// Don't show header and link to the quiz if we ARE at the quiz...
|
||||
$this->content->text .= '<h1><a href="'.$CFG->wwwroot.'/mod/quiz/view.php?q='.$quizid.'">'.$quiz->name.'</a></h1>';
|
||||
}
|
||||
|
||||
$rank = 0;
|
||||
if(!empty($best)) {
|
||||
$this->content->text .= '<table class="grades"><caption>';
|
||||
$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) {
|
||||
switch($nameformat) {
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ID:
|
||||
$thisname = get_string('user').' '.$users[$userid]->idnumber;
|
||||
break;
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ANON:
|
||||
$thisname = get_string('user');
|
||||
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 B_QUIZRESULTS_GRADE_FORMAT_FRA:
|
||||
$this->content->text .= quiz_format_grade($quiz, $grades[$gradeid]->grade).'/'.$quiz->grade;
|
||||
break;
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_ABS:
|
||||
$this->content->text .= quiz_format_grade($quiz, $grades[$gradeid]->grade);
|
||||
break;
|
||||
default:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_PCT:
|
||||
if ($quiz->grade) {
|
||||
$this->content->text .= round((float)$grades[$gradeid]->grade / (float)$quiz->grade * 100).'%';
|
||||
} else {
|
||||
$this->content->text .= '--%';
|
||||
}
|
||||
break;
|
||||
}
|
||||
$this->content->text .= '</td></tr>';
|
||||
}
|
||||
$this->content->text .= '</tbody></table>';
|
||||
}
|
||||
|
||||
$rank = 0;
|
||||
if(!empty($worst)) {
|
||||
$worst = array_reverse($worst, true);
|
||||
$this->content->text .= '<table class="grades"><caption>';
|
||||
$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) {
|
||||
switch($nameformat) {
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ID:
|
||||
$thisname = get_string('user').' '.$users[$userid]->idnumber;
|
||||
break;
|
||||
case B_QUIZRESULTS_NAME_FORMAT_ANON:
|
||||
$thisname = get_string('user');
|
||||
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 B_QUIZRESULTS_GRADE_FORMAT_FRA:
|
||||
$this->content->text .= quiz_format_grade($quiz, $grades[$gradeid]->grade).'/'.$quiz->grade;
|
||||
break;
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_ABS:
|
||||
$this->content->text .= quiz_format_grade($quiz, $grades[$gradeid]->grade);
|
||||
break;
|
||||
default:
|
||||
case B_QUIZRESULTS_GRADE_FORMAT_PCT:
|
||||
$this->content->text .= round((float)$grades[$gradeid]->grade / (float)$quiz->grade * 100).'%';
|
||||
break;
|
||||
}
|
||||
$this->content->text .= '</td></tr>';
|
||||
}
|
||||
$this->content->text .= '</tbody></table>';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
function instance_allow_multiple() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
93
blocks/quiz_results/db/upgrade.php
Normal file
93
blocks/quiz_results/db/upgrade.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?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 file keeps track of upgrades to the quiz_results block
|
||||
*
|
||||
* Sometimes, changes between versions involve alterations to database structures
|
||||
* and other major things that may break installations.
|
||||
*
|
||||
* The upgrade function in this file will attempt to perform all the necessary
|
||||
* actions to upgrade your older installation to the current version.
|
||||
*
|
||||
* If there's something it cannot do itself, it will tell you what you need to do.
|
||||
*
|
||||
* The commands in here will all be database-neutral, using the methods of
|
||||
* database_manager class
|
||||
*
|
||||
* Please do not forget to use upgrade_set_timeout()
|
||||
* before any action that may take longer time to finish.
|
||||
*
|
||||
* @since Moodle 2.9
|
||||
* @package block_quiz_results
|
||||
* @copyright 2015 Stephen Bourget
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Upgrade the quiz_results block
|
||||
* @param int $oldversion
|
||||
* @param object $block
|
||||
*/
|
||||
function xmldb_block_quiz_results_upgrade($oldversion, $block) {
|
||||
global $DB, $CFG;
|
||||
|
||||
if ($oldversion < 2015022200) {
|
||||
// Only migrate if the block_activity_results is installed.
|
||||
if (!check_dir_exists($CFG->dirroot . '/blocks/activity_results', false)) {
|
||||
|
||||
// Migrate all instances of block_quiz_results to block_activity_results.
|
||||
$records = $DB->get_records('block_instances', array('blockname' => 'quiz_results'));
|
||||
foreach ($records as $record) {
|
||||
$config = unserialize(base64_decode($record->configdata));
|
||||
$config->activityparent = 'quiz';
|
||||
$config->activityparentid = $config->quizid;
|
||||
|
||||
// Set the decimal valuue as appropriate.
|
||||
if ($config->gradeformat == 1) {
|
||||
// This block is using percentages, do not display any decimal places.
|
||||
$config->decimalpoints = 0;
|
||||
} else {
|
||||
// Get the decimal value from the corresponding quiz.
|
||||
$config->decimalpoints = $DB->get_field('quiz', 'decimalpoints', array('id' => $config->activityparentid));
|
||||
}
|
||||
|
||||
// Get the grade_items record to set the activitygradeitemid.
|
||||
$info = $DB->get_record('grade_items',
|
||||
array('iteminstance' => $config->activityparentid, 'itemmodule' => $config->activityparent));
|
||||
$config->activitygradeitemid = $info->id;
|
||||
unset($config->quizid);
|
||||
|
||||
// Save the new configuration and update the record.
|
||||
$record->configdata = base64_encode(serialize($config));
|
||||
$record->blockname = 'activity_results';
|
||||
$DB->update_record('block_instances', $record);
|
||||
}
|
||||
|
||||
// Disable the Quiz_results block.
|
||||
if ($block = $DB->get_record("block", array("name" => "quiz_results"))) {
|
||||
$DB->set_field("block", "visible", "0", array("id" => $block->id));
|
||||
}
|
||||
|
||||
}
|
||||
upgrade_block_savepoint(true, 2015022200, 'quiz_results');
|
||||
}
|
||||
|
||||
// Moodle v2.8.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
return true;
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Defines the form for editing Quiz results block instances.
|
||||
*
|
||||
* @package block_quiz_results
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
/**
|
||||
* Form for editing Quiz results block instances.
|
||||
*
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class block_quiz_results_edit_form extends block_edit_form {
|
||||
protected function specific_definition($mform) {
|
||||
global $DB;
|
||||
|
||||
// Fields for editing HTML block title and contents.
|
||||
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
|
||||
|
||||
if (!$this->block->get_owning_quiz()) {
|
||||
$quizzes = $DB->get_records_menu('quiz', array('course' => $this->page->course->id), '', 'id, name');
|
||||
if(empty($quizzes)) {
|
||||
$mform->addElement('static', 'noquizzeswarning', get_string('config_select_quiz', 'block_quiz_results'),
|
||||
get_string('config_no_quizzes_in_course', 'block_quiz_results'));
|
||||
} else {
|
||||
foreach($quizzes as $id => $name) {
|
||||
$quizzes[$id] = strip_tags(format_string($name));
|
||||
}
|
||||
$mform->addElement('select', 'config_quizid', get_string('config_select_quiz', 'block_quiz_results'), $quizzes);
|
||||
}
|
||||
}
|
||||
|
||||
$mform->addElement('text', 'config_showbest', get_string('config_show_best', 'block_quiz_results'), array('size' => 3));
|
||||
$mform->setDefault('config_showbest', 3);
|
||||
$mform->setType('config_showbest', PARAM_INT);
|
||||
|
||||
$mform->addElement('text', 'config_showworst', get_string('config_show_worst', 'block_quiz_results'), array('size' => 3));
|
||||
$mform->setDefault('config_showworst', 0);
|
||||
$mform->setType('config_showworst', PARAM_INT);
|
||||
|
||||
$mform->addElement('selectyesno', 'config_usegroups', get_string('config_use_groups', 'block_quiz_results'));
|
||||
|
||||
$nameoptions = 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')
|
||||
);
|
||||
$mform->addElement('select', 'config_nameformat', get_string('config_name_format', 'block_quiz_results'), $nameoptions);
|
||||
$mform->setDefault('config_nameformat', B_QUIZRESULTS_NAME_FORMAT_FULL);
|
||||
|
||||
$gradeeoptions = 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')
|
||||
);
|
||||
$mform->addElement('select', 'config_gradeformat', get_string('config_grade_format', 'block_quiz_results'), $gradeeoptions);
|
||||
$mform->setDefault('config_gradeformat', B_QUIZRESULTS_GRADE_FORMAT_PCT);
|
||||
}
|
||||
}
|
@ -22,6 +22,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['pluginname'] = 'Quiz results (disabled)';
|
||||
$string['quiz_results:addinstance'] = 'Add a new quiz results block';
|
||||
|
||||
// Deprecated since Moodle 2.9.
|
||||
$string['bestgrade'] = 'The highest grade:';
|
||||
$string['bestgrades'] = 'The {$a} highest grades:';
|
||||
$string['bestgroupgrade'] = 'The group with the highest average:';
|
||||
@ -43,8 +47,6 @@ $string['config_use_groups'] = 'Show groups instead of students (only if the qui
|
||||
$string['error_emptyquizid'] = 'There is an error right now with this block: you need to select which quiz it should display results from.';
|
||||
$string['error_emptyquizrecord'] = 'There is an error right now with this block: the selected quiz does not seem to exist in the database.';
|
||||
$string['error_nogroupsexist'] = 'There is an error right now with this block: it is set to display grades in group mode, but the course has no defined groups.';
|
||||
$string['pluginname'] = 'Quiz results';
|
||||
$string['quiz_results:addinstance'] = 'Add a new quiz results block';
|
||||
$string['worstgrade'] = 'The lowest grade:';
|
||||
$string['worstgrades'] = 'The {$a} lowest grades:';
|
||||
$string['worstgroupgrade'] = 'The group with the lowest average:';
|
||||
|
25
blocks/quiz_results/lang/en/depreciated.txt
Normal file
25
blocks/quiz_results/lang/en/depreciated.txt
Normal file
@ -0,0 +1,25 @@
|
||||
bestgrade,block_quiz_results
|
||||
bestgrades,block_quiz_results
|
||||
bestgroupgrade,block_quiz_results
|
||||
bestgroupgrades,block_quiz_results
|
||||
config_format_absolute,block_quiz_results
|
||||
config_format_fraction,block_quiz_results
|
||||
config_format_percentage,block_quiz_results
|
||||
config_grade_format,block_quiz_results
|
||||
config_name_format,block_quiz_results
|
||||
config_names_anon,block_quiz_results
|
||||
config_names_full,block_quiz_results
|
||||
config_names_id,block_quiz_results
|
||||
config_no_quizzes_in_course,block_quiz_results
|
||||
config_select_quiz,block_quiz_results
|
||||
config_show_best,block_quiz_results
|
||||
config_show_worst,block_quiz_results
|
||||
configuredtoshownothing,block_quiz_results
|
||||
config_use_groups,block_quiz_results
|
||||
error_emptyquizid,block_quiz_results
|
||||
error_emptyquizrecord,block_quiz_results
|
||||
error_nogroupsexist,block_quiz_results
|
||||
worstgrade,block_quiz_results
|
||||
worstgrades,block_quiz_results
|
||||
worstgroupgrade,block_quiz_results
|
||||
worstgroupgrades,block_quiz_results
|
@ -1,6 +0,0 @@
|
||||
.block_quiz_results {text-align: center;}
|
||||
.block_quiz_results h1 {margin: 4px;font-size: 1.1em;}
|
||||
.block_quiz_results table.grades {text-align: left;width: 100%;}
|
||||
.block_quiz_results table.grades .number,
|
||||
.block_quiz_results table.grades .grade {text-align: right;width: 10%;}
|
||||
.block_quiz_results table.grades caption {margin: 1em 0px 0px 0px;border-bottom-width: 1px;border-bottom-style: solid;font-weight: bold;}
|
@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2014111000; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2015022200; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2014110400; // Requires this Moodle version
|
||||
$plugin->component = 'block_quiz_results'; // Full name of the plugin (used for diagnostics)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user