mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-66722 core_grades: Add simple direct grading to gradingpanel
Part of MDL-66074
- Loading branch information
1 parent
f8da1b9
commit 9adedcc
Showing
13 changed files
with
988 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
grade/amd/build/grades/grader/gradingpanel/repository.min.js.map
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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/>. | ||
|
||
/** | ||
* Grading panel for simple direct grading. | ||
* | ||
* @module core_grades/grades/grader/gradingpanel/point | ||
* @package core_grades | ||
* @copyright 2019 Andrew Nicols <andrew@nicols.co.uk> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
import {saveGrade, fetchGrade} from './repository'; | ||
// Note: We use jQuery.serializer here until we can rewrite Ajax to use XHR.send() | ||
import jQuery from 'jquery'; | ||
|
||
export const fetchCurrentGrade = (...args) => fetchGrade('point')(...args); | ||
|
||
export const storeCurrentGrade = (component, context, itemname, userId, rootNode) => { | ||
const form = rootNode.querySelector('form'); | ||
return saveGrade('point')(component, context, itemname, userId, jQuery(form).serialize()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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/>. | ||
|
||
/** | ||
* Repository for simple direct grading panel. | ||
* | ||
* @module core_grades/grades/grader/gradingpanel/repository | ||
* @package core_grades | ||
* @copyright 2019 Andrew Nicols <andrew@nicols.co.uk> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
import {call as fetchMany} from 'core/ajax'; | ||
|
||
export const fetchGrade = type => (component, contextid, itemname, gradeduserid) => { | ||
return fetchMany([{ | ||
methodname: `core_grades_grader_gradingpanel_${type}_fetch`, | ||
args: { | ||
component, | ||
contextid, | ||
itemname, | ||
gradeduserid, | ||
}, | ||
}])[0]; | ||
}; | ||
|
||
export const saveGrade = type => (component, contextid, itemname, gradeduserid, formdata) => { | ||
return fetchMany([{ | ||
methodname: `core_grades_grader_gradingpanel_${type}_store`, | ||
args: { | ||
component, | ||
contextid, | ||
itemname, | ||
gradeduserid, | ||
formdata, | ||
}, | ||
}])[0]; | ||
}; |
167 changes: 167 additions & 0 deletions
167
grade/classes/grades/grader/gradingpanel/point/external/fetch.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Web service functions relating to point grades and grading. | ||
* | ||
* @package core_grades | ||
* @copyright 2019 Andrew Nicols <andrew@nicols.co.uk> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace core_grades\grades\grader\gradingpanel\point\external; | ||
|
||
use coding_exception; | ||
use context; | ||
use core_user; | ||
use core_grades\component_gradeitem as gradeitem; | ||
use core_grades\component_gradeitems; | ||
use external_api; | ||
use external_function_parameters; | ||
use external_multiple_structure; | ||
use external_single_structure; | ||
use external_value; | ||
use external_warnings; | ||
use moodle_exception; | ||
use required_capability_exception; | ||
use stdClass; | ||
|
||
/** | ||
* External grading panel point API | ||
* | ||
* @package core_grades | ||
* @copyright 2019 Andrew Nicols <andrew@nicols.co.uk> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class fetch extends external_api { | ||
|
||
/** | ||
* Describes the parameters for fetching the grading panel for a simple grade. | ||
* | ||
* @return external_function_parameters | ||
* @since Moodle 3.8 | ||
*/ | ||
public static function execute_parameters(): external_function_parameters { | ||
return new external_function_parameters ([ | ||
'component' => new external_value( | ||
PARAM_ALPHANUMEXT, | ||
'The name of the component', | ||
VALUE_REQUIRED | ||
), | ||
'contextid' => new external_value( | ||
PARAM_INT, | ||
'The ID of the context being graded', | ||
VALUE_REQUIRED | ||
), | ||
'itemname' => new external_value( | ||
PARAM_ALPHANUM, | ||
'The grade item itemname being graded', | ||
VALUE_REQUIRED | ||
), | ||
'gradeduserid' => new external_value( | ||
PARAM_INT, | ||
'The ID of the user show', | ||
VALUE_REQUIRED | ||
), | ||
]); | ||
} | ||
|
||
/** | ||
* Fetch the data required to build a grading panel for a simple grade. | ||
* | ||
* @param string $component | ||
* @param int $contextid | ||
* @param string $itemname | ||
* @param int $gradeduserid | ||
* @return array | ||
* @since Moodle 3.8 | ||
*/ | ||
public static function execute(string $component, int $contextid, string $itemname, int $gradeduserid): array { | ||
global $USER; | ||
|
||
[ | ||
'component' => $component, | ||
'contextid' => $contextid, | ||
'itemname' => $itemname, | ||
'gradeduserid' => $gradeduserid, | ||
] = self::validate_parameters(self::execute_parameters(), [ | ||
'component' => $component, | ||
'contextid' => $contextid, | ||
'itemname' => $itemname, | ||
'gradeduserid' => $gradeduserid, | ||
]); | ||
|
||
// Validate the context. | ||
$context = context::instance_by_id($contextid); | ||
self::validate_context($context); | ||
|
||
// Validate that the supplied itemname is a gradable item. | ||
if (!component_gradeitems::is_valid_itemname($component, $itemname)) { | ||
throw new coding_exception("The '{$itemname}' item is not valid for the '{$component}' component"); | ||
} | ||
|
||
// Fetch the gradeitem instance. | ||
$gradeitem = gradeitem::instance($component, $context, $itemname); | ||
|
||
if (!$gradeitem->is_using_direct_grading()) { | ||
throw new moodle_exception("The {$itemname} item in {$component}/{$contextid} is not configured for direct grading"); | ||
} | ||
|
||
// Fetch the actual data. | ||
$gradeduser = \core_user::get_user($gradeduserid); | ||
$grade = $gradeitem->get_grade_for_user($gradeduser, $USER); | ||
|
||
return self::get_fetch_data($grade); | ||
} | ||
|
||
/** | ||
* Get the data to be fetched. | ||
* | ||
* @param component_gradeitem $gradeitem | ||
* @return array | ||
*/ | ||
public static function get_fetch_data(stdClass $grade): array { | ||
return [ | ||
'templatename' => 'core_grades/grades/grader/gradingpanel/point', | ||
'grade' => [ | ||
'grade' => $grade->grade, | ||
'timecreated' => $grade->timecreated, | ||
'timemodified' => $grade->timemodified, | ||
], | ||
'warnings' => [], | ||
]; | ||
} | ||
|
||
/** | ||
* Describes the data returned from the external function. | ||
* | ||
* @return external_single_structure | ||
* @since Moodle 3.8 | ||
*/ | ||
public static function execute_returns(): external_single_structure { | ||
return new external_single_structure([ | ||
'templatename' => new external_value(PARAM_SAFEPATH, 'The template to use when rendering this data'), | ||
'grade' => new external_single_structure([ | ||
'grade' => new external_value(PARAM_FLOAT, 'The numeric grade'), | ||
'timecreated' => new external_value(PARAM_INT, 'The time that the grade was created'), | ||
'timemodified' => new external_value(PARAM_INT, 'The time that the grade was last updated'), | ||
]), | ||
'warnings' => new external_warnings(), | ||
]); | ||
} | ||
} |
Oops, something went wrong.