Merge branch 'MDL-77638-master' of https://github.com/ilyatregubov/moodle

This commit is contained in:
Jun Pataleta 2023-07-25 17:56:59 +08:00
commit 8438a7d03b
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
21 changed files with 723 additions and 102 deletions

View File

@ -5,6 +5,6 @@ define("core_grades/gradebooksetup_forms",["exports","core_form/modalform","core
* @module core_grades
* @copyright 2023 Mathew May <mathew.solutions>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_modalform=_interopRequireDefault(_modalform),_notification=_interopRequireDefault(_notification);_exports.init=()=>{document.addEventListener("click",(event=>{if(event.target.closest('[data-trigger="add-item-form"]')){event.preventDefault();const trigger=event.target.closest('[data-trigger="add-item-form"]'),title="-1"===trigger.getAttribute("data-itemid")?(0,_str.get_string)("newitem","core_grades"):(0,_str.get_string)("itemsedit","core_grades"),modalForm=new _modalform.default({modalConfig:{title:title},formClass:"core_grades\\form\\add_item",args:{itemid:trigger.getAttribute("data-itemid"),courseid:trigger.getAttribute("data-courseid"),gpr_plugin:trigger.getAttribute("data-gprplugin")},saveButtonText:(0,_str.get_string)("save","core"),returnFocus:trigger});modalForm.addEventListener(modalForm.events.FORM_SUBMITTED,(event=>{event.detail.result?window.location.assign(event.detail.url):_notification.default.addNotification({type:"error",message:(0,_str.get_string)("saving_failed","core_grades")})})),modalForm.show()}}))}}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_modalform=_interopRequireDefault(_modalform),_notification=_interopRequireDefault(_notification);_exports.init=()=>{document.addEventListener("click",(event=>{const args={};let formClass=null,title=null,trigger=null;if(event.target.closest('[data-trigger="add-item-form"]')?(event.preventDefault(),trigger=event.target.closest('[data-trigger="add-item-form"]'),formClass="core_grades\\form\\add_item",title="-1"===trigger.getAttribute("data-itemid")?(0,_str.get_string)("newitem","core_grades"):(0,_str.get_string)("itemsedit","core_grades"),args.itemid=trigger.getAttribute("data-itemid")):event.target.closest('[data-trigger="add-category-form"]')&&(event.preventDefault(),trigger=event.target.closest('[data-trigger="add-category-form"]'),formClass="core_grades\\form\\add_category",title="-1"===trigger.getAttribute("data-category")?(0,_str.get_string)("newcategory","core_grades"):(0,_str.get_string)("categoryedit","core_grades"),args.category=trigger.getAttribute("data-category")),trigger){args.courseid=trigger.getAttribute("data-courseid"),args.gpr_plugin=trigger.getAttribute("data-gprplugin");const modalForm=new _modalform.default({modalConfig:{title:title},formClass:formClass,args:args,saveButtonText:(0,_str.get_string)("save","core"),returnFocus:trigger});modalForm.addEventListener(modalForm.events.FORM_SUBMITTED,(event=>{event.detail.result?window.location.assign(event.detail.url):_notification.default.addNotification({type:"error",message:(0,_str.get_string)("saving_failed","core_grades")})})),modalForm.show()}}))}}));
//# sourceMappingURL=gradebooksetup_forms.min.js.map

View File

