MDL-66360 core_grade: grade notifications for scale-based marking

This commit is contained in:
Shamim Rezaie
2019-11-11 15:27:05 +08:00
committed by Simey Lameze
parent 4fe3ce8f64
commit f0744fa0ff
4 changed files with 19 additions and 8 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
define ("core_grades/grades/grader/gradingpanel/scale",["exports","./repository","core_grades/grades/grader/gradingpanel/comparison","jquery","./normalise"],function(a,b,c,d,e){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.storeCurrentGrade=a.fetchCurrentGrade=void 0;d=function(a){return a&&a.__esModule?a:{default:a}}(d);a.fetchCurrentGrade=function fetchCurrentGrade(){return(0,b.fetchGrade)("scale").apply(void 0,arguments)};var f=function(a,f,g,h,i){var j=i.querySelector("form"),k=j.querySelector("select[name=\"grade\"]");if(!k.checkValidity()||!k.value.trim()){return e.invalidResult}if(!0===(0,c.compareData)(j)){return(0,b.saveGrade)("scale")(a,f,g,h,(0,d.default)(j).serialize())}else{return""}};a.storeCurrentGrade=f});
define ("core_grades/grades/grader/gradingpanel/scale",["exports","./repository","core_grades/grades/grader/gradingpanel/comparison","jquery","./normalise"],function(a,b,c,d,e){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.storeCurrentGrade=a.fetchCurrentGrade=void 0;d=function(a){return a&&a.__esModule?a:{default:a}}(d);a.fetchCurrentGrade=function fetchCurrentGrade(){return(0,b.fetchGrade)("scale").apply(void 0,arguments)};var f=function(a,f,g,h,i){var j=5<arguments.length&&arguments[5]!==void 0?arguments[5]:!1,k=i.querySelector("form"),l=k.querySelector("select[name=\"grade\"]");if(!l.checkValidity()||!l.value.trim()){return e.invalidResult}if(!0===(0,c.compareData)(k)){return(0,b.saveGrade)("scale")(a,f,g,h,(0,d.default)(k).serialize(),j)}else{return""}};a.storeCurrentGrade=f});
//# sourceMappingURL=scale.min.js.map
@@ -1 +1 @@
{"version":3,"sources":["../../../../src/grades/grader/gradingpanel/scale.js"],"names":["fetchCurrentGrade","storeCurrentGrade","component","context","itemname","userId","rootNode","form","querySelector","grade","checkValidity","value","trim","invalidResult","serialize"],"mappings":"8RA2BA,uD,oBAGiC,QAApBA,CAAAA,iBAAoB,SAAa,iBAAW,OAAX,yBAAb,C,CAE1B,GAAMC,CAAAA,CAAiB,CAAG,SAACC,CAAD,CAAYC,CAAZ,CAAqBC,CAArB,CAA+BC,CAA/B,CAAuCC,CAAvC,CAAoD,IAC3EC,CAAAA,CAAI,CAAGD,CAAQ,CAACE,aAAT,CAAuB,MAAvB,CADoE,CAE3EC,CAAK,CAAGF,CAAI,CAACC,aAAL,CAAmB,wBAAnB,CAFmE,CAIjF,GAAI,CAACC,CAAK,CAACC,aAAN,EAAD,EAA0B,CAACD,CAAK,CAACE,KAAN,CAAYC,IAAZ,EAA/B,CAAmD,CAC/C,MAAOC,gBACV,CAED,GAAI,uBAAYN,CAAZ,CAAJ,CAAgC,CAC5B,MAAO,gBAAU,OAAV,EAAmBL,CAAnB,CAA8BC,CAA9B,CAAuCC,CAAvC,CAAiDC,CAAjD,CAAyD,cAAOE,CAAP,EAAaO,SAAb,EAAzD,CACV,CAFD,IAEO,CACH,MAAO,EACV,CACJ,CAbM,C","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 * Grading panel for simple direct grading.\n *\n * @module core_grades/grades/grader/gradingpanel/scale\n * @package core_grades\n * @copyright 2019 Andrew Nicols <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {saveGrade, fetchGrade} from './repository';\nimport {compareData} from 'core_grades/grades/grader/gradingpanel/comparison';\n// Note: We use jQuery.serializer here until we can rewrite Ajax to use XHR.send()\nimport jQuery from 'jquery';\nimport {invalidResult} from './normalise';\n\nexport const fetchCurrentGrade = (...args) => fetchGrade('scale')(...args);\n\nexport const storeCurrentGrade = (component, context, itemname, userId, rootNode) => {\n const form = rootNode.querySelector('form');\n const grade = form.querySelector('select[name=\"grade\"]');\n\n if (!grade.checkValidity() || !grade.value.trim()) {\n return invalidResult;\n }\n\n if (compareData(form) === true) {\n return saveGrade('scale')(component, context, itemname, userId, jQuery(form).serialize());\n } else {\n return '';\n }\n};\n"],"file":"scale.min.js"}
{"version":3,"sources":["../../../../src/grades/grader/gradingpanel/scale.js"],"names":["fetchCurrentGrade","storeCurrentGrade","component","context","itemname","userId","rootNode","notifyUser","form","querySelector","grade","checkValidity","value","trim","invalidResult","serialize"],"mappings":"8RA2BA,uD,oBAGiC,QAApBA,CAAAA,iBAAoB,SAAa,iBAAW,OAAX,yBAAb,C,CAE1B,GAAMC,CAAAA,CAAiB,CAAG,SAACC,CAAD,CAAYC,CAAZ,CAAqBC,CAArB,CAA+BC,CAA/B,CAAuCC,CAAvC,CAAwE,IAAvBC,CAAAA,CAAuB,2DAC/FC,CAAI,CAAGF,CAAQ,CAACG,aAAT,CAAuB,MAAvB,CADwF,CAE/FC,CAAK,CAAGF,CAAI,CAACC,aAAL,CAAmB,wBAAnB,CAFuF,CAIrG,GAAI,CAACC,CAAK,CAACC,aAAN,EAAD,EAA0B,CAACD,CAAK,CAACE,KAAN,CAAYC,IAAZ,EAA/B,CAAmD,CAC/C,MAAOC,gBACV,CAED,GAAI,uBAAYN,CAAZ,CAAJ,CAAgC,CAC5B,MAAO,gBAAU,OAAV,EAAmBN,CAAnB,CAA8BC,CAA9B,CAAuCC,CAAvC,CAAiDC,CAAjD,CAAyD,cAAOG,CAAP,EAAaO,SAAb,EAAzD,CAAmFR,CAAnF,CACV,CAFD,IAEO,CACH,MAAO,EACV,CACJ,CAbM,C","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 * Grading panel for simple direct grading.\n *\n * @module core_grades/grades/grader/gradingpanel/scale\n * @package core_grades\n * @copyright 2019 Andrew Nicols <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {saveGrade, fetchGrade} from './repository';\nimport {compareData} from 'core_grades/grades/grader/gradingpanel/comparison';\n// Note: We use jQuery.serializer here until we can rewrite Ajax to use XHR.send()\nimport jQuery from 'jquery';\nimport {invalidResult} from './normalise';\n\nexport const fetchCurrentGrade = (...args) => fetchGrade('scale')(...args);\n\nexport const storeCurrentGrade = (component, context, itemname, userId, rootNode, notifyUser = false) => {\n const form = rootNode.querySelector('form');\n const grade = form.querySelector('select[name=\"grade\"]');\n\n if (!grade.checkValidity() || !grade.value.trim()) {\n return invalidResult;\n }\n\n if (compareData(form) === true) {\n return saveGrade('scale')(component, context, itemname, userId, jQuery(form).serialize(), notifyUser);\n } else {\n return '';\n }\n};\n"],"file":"scale.min.js"}
@@ -30,7 +30,7 @@ import {invalidResult} from './normalise';
export const fetchCurrentGrade = (...args) => fetchGrade('scale')(...args);
export const storeCurrentGrade = (component, context, itemname, userId, rootNode) => {
export const storeCurrentGrade = (component, context, itemname, userId, rootNode, notifyUser = false) => {
const form = rootNode.querySelector('form');
const grade = form.querySelector('select[name="grade"]');
@@ -39,7 +39,7 @@ export const storeCurrentGrade = (component, context, itemname, userId, rootNode
}
if (compareData(form) === true) {
return saveGrade('scale')(component, context, itemname, userId, jQuery(form).serialize());
return saveGrade('scale')(component, context, itemname, userId, jQuery(form).serialize(), notifyUser);
} else {
return '';
}
@@ -82,6 +82,12 @@ class store extends external_api {
'The serialised form data representing the grade',
VALUE_REQUIRED
),
'notifyuser' => new external_value(
PARAM_BOOL,
'Wheteher to notify the user or not',
VALUE_DEFAULT,
false
),
]);
}
@@ -93,15 +99,14 @@ class store extends external_api {
* @param string $itemname
* @param int $gradeduserid
* @param string $formdata
* @param bool $notifyuser
* @return array
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \restricted_context_exception
* @throws coding_exception
* @throws moodle_exception
* @since Moodle 3.8
*/
public static function execute(string $component, int $contextid, string $itemname, int $gradeduserid, string $formdata): array {
public static function execute(string $component, int $contextid, string $itemname, int $gradeduserid, string $formdata,
bool $notifyuser): array {
global $USER;
[
@@ -152,6 +157,12 @@ class store extends external_api {
// Grade.
$gradeitem->store_grade_from_formdata($gradeduser, $USER, (object) $data);
// Notify.
if ($notifyuser) {
// Send notification.
$gradeitem->send_student_notification($gradeduser, $USER);
}
return fetch::get_fetch_data($gradeitem, $gradeduser);
}