Skip to content

Commit

Permalink
Revert "MDL-42425 modify mod_assign_save_grade to process advanced gr…
Browse files Browse the repository at this point in the history
…ading data"

This reverts commit 29932b2.

Conflicts:
	mod/assign/upgrade.txt
  • Loading branch information
stronk7 committed Dec 20, 2013
1 parent 9f9618f commit c7df865
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 505 deletions.
8 changes: 0 additions & 8 deletions mod/assign/db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@
'type' => 'write'
),

'mod_assign_save_grades' => array(
'classname' => 'mod_assign_external',
'methodname' => 'save_grades',
'classpath' => 'mod/assign/externallib.php',
'description' => 'Save multiple grade updates for an assignment.',
'type' => 'write'
),

'mod_assign_save_user_extensions' => array(
'classname' => 'mod_assign_external',
'methodname' => 'save_user_extensions',
Expand Down
201 changes: 6 additions & 195 deletions mod/assign/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,6 @@ public static function save_submission_returns() {
public static function save_grade_parameters() {
global $CFG;
require_once("$CFG->dirroot/mod/assign/locallib.php");
require_once("$CFG->dirroot/grade/grading/lib.php");
$instance = new assign(null, null, null);
$pluginfeedbackparams = array();

Expand All @@ -1655,41 +1654,20 @@ public static function save_grade_parameters() {
}
}

$advancedgradingdata = array();
$methods = array_keys(grading_manager::available_methods(false));
foreach ($methods as $method) {
require_once($CFG->dirroot.'/grade/grading/form/'.$method.'/lib.php');
$details = call_user_func('gradingform_'.$method.'_controller::get_external_instance_filling_details');
if (!empty($details)) {
$items = array();
foreach ($details as $key => $value) {
$value->required = VALUE_OPTIONAL;
unset($value->content->keys['id']);
$items[$key] = new external_multiple_structure (new external_single_structure(
array(
'criterionid' => new external_value(PARAM_INT, 'criterion id'),
'fillings' => $value
)
));
}
$advancedgradingdata[$method] = new external_single_structure($items, 'items', VALUE_OPTIONAL);
}
}

return new external_function_parameters(
array(
'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'),
'userid' => new external_value(PARAM_INT, 'The student id to operate on'),
'grade' => new external_value(PARAM_FLOAT, 'The new grade for this user. Ignored if advanced grading used'),
'grade' => new external_value(PARAM_FLOAT, 'The new grade for this user'),
'attemptnumber' => new external_value(PARAM_INT, 'The attempt number (-1 means latest attempt)'),
'addattempt' => new external_value(PARAM_BOOL, 'Allow another attempt if the attempt reopen method is manual'),
'workflowstate' => new external_value(PARAM_ALPHA, 'The next marking workflow state'),
'applytoall' => new external_value(PARAM_BOOL, 'If true, this grade will be applied ' .
'to all members ' .
'of the group (for group assignments).'),
'plugindata' => new external_single_structure($pluginfeedbackparams, 'plugin data', VALUE_DEFAULT, array()),
'advancedgradingdata' => new external_single_structure($advancedgradingdata, 'advanced grading data',
VALUE_DEFAULT, array())
'plugindata' => new external_single_structure(
$pluginfeedbackparams
)
)
);
}
Expand All @@ -1705,7 +1683,6 @@ public static function save_grade_parameters() {
* @param string $workflowstate New workflow state
* @param bool $applytoall Apply the grade to all members of the group
* @param array $plugindata Custom data used by plugins
* @param array $advancedgradingdata Advanced grading data
* @return null
* @since Moodle 2.6
*/
Expand All @@ -1716,8 +1693,7 @@ public static function save_grade($assignmentid,
$addattempt,
$workflowstate,
$applytoall,
$plugindata = array(),
$advancedgradingdata = array()) {
$plugindata) {
global $CFG, $USER;
require_once("$CFG->dirroot/mod/assign/locallib.php");

Expand All @@ -1729,8 +1705,7 @@ public static function save_grade($assignmentid,
'workflowstate' => $workflowstate,
'addattempt' => $addattempt,
'applytoall' => $applytoall,
'plugindata' => $plugindata,
'advancedgradingdata' => $advancedgradingdata));
'plugindata' => $plugindata));