@ -1 +1 @@
{"version":3,"file":"gradebooksetup_forms.min.js","sources":["../src/gradebooksetup_forms.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Prints the add item gradebook form\n *\n * @module core_grades\n * @copyright 2023 Mathew May <mathew.solutions>\n * @license http://www.gnu.org/copyleft/gpl.html GNU Public License\n */\n\nimport ModalForm from 'core_form/modalform';\nimport {get_string as getString} from 'core/str';\nimport Notification from 'core/notification';\n\n/**\n * Initialize module\n */\nexport const init = () => {\n // Sometimes the trigger does not exist, so lets conditionally add it.\n document.addEventListener('click', event => {\n if (event.target.closest('[data-trigger=\"add-item-form\"]')) {\n event.preventDefault();\n const trigger = event.target.closest('[data-trigger=\"add-item-form\"]');\n // If we are adding or editing a grade item change the Modal header.\n const title = trigger.getAttribute('data-itemid') === '-1' ?\n getString('newitem', 'core_grades') : getString('itemsedit', 'core_grades');\n const modalForm = new ModalForm({\n modalConfig: {\n title: title,\n },\n formClass: 'core_grades\\\\form\\\\add_item',\n args: {\n itemid: trigger.getAttribute('data-itemid'),\n courseid: trigger.getAttribute('data-courseid'),\n gpr_plugin: trigger.getAttribute('data-gprplugin'),\n },\n saveButtonText: getString('save', 'core'),\n returnFocus: trigger,\n });\n\n // Show a toast notification when the form is submitted.\n modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {\n if (event.detail.result) {\n window.location.assign(event.detail.url);\n } else {\n Notification.addNotification({\n type: 'error',\n message: getString('saving_failed', 'core_grades')\n });\n }\n });\n\n modalForm.show();\n }\n });\n};\n"],"names":["document","addEventListener","event","target","closest","preventDefault","trigger","title","getAttribute","modalForm","ModalForm","modalConfig","formClass","args","itemid","courseid","gpr_plugin","saveButtonText","returnFocus","events","FORM_SUBMITTED","detail","result","window","location","assign","url","addNotification","type","message","show"],"mappings":";;;;;;;kMA8BoB,KAEhBA,SAASC,iBAAiB,SAASC,WAC3BA,MAAMC,OAAOC,QAAQ,kCAAmC,CACxDF,MAAMG,uBACAC,QAAUJ,MAAMC,OAAOC,QAAQ,kCAE/BG,MAAgD,OAAxCD,QAAQE,aAAa,gBAC/B,mBAAU,UAAW,gBAAiB,mBAAU,YAAa,eAC3DC,UAAY,IAAIC,mBAAU,CAC5BC,YAAa,CACTJ,MAAOA,OAEXK,UAAW,8BACXC,KAAM,CACFC,OAAQR,QAAQE,aAAa,eAC7BO,SAAUT,QAAQE,aAAa,iBAC/BQ,WAAYV,QAAQE,aAAa,mBAErCS,gBAAgB,mBAAU,OAAQ,QAClCC,YAAaZ,UAIjBG,UAAUR,iBAAiBQ,UAAUU,OAAOC,gBAAgBlB,QACpDA,MAAMmB,OAAOC,OACbC,OAAOC,SAASC,OAAOvB,MAAMmB,OAAOK,2BAEvBC,gBAAgB,CACzBC,KAAM,QACNC,SAAU,mBAAU,gBAAiB,oBAKjDpB,UAAUqB"}
{"version":3,"file":"gradebooksetup_forms.min.js","sources":["../src/gradebooksetup_forms.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Prints the add item gradebook form\n *\n * @module core_grades\n * @copyright 2023 Mathew May <mathew.solutions>\n * @license http://www.gnu.org/copyleft/gpl.html GNU Public License\n */\n\nimport ModalForm from 'core_form/modalform';\nimport {get_string as getString} from 'core/str';\nimport Notification from 'core/notification';\n\n/**\n * Initialize module\n */\nexport const init = () => {\n // Sometimes the trigger does not exist, so lets conditionally add it.\n document.addEventListener('click', event => {\n const args = {};\n\n let formClass = null;\n let title = null;\n let trigger = null;\n if (event.target.closest('[data-trigger=\"add-item-form\"]')) {\n event.preventDefault();\n trigger = event.target.closest('[data-trigger=\"add-item-form\"]');\n formClass = 'core_grades\\\\form\\\\add_item';\n title = trigger.getAttribute('data-itemid') === '-1' ?\n getString('newitem', 'core_grades') : getString('itemsedit', 'core_grades');\n args.itemid = trigger.getAttribute('data-itemid');\n } else if (event.target.closest('[data-trigger=\"add-category-form\"]')) {\n event.preventDefault();\n trigger = event.target.closest('[data-trigger=\"add-category-form\"]');\n formClass = 'core_grades\\\\form\\\\add_category';\n title = trigger.getAttribute('data-category') === '-1' ?\n getString('newcategory', 'core_grades') : getString('categoryedit', 'core_grades');\n args.category = trigger.getAttribute('data-category');\n }\n\n if (trigger) {\n args.courseid = trigger.getAttribute('data-courseid');\n args.gpr_plugin = trigger.getAttribute('data-gprplugin');\n\n const modalForm = new ModalForm({\n modalConfig: {\n title: title,\n },\n formClass: formClass,\n args: args,\n saveButtonText: getString('save', 'core'),\n returnFocus: trigger,\n });\n\n // Show a toast notification when the form is submitted.\n modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {\n if (event.detail.result) {\n window.location.assign(event.detail.url);\n } else {\n Notification.addNotification({\n type: 'error',\n message: getString('saving_failed', 'core_grades')\n });\n }\n });\n\n modalForm.show();\n }\n\n });\n};\n"],"names":["document","addEventListener","event","args","formClass","title","trigger","target","closest","preventDefault","getAttribute","itemid","category","courseid","gpr_plugin","modalForm","ModalForm","modalConfig","saveButtonText","returnFocus","events","FORM_SUBMITTED","detail","result","window","location","assign","url","addNotification","type","message","show"],"mappings":";;;;;;;kMA8BoB,KAEhBA,SAASC,iBAAiB,SAASC,cACzBC,KAAO,OAETC,UAAY,KACZC,MAAQ,KACRC,QAAU,QACVJ,MAAMK,OAAOC,QAAQ,mCACrBN,MAAMO,iBACNH,QAAUJ,MAAMK,OAAOC,QAAQ,kCAC/BJ,UAAY,8BACZC,MAAgD,OAAxCC,QAAQI,aAAa,gBACzB,mBAAU,UAAW,gBAAiB,mBAAU,YAAa,eACjEP,KAAKQ,OAASL,QAAQI,aAAa,gBAC5BR,MAAMK,OAAOC,QAAQ,wCAC5BN,MAAMO,iBACNH,QAAUJ,MAAMK,OAAOC,QAAQ,sCAC/BJ,UAAY,kCACZC,MAAkD,OAA1CC,QAAQI,aAAa,kBACzB,mBAAU,cAAe,gBAAiB,mBAAU,eAAgB,eACxEP,KAAKS,SAAWN,QAAQI,aAAa,kBAGrCJ,QAAS,CACTH,KAAKU,SAAWP,QAAQI,aAAa,iBACrCP,KAAKW,WAAaR,QAAQI,aAAa,wBAEjCK,UAAY,IAAIC,mBAAU,CAC5BC,YAAa,CACTZ,MAAOA,OAEXD,UAAWA,UACXD,KAAMA,KACNe,gBAAgB,mBAAU,OAAQ,QAClCC,YAAab,UAIjBS,UAAUd,iBAAiBc,UAAUK,OAAOC,gBAAgBnB,QACpDA,MAAMoB,OAAOC,OACbC,OAAOC,SAASC,OAAOxB,MAAMoB,OAAOK,2BAEvBC,gBAAgB,CACzBC,KAAM,QACNC,SAAS,mBAAU,gBAAiB,oBAKhDf,UAAUgB"}

View File

@ -31,22 +31,37 @@ import Notification from 'core/notification';
export const init = () => {
// Sometimes the trigger does not exist, so lets conditionally add it.
document.addEventListener('click', event => {
const args = {};
let formClass = null;
let title = null;
let trigger = null;
if (event.target.closest('[data-trigger="add-item-form"]')) {
event.preventDefault();
const trigger = event.target.closest('[data-trigger="add-item-form"]');
// If we are adding or editing a grade item change the Modal header.
const title = trigger.getAttribute('data-itemid') === '-1' ?
trigger = event.target.closest('[data-trigger="add-item-form"]');
formClass = 'core_grades\\form\\add_item';
title = trigger.getAttribute('data-itemid') === '-1' ?
getString('newitem', 'core_grades') : getString('itemsedit', 'core_grades');
args.itemid = trigger.getAttribute('data-itemid');
} else if (event.target.closest('[data-trigger="add-category-form"]')) {
event.preventDefault();
trigger = event.target.closest('[data-trigger="add-category-form"]');
formClass = 'core_grades\\form\\add_category';
title = trigger.getAttribute('data-category') === '-1' ?
getString('newcategory', 'core_grades') : getString('categoryedit', 'core_grades');
args.category = trigger.getAttribute('data-category');
}
if (trigger) {
args.courseid = trigger.getAttribute('data-courseid');
args.gpr_plugin = trigger.getAttribute('data-gprplugin');
const modalForm = new ModalForm({
modalConfig: {
title: title,
},
formClass: 'core_grades\\form\\add_item',
args: {
itemid: trigger.getAttribute('data-itemid'),
courseid: trigger.getAttribute('data-courseid'),
gpr_plugin: trigger.getAttribute('data-gprplugin'),
},
formClass: formClass,
args: args,
saveButtonText: getString('save', 'core'),
returnFocus: trigger,
});
@ -58,12 +73,13 @@ export const init = () => {
} else {
Notification.addNotification({
type: 'error',
message: getString('saving_failed', 'core_grades')
message: getString('saving_failed', 'core_grades')
});
}
});
modalForm.show();
}
});
};

View File

