Commit d6383f6a authored by Stephen Bourget's avatar Stephen Bourget
Browse files

MDL-48969 Block: Implement a high scores block

AMOS BEGIN
CPY [bestgrade,block_quiz_results],[bestgrade,block_activity_results]
CPY [bestgrades,block_quiz_results],[bestgrades,block_activity_results]
CPY
[bestgroupgrade,block_quiz_results],[bestgroupgrade,block_activity_resul
ts]
CPY
[bestgroupgrades,block_quiz_results],[bestgroupgrades,block_activity_res
ults]
CPY
[config_format_absolute,block_quiz_results],[config_format_absolute,bloc
k_activity_results]
CPY
[config_format_fraction,block_quiz_results],[config_format_fraction,bloc
k_activity_results]
CPY
[config_format_percentage,block_quiz_results],[config_format_percentage,
block_activity_results]
CPY
[config_grade_format,block_quiz_results],[config_grade_format,block_acti
vity_results]
CPY
[config_name_format,block_quiz_results],[config_name_format,block_activi
ty_results]
CPY
[config_names_anon,block_quiz_results],[config_names_anon,block_activity
_results]
CPY
[config_names_full,block_quiz_results],[config_names_full,block_activity
_results]
CPY
[config_names_id,block_quiz_results],[config_names_id,block_activity_res
ults]
CPY
[config_show_best,block_quiz_results],[config_show_best,block_activity_r
esults]
CPY
[config_show_worst,block_quiz_results],[config_show_worst,block_activity
_results]
CPY
[configuredtoshownothing,block_quiz_results],[configuredtoshownothing,bl
ock_activity_results]
CPY
[config_use_groups,block_quiz_results],[config_use_groups,block_activity
_results]
CPY
[error_nogroupsexist,block_quiz_results],[error_nogroupsexist,block_acti
vity_results]
CPY [worstgrade,block_quiz_results],[worstgrade,block_activity_results]
CPY
[worstgrades,block_quiz_results],[worstgrades,block_activity_results]
CPY
[worstgroupgrade,block_quiz_results],[worstgroupgrade,block_activity_res
ults]
CPY
[worstgroupgrades,block_quiz_results],[worstgroupgrades,block_activity_r
esults]
AMOS END
parent 06122e46
<?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();
}
}
This diff is collapsed.
<?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'
),
);
<?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);
}
}
\ No newline at end of file
<?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:';
.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;}
@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"
\ No newline at end of file
@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"
@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"
@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"