$cm = get_coursemodule_from_instance('assign', $assignmentid, 0, false, MUST_EXIST);
$context = context_module::instance($cm->id);
Expand All @@ -1745,21 +1720,6 @@ public static function save_grade($assignmentid,
$gradedata->applytoall = $applytoall;
$gradedata->grade = $grade;

if (!empty($advancedgradingdata)) {
$advancedgrading = array();
$criteria = reset($advancedgradingdata);
foreach ($criteria as $key => $criterion) {
$details = array();
foreach ($criterion as $value) {
foreach ($value['fillings'] as $filling) {
$details[$value['criterionid']] = $filling;
}
}
$advancedgrading[$key] = $details;
}
$gradedata->advancedgrading = $advancedgrading;
}

$assignment->save_grade($userid, $gradedata);

return null;
Expand All @@ -1775,155 +1735,6 @@ public static function save_grade_returns() {
return null;
}

/**
* Describes the parameters for save_grades
* @return external_external_function_parameters
* @since Moodle 2.7
*/
public static function save_grades_parameters() {
global $CFG;
require_once("$CFG->dirroot/mod/assign/locallib.php");
require_once("$CFG->dirroot/grade/grading/lib.php");
$instance = new assign(null, null, null);
$pluginfeedbackparams = array();

foreach ($instance->get_feedback_plugins() as $plugin) {
$pluginparams = $plugin->get_external_parameters();
if (!empty($pluginparams)) {
$pluginfeedbackparams = array_merge($pluginfeedbackparams, $pluginparams);
}
}

$advancedgradingdata = array();
$methods = array_keys(grading_manager::available_methods(false));
foreach ($methods as $method) {
require_once($CFG->dirroot.'/grade/grading/form/'.$method.'/lib.php');
$details = call_user_func('gradingform_'.$method.'_controller::get_external_instance_filling_details');
if (!empty($details)) {
$items = array();
foreach ($details as $key => $value) {
$value->required = VALUE_OPTIONAL;
unset($value->content->keys['id']);
$items[$key] = new external_multiple_structure (new external_single_structure(
array(
'criterionid' => new external_value(PARAM_INT, 'criterion id'),
'fillings' => $value
)
));
}
$advancedgradingdata[$method] = new external_single_structure($items, 'items', VALUE_OPTIONAL);
}
}

return new external_function_parameters(
array(
'assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'),
'applytoall' => new external_value(PARAM_BOOL, 'If true, this grade will be applied ' .
'to all members ' .
'of the group (for group assignments).'),
'grades' => new external_multiple_structure(
new external_single_structure(
array (
'userid' => new external_value(PARAM_INT, 'The student id to operate on'),
'grade' => new external_value(PARAM_FLOAT, 'The new grade for this user'),
'attemptnumber' => new external_value(PARAM_INT, 'The attempt number (-1 means latest attempt)'),
'addattempt' => new external_value(PARAM_BOOL, 'Allow another attempt if manual attempt reopen method'),
'workflowstate' => new external_value(PARAM_ALPHA, 'The next marking workflow state'),
'plugindata' => new external_single_structure($pluginfeedbackparams, 'plugin data',
VALUE_DEFAULT, array()),
'advancedgradingdata' => new external_single_structure($advancedgradingdata, 'advanced grading data',
VALUE_DEFAULT, array())
)
)
)
)
);
}

/**
* Save multiple student grades for a single assignment.
*
* @param int $assignmentid The id of the assignment
* @param boolean $applytoall If set to true and this is a team assignment,
* apply the grade to all members of the group
* @param array $grades grade data for one or more students that includes
* userid - The id of the student being graded
* grade - The grade
* attemptnumber - The attempt number
* addattempt - Allow another attempt
* workflowstate - New workflow state
* plugindata - optional feedback data used by plugins
* advancedgradingdata - optional Advanced grading data
* @throws invalid_parameter_exception if multiple grades are supplied for
* a team assignment that has $applytoall set to true
* @return null
* @since Moodle 2.7
*/
public static function save_grades($assignmentid, $applytoall = false, $grades) {
global $CFG, $USER;
require_once("$CFG->dirroot/mod/assign/locallib.php");

$params = self::validate_parameters(self::save_grades_parameters(),
array('assignmentid' => $assignmentid,
'applytoall' => $applytoall,
'grades' => $grades));

$cm = get_coursemodule_from_instance('assign', $assignmentid, 0, false, MUST_EXIST);
$context = context_module::instance($cm->id);

$assignment = new assign($context, $cm, null);
if ($assignment->get_instance()->teamsubmission && $applytoall) {
// Check that only 1 user per submission group is provided.
$groupids = array();
foreach ($grades as $gradeinfo) {
$group = $assignment->get_submission_group($gradeinfo['userid']);
if (in_array($group->id, $groupids)) {
throw new invalid_parameter_exception('Multiple grades for the same team have been supplied '
.' this is not permitted when the applytoall flag is set');
} else {
$groupids[] = $group->id;
}
}
}

foreach ($grades as $gradeinfo) {
$gradedata = (object)$gradeinfo['plugindata'];
$gradedata->addattempt = $gradeinfo['addattempt'];
$gradedata->attemptnumber = $gradeinfo['attemptnumber'];
$gradedata->workflowstate = $gradeinfo['workflowstate'];
$gradedata->applytoall = $applytoall;
$gradedata->grade = $gradeinfo['grade'];

if (!empty($gradeinfo['advancedgradingdata'])) {
$advancedgrading = array();
$criteria = reset($gradeinfo['advancedgradingdata']);
foreach ($criteria as $key => $criterion) {
$details = array();
foreach ($criterion as $value) {
foreach ($value['fillings'] as $filling) {
$details[$value['criterionid']] = $filling;
}
}
$advancedgrading[$key] = $details;
}
$gradedata->advancedgrading = $advancedgrading;
}
$assignment->save_grade($gradeinfo['userid'], $gradedata);
}

return null;
}

/**
* Describes the return value for save_grades
*
* @return external_single_structure
* @since Moodle 2.7
*/
public static function save_grades_returns() {
return null;
}

/**
* Describes the parameters for copy_previous_attempt
* @return external_external_function_parameters
Expand Down
Loading

0 comments on commit c7df865

Please sign in to comment.