@ -0,0 +1,571 @@
<?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/>.
namespace core_grades\form;
use context;
use context_course;
use core_form\dynamic_form;
use grade_category;
use grade_edit_tree;
use grade_helper;
use grade_item;
use grade_plugin_return;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/grade/lib.php');
require_once($CFG->dirroot . '/grade/edit/tree/lib.php');
/**
* Prints the add category gradebook form
*
* @copyright 2023 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package core_grades
*/
class add_category extends dynamic_form {
/** Grade plugin return tracking object.
* @var object $gpr
*/
public $gpr;
/** Available aggregations.
* @var array|null $aggregation_options
*/
private ?array $aggregation_options;
/**
* Helper function to grab the current grade category based on information within the form.
*
* @return array
* @throws \moodle_exception
*/
private function get_gradecategory(): array {
$courseid = $this->optional_param('courseid', null, PARAM_INT);
$id = $this->optional_param('category', null, PARAM_INT);
if (!isset($id) || $id !== -1) {
if (!$gradecategory = grade_category::fetch(['id' => $id, 'courseid' => $courseid])) {
throw new \moodle_exception('invalidcategory');
}
$gradecategory->apply_forced_settings();
$category = $gradecategory->get_record_data();
// Set parent.
$category->parentcategory = $gradecategory->parent;
$gradeitem = $gradecategory->load_grade_item();
// Normalize coef values if needed.
$parentcategory = $gradecategory->get_parent_category();
foreach ($gradeitem->get_record_data() as $key => $value) {
$category->{"grade_item_$key"} = $value;
}
$decimalpoints = $gradeitem->get_decimals();
$category->grade_item_grademax = format_float($category->grade_item_grademax, $decimalpoints);
$category->grade_item_grademin = format_float($category->grade_item_grademin, $decimalpoints);
$category->grade_item_gradepass = format_float($category->grade_item_gradepass, $decimalpoints);
$category->grade_item_multfactor = format_float($category->grade_item_multfactor, 4);
$category->grade_item_plusfactor = format_float($category->grade_item_plusfactor, 4);
$category->grade_item_aggregationcoef2 = format_float($category->grade_item_aggregationcoef2 * 100.0, 4);
if (isset($parentcategory)) {
if ($parentcategory->aggregation == GRADE_AGGREGATE_SUM ||
$parentcategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
$category->grade_item_aggregationcoef = $category->grade_item_aggregationcoef == 0 ? 0 : 1;
} else {
$category->grade_item_aggregationcoef = format_float($category->grade_item_aggregationcoef, 4);
}
}
// Check if the gradebook is frozen. This allows grades not be altered at all until a user verifies that they
// wish to update the grades.
$gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $courseid);
// Stick with the original code if the grade book is frozen.
if ($gradebookcalculationsfreeze && (int)$gradebookcalculationsfreeze <= 20150627) {
if ($category->aggregation == GRADE_AGGREGATE_SUM) {
// Input fields for grademin and grademax are disabled for the "Natural" category,
// this means they will be ignored if user does not change aggregation method.
// But if user does change aggregation method the default values should be used.
$category->grademax = 100;
$category->grade_item_grademax = 100;
$category->grademin = 0;
$category->grade_item_grademin = 0;
}
} else {
if ($category->aggregation == GRADE_AGGREGATE_SUM && !$gradeitem->is_calculated()) {
// Input fields for grademin and grademax are disabled for the "Natural" category,
// this means they will be ignored if user does not change aggregation method.
// But if user does change aggregation method the default values should be used.
// This does not apply to calculated category totals.
$category->grademax = 100;
$category->grade_item_grademax = 100;
$category->grademin = 0;
$category->grade_item_grademin = 0;
}
}
} else {
$gradecategory = new grade_category(['courseid' => $courseid], false);
$gradecategory->apply_default_settings();
$gradecategory->apply_forced_settings();
$category = $gradecategory->get_record_data();
$gradeitem = new grade_item(['courseid' => $courseid, 'itemtype' => 'manual'], false);
foreach ($gradeitem->get_record_data() as $key => $value) {
$category->{"grade_item_$key"} = $value;
}
}
return [
'gradecategory' => $gradecategory,
'categoryitem' => $category
];
}
/**
* Form definition
*
* @return void
* @throws \coding_exception
* @throws \dml_exception
* @throws \moodle_exception
*/
protected function definition(): void {
global $CFG;
$courseid = $this->optional_param('courseid', null, PARAM_INT);
$id = $this->optional_param('category', 0, PARAM_INT);
$gprplugin = $this->optional_param('gpr_plugin', '', PARAM_TEXT);
if ($gprplugin && ($gprplugin !== 'tree')) {
$this->gpr = new grade_plugin_return(['type' => 'report', 'plugin' => $gprplugin, 'courseid' => $courseid]);
} else {
$this->gpr = new grade_plugin_return(['type' => 'edit', 'plugin' => 'tree', 'courseid' => $courseid]);
}
$mform = $this->_form;
$this->aggregation_options = grade_helper::get_aggregation_strings();
$local = $this->get_gradecategory();
$category = $local['categoryitem'];
// Hidden elements.
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'courseid', $courseid);
$mform->setType('courseid', PARAM_INT);
$mform->addElement('hidden', 'category', $id);
$mform->setType('category', PARAM_INT);
// Visible elements.
$mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
$mform->setType('fullname', PARAM_TEXT);
$mform->addRule('fullname', null, 'required', null, 'client');
$mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_options);
$mform->addHelpButton('aggregation', 'aggregation', 'grades');
$mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
$mform->addHelpButton('aggregateonlygraded', 'aggregateonlygraded', 'grades');
$mform->addElement('float', 'grade_item_grademax', get_string('grademax', 'grades'));
$mform->addHelpButton('grade_item_grademax', 'grademax', 'grades');
$mform->hideIf('grade_item_grademax', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE);
$mform->hideIf('grade_item_grademax', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
if ((bool) get_config('moodle', 'grade_report_showmin')) {
$mform->addElement('float', 'grade_item_grademin', get_string('grademin', 'grades'));
$mform->addHelpButton('grade_item_grademin', 'grademin', 'grades');
$mform->hideIf('grade_item_grademin', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE);
$mform->hideIf('grade_item_grademin', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
}
if (empty($CFG->enableoutcomes)) {
$mform->addElement('hidden', 'aggregateoutcomes');
$mform->setType('aggregateoutcomes', PARAM_INT);
} else {
$mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
$mform->addHelpButton('aggregateoutcomes', 'aggregateoutcomes', 'grades');
}
$mform->addElement('text', 'keephigh', get_string('keephigh', 'grades'), 'size="3"');
$mform->setType('keephigh', PARAM_INT);
$mform->addHelpButton('keephigh', 'keephigh', 'grades');
$mform->addElement('text', 'droplow', get_string('droplow', 'grades'), 'size="3"');
$mform->setType('droplow', PARAM_INT);
$mform->addHelpButton('droplow', 'droplow', 'grades');
$mform->hideIf('droplow', 'keephigh', 'noteq', 0);
$mform->hideIf('keephigh', 'droplow', 'noteq', 0);
$mform->hideIf('droplow', 'keephigh', 'noteq', 0);
// Hiding.
// advcheckbox is not compatible with disabledIf!
$mform->addElement('checkbox', 'grade_item_hidden', get_string('hidden', 'grades'));
$mform->addHelpButton('grade_item_hidden', 'hidden', 'grades');
// Locking.
$mform->addElement('checkbox', 'grade_item_locked', get_string('locked', 'grades'));
$mform->addHelpButton('grade_item_locked', 'locked', 'grades');
$mform->addElement('advcheckbox', 'grade_item_weightoverride', get_string('adjustedweight', 'grades'));
$mform->addHelpButton('grade_item_weightoverride', 'weightoverride', 'grades');
$mform->addElement('float', 'grade_item_aggregationcoef2', get_string('weight', 'grades'));
$mform->addHelpButton('grade_item_aggregationcoef2', 'weight', 'grades');
$mform->hideIf('grade_item_aggregationcoef2', 'grade_item_weightoverride');
$options = [];
$default = -1;
$categories = grade_category::fetch_all(['courseid' => $courseid]);
foreach ($categories as $cat) {
$cat->apply_forced_settings();
$options[$cat->id] = $cat->get_name();
if ($cat->is_course_category()) {
$default = $cat->id;
}
}
if (count($categories) > 1) {
$mform->addElement('select', 'parentcategory', get_string('parentcategory', 'grades'), $options);
$mform->setDefault('parentcategory', $default);
}
$params = ['courseid' => $courseid];
if ($id > 0) {
$params['id'] = $id;
}
$url = new moodle_url('/grade/edit/tree/category.php', $params);
$url = $this->gpr->add_url_params($url);
$url = '<a href="' . $url . '">' . get_string('showmore', 'form') .'</a>';
$mform->addElement('static', 'test', $url);
// Add return tracking info.
$this->gpr->add_mform_elements($mform);
$this->set_data($category);
}
/**
* This method implements changes to the form that need to be made once the form data is set.
*/
public function definition_after_data(): void {
global $CFG;
$mform =& $this->_form;
$categoryobject = new grade_category();
foreach ($categoryobject->forceable as $property) {
if ((int)$CFG->{"grade_{$property}_flag"} & 1) {
if ($mform->elementExists($property)) {
if (empty($CFG->grade_hideforcedsettings)) {
$mform->hardFreeze($property);
} else {
if ($mform->elementExists($property)) {
$mform->removeElement($property);
}
}
}
}
}
if ($CFG->grade_droplow > 0) {
if ($mform->elementExists('keephigh')) {
$mform->removeElement('keephigh');
}
} else if ($CFG->grade_keephigh > 0) {
if ($mform->elementExists('droplow')) {
$mform->removeElement('droplow');
}
}
if ($id = $mform->getElementValue('id')) {
$gradecategory = grade_category::fetch(['id' => $id]);
$gradeitem = $gradecategory->load_grade_item();
// Remove agg coef if not used.
if ($gradecategory->is_course_category()) {
if ($mform->elementExists('parentcategory')) {
$mform->removeElement('parentcategory');
}
} else {
// If we wanted to change parent of existing category
// we would have to verify there are no circular references in parents!!!
if ($mform->elementExists('parentcategory')) {
$mform->hardFreeze('parentcategory');
}
}
// Prevent the user from using drop lowest/keep highest when the aggregation method cannot handle it.
if (!$gradecategory->can_apply_limit_rules()) {
if ($mform->elementExists('keephigh')) {
$mform->setConstant('keephigh', 0);
$mform->hardFreeze('keephigh');
}
if ($mform->elementExists('droplow')) {
$mform->setConstant('droplow', 0);
$mform->hardFreeze('droplow');
}
}
if ($gradeitem->is_calculated()) {
$gradesexistmsg = get_string('calculationwarning', 'grades');
$gradesexisthtml = '<div class=\'alert alert-warning\'>' . $gradesexistmsg . '</div>';
$mform->addElement('static', 'gradesexistmsg', '', $gradesexisthtml);
// Following elements are ignored when calculation formula used.
if ($mform->elementExists('aggregation')) {
$mform->removeElement('aggregation');
}
if ($mform->elementExists('keephigh')) {
$mform->removeElement('keephigh');
}
if ($mform->elementExists('droplow')) {
$mform->removeElement('droplow');
}
if ($mform->elementExists('aggregateonlygraded')) {
$mform->removeElement('aggregateonlygraded');
}
if ($mform->elementExists('aggregateoutcomes')) {
$mform->removeElement('aggregateoutcomes');
}
}
// If it is a course category, remove the "required" rule from the "fullname" element.
if ($gradecategory->is_course_category()) {
unset($mform->_rules['fullname']);
$key = array_search('fullname', $mform->_required);
unset($mform->_required[$key]);
}
// If it is a course category and its fullname is ?, show an empty field.
if ($gradecategory->is_course_category() && $mform->getElementValue('fullname') == '?') {
$mform->setDefault('fullname', '');
}
// Remove unwanted aggregation options.
if ($mform->elementExists('aggregation')) {
$allaggoptions = array_keys($this->aggregation_options);
$aggel =& $mform->getElement('aggregation');
$visible = explode(',', $CFG->grade_aggregations_visible);
if (!is_null($gradecategory->aggregation)) {
// Current type is always visible.
$visible[] = $gradecategory->aggregation;
}
foreach ($allaggoptions as $type) {
if (!in_array($type, $visible)) {
$aggel->removeOption($type);
}
}
}
} else {
// Remove unwanted aggregation options.
if ($mform->elementExists('aggregation')) {
$allaggoptions = array_keys($this->aggregation_options);
$aggel =& $mform->getElement('aggregation');
$visible = explode(',', $CFG->grade_aggregations_visible);
foreach ($allaggoptions as $type) {
if (!in_array($type, $visible)) {
$aggel->removeOption($type);
}
}
}
}
// Grade item.
if ($id = $mform->getElementValue('id')) {
$gradecategory = grade_category::fetch(['id' => $id]);
$gradeitem = $gradecategory->load_grade_item();
// Load appropriate "hidden"/"hidden until" defaults.
if (!$gradeitem->is_hiddenuntil()) {
$mform->setDefault('grade_item_hidden', $gradeitem->get_hidden());
}
// Remove the aggregation coef element if not needed.
if ($gradeitem->is_course_item()) {
if ($mform->elementExists('grade_item_aggregationcoef')) {
$mform->removeElement('grade_item_aggregationcoef');
}
} else {
if ($gradeitem->is_category_item()) {
$category = $gradeitem->get_item_category();
$parentcategory = $category->get_parent_category();
} else {
$parentcategory = $gradeitem->get_parent_category();
}
$parentcategory->apply_forced_settings();
if (!$parentcategory->is_aggregationcoef_used()) {
if ($mform->elementExists('grade_item_aggregationcoef')) {
$mform->removeElement('grade_item_aggregationcoef');
}
} else {
$coefstring = $gradeitem->get_coefstring();
if ($coefstring == 'aggregationcoefextrasum' || $coefstring == 'aggregationcoefextraweightsum') {
// Advcheckbox is not compatible with disabledIf!
$coefstring = 'aggregationcoefextrasum';
$element =& $mform->createElement('checkbox', 'grade_item_aggregationcoef',
get_string($coefstring, 'grades'));
} else {
$element =& $mform->createElement('text', 'grade_item_aggregationcoef',
get_string($coefstring, 'grades'));
}
$mform->insertElementBefore($element, 'parentcategory');
$mform->addHelpButton('grade_item_aggregationcoef', $coefstring, 'grades');
}
}
}
}
/**
* Return form context
*
* @return context
*/
protected function get_context_for_dynamic_submission(): context {
$courseid = $this->optional_param('courseid', null, PARAM_INT);
return context_course::instance($courseid);
}
/**
* Check if current user has access to this form, otherwise throw exception
*
* @return void
* @throws \required_capability_exception
*/
protected function check_access_for_dynamic_submission(): void {
$courseid = $this->optional_param('courseid', null, PARAM_INT);
require_capability('moodle/grade:manage', context_course::instance($courseid));
}
/**
* Load in existing data as form defaults
*
* @return void
*/
public function set_data_for_dynamic_submission(): void {
$this->set_data((object)[
'courseid' => $this->optional_param('courseid', null, PARAM_INT),
'category' => $this->optional_param('category', null, PARAM_INT)
]);
}
/**
* Returns url to set in $PAGE->set_url() when form is being rendered or submitted via AJAX
*
* @return moodle_url
* @throws \moodle_exception
*/
protected function get_page_url_for_dynamic_submission(): moodle_url {
$params = [
'id' => $this->optional_param('courseid', null, PARAM_INT),
'category' => $this->optional_param('category', null, PARAM_INT),
];
return new moodle_url('/grade/edit/tree/index.php', $params);
}
/**
* Process the form submission, used if form was submitted via AJAX
*
* @return array
* @throws \moodle_exception
*/
public function process_dynamic_submission(): array {
$data = $this->get_data();
$url = $this->gpr->get_return_url('index.php?id=' . $data->courseid);
$local = $this->get_gradecategory();
$gradecategory = $local['gradecategory'];
// GRADE ITEM.
// Grade item data saved with prefix "grade_item_".
$data->grade_item_gradepass = $local['categoryitem']->grade_item_gradepass;
$data->grade_item_grademax = $local['categoryitem']->grade_item_grademax;
$data->grade_item_grademin = $local['categoryitem']->grade_item_grademin;
grade_edit_tree::update_gradecategory($gradecategory, $data);
return [
'result' => true,
'url' => $url,
'errors' => [],
];
}
/**
* Form validation.
*
* @param array $data array of ("fieldname"=>value) of submitted data
* @param array $files array of uploaded files "element_name"=>tmp_file_path
* @return array of "element_name"=>"error_description" if there are errors,
* or an empty array if everything is OK (true allowed for backwards compatibility too).
*/
public function validation($data, $files): array {
$gradeitem = false;
if ($data['id']) {
$gradecategory = grade_category::fetch(['id' => $data['id']]);
$gradeitem = $gradecategory->load_grade_item();
}
$errors = parent::validation($data, $files);
if (array_key_exists('grade_item_gradetype', $data) && $data['grade_item_gradetype'] == GRADE_TYPE_SCALE) {
if (empty($data['grade_item_scaleid'])) {
$errors['grade_item_scaleid'] = get_string('missingscale', 'grades');
}
}
// We need to make all the validations related with grademax and grademin
// with them being correct floats, keeping the originals unmodified for
// later validations / showing the form back...
// TODO: Note that once MDL-73994 is fixed we'll have to re-visit this and
// adapt the code below to the new values arriving here, without forgetting
// the special case of empties and nulls.
$grademax = isset($data['grade_item_grademax']) ? unformat_float($data['grade_item_grademax']) : null;
$grademin = isset($data['grade_item_grademin']) ? unformat_float($data['grade_item_grademin']) : null;
if (!is_null($grademin) && !is_null($grademax)) {
if (($grademax != 0 || $grademin != 0) && ($grademax == $grademin || $grademax < $grademin)) {
$errors['grade_item_grademin'] = get_string('incorrectminmax', 'grades');
$errors['grade_item_grademax'] = get_string('incorrectminmax', 'grades');
}
}
if ($data['id'] && $gradeitem->has_overridden_grades()) {
if ($gradeitem->gradetype == GRADE_TYPE_VALUE) {
if (grade_floats_different($grademin, $gradeitem->grademin) ||
grade_floats_different($grademax, $gradeitem->grademax)) {
if (empty($data['grade_item_rescalegrades'])) {
$errors['grade_item_rescalegrades'] = get_string('mustchooserescaleyesorno', 'grades');
}
}
}
}
return $errors;
}
}

