Merge branch 'MDL-48969_m29v9' of https://github.com/sbourget/moodle

This commit is contained in:
Dan Poltawski 2015-03-24 11:48:44 +00:00
commit 9569976f86
25 changed files with 3346 additions and 517 deletions

View File

@ -0,0 +1,115 @@
<?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/>.
/**
* Define all the backup steps that will be used by the backup_block_task
* @package block_activity_results
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Specialised restore task for the activity_results block
* (using execute_after_tasks for recoding of target activity)
*
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_activity_results_block_task extends restore_block_task {
/**
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
}
/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
}
/**
* Define the associated file areas
*/
public function get_fileareas() {
return array(); // No associated fileareas.
}
/**
* Define special handling of configdata.
*/
public function get_configdata_encoded_attributes() {
return array(); // No special handling of configdata.
}
/**
* This function, executed after all the tasks in the plan
* have been executed, will perform the recode of the
* target activity for the block. This must be done here
* and not in normal execution steps because the activity
* can be restored after the block.
*/
public function after_restore() {
global $DB;
// Get the blockid.
$blockid = $this->get_blockid();
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
$config = unserialize(base64_decode($configdata));
if (!empty($config->activityparentid)) {
// Get the mapping and replace it in config.
if ($mapping = restore_dbops::get_backup_ids_record($this->get_restoreid(),
$config->activityparent, $config->activityparentid)) {
// Update the parent module id (the id from mdl_quiz etc...)
$config->activityparentid = $mapping->newitemid;
// Get the grade_items record to update the activitygradeitemid.
$info = $DB->get_record('grade_items',
array('iteminstance' => $config->activityparentid, 'itemmodule' => $config->activityparent));
// Update the activitygradeitemid the id from the grade_items table.
$config->activitygradeitemid = $info->id;
// Encode and save the config.
$configdata = base64_encode(serialize($config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
}
}
}
}
/**
* Define the contents in the activity that must be
* processed by the link decoder
*/
static public function define_decode_contents() {
return array();
}
/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
static public function define_decode_rules() {
return array();
}
}

View File