View File

@ -59,12 +59,6 @@ class add_item extends dynamic_form {
$url = new moodle_url('/grade/edit/tree/outcomeitem.php', ['id' => $id, 'courseid' => $courseid]);
redirect($this->gpr->add_url_params($url));
}
if ($gradeitem->is_course_item() || $gradeitem->is_category_item()) {
$gradecategory = $gradeitem->get_item_category();
$url = new moodle_url('/grade/edit/tree/category.php', ['id' => $gradecategory->id, 'courseid' => $courseid]);
redirect($this->gpr->add_url_params($url));
}
$item = $gradeitem->get_record_data();
$parentcategory = $gradeitem->get_parent_category();

View File

@ -81,10 +81,20 @@ class gradebook_setup_action_bar extends action_bar {
}
// Add a button to the action bar with a link to the 'add category' page.
$addcategorylink = new moodle_url('/grade/edit/tree/category.php', ['courseid' => $courseid]);
$addcategorybutton = new \single_button($addcategorylink, get_string('addcategory', 'grades'), 'get');
$data['addcategorybutton'] = $addcategorybutton->export_for_template($output);
$addgradecategorybutton = new \single_button(
$addgradeitemlink,
get_string('addcategory', 'grades'),
'get',
\single_button::BUTTON_SECONDARY,
[
'class' => 'btn btn-secondary',
'data-courseid' => $courseid,
'data-category' => -1,
'data-trigger' => 'add-category-form',
'data-gprplugin' => 'tree'
]
);
$data['addcategorybutton'] = $addgradecategorybutton->export_for_template($output);
return $data;
}
}

View File

@ -48,42 +48,25 @@ class edit_category_form extends moodleform {
$mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_options);
$mform->addHelpButton('aggregation', 'aggregation', 'grades');
if ((int)$CFG->grade_aggregation_flag & 2) {
$mform->setAdvanced('aggregation');
}
$mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
$mform->addHelpButton('aggregateonlygraded', 'aggregateonlygraded', 'grades');
if ((int)$CFG->grade_aggregateonlygraded_flag & 2) {
$mform->setAdvanced('aggregateonlygraded');
}
if (empty($CFG->enableoutcomes)) {
$mform->addElement('hidden', 'aggregateoutcomes');
$mform->setType('aggregateoutcomes', PARAM_INT);
} else {
$mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
$mform->addHelpButton('aggregateoutcomes', 'aggregateoutcomes', 'grades');
if ((int)$CFG->grade_aggregateoutcomes_flag & 2) {
$mform->setAdvanced('aggregateoutcomes');
}
}
$mform->addElement('text', 'keephigh', get_string('keephigh', 'grades'), 'size="3"');
$mform->setType('keephigh', PARAM_INT);
$mform->addHelpButton('keephigh', 'keephigh', 'grades');
if ((int)$CFG->grade_keephigh_flag & 2) {
$mform->setAdvanced('keephigh');
}
$mform->addElement('text', 'droplow', get_string('droplow', 'grades'), 'size="3"');
$mform->setType('droplow', PARAM_INT);
$mform->addHelpButton('droplow', 'droplow', 'grades');
$mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
if ((int)$CFG->grade_droplow_flag & 2) {
$mform->setAdvanced('droplow');
}
$mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
$mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
@ -91,10 +74,10 @@ class edit_category_form extends moodleform {
// Grade item settings
// Displayed as Category total to avoid confusion between grade items requiring marking and category totals
$mform->addElement('header', 'general', get_string('categorytotal', 'grades'));
$mform->setExpanded('general');
$mform->addElement('text', 'grade_item_itemname', get_string('categorytotalname', 'grades'));
$mform->setType('grade_item_itemname', PARAM_TEXT);
$mform->setAdvanced('grade_item_itemname');
$mform->addElement('text', 'grade_item_iteminfo', get_string('iteminfo', 'grades'));
$mform->addHelpButton('grade_item_iteminfo', 'iteminfo', 'grades');
@ -240,6 +223,7 @@ class edit_category_form extends moodleform {
/// parent category related settings
$mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
$mform->setExpanded('headerparent');
$mform->addElement('advcheckbox', 'grade_item_weightoverride', get_string('adjustedweight', 'grades'));
$mform->addHelpButton('grade_item_weightoverride', 'weightoverride', 'grades');
@ -277,17 +261,6 @@ class edit_category_form extends moodleform {
$gpr = $this->_customdata['gpr'];
$gpr->add_mform_elements($mform);
/// mark advanced according to site settings
if (isset($CFG->grade_item_advanced)) {
$advanced = explode(',', $CFG->grade_item_advanced);
foreach ($advanced as $el) {
$el = 'grade_item_'.$el;
if ($mform->elementExists($el)) {
$mform->setAdvanced($el);
}
}
}
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
@ -296,7 +269,6 @@ class edit_category_form extends moodleform {
}
/// tweak the form - depending on existing data
function definition_after_data() {
global $CFG, $COURSE;
@ -534,7 +506,6 @@ class edit_category_form extends moodleform {
}
}
/// perform extra validation before submission
function validation($data, $files) {
global $COURSE;
$gradeitem = false;

View File

@ -1062,29 +1062,33 @@ class grade_edit_tree_column_status extends grade_edit_tree_column {
$element['object'] = $category;
$categorycell->text = $gtree->set_grade_status_icons($element);
// Aggregation type.
$aggrstrings = grade_helper::get_aggregation_strings();
$context = new stdClass();
$context->aggregation = $aggrstrings[$category->aggregation];
if ($category->grade_item->is_calculated()) {
$context->calculatedgrade = grade_helper::get_lang_string('calculatedgrade', 'grades');
} else {
// Aggregation type.
$aggrstrings = grade_helper::get_aggregation_strings();
$context->aggregation = $aggrstrings[$category->aggregation];
// Include/exclude empty grades.
if ($category->aggregateonlygraded) {
$context->aggregateonlygraded = $category->aggregateonlygraded;
}
// Include/exclude empty grades.
if ($category->aggregateonlygraded) {
$context->aggregateonlygraded = $category->aggregateonlygraded;
}
// Aggregate outcomes.
if ($category->aggregateoutcomes) {
$context->aggregateoutcomes = $category->aggregateoutcomes;
}
// Aggregate outcomes.
if ($category->aggregateoutcomes) {
$context->aggregateoutcomes = $category->aggregateoutcomes;
}
// Drop the lowest.
if ($category->droplow) {
$context->droplow = $category->droplow;
}
// Drop the lowest.
if ($category->droplow) {
$context->droplow = $category->droplow;
}
// Keep the highest.
if ($category->keephigh) {
$context->keephigh = $category->keephigh;
// Keep the highest.
if ($category->keephigh) {
$context->keephigh = $category->keephigh;
}
}
$categorycell->text .= $OUTPUT->render_from_template('core_grades/category_settings', $context);
return $categorycell;

View File

@ -2101,10 +2101,17 @@ class grade_structure {
$url = $gpr->add_url_params($url);
$title = grade_helper::get_lang_string('itemsedit', 'grades');
} else if ($element['type'] == 'category') {
$url = new moodle_url('/grade/edit/tree/category.php',
['courseid' => $this->courseid, 'id' => $object->id]);
$url = $gpr->add_url_params($url);
$url = new moodle_url('#');
$title = grade_helper::get_lang_string('categoryedit', 'grades');
return html_writer::link($url, $title, [
'class' => 'dropdown-item',
'aria-label' => $title,
'role' => 'menuitem',
'data-gprplugin' => $gpr->plugin,
'data-courseid' => $this->courseid,
'data-category' => $object->id,
'data-trigger' => 'add-category-form'
]);
}
return html_writer::link($url, $title,
['class' => 'dropdown-item', 'aria-label' => $title, 'role' => 'menuitem']);

View File

@ -24,10 +24,16 @@
"aggregateonlygraded": 1,
"aggregateoutcomes": 0,
"droplow": 1,
"keephigh": 1
"keephigh": 1,
"calculatedgrade": "calculated grade"
}
}}
<div class="card-deck" role="list">
{{#calculatedgrade}}
<span class="badge badge-pill badge-light" role="listitem">
<strong>{{calculatedgrade}}</strong>
</span>
{{/calculatedgrade}}
{{#aggregation}}
<span class="badge badge-pill badge-light" role="listitem">
<strong>{{aggregation}}</strong>

View File

@ -63,15 +63,15 @@ class behat_grade extends behat_base {
$this->execute("behat_grades::i_click_on_grade_item_menu", [$gradeitem, $type, $page]);
}
if ($type == 'gradeitem') {
$linktext = get_string('itemsedit', 'grades');
} else if ($type == 'category') {
$linktext = get_string('categoryedit', 'grades');
} else {
$linktext = get_string('categoryedit', 'grades');
}
$linktext = $type == 'gradeitem' ? get_string('itemsedit', 'grades') : get_string('categoryedit', 'grades');
$this->execute("behat_action_menu::i_choose_in_the_open_action_menu", $linktext);
if ($type !== 'gradeitem') {
$this->execute('behat_general::i_click_on_in_the', [get_string('showmore', 'form'),
'link', '.modal-dialog', 'css_element']);
}
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
if ($this->getSession()->getPage()->find('xpath', './/button[@data-action="save"]')) {
$container = $this->get_selected_node("core_grades > gradeitem modal", "form");

View File

@ -398,7 +398,8 @@ Feature: We can use calculated grade totals
| Category name | Sub category 3 |
| Aggregation | Natural |
| Drop the lowest | 1 |
And I press "Save changes"
And I click on "Save" "button" in the "New category" "dialogue"
And I wait until the page is ready
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Manual item 1 |
@ -457,7 +458,8 @@ Feature: We can use calculated grade totals
And I set the following fields to these values:
| Category name | Sub sub category 1 |
| Parent category | Sub category 3 |
And I press "Save changes"
And I click on "Save" "button" in the "New category" "dialogue"
And I wait until the page is ready
And I navigate to "View > Grader report" in the course gradebook
And I should see "270.00 (24.77 %)" in the ".course" "css_element"

View File

@ -39,6 +39,7 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I turn editing mode on
And I click on grade item menu "Cat mean" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I set the following fields to these values:
| Weight adjusted | 1 |
| Weight | 20 |
@ -46,6 +47,7 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I press "Save changes"
And I click on grade item menu "Cat median" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I set the following fields to these values:
| Weight adjusted | 1 |
| Weight | 5 |
@ -53,6 +55,7 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I press "Save changes"
And I click on grade item menu "Cat min" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I set the following fields to these values:
| Weight adjusted | 0 |
| Weight | 0 |
@ -107,7 +110,7 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
Given I click on grade item menu "Course 1" of type "course" on "grader" page
And I choose "Edit category" in the open action menu
And I set the field "Aggregation" to "Mean of grades"
When I press "Save changes"
When I click on "Save" "button" in the "Edit category" "dialogue"
And I click on grade item menu "Item a1" of type "gradeitem" on "grader" page
And I choose "Edit grade item" in the open action menu
Then I should not see "Weight adjusted"
@ -134,6 +137,7 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I click on "Cancel" "button" in the "Edit grade item" "dialogue"
And I click on grade item menu "Cat mean" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And I should not see "Weight adjusted"
And I should not see "Weight" in the "#id_headerparent" "css_element"
@ -141,6 +145,7 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I press "Cancel"
And I click on grade item menu "Cat median" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And I should not see "Weight adjusted"
And I should not see "Weight" in the "#id_headerparent" "css_element"
@ -148,6 +153,7 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I press "Cancel"
And I click on grade item menu "Cat min" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And I should not see "Weight adjusted"
And I should not see "Weight" in the "#id_headerparent" "css_element"
@ -156,7 +162,8 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I click on grade item menu "Cat natural &" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I set the field "Aggregation" to "Mean of grades"
And I press "Save changes"
And I click on "Save" "button" in the "Edit category" "dialogue"
And I wait until the page is ready
And I click on grade item menu "Item b1" of type "gradeitem" on "grader" page
And I choose "Edit grade item" in the open action menu
And I should not see "Weight adjusted"
@ -185,7 +192,8 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I click on grade item menu "Course 1" of type "course" on "grader" page
And I choose "Edit category" in the open action menu
And I set the field "Aggregation" to "Natural"
And I press "Save changes"
And I click on "Save" "button" in the "Edit category" "dialogue"
And I wait until the page is ready
And I click on grade item menu "Item a1" of type "gradeitem" on "grader" page
And I choose "Edit grade item" in the open action menu
And the field "Weight adjusted" matches value "0"
@ -208,18 +216,21 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I click on "Cancel" "button" in the "Edit grade item" "dialogue"
And I click on grade item menu "Cat mean" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And the field "Weight adjusted" matches value "0"
And the field "Extra credit" matches value "0"
And I press "Cancel"
And I click on grade item menu "Cat median" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And the field "Weight adjusted" matches value "0"
And the field "Extra credit" matches value "0"
And I press "Cancel"
And I click on grade item menu "Cat min" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And the field "Weight adjusted" matches value "0"
And the field "Extra credit" matches value "0"
@ -227,7 +238,8 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I click on grade item menu "Cat natural &" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I set the field "Aggregation" to "Natural"
And I press "Save changes"
And I click on "Save" "button" in the "Edit category" "dialogue"
And I wait until the page is ready
And I click on grade item menu "Item b1" of type "gradeitem" on "grader" page
And I choose "Edit grade item" in the open action menu
And the field "Weight adjusted" matches value "0"
@ -253,7 +265,8 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
Given I click on grade item menu "Course 1" of type "course" on "grader" page
And I choose "Edit category" in the open action menu
And I set the field "Aggregation" to "Weighted mean of grades"
And I press "Save changes"
And I click on "Save" "button" in the "Edit category" "dialogue"
And I wait until the page is ready
And I click on grade item menu "Item a1" of type "gradeitem" on "grader" page
And I choose "Edit grade item" in the open action menu
Then I should not see "Weight adjusted"
@ -280,6 +293,7 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I click on "Cancel" "button" in the "Edit grade item" "dialogue"
And I click on grade item menu "Cat mean" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And I should not see "Weight adjusted"
And I should not see "Extra credit"
@ -287,6 +301,7 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I press "Cancel"
And I click on grade item menu "Cat median" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And I should not see "Weight adjusted"
And I should not see "Extra credit"
@ -294,6 +309,7 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I press "Cancel"
And I click on grade item menu "Cat min" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And I should not see "Weight adjusted"
And I should not see "Extra credit"
@ -302,7 +318,8 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I click on grade item menu "Cat natural &" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I set the field "Aggregation" to "Weighted mean of grades"
And I press "Save changes"
And I click on "Save" "button" in the "Edit category" "dialogue"
And I wait until the page is ready
And I click on grade item menu "Item b1" of type "gradeitem" on "grader" page
And I choose "Edit grade item" in the open action menu
And I should not see "Weight adjusted"
@ -331,7 +348,8 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I click on grade item menu "Course 1" of type "course" on "grader" page
And I choose "Edit category" in the open action menu
And I set the field "Aggregation" to "Natural"
And I press "Save changes"
And I click on "Save" "button" in the "Edit category" "dialogue"
And I wait until the page is ready
And I click on grade item menu "Item a1" of type "gradeitem" on "grader" page
And I choose "Edit grade item" in the open action menu
And the field "Weight adjusted" matches value "0"
@ -354,18 +372,21 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I click on "Cancel" "button" in the "Edit grade item" "dialogue"
And I click on grade item menu "Cat mean" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And the field "Weight adjusted" matches value "0"
And the field "Extra credit" matches value "0"
And I press "Cancel"
And I click on grade item menu "Cat median" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And the field "Weight adjusted" matches value "0"
And the field "Extra credit" matches value "0"
And I press "Cancel"
And I click on grade item menu "Cat min" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And the field "Weight adjusted" matches value "0"
And the field "Extra credit" matches value "0"
@ -373,7 +394,8 @@ Feature: Changing the aggregation of an item affects its weight and extra credit
And I click on grade item menu "Cat natural &" of type "category" on "grader" page
And I choose "Edit category" in the open action menu
And I set the field "Aggregation" to "Natural"
And I press "Save changes"
And I click on "Save" "button" in the "Edit category" "dialogue"
And I wait until the page is ready
And I click on grade item menu "Item b1" of type "gradeitem" on "grader" page
And I choose "Edit grade item" in the open action menu
And the field "Weight adjusted" matches value "0"

View File

@ -27,7 +27,8 @@ Feature: Calculated grade items can be used in the gradebook
Given I press "Add category"
And I set the following fields to these values:
| Category name | Calc cat |
And I press "Save changes"
And I click on "Save" "button" in the "New category" "dialogue"
And I wait until the page is ready
And I press "Add grade item"
And I set the following fields to these values:
| Item name | grade item 1 |
@ -54,7 +55,9 @@ Feature: Calculated grade items can be used in the gradebook
Given I press "Add category"
And I set the following fields to these values:
| Category name | Calc cat |
And I press "Save changes"
And I click on "Save" "button" in the "New category" "dialogue"
And I wait until the page is ready
And I should not see "Calculated grade" in the "Calc cat" "table_row"
And I press "Add grade item"
And I set the following fields to these values:
| Item name | grade item 1 |
@ -62,6 +65,7 @@ Feature: Calculated grade items can be used in the gradebook
And I click on "Save" "button" in the "New grade item" "dialogue"
And I set "=[[gi1]]/2" calculation for grade category "Calc cat" with idnumbers:
| grade item 1 | gi1 |
And I should see "Calculated grade" in the "Calc cat" "table_row"
And I set the following settings for grade item "Calc cat" of type "category" on "setup" page:
| Maximum grade | 50 |
And I navigate to "View > Grader report" in the course gradebook

View File

@ -28,7 +28,8 @@ Feature: Gradebook calculations for calculated grade items before the fix 201506
Given I press "Add category"
And I set the following fields to these values:
| Category name | Calc cat |
And I press "Save changes"
And I click on "Save" "button" in the "New category" "dialogue"
And I wait until the page is ready
And I press "Add grade item"
And I set the following fields to these values:
| Item name | grade item 1 |
@ -55,7 +56,8 @@ Feature: Gradebook calculations for calculated grade items before the fix 201506
Given I press "Add category"
And I set the following fields to these values:
| Category name | Calc cat |
And I press "Save changes"
And I click on "Save" "button" in the "New category" "dialogue"
And I wait until the page is ready
And I press "Add grade item"
And I set the following fields to these values:
| Item name | grade item 1 |

View File

@ -46,7 +46,8 @@ Feature: We can understand the gradebook user report
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I press "Add category"
And I set the field "Category name" to "Sub category"
And I press "Save changes"
And I click on "Save" "button" in the "New category" "dialogue"
And I wait until the page is ready
And I click on "Move" "link" in the "Test assignment six" "table_row"
# This xpath finds the forth last row in the table.
And I click on "Move to here" "link" in the "//tbody//tr[position()=last()-3]" "xpath_element"

View File

@ -38,7 +38,8 @@ Feature: Editing a grade item
And I set the following fields to these values:
| Category name | Cat 1 |
| Aggregation | Highest grade |
And I press "Save changes"
And I click on "Save" "button" in the "New category" "dialogue"
And I wait until the page is ready
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Item 1 |
@ -53,6 +54,7 @@ Feature: Editing a grade item
Scenario: Being able to change the grade type, scale and maximum grade for a grade category when there are no overridden grades
Given I click on grade item menu "Cat 1" of type "category" on "setup" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
Then I should not see "This category has associated grade items which have been overridden. Therefore some grades have already been awarded"
And I expand all fieldsets
And I set the field "Grade type" to "Scale"
@ -63,6 +65,7 @@ Feature: Editing a grade item
And I should not see "You cannot change the type, as grades already exist for this item"
And I click on grade item menu "Cat 1" of type "category" on "setup" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I should not see "This category has associated grade items which have been overridden. Therefore some grades have already been awarded"
And I expand all fieldsets
And I set the field "Scale" to "Letter scale"
@ -77,6 +80,7 @@ Feature: Editing a grade item
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I click on grade item menu "Cat 1" of type "category" on "setup" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
Then I should see "This category has associated grade items which have been overridden. Therefore some grades have already been awarded, so the grade type cannot be changed. If you wish to change the maximum grade, you must first choose whether or not to rescale existing grades."
And "//div[contains(concat(' ', normalize-space(@class), ' '), 'felement') and contains(text(), 'Value')]" "xpath_element" should exist
@ -84,6 +88,7 @@ Feature: Editing a grade item
Scenario: Attempting to change a category item's scale when overridden grades already exist
Given I click on grade item menu "Cat 1" of type "category" on "setup" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And I set the field "Grade type" to "Scale"
And I set the field "Scale" to "ABCDEF"
@ -95,6 +100,7 @@ Feature: Editing a grade item
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I click on grade item menu "Cat 1" of type "category" on "setup" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
Then I should see "This category has associated grade items which have been overridden. Therefore some grades have already been awarded, so the grade type and scale cannot be changed."
And "//div[contains(concat(' ', normalize-space(@class), ' '), 'felement') and contains(text(), 'ABCDEF')]" "xpath_element" should exist
@ -107,6 +113,7 @@ Feature: Editing a grade item
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I click on grade item menu "Cat 1" of type "category" on "setup" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
Then I should see "This category has associated grade items which have been overridden. Therefore some grades have already been awarded, so the grade type cannot be changed. If you wish to change the maximum grade, you must first choose whether or not to rescale existing grades."
And I should see "Choose" in the "Rescale overridden grades" "field"
@ -123,6 +130,7 @@ Feature: Editing a grade item
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I click on grade item menu "Cat 1" of type "category" on "setup" page
And I choose "Edit category" in the open action menu
And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
And I expand all fieldsets
And I set the field "Rescale overridden grades" to "Yes"
And I set the field "Maximum grade" to "87#50"

View File

@ -23,7 +23,8 @@ Feature: Hidden grade items should be hidden when grade category is locked, but
And I press "Add category"
And I set the following fields to these values:
| Category name | Test locked category |
And I press "Save changes"
And I click on "Save" "button" in the "New category" "dialogue"
And I wait until the page is ready
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Hidden item |
@ -70,7 +71,8 @@ Feature: Hidden grade items should be hidden when grade category is locked, but
And I press "Add category"
And I set the following fields to these values:
| Category name | Test overridden category B|
And I press "Save changes"
And I click on "Save" "button" in the "New category" "dialogue"
And I wait until the page is ready
And I press "Add grade item"
And I set the following fields to these values:
| Item name | Cat b item |

View File

@ -93,7 +93,7 @@ Feature: Teacher can unhide grades on the edit page allowing students to view th
And I choose "Edit category" in the open action menu
And the field "Hidden" matches value "1"
And I set the field "Hidden" to "0"
And I press "Save changes"
And I click on "Save" "button" in the "Edit category" "dialogue"
And I log out
And I am on the "Test assignment name" "assign activity" page logged in as student1
Then I should see "50.00"

View File

@ -111,6 +111,7 @@ $string['calculationadd'] = 'Add calculation';
$string['calculationedit'] = 'Edit calculation';
$string['calculationsaved'] = 'Calculation saved';
$string['calculationview'] = 'View calculation';
$string['calculationwarning'] = 'This category uses a grade calculation for the category total rather than an aggregation.';
$string['cannotaccessgroup'] = 'Can not access grades of selected group, sorry.';
$string['categories'] = 'Categories';
$string['category'] = 'Category';

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2023072100.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2023072100.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.3dev (Build: 20230721)'; // Human-friendly version name