@ -0,0 +1,693 @@
<?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/>.
/**
* Classes to enforce the various access rules that can apply to a activity.
*
* @package block_activity_results
* @copyright 2009 Tim Hunt
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/lib/grade/constants.php');
define('B_ACTIVITYRESULTS_NAME_FORMAT_FULL', 1);
define('B_ACTIVITYRESULTS_NAME_FORMAT_ID', 2);
define('B_ACTIVITYRESULTS_NAME_FORMAT_ANON', 3);
define('B_ACTIVITYRESULTS_GRADE_FORMAT_PCT', 1);
define('B_ACTIVITYRESULTS_GRADE_FORMAT_FRA', 2);
define('B_ACTIVITYRESULTS_GRADE_FORMAT_ABS', 3);
define('B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE', 4);
/**
* Block activity_results class definition.
*
* This block can be added to a course page or a activity page to display of list of
* the best/worst students/groups in a particular activity.
*
* @package block_activity_results
* @copyright 2009 Tim Hunt
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_activity_results extends block_base {
/**
* Core function used to initialize the block.
*/
public function init() {
$this->title = get_string('pluginname', 'block_activity_results');
}
/**
* Core function, specifies where the block can be used.
* @return array
*/
public function applicable_formats() {
return array('course-view' => true, 'mod' => true);
}
/**
* If this block belongs to a activity context, then return that activity's id.
* Otherwise, return 0.
* @return stdclass the activity record.
*/
public function get_owning_activity() {
global $DB;
// Set some defaults.
$result = new stdClass();
$result->id = 0;
if (empty($this->instance->parentcontextid)) {
return $result;
}
$parentcontext = context::instance_by_id($this->instance->parentcontextid);
if ($parentcontext->contextlevel != CONTEXT_MODULE) {
return $result;
}
$cm = get_coursemodule_from_id($this->page->cm->modname, $parentcontext->instanceid);
if (!$cm) {
return $result;
}
// Get the grade_items id.
$rec = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $this->page->cm->modname));
if (!$rec) {
return $result;
}
// See if it is a gradable activity.
if (($rec->gradetype != GRADE_TYPE_VALUE) || ($rec->gradetype != GRADE_TYPE_SCALE)) {
return $result;
}
return $rec;
}
/**
* Used to save the form config data
* @param stdclass $data
* @param bool $nolongerused
*/
public function instance_config_save($data, $nolongerused = false) {
global $DB;
if (empty($data->activitygradeitemid)) {
// Figure out info about parent module.
$info = $this->get_owning_activity();
$data->activitygradeitemid = $info->id;
if ($info->id < 1) {
// No activity was selected.
$info->itemmodule = '';
$info->iteminstance = '';
} else {
$data->activityparent = $info->itemmodule;
$data->activityparentid = $info->iteminstance;
}
} else {
// Lookup info about the parent module (we have the id from mdl_grade_items.
$info = $DB->get_record('grade_items', array('id' => $data->activitygradeitemid));
$data->activityparent = $info->itemmodule;
$data->activityparentid = $info->iteminstance;
}
parent::instance_config_save($data);
}
/**
* Used to generate the content for the block.
* @return string
*/
public 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;
}
// We are configured so use the configuration.
if (!empty($this->config->activitygradeitemid)) {
// We are configured.
$activitygradeitemid = $this->config->activitygradeitemid;
// Lookup the module in the grade_items table.
$activity = $DB->get_record('grade_items', array('id' => $activitygradeitemid));
if (empty($activity)) {
// Activity does not exist.
$this->content->text = get_string('error_emptyactivityrecord', 'block_activity_results');
return $this->content;
}
$courseid = $activity->courseid;
$inactivity = false;
} else {
// Not configured.
$activitygradeitemid = 0;
}
// Check to see if we are in the moule we are displaying results for.
if (!empty($this->config->activitygradeitemid)) {
if ($this->get_owning_activity()->id == $this->config->activitygradeitemid) {
$inactivity = true;
} else {
$inactivity = false;
}
}
// Activity ID is missing.
if (empty($activitygradeitemid)) {
$this->content->text = get_string('error_emptyactivityid', 'block_activity_results');
return $this->content;
}
// Check to see if we are configured.
if (empty($this->config->showbest) && empty($this->config->showworst)) {
$this->content->text = get_string('configuredtoshownothing', 'block_activity_results');
return $this->content;
}
// Check to see if it is a supported grade type.
if (empty($activity->gradetype) || ($activity->gradetype != GRADE_TYPE_VALUE && $activity->gradetype != GRADE_TYPE_SCALE)) {
$this->content->text = get_string('error_unsupportedgradetype', 'block_activity_results');
return $this->content;
}
// Get the grades for this activity.
$sql = 'SELECT * FROM {grade_grades}
WHERE itemid = ? AND finalgrade is not NULL
ORDER BY finalgrade, timemodified DESC';
$grades = $DB->get_records_sql($sql, array( $activitygradeitemid));
if (empty($grades) || $activity->hidden) {
// No grades available, The block will hide itself in this case.
return $this->content;
}
// Set up results.
$groupmode = NOGROUPS;
$best = array();
$worst = array();
if (!empty($this->config->nameformat)) {
$nameformat = $this->config->nameformat;
} else {
$nameformat = B_ACTIVITYRESULTS_NAME_FORMAT_FULL;
}
// Get $cm and context.
if ($inactivity) {
$cm = $this->page->cm;
$context = $this->page->context;
} else {
$cm = get_coursemodule_from_instance($activity->itemmodule, $activity->iteminstance, $courseid);
$context = context_module::instance($cm->id);
}
if (!empty($this->config->usegroups)) {
$groupmode = groups_get_activity_groupmode($cm);
if ($groupmode == SEPARATEGROUPS && has_capability('moodle/site:accessallgroups', $context)) {
// If you have the ability to see all groups then lets show them.
$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_activity_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->finalgrade;
}
// 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!
if ($activity->gradetype == GRADE_TYPE_SCALE) {
// We must display the results using scales.
$gradeformat = B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE;
// Preload the scale.
$scale = $this->get_scale($activity->scaleid);
} else if (intval(empty($this->config->gradeformat))) {
$gradeformat = B_ACTIVITYRESULTS_GRADE_FORMAT_PCT;
} else {
$gradeformat = $this->config->gradeformat;
}
// Generate the header.
$this->content->text .= $this->activity_link($activity, $cm);
if ($nameformat == B_ACTIVITYRESULTS_NAME_FORMAT_FULL) {
if (has_capability('moodle/course:managegroups', $context)) {
$grouplink = $CFG->wwwroot.'/group/overview.php?id='.$courseid.'&amp;group=';
} else if (has_capability('moodle/course:viewparticipants', $context)) {
$grouplink = $CFG->wwwroot.'/user/index.php?id='.$courseid.'&amp;group=';
} else {
$grouplink = '';
}
}
$rank = 0;
if (!empty($best)) {
$this->content->text .= '<table class="grades"><caption>';
if ($numbest == 1) {
$this->content->text .= get_string('bestgroupgrade', 'block_activity_results');
} else {
$this->content->text .= get_string('bestgroupgrades', 'block_activity_results', $numbest);
}
$this->content->text .= '</caption><colgroup class="number" />';
$this->content->text .= '<colgroup class="name" /><colgroup class="grade" /><tbody>';
foreach ($best as $groupid => $averagegrade) {
switch ($nameformat) {
case B_ACTIVITYRESULTS_NAME_FORMAT_ANON:
case B_ACTIVITYRESULTS_NAME_FORMAT_ID:
$thisname = get_string('group');
break;
default:
case B_ACTIVITYRESULTS_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_ACTIVITYRESULTS_GRADE_FORMAT_SCALE:
// Round answer up and locate appropriate scale.
$answer = (round($averagegrade, 0, PHP_ROUND_HALF_UP) - 1);
if (isset($scale[$answer])) {
$this->content->text .= $scale[$answer];
} else {
// Value is not in the scale.
$this->content->text .= get_string('unknown', 'block_activity_results');
}
break;
case B_ACTIVITYRESULTS_GRADE_FORMAT_FRA:
$this->content->text .= $this->activity_format_grade($averagegrade)
. '/' . $this->activity_format_grade($activity->grademax);
break;
case B_ACTIVITYRESULTS_GRADE_FORMAT_ABS:
$this->content->text .= $this->activity_format_grade($averagegrade);
break;
default:
case B_ACTIVITYRESULTS_GRADE_FORMAT_PCT:
$this->content->text .= $this->activity_format_grade((float)$averagegrade /
(float)$activity->grademax * 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>';
if ($numworst == 1) {
$this->content->text .= get_string('worstgroupgrade', 'block_activity_results');
} else {
$this->content->text .= get_string('worstgroupgrades', 'block_activity_results', $numworst);
}
$this->content->text .= '</caption><colgroup class="number" />';
$this->content->text .= '<colgroup class="name" /><colgroup class="grade" /><tbody>';
foreach ($worst as $groupid => $averagegrade) {
switch ($nameformat) {
case B_ACTIVITYRESULTS_NAME_FORMAT_ANON:
case B_ACTIVITYRESULTS_NAME_FORMAT_ID:
$thisname = get_string('group');
break;
default:
case B_ACTIVITYRESULTS_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_ACTIVITYRESULTS_GRADE_FORMAT_SCALE:
// Round answer up and locate appropriate scale.
$answer = (round($averagegrade, 0, PHP_ROUND_HALF_UP) - 1);
if (isset($scale[$answer])) {
$this->content->text .= $scale[$answer];
} else {
// Value is not in the scale.
$this->content->text .= get_string('unknown', 'block_activity_results');
}
break;
case B_ACTIVITYRESULTS_GRADE_FORMAT_FRA:
$this->content->text .= $this->activity_format_grade($averagegrade)
. '/' . $this->activity_format_grade($activity->grademax);
break;
case B_ACTIVITYRESULTS_GRADE_FORMAT_ABS:
$this->content->text .= $this->activity_format_grade($averagegrade);
break;
default:
case B_ACTIVITYRESULTS_GRADE_FORMAT_PCT:
$this->content->text .= $this->activity_format_grade((float)$averagegrade /
(float)$activity->grademax * 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!
if ($activity->gradetype == GRADE_TYPE_SCALE) {
// We must display the results using scales.
$gradeformat = B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE;
// Preload the scale.
$scale = $this->get_scale($activity->scaleid);
} else if (intval(empty($this->config->gradeformat))) {
$gradeformat = B_ACTIVITYRESULTS_GRADE_FORMAT_PCT;
} else {
$gradeformat = $this->config->gradeformat;
}
// Generate the header.
$this->content->text .= $this->activity_link($activity, $cm);
$rank = 0;
if (!empty($best)) {
$this->content->text .= '<table class="grades"><caption>';
if ($numbest == 1) {
$this->content->text .= get_string('bestgrade', 'block_activity_results');
} else {
$this->content->text .= get_string('bestgrades', 'block_activity_results', $numbest);
}
$this->content->text .= '</caption><colgroup class="number" />';
$this->content->text .= '<colgroup class="name" /><colgroup class="grade" /><tbody>';
foreach ($best as $userid => $gradeid) {
switch ($nameformat) {
case B_ACTIVITYRESULTS_NAME_FORMAT_ID:
$thisname = get_string('user').' '.$users[$userid]->idnumber;
break;
case B_ACTIVITYRESULTS_NAME_FORMAT_ANON:
$thisname = get_string('user');
break;
default:
case B_ACTIVITYRESULTS_NAME_FORMAT_FULL:
if (has_capability('moodle/user:viewdetails', $context)) {
$thisname = html_writer::link(new moodle_url('/user/view.php',
array('id' => $userid, 'course' => $courseid)), fullname($users[$userid]));
} else {
$thisname = fullname($users[$userid]);
}
break;
}
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
switch ($gradeformat) {
case B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE:
// Round answer up and locate appropriate scale.
$answer = (round($grades[$gradeid]->finalgrade, 0, PHP_ROUND_HALF_UP) - 1);
if (isset($scale[$answer])) {
$this->content->text .= $scale[$answer];
} else {
// Value is not in the scale.
$this->content->text .= get_string('unknown', 'block_activity_results');
}
break;
case B_ACTIVITYRESULTS_GRADE_FORMAT_FRA:
$this->content->text .= $this->activity_format_grade($grades[$gradeid]->finalgrade);
$this->content->text .= '/'.$this->activity_format_grade($activity->grademax);
break;
case B_ACTIVITYRESULTS_GRADE_FORMAT_ABS:
$this->content->text .= $this->activity_format_grade($grades[$gradeid]->finalgrade);
break;
default:
case B_ACTIVITYRESULTS_GRADE_FORMAT_PCT:
if ($activity->grademax) {
$this->content->text .= $this->activity_format_grade((float)$grades[$gradeid]->finalgrade /
(float)$activity->grademax * 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>';
if ($numbest == 1) {
$this->content->text .= get_string('worstgrade', 'block_activity_results');
} else {
$this->content->text .= get_string('worstgrades', 'block_activity_results', $numworst);
}
$this->content->text .= '</caption><colgroup class="number" />';
$this->content->text .= '<colgroup class="name" /><colgroup class="grade" /><tbody>';
foreach ($worst as $userid => $gradeid) {
switch ($nameformat) {
case B_ACTIVITYRESULTS_NAME_FORMAT_ID:
$thisname = get_string('user').' '.$users[$userid]->idnumber;
break;
case B_ACTIVITYRESULTS_NAME_FORMAT_ANON:
$thisname = get_string('user');
break;
default:
case B_ACTIVITYRESULTS_NAME_FORMAT_FULL:
if (has_capability('moodle/user:viewdetails', $context)) {
$thisname = html_writer::link(new moodle_url('/user/view.php',
array('id' => $userid, 'course' => $courseid)), fullname($users[$userid]));
} else {
$thisname = fullname($users[$userid]);
}
break;
}
$this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
switch ($gradeformat) {
case B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE:
// Round answer up and locate appropriate scale.
$answer = (round($grades[$gradeid]->finalgrade, 0, PHP_ROUND_HALF_UP) - 1);
if (isset($scale[$answer])) {
$this->content->text .= $scale[$answer];
} else {
// Value is not in the scale.
$this->content->text .= get_string('unknown', 'block_activity_results');
}
break;
case B_ACTIVITYRESULTS_GRADE_FORMAT_FRA:
$this->content->text .= $this->activity_format_grade($grades[$gradeid]->finalgrade);
$this->content->text .= '/'.$this->activity_format_grade($activity->grademax);
break;
case B_ACTIVITYRESULTS_GRADE_FORMAT_ABS:
$this->content->text .= $this->activity_format_grade($grades[$gradeid]->finalgrade);
break;
default:
case B_ACTIVITYRESULTS_GRADE_FORMAT_PCT:
if ($activity->grademax) {
$this->content->text .= $this->activity_format_grade((float)$grades[$gradeid]->finalgrade /
(float)$activity->grademax * 100).'%';
} else {
$this->content->text .= '--%';
}
break;
}
$this->content->text .= '</td></tr>';
}
$this->content->text .= '</tbody></table>';
}
break;
}
return $this->content;
}
/**
* Allows the block to be added multiple times to a single page
* @return boolean
*/
public function instance_allow_multiple() {
return true;
}
/**
* Formats the grade to the specified decimal points
* @param float $grade
* @return string
*/
private function activity_format_grade($grade) {
if (is_null($grade)) {
return get_string('notyetgraded', 'block_activity_results');
}
return format_float($grade, $this->config->decimalpoints);
}
/**
* Generates the Link to the activity module when displaed outside of the module
* @param stdclass $activity
* @param stdclass $cm
* @return string
*/
private function activity_link($activity, $cm) {
$o = html_writer::start_tag('h3');
$o .= html_writer::link(new moodle_url('/mod/'.$activity->itemmodule.'/view.php',
array('id' => $cm->id)), $activity->itemname);
$o .= html_writer::end_tag('h3');
return $o;
}
/**
* Generates a numeric array of scale entries
* @param int $scaleid
* @return array
*/
private function get_scale($scaleid) {
global $DB;
$scaletext = $DB->get_field('scale', 'scale', array('id' => $scaleid), IGNORE_MISSING);
$scale = explode ( ',', $scaletext);
return $scale;
}
}

View File

@ -0,0 +1,41 @@
<?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/>.
/**
* Activity results block caps.
*
* @package block_activity_results
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/activity_results:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);

View File

@ -0,0 +1,104 @@
<?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_activity_results
* @copyright 2009 Tim Hunt
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/lib/grade/constants.php');
/**
* Form for editing activity results block instances.
*
* @copyright 2009 Tim Hunt
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_activity_results_edit_form extends block_edit_form {
/**
* The definition of the fields to use.
*
* @param MoodleQuickForm $mform
*/
protected function specific_definition($mform) {
global $DB;
// Fields for editing activity_results block title and contents.
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
// Get supported modules (Only modules using grades or scales will be listed).
$sql = 'SELECT id, itemname FROM {grade_items} WHERE courseid = ? and itemtype = ? and (gradetype = ? or gradetype = ?)';
$params = array($this->page->course->id, 'mod', GRADE_TYPE_VALUE, GRADE_TYPE_SCALE);
$activities = $DB->get_records_sql_menu($sql, $params);
if (empty($activities)) {
$mform->addElement('static', 'noactivitieswarning', get_string('config_select_activity', 'block_activity_results'),
get_string('config_no_activities_in_course', 'block_activity_results'));
} else {
foreach ($activities as $id => $name) {
$activities[$id] = strip_tags(format_string($name));
}
$mform->addElement('select', 'config_activitygradeitemid',
get_string('config_select_activity', 'block_activity_results'), $activities);
$mform->setDefault('config_activitygradeitemid', $this->block->get_owning_activity()->id);
}
$mform->addElement('text', 'config_showbest',
get_string('config_show_best', 'block_activity_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_activity_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_activity_results'));
$nameoptions = array(
B_ACTIVITYRESULTS_NAME_FORMAT_FULL => get_string('config_names_full', 'block_activity_results'),
B_ACTIVITYRESULTS_NAME_FORMAT_ID => get_string('config_names_id', 'block_activity_results'),
B_ACTIVITYRESULTS_NAME_FORMAT_ANON => get_string('config_names_anon', 'block_activity_results')
);
$mform->addElement('select', 'config_nameformat',
get_string('config_name_format', 'block_activity_results'), $nameoptions);
$mform->setDefault('config_nameformat', B_ACTIVITYRESULTS_NAME_FORMAT_FULL);
$gradeeoptions = array(
B_ACTIVITYRESULTS_GRADE_FORMAT_PCT => get_string('config_format_percentage', 'block_activity_results'),
B_ACTIVITYRESULTS_GRADE_FORMAT_FRA => get_string('config_format_fraction', 'block_activity_results'),
B_ACTIVITYRESULTS_GRADE_FORMAT_ABS => get_string('config_format_absolute', 'block_activity_results')
);
$mform->addElement('select', 'config_gradeformat',
get_string('config_grade_format', 'block_activity_results'), $gradeeoptions);
$mform->setDefault('config_gradeformat', B_ACTIVITYRESULTS_GRADE_FORMAT_PCT);
$options = array();
for ($i = 0; $i <= 5; $i++) {
$options[$i] = $i;
}
$mform->addElement('select', 'config_decimalpoints', get_string('config_decimalplaces', 'block_activity_results'),
$options);
$mform->setDefault('config_decimalpoints', 2);
$mform->setType('config_decimalpoints', PARAM_INT);
}
}

View File

@ -0,0 +1,55 @@
<?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/>.
/**
* Strings for component 'block_activity_results', language 'en', branch 'MOODLE_20_STABLE'
*
* @package block_activity_results
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['activity_results:addinstance'] = 'Add a new activity results block';
$string['bestgrade'] = 'The highest grade:';
$string['bestgrades'] = 'The {$a} highest grades:';
$string['bestgroupgrade'] = 'The group with the highest average:';
$string['bestgroupgrades'] = 'The {$a} groups with the highest average:';
$string['config_format_absolute'] = 'Absolute numbers';
$string['config_format_fraction'] = 'Fractions';
$string['config_format_percentage'] = 'Percentages';
$string['config_decimalplaces'] = 'Decimal places to display';
$string['config_grade_format'] = 'Display grades as:';
$string['config_name_format'] = 'Privacy level for displayed results:';
$string['config_names_anon'] = 'Anonymous results';
$string['config_names_full'] = 'Display full names';
$string['config_names_id'] = 'Display only ID numbers';
$string['config_no_activities_in_course'] = 'This course does not contain any activity activities . You must add at least one before you are able to use this block correctly.';
$string['config_select_activity'] = 'Which activity should this block display results from?';
$string['config_show_best'] = 'How many of the highest grades should be shown (0 to disable)?';
$string['config_show_worst'] = 'How many of the lowest grades should be shown (0 to disable)?';
$string['configuredtoshownothing'] = 'This block\'s configuration currently does not allow it to show any results. You may want to either configure it or hide it.';
$string['config_use_groups'] = 'Show groups instead of students (only if the activity supports groups)?';
$string['error_emptyactivityid'] = 'There is an error right now with this block: you need to select which activity it should display results from.';
$string['error_emptyactivityrecord'] = 'There is an error right now with this block: the selected activity 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['error_unsupportedgradetype'] = 'There is an error right now with this block: The activity selected is configured to use a grading method that is not supported by this block.';
$string['notyetgraded'] = 'Not yet graded';
$string['pluginname'] = 'Activity results';
$string['unknown'] = 'Unknown scale';
$string['worstgrade'] = 'The lowest grade:';
$string['worstgrades'] = 'The {$a} lowest grades:';
$string['worstgroupgrade'] = 'The group with the lowest average:';
$string['worstgroupgrades'] = 'The {$a} groups with the lowest average:';

View File

@ -0,0 +1,6 @@
.block_activity_results {text-align: center;}
.block_activity_results h1 {margin: 4px;font-size: 1.1em;}
.block_activity_results table.grades {text-align: left;width: 100%;}
.block_activity_results table.grades .number{text-align: right;width:10%;}
.block_activity_results table.grades .grade {text-align: right;}
.block_activity_results table.grades caption {margin: 1em 0px 0px 0px;border-bottom-width: 1px;border-bottom-style: solid;font-weight: bold;}

View File

@ -0,0 +1,66 @@
@block @block_activity_results
Feature: The activity results block displays student scores
In order to be display student scores
As a user
I need to see the activity results block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | T1 |
| student1 | Student | 1 | student1@asd.com | S1 |
| student2 | Student | 2 | student2@asd.com | S2 |
| student3 | Student | 3 | student3@asd.com | S3 |
| student4 | Student | 4 | student4@asd.com | S4 |
| student5 | Student | 5 | student5@asd.com | S5 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| student4 | C1 | student |
| student5 | C1 | student |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "90.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "60.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "50.00" to the user "Student 5" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
Scenario: Configure the block on a non-graded activity to show 3 high scores
Given I add a "Page" to section "1"
And I set the following fields to these values:
| Name | Test page name |
| Description | Test page description |
| page | This is a page |
And I press "Save and display"
When I add the "Activity results" block
And I configure the "Activity results" block
And I set the following fields to these values:
| id_config_activitygradeitemid | Test assignment |
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
And I press "Save changes"
Then I should see "Student 1" in the "Activity results" "block"
And I should see "90.00" in the "Activity results" "block"
And I should see "Student 2" in the "Activity results" "block"
And I should see "80.00" in the "Activity results" "block"
And I should see "Student 3" in the "Activity results" "block"
And I should see "70.00" in the "Activity results" "block"

View File

@ -0,0 +1,43 @@
@block @block_activity_results
Feature: The activity results block displays student scores
In order to be display student scores
As a user
I need to see the activity results block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | T1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
Scenario: Add the block to a the course
Given I add the "Activity results" block
Then I should see "There is an error right now with this block: you need to select which activity it should display results from." in the "Activity results" "block"
Scenario: Try to configure the block on the course page in a course without activities
Given I add the "Activity results" block
When I configure the "Activity results" block
And I should see "This course does not contain any activity activities . You must add at least one before you are able to use this block correctly."
And I press "Save changes"
Then I should see "There is an error right now with this block: you need to select which activity it should display results from." in the "Activity results" "block"
Scenario: Try to configure the block on a resource page in a course without activities
Given I add a "Page" to section "1"
And I set the following fields to these values:
| Name | Test page name |
| Description | Test page description |
| page | This is a page |
And I press "Save and display"
When I add the "Activity results" block
And I configure the "Activity results" block
And I should see "This course does not contain any activity activities . You must add at least one before you are able to use this block correctly."
And I press "Save changes"
Then I should see "There is an error right now with this block: you need to select which activity it should display results from." in the "Activity results" "block"

View File

@ -0,0 +1,40 @@
@block @block_activity_results
Feature: The activity results block displays student scores
In order to be display student scores
As a user
I need to properly configure the activity results block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | T1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
Scenario: Try to configure the block to use an activity without grades
Given I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
And I follow "C1"
And I add the "Activity results" block
And I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 1 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
And I press "Save changes"
When I follow "Test assignment"
And I click on "Edit settings" "link" in the "Administration" "block"
And I set the following fields to these values:
| id_modgrade_type | None |
And I press "Save and return to course"
Then I should see "There is an error right now with this block: The activity selected is configured to use a grading method that is not supported by this block." in the "Activity results" "block"

View File

@ -0,0 +1,170 @@
@block @block_activity_results
Feature: The activity results block displays student scores
In order to be display student scores
As a user
I need to see the activity results block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | T1 |
| student1 | Student | 1 | student1@asd.com | S1 |
| student2 | Student | 2 | student2@asd.com | S2 |
| student3 | Student | 3 | student3@asd.com | S3 |
| student4 | Student | 4 | student4@asd.com | S4 |
| student5 | Student | 5 | student5@asd.com | S5 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| student4 | C1 | student |
| student5 | C1 | student |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "90.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "60.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "50.00" to the user "Student 5" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
Scenario: Configure the block on the course page to show 0 high scores
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
And I press "Save changes"
Then I should see "This block's configuration currently does not allow it to show any results." in the "Activity results" "block"
Scenario: Configure the block on the course page to show 1 high score
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 1 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
And I press "Save changes"
Then I should see "Student 1" in the "Activity results" "block"
And I should see "90%" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show 1 high score as a fraction
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 1 |
| id_config_showworst | 0 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
And I press "Save changes"
Then I should see "Student 1" in the "Activity results" "block"
And I should see "90.00/100.00" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show 1 high score as a absolute numbers
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 1 |
| id_config_showworst | 0 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
And I press "Save changes"
Then I should see "Student 1" in the "Activity results" "block"
And I should see "90.00" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show multiple high scores as percentages
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
And I press "Save changes"
Then I should see "Student 1" in the "Activity results" "block"
And I should see "90%" in the "Activity results" "block"
And I should see "Student 2" in the "Activity results" "block"
And I should see "80%" in the "Activity results" "block"
And I should see "Student 3" in the "Activity results" "block"
And I should see "70%" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show multiple high scores as fractions
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
And I press "Save changes"
Then I should see "Student 1" in the "Activity results" "block"
And I should see "90.00/100.00" in the "Activity results" "block"
And I should see "Student 2" in the "Activity results" "block"
And I should see "80.00/100.00" in the "Activity results" "block"
And I should see "Student 3" in the "Activity results" "block"
And I should see "70.00/100.00" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show multiple high scores as absolute numbers
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
And I press "Save changes"
Then I should see "Student 1" in the "Activity results" "block"
And I should see "90.00" in the "Activity results" "block"
And I should see "Student 2" in the "Activity results" "block"
And I should see "80.00" in the "Activity results" "block"
And I should see "Student 3" in the "Activity results" "block"
And I should see "70.00" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show multiple high scores using ID numbers
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display only ID numbers |
And I press "Save changes"
Then I should see "User S1" in the "Activity results" "block"
And I should see "90.00%" in the "Activity results" "block"
And I should see "User S2" in the "Activity results" "block"
And I should see "80.00%" in the "Activity results" "block"
And I should see "User S3" in the "Activity results" "block"
And I should see "70.00%" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show multiple high scores using anonymous names
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Anonymous results |
And I press "Save changes"
Then I should see "User" in the "Activity results" "block"
And I should see "90.00%" in the "Activity results" "block"
And I should see "80.00%" in the "Activity results" "block"
And I should see "70.00%" in the "Activity results" "block"

View File

@ -0,0 +1,433 @@
@block @block_activity_results
Feature: The activity results block displays student scores
In order to be display student scores
As a user
I need to see the activity results block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | T1 |
| student1 | Student | 1 | student1@asd.com | S1 |
| student2 | Student | 2 | student2@asd.com | S2 |
| student3 | Student | 3 | student3@asd.com | S3 |
| student4 | Student | 4 | student4@asd.com | S4 |
| student5 | Student | 5 | student5@asd.com | S5 |
| student6 | Student | 6 | student6@asd.com | S6 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
| Group 3 | C1 | G3 |
| Group 4 | C1 | G4 |
| Group 5 | C1 | G5 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| student4 | C1 | student |
| student5 | C1 | student |
| student6 | C1 | student |
@javascript
Scenario: Configure the block on the course page to show 1 high score
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 1 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 1" in the "Activity results" "block"
And I should see "95%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show 1 high score as a fraction
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 1 |
| id_config_showworst | 0 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 1" in the "Activity results" "block"
And I should see "95.00/100.00" in the "Activity results" "block"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I should see "Student 1" in the "Activity results" "block"
And I should see "100.00/100.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show 1 high score as a absolute numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 1 |
| id_config_showworst | 0 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 1" in the "Activity results" "block"
And I should see "95.00" in the "Activity results" "block"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I should see "Student 1" in the "Activity results" "block"
And I should see "100.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple high scores as percentages
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 1" in the "Activity results" "block"
And I should see "95%" in the "Activity results" "block"
And I should see "Group 2" in the "Activity results" "block"
And I should see "85%" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75%" in the "Activity results" "block"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I should see "Student 1" in the "Activity results" "block"
And I should see "100%" in the "Activity results" "block"
And I should see "Student 2" in the "Activity results" "block"
And I should see "90%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple high scores as fractions
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 1" in the "Activity results" "block"
And I should see "95.00/100.00" in the "Activity results" "block"
And I should see "Group 2" in the "Activity results" "block"
And I should see "85.00/100.00" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75.00/100.00" in the "Activity results" "block"
And I log out
And I log in as "student3"
And I follow "Course 1"
And I should see "Student 3" in the "Activity results" "block"
And I should see "90.00/100.00" in the "Activity results" "block"
And I should see "Student 4" in the "Activity results" "block"
And I should see "80.00/100.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple high scores as absolute numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 1" in the "Activity results" "block"
And I should see "95.00" in the "Activity results" "block"
And I should see "Group 2" in the "Activity results" "block"
And I should see "85.00" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75.00" in the "Activity results" "block"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I should see "Student 1" in the "Activity results" "block"
And I should see "100.00" in the "Activity results" "block"
And I should see "Student 2" in the "Activity results" "block"
And I should see "90.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple high scores using ID numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display only ID numbers |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group" in the "Activity results" "block"
And I should see "95.00%" in the "Activity results" "block"
And I should see "85.00%" in the "Activity results" "block"
And I should see "75.00%" in the "Activity results" "block"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I should see "User S1" in the "Activity results" "block"
And I should see "100.00%" in the "Activity results" "block"
And I should see "User S2" in the "Activity results" "block"
And I should see "90.00%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple high scores using anonymous names
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Anonymous results |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group" in the "Activity results" "block"
And I should see "95.00%" in the "Activity results" "block"
And I should see "85.00%" in the "Activity results" "block"
And I should see "75.00%" in the "Activity results" "block"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I should see "User" in the "Activity results" "block"
And I should see "100.00%" in the "Activity results" "block"
And I should see "90.00%" in the "Activity results" "block"

View File

@ -0,0 +1,410 @@
@block @block_activity_results
Feature: The activity results block displays student scores
In order to be display student scores
As a user
I need to see the activity results block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | T1 |
| student1 | Student | 1 | student1@asd.com | S1 |
| student2 | Student | 2 | student2@asd.com | S2 |
| student3 | Student | 3 | student3@asd.com | S3 |
| student4 | Student | 4 | student4@asd.com | S4 |
| student5 | Student | 5 | student5@asd.com | S5 |
| student6 | Student | 6 | student6@asd.com | S6 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
| Group 3 | C1 | G3 |
| Group 4 | C1 | G4 |
| Group 5 | C1 | G5 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| student4 | C1 | student |
| student5 | C1 | student |
| student6 | C1 | student |
@javascript
Scenario: Configure the block on the course page to show 1 high score
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 1 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 1" in the "Activity results" "block"
And I should see "95%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show 1 high score as a fraction
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 1 |
| id_config_showworst | 0 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group 1" in the "Activity results" "block"
And I should see "95.00/100.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show 1 high score as a absolute numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 1 |
| id_config_showworst | 0 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group 1" in the "Activity results" "block"
And I should see "95.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple high scores as percentages
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group 1" in the "Activity results" "block"
And I should see "95%" in the "Activity results" "block"
And I should see "Group 2" in the "Activity results" "block"
And I should see "85%" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple high scores as fractions
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group 1" in the "Activity results" "block"
And I should see "95.00/100.00" in the "Activity results" "block"
And I should see "Group 2" in the "Activity results" "block"
And I should see "85.00/100.00" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75.00/100.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple high scores as absolute numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group 1" in the "Activity results" "block"
And I should see "95.00" in the "Activity results" "block"
And I should see "Group 2" in the "Activity results" "block"
And I should see "85.00" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple high scores using ID numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display only ID numbers |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group" in the "Activity results" "block"
And I should see "95.00%" in the "Activity results" "block"
And I should see "85.00%" in the "Activity results" "block"
And I should see "75.00%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple high scores using anonymous names
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 3 |
| id_config_showworst | 0 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Anonymous results |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group" in the "Activity results" "block"
And I should see "95.00%" in the "Activity results" "block"
And I should see "85.00%" in the "Activity results" "block"
And I should see "75.00%" in the "Activity results" "block"

View File

@ -0,0 +1,159 @@
@block @block_activity_results
Feature: The activity results block displays student scores
In order to be display student scores
As a user
I need to see the activity results block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | T1 |
| student1 | Student | 1 | student1@asd.com | S1 |
| student2 | Student | 2 | student2@asd.com | S2 |
| student3 | Student | 3 | student3@asd.com | S3 |
| student4 | Student | 4 | student4@asd.com | S4 |
| student5 | Student | 5 | student5@asd.com | S5 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| student4 | C1 | student |
| student5 | C1 | student |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "90.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "60.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "50.00" to the user "Student 5" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
Scenario: Configure the block on the course page to show 1 low score
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 1 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
And I press "Save changes"
Then I should see "Student 5" in the "Activity results" "block"
And I should see "50%" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show 1 low score as a fraction
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 1 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
And I press "Save changes"
Then I should see "Student 5" in the "Activity results" "block"
And I should see "50.00/100.00" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show 1 low score as a absolute number
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 1 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
And I press "Save changes"
Then I should see "Student 5" in the "Activity results" "block"
And I should see "50.00" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show multiple low scores as percentages
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 3 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
And I press "Save changes"
Then I should see "Student 5" in the "Activity results" "block"
And I should see "50%" in the "Activity results" "block"
And I should see "Student 4" in the "Activity results" "block"
And I should see "60%" in the "Activity results" "block"
And I should see "Student 3" in the "Activity results" "block"
And I should see "70%" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show multiple low scores as fractions
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 3 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
And I press "Save changes"
Then I should see "Student 5" in the "Activity results" "block"
And I should see "50.00/100.00" in the "Activity results" "block"
And I should see "Student 4" in the "Activity results" "block"
And I should see "60.00/100.00" in the "Activity results" "block"
And I should see "Student 3" in the "Activity results" "block"
And I should see "70.00/100.00" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show multiple low scores as absolute numbers
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 3 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
And I press "Save changes"
Then I should see "Student 5" in the "Activity results" "block"
And I should see "50.00" in the "Activity results" "block"
And I should see "Student 4" in the "Activity results" "block"
And I should see "60.00" in the "Activity results" "block"
And I should see "Student 3" in the "Activity results" "block"
And I should see "70.00" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show multiple low scores using ID numbers
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 3 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display only ID numbers |
And I press "Save changes"
Then I should see "User S5" in the "Activity results" "block"
And I should see "50.00%" in the "Activity results" "block"
And I should see "User S4" in the "Activity results" "block"
And I should see "60.00%" in the "Activity results" "block"
And I should see "User S3" in the "Activity results" "block"
And I should see "70.00%" in the "Activity results" "block"
Scenario: Try to configure the block on the course page to show multiple low scores using anonymous names
Given I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 3 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Anonymous results |
And I press "Save changes"
Then I should see "User" in the "Activity results" "block"
And I should see "50.00%" in the "Activity results" "block"
And I should see "60.00%" in the "Activity results" "block"
And I should see "70.00%" in the "Activity results" "block"

View File

@ -0,0 +1,425 @@
@block @block_activity_results
Feature: The activity results block displays student scores
In order to be display student scores
As a user
I need to see the activity results block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | T1 |
| student1 | Student | 1 | student1@asd.com | S1 |
| student2 | Student | 2 | student2@asd.com | S2 |
| student3 | Student | 3 | student3@asd.com | S3 |
| student4 | Student | 4 | student4@asd.com | S4 |
| student5 | Student | 5 | student5@asd.com | S5 |
| student6 | Student | 6 | student6@asd.com | S6 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
| Group 3 | C1 | G3 |
| Group 4 | C1 | G4 |
| Group 5 | C1 | G5 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| student4 | C1 | student |
| student5 | C1 | student |
| student6 | C1 | student |
@javascript
Scenario: Configure the block on the course page to show 1 low score
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 1 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 3" in the "Activity results" "block"
And I should see "75%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show 1 low score as a fraction
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 1 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 3" in the "Activity results" "block"
And I should see "75.00/100.00" in the "Activity results" "block"
And I log out
And I log in as "student5"
And I follow "Course 1"
And I should see "Student 6" in the "Activity results" "block"
And I should see "70.00/100.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show 1 low score as a absolute numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 1 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 3" in the "Activity results" "block"
And I should see "75.00" in the "Activity results" "block"
And I log out
And I log in as "student5"
And I follow "Course 1"
And I should see "Student 6" in the "Activity results" "block"
And I should see "70.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple low scores as percentages
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 2 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 2" in the "Activity results" "block"
And I should see "85%" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75%" in the "Activity results" "block"
And I log out
And I log in as "student5"
And I follow "Course 1"
And I should see "Student 6" in the "Activity results" "block"
And I should see "70%" in the "Activity results" "block"
And I should see "Student 5" in the "Activity results" "block"
And I should see "80%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple low scores as fractions
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 2 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 2" in the "Activity results" "block"
And I should see "85.00/100.00" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75.00/100.00" in the "Activity results" "block"
And I log out
And I log in as "student3"
And I follow "Course 1"
And I should see "Student 3" in the "Activity results" "block"
And I should see "90.00/100.00" in the "Activity results" "block"
And I should see "Student 4" in the "Activity results" "block"
And I should see "80.00/100.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple low scores as absolute numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 2 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 2" in the "Activity results" "block"
And I should see "85.00" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75.00" in the "Activity results" "block"
And I log out
And I log in as "student5"
And I follow "Course 1"
And I should see "Student 5" in the "Activity results" "block"
And I should see "80.00" in the "Activity results" "block"
And I should see "Student 6" in the "Activity results" "block"
And I should see "70.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple low scores using ID numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 2 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display only ID numbers |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group" in the "Activity results" "block"
And I should see "85.00%" in the "Activity results" "block"
And I should see "75.00%" in the "Activity results" "block"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I should see "User S1" in the "Activity results" "block"
And I should see "100.00%" in the "Activity results" "block"
And I should see "User S2" in the "Activity results" "block"
And I should see "90.00%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple low scores using anonymous names
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Separate groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 2 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Anonymous results |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group" in the "Activity results" "block"
And I should see "85.00%" in the "Activity results" "block"
And I should see "75.00%" in the "Activity results" "block"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I should see "User" in the "Activity results" "block"
And I should see "100.00%" in the "Activity results" "block"
And I should see "90.00%" in the "Activity results" "block"

View File

@ -0,0 +1,406 @@
@block @block_activity_results
Feature: The activity results block displays student scores
In order to be display student scores
As a user
I need to see the activity results block
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | T1 |
| student1 | Student | 1 | student1@asd.com | S1 |
| student2 | Student | 2 | student2@asd.com | S2 |
| student3 | Student | 3 | student3@asd.com | S3 |
| student4 | Student | 4 | student4@asd.com | S4 |
| student5 | Student | 5 | student5@asd.com | S5 |
| student6 | Student | 6 | student6@asd.com | S6 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
| Group 3 | C1 | G3 |
| Group 4 | C1 | G4 |
| Group 5 | C1 | G5 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| student4 | C1 | student |
| student5 | C1 | student |
| student6 | C1 | student |
@javascript
Scenario: Configure the block on the course page to show 1 low score
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 1 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 3" in the "Activity results" "block"
And I should see "75%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show 1 low score as a fraction
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 1 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75.00/100.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show 1 low score as a absolute numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 1 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple low scores as percentages
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 2 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display full names |
| id_config_decimalpoints | 0 |
| id_config_usegroups | Yes |
And I press "Save changes"
Then I should see "Group 2" in the "Activity results" "block"
And I should see "85%" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75%" in the "Activity results" "block"
And I log out
And I log in as "student5"
And I follow "Course 1"
Then I should see "Group 2" in the "Activity results" "block"
And I should see "85%" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple low scores as fractions
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 2 |
| id_config_gradeformat | Fractions |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group 2" in the "Activity results" "block"
And I should see "85.00/100.00" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75.00/100.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple low scores as absolute numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 2 |
| id_config_gradeformat | Absolute numbers |
| id_config_nameformat | Display full names |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group 2" in the "Activity results" "block"
And I should see "85.00" in the "Activity results" "block"
And I should see "Group 3" in the "Activity results" "block"
And I should see "75.00" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple low scores using ID numbers
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 2 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Display only ID numbers |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group" in the "Activity results" "block"
And I should see "85.00%" in the "Activity results" "block"
And I should see "75.00%" in the "Activity results" "block"
@javascript
Scenario: Try to configure the block on the course page to show multiple low scores using anonymous names
Given I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I add "Student 1 (student1@asd.com)" user to "Group 1" group members
And I add "Student 2 (student2@asd.com)" user to "Group 1" group members
And I add "Student 3 (student3@asd.com)" user to "Group 2" group members
And I add "Student 4 (student4@asd.com)" user to "Group 2" group members
And I add "Student 5 (student5@asd.com)" user to "Group 3" group members
And I add "Student 6 (student6@asd.com)" user to "Group 3" group members
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test assignment |
| Description | Offline text |
| assignsubmission_file_enabled | 0 |
| Group mode | Visible groups |
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 2" for the grade item "Test assignment"
And I give the grade "90.00" to the user "Student 3" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 4" for the grade item "Test assignment"
And I give the grade "80.00" to the user "Student 5" for the grade item "Test assignment"
And I give the grade "70.00" to the user "Student 6" for the grade item "Test assignment"
And I press "Save changes"
And I follow "Course 1"
And I add the "Activity results" block
When I configure the "Activity results" block
And I set the following fields to these values:
| id_config_showbest | 0 |
| id_config_showworst | 2 |
| id_config_gradeformat | Percentages |
| id_config_nameformat | Anonymous results |
| id_config_usegroups | Yes |
And I press "Save changes"
And I log out
Then I log in as "student1"
And I follow "Course 1"
And I should see "Group" in the "Activity results" "block"
And I should see "85.00%" in the "Activity results" "block"
And I should see "75.00%" in the "Activity results" "block"

View File

@ -0,0 +1,29 @@
<?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/>.
/**
* Version information for the block_quiz_results plugin.
*
* @package block_activity_results
* @copyright 2015 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014111000; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014110400; // Requires this Moodle version.
$plugin->component = 'block_activity_results'; // Full name of the plugin (used for diagnostics).

View File

@ -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));
}
}
}

View File

@ -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.'&amp;group=';
} else if (has_capability('moodle/course:viewparticipants', $context)) {
$grouplink = $CFG->wwwroot.'/user/index.php?id='.$courseid.'&amp;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.'&amp;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.'&amp;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.'&amp;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;
}
}

View 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;
}

View File

@ -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);
}
}

View File

@ -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:';

View 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

View File

@ -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;}

View File

@ -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)

View File

@ -967,8 +967,8 @@ class core_plugin_manager {
),
'block' => array(
'activity_modules', 'admin_bookmarks', 'badges', 'blog_menu',
'blog_recent', 'blog_tags', 'calendar_month',
'activity_modules', 'activity_results', 'admin_bookmarks', 'badges',
'blog_menu', 'blog_recent', 'blog_tags', 'calendar_month',
'calendar_upcoming', 'comments', 'community',
'completionstatus', 'course_list', 'course_overview',
'course_summary', 'feedback', 'glossary_random', 'html',