コード例 #1
0
ファイル: actDeleteMark.php プロジェクト: eduagdo/emarking
// 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/>.
/**
 * @package mod
 * @subpackage emarking
 * @copyright 2012 Jorge Villalón {@link http://www.uai.cl}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
/** The rubric level to be deleted in the corresponding submission **/
$rubriclevel = required_param('level', PARAM_INT);
// Basic validation
if ($rubriclevel <= 0) {
    emarking_json_error("Invalid rubric level id");
}
// Get the comment corresponding the the level in this submission
if (!($comment = $DB->get_record_sql("SELECT ec.*\n\t\tFROM {emarking_comment} AS ec\n\t\tWHERE ec.levelid = :level AND ec.draft = :draft", array('level' => $rubriclevel, 'draft' => $draft->id)))) {
    emarking_json_error("Invalid comment", array('levelid' => $rubriclevel, 'draft' => $draft->id));
}
// Delete the comment
$DB->delete_records('emarking_comment', array('id' => $comment->id));
// Update the final grade for the submission
list($finalgrade, $previouslvlid, $previouscomment) = emarking_set_finalgrade($userid, $rubriclevel, '', $submission, $draft, $emarking, $context, null, true);
// Send the output if everything went well
if ($finalgrade === false) {
    $output = array('error' => 'Invalid values from finalgrade', 'grade' => $finalgrade, 'lvlidprev' => $previouslvlid, 'timemodified' => time());
} else {
    $output = array('error' => '', 'grade' => $finalgrade, 'lvlidprev' => $previouslvlid, 'timemodified' => time());
}
コード例 #2
0
ファイル: a.php プロジェクト: hansnok/emarking
        break;
    case 'rotatepage':
        if (!$issupervisor) {
            emarking_json_error('Invalid access');
        }
        list($imageurl, $anonymousurl, $imgwidth, $imgheight) = emarking_rotate_image($pageno, $submission, $context);
        if (strlen($imageurl) == 0) {
            emarking_json_error('Image is empty');
        }
        $output = array('imageurl' => $imageurl, 'anonymousimageurl' => $anonymousurl, 'width' => $imgwidth, 'height' => $imgheight);
        emarking_json_array($output);
        break;
    case 'sortpages':
        $neworder = required_param('neworder', PARAM_SEQUENCE);
        $neworderarr = explode(',', $neworder);
        if (!emarking_sort_submission_pages($submission, $neworderarr)) {
            emarking_json_error('Error trying to resort pages!');
        }
        $output = array('neworder' => $neworder);
        emarking_json_array($output);
        break;
    case 'updcomment':
        emarking_check_grade_permission($readonly, $draft, $context);
        // Add to Moodle log so some auditing can be done.
        \mod_emarking\event\emarking_graded::create_from_draft($draft, $submission, $context)->trigger();
        $newgrade = emarking_update_comment($submission, $draft, $emarking, $context);
        emarking_json_array(array('message' => 'Success!', 'newgrade' => $newgrade, 'timemodified' => time()));
        break;
    default:
        emarking_json_error('Invalid action!');
}
コード例 #3
0
ファイル: updComment.php プロジェクト: mandrato1/emarking
    emarking_json_error("Invalid comment", array("id" => $commentid));
}
if ($regradeid > 0 && !($regrade = $DB->get_record('emarking_regrade', array('id' => $regradeid)))) {
    emarking_json_error("Invalid regrade", array("id" => $regradeid));
}
$previousbonus = $comment->bonus;
$previouslvlid = $comment->levelid;
$previouscomment = $comment->rawtext;
if ($bonus < 0) {
    $bonus = $previousbonus;
}
if ($commentrawtext === 'delphi') {
    $commentrawtext = $previouscomment;
}
if ($previouslvlid > 0 && $levelid <= 0) {
    emarking_json_error("Invalid level id for a rubric id which has a previous level", array("id" => $commentid, "levelid" => $previouslvlid));
}
/** transformation pixels screen to percentages **/
$posx = $posx / $winwidth;
$posy = $posy / $winheight;
$comment->posx = $posx;
$comment->posy = $posy;
$comment->id = $commentid;
$comment->rawtext = $commentrawtext;
$comment->bonus = $bonus;
$comment->textformat = $format;
$comment->levelid = $levelid;
$comment->markerid = $USER->id;
$DB->update_record('emarking_comment', $comment);
$diff = abs($previousbonus - $bonus);
if ($comment->levelid > 0) {
コード例 #4
0
ファイル: actAddComment.php プロジェクト: eduagdo/emarking
$posy = required_param('posy', PARAM_INT);
/**  Measures the correction window **/
$winwidth = required_param('windowswidth', PARAM_NUMBER);
$winheight = required_param('windowsheight', PARAM_NUMBER);
/** Height and Width **/
$width = required_param('width', PARAM_INT);
$height = required_param('height', PARAM_INT);
/** Page number **/
$pageno = required_param('pageno', PARAM_INT);
/** The comment itself **/
$comment = required_param('comment', PARAM_RAW_TRIMMED);
/** Comment format **/
$format = required_param('format', PARAM_INT);
// Get the page for this submission and page number
if (!($page = $DB->get_record('emarking_page', array('submission' => $submission->id, 'page' => $pageno)))) {
    emarking_json_error("Invalid page for insterting comment");
}
/**if the comment belongs to a rubric criterion  **/
$criterionid = optional_param("criterionid", 0, PARAM_INT);
/**if the comment belongs to a rubric criterion  **/
$colour = optional_param("colour", NULL, PARAM_ALPHANUM);
/** transformation pixels screen to percentages **/
$posx = $posx / $winwidth;
$posy = $posy / $winheight;
// Create the new comment record
$emarking_comment = new stdClass();
$emarking_comment->page = $page->id;
$emarking_comment->draft = $draft->id;
$emarking_comment->posx = $posx;
$emarking_comment->posy = $posy;
$emarking_comment->width = $width;
コード例 #5
0
ファイル: actRegrade.php プロジェクト: eduagdo/emarking
 * @copyright 2012 Jorge Villalón {@link http://www.uai.cl}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
/** Level id represents the level in the rubric **/
$rubriclevel = required_param('level', PARAM_INT);
/** Page number **/
$motive = required_param('motive', PARAM_INT);
/** Comment text **/
$comment = required_param('comment', PARAM_RAW_TRIMMED);
// Verify that dates are ok
if (!emarking_is_regrade_requests_allowed($emarking)) {
    emarking_json_error('Regrade requests are not allowed for this activity.');
}
// Get the rubric info from the level
if (!($rubricinfo = $DB->get_record_sql("\n\t\tSELECT c.definitionid, l.definition, l.criterionid, l.score, c.description\n\t\tFROM {gradingform_rubric_levels} as l\n\t\tINNER JOIN {gradingform_rubric_criteria} as c on (l.criterionid = c.id)\n\t\tWHERE l.id = ?", array($rubriclevel)))) {
    emarking_json_error("Invalid rubric info");
}
$emarking_comment = $DB->get_record_sql('
		SELECT ec.* 
		FROM {emarking_comment} AS ec
		WHERE ec.levelid = :levelid AND ec.draft = :draft', array('levelid' => $rubriclevel, 'draft' => $draft->id));
// Check if there was already a regrade request
$newrecord = false;
if (!($emarking_regrade = $DB->get_record('emarking_regrade', array('draft' => $draft->id, 'criterion' => $rubricinfo->criterionid)))) {
    $emarking_regrade = new stdClass();
    $newrecord = true;
}
// Make the changes that are for new records and previous
$emarking_regrade->motive = $motive;
$emarking_regrade->comment = $comment;
$emarking_regrade->accepted = 0;
コード例 #6
0
 */
$commentid = required_param('commentid', PARAM_INT);
$rownum = optional_param('rownum', 1, PARAM_INT);
if ($rownum < 1) {
    $rownum = 1;
}
if (!($comment = $DB->get_record('emarking_comment', array('id' => $commentid)))) {
    emarking_json_error('Invalid comment id for searching.');
}
$params = array($submission->emarkingid, $submission->id, $comment->levelid);
$similaranswers = $DB->get_records_sql("SELECT c.id, c.rawtext as text, c.pageno, c.pagesid\n\t\tFROM {emarking_comment} as c\n\t\tWHERE pagesid in (\n\t\tSELECT id FROM {emarking_page}\n\t\tWHERE assignment in (SELECT emarking FROM {emarking_page} WHERE id = ?))\n\t\tAND pagesid <> ? AND c.levelid = ?\n\t\tORDER BY c.id", $params);
$count = 0;
foreach ($similaranswers as $answer) {
    $count++;
    if ($count == $rownum) {
        if (!($submission = $DB->get_record('emarking_draft', array('id' => $answer->pagesid)))) {
            emarking_json_error('Invalid submission');
        }
        if (!($emarking = $DB->get_record("emarking", array("id" => $submission->emarkingid)))) {
            emarking_json_error('Invalid assignment');
        }
        if (!($course = $DB->get_record("course", array("id" => $emarking->course)))) {
            emarking_json_error('Invalid course');
        }
        if (!($cm = get_coursemodule_from_instance("emarking", $emarking->id, $course->id))) {
            emarking_json_error('Invalid course module');
        }
        list($imageurl, $imgwidth, $imgheight, $numfiles) = emarking_get_page_image($pageno, $submission, $context->id);
        emarking_json_array(array('error' => '', 'url' => $imageurl, 'width' => $imgwidth, 'height' => $imgheight, 'pagecount' => $numfiles));
    }
}
コード例 #7
0
ファイル: actDeleteComment.php プロジェクト: eduagdo/emarking
// 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/>.
/**
 * @package mod
 * @subpackage emarking
 * @copyright 2012 Jorge Villalón {@link http://www.uai.cl}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
/** The comment to delete **/
$commentid = required_param('id', PARAM_INT);
// Basic validation
if ($commentid <= 0) {
    emarking_json_error("Invalid comment id");
}
// Get the comment from the database
if (!($comment = $DB->get_record("emarking_comment", array("id" => $commentid)))) {
    emarking_json_error("Comment not found with id");
}
// Verify comment is not a mark
if ($comment->textformat == 2) {
    emarking_json_error("You can not delete a mark as a comment");
}
// Delete the comment record
$DB->delete_records('emarking_comment', array('id' => $commentid));
// Send the output
$output = array('error' => '', 'id' => $commentid, 'timemodified' => time());
emarking_json_array($output);
コード例 #8
0
ファイル: locallib.php プロジェクト: eduagdo/emarking
/**
 * Returns a json array
 *
 * @param unknown $output            
 */
function emarking_json_array($output)
{
    // Verify that parameter is OK. Output should not be null.
    if (!$output) {
        emarking_json_error('Invalid parameters for encoding json. output is null.');
    }
    $output = array('error' => '', 'values' => $output);
    emarking_json_output(json_encode($output));
}
コード例 #9
0
// 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/>.
/**
 * @package mod
 * @subpackage emarking
 * @copyright 2012 Jorge Villalón {@link http://www.uai.cl}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
/** The rubric level to be deleted in the corresponding submission **/
$rubriclevel = required_param('level', PARAM_INT);
// Basic validation
if ($rubriclevel <= 0) {
    emarking_json_error("Invalid rubric level id");
}
// Get the comment corresponding the the level in this submission
if (!($comment = $DB->get_record_sql("SELECT ec.*\n\t\tFROM {emarking_comment} AS ec\n\t\tINNER JOIN {emarking_page} AS ep \n\t\t\tON (ec.levelid = :level AND ep.submission = :submission AND ec.page = ep.id)", array('level' => $rubriclevel, 'submission' => $submission->id)))) {
    emarking_json_error("Invalid comment", array('levelid' => $rubriclevel, 'pagesid' => $submission->id));
}
// Delete the comment
$DB->delete_records('emarking_comment', array('id' => $comment->id));
// Update the final grade for the submission
list($finalgrade, $previouslvlid, $previouscomment) = emarking_set_finalgrade($userid, $rubriclevel, '', $submission, $emarking, $context, null, true);
// Send the output if everything went well
if ($finalgrade === false) {
    $output = array('error' => 'Invalid values from finalgrade', 'grade' => $finalgrade, 'lvlidprev' => $previouslvlid, 'timemodified' => time());
} else {
    $output = array('error' => '', 'grade' => $finalgrade, 'lvlidprev' => $previouslvlid, 'timemodified' => time());
}
コード例 #10
0
<?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/>.
/**
 * @package mod
 * @subpackage emarking
 * @copyright 2012 Jorge Villalón {@link http://www.uai.cl}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
// Checks and logs attempt if we are within an grading action
if ($readonly) {
    $item = array('context' => context_module::instance($cm->id), 'objectid' => $cm->id);
    // Add to Moodle log so some auditing can be done
    \mod_emarking\event\unauthorized_granted::create($item)->trigger();
    emarking_json_error('Unauthorized access!');
}
コード例 #11
0
ファイル: locallib.php プロジェクト: hansnok/emarking
/**
 *
 * @param unknown $submission
 * @param unknown $draft
 * @param unknown $emarking
 * @param unknown $context
 * @return unknown
 */
function emarking_update_comment($submission, $draft, $emarking, $context)
{
    global $CFG, $DB;
    require_once "{$CFG->dirroot}/grade/grading/form/rubric/lib.php";
    // Required and optional params for emarking.
    $userid = required_param('markerid', PARAM_INT);
    $commentid = required_param('cid', PARAM_INT);
    $commentrawtext = required_param('comment', PARAM_RAW_TRIMMED);
    $bonus = optional_param('bonus', -111111, PARAM_FLOAT);
    $levelid = optional_param('levelid', 0, PARAM_INT);
    $format = optional_param('format', 2, PARAM_INT);
    $regradeid = optional_param('regradeid', 0, PARAM_INT);
    $regrademarkercomment = optional_param('regrademarkercomment', null, PARAM_RAW_TRIMMED);
    $regradeaccepted = optional_param('regradeaccepted', 0, PARAM_INT);
    $feedback = optional_param('feedback', 0, PARAM_RAW_TRIMMED);
    $posx = required_param('posx', PARAM_INT);
    $posy = required_param('posy', PARAM_INT);
    // Measures the correction window.
    $winwidth = optional_param('windowswidth', '-1', PARAM_NUMBER);
    $winheight = optional_param('windowsheight', '-1', PARAM_NUMBER);
    if (!($comment = $DB->get_record('emarking_comment', array('id' => $commentid)))) {
        emarking_json_error("Invalid comment", array("id" => $commentid));
    }
    if ($regradeid > 0 && !($regrade = $DB->get_record('emarking_regrade', array('id' => $regradeid)))) {
        emarking_json_error("Invalid regrade", array("id" => $regradeid));
    }
    $previousbonus = $comment->bonus;
    $previouslvlid = $comment->levelid;
    $previouscomment = $comment->rawtext;
    if ($bonus < -111110) {
        $bonus = $previousbonus;
    }
    if ($commentrawtext === 'delphi') {
        $commentrawtext = $previouscomment;
    }
    if ($previouslvlid > 0 && $levelid <= 0) {
        emarking_json_error("Invalid level id for a rubric id which has a previous level", array("id" => $commentid, "levelid" => $previouslvlid));
    }
    // Transformation pixels screen to percentages.
    if ($winheight != -1 && $winheight != -1) {
        $posx = $posx / $winwidth;
        $posy = $posy / $winheight;
        $comment->posx = $posx;
        $comment->posy = $posy;
    }
    $comment->id = $commentid;
    $comment->rawtext = $commentrawtext;
    $comment->bonus = $bonus;
    $comment->textformat = $format;
    $comment->levelid = $levelid;
    if ($previouslvlid != $levelid) {
        $comment->markerid = $userid;
    }
    $DB->update_record('emarking_comment', $comment);
    if ($feedback) {
        // Delete previous feedback
        $DB->delete_records('emarking_feedback', array('commentid' => $commentid));
        // Inserte current feedback
        $insertfeedback = array();
        $arrayfeedback = explode("__separador__", $feedback);
        //TODO: validar que el split por @@separador@@ contenga 3 objetos de lo contrario el insert fallara
        for ($count = 0; $count < count($arrayfeedback); $count++) {
            $fields = explode("@@separador@@", $arrayfeedback[$count]);
            $row = new stdClass();
            $row->commentid = $commentid;
            $row->oer = $fields[0];
            $row->name = $fields[1];
            $row->link = $fields[2];
            $row->timecreated = time();
            $insertfeedback[] = $row;
        }
        $DB->insert_records('emarking_feedback', $insertfeedback);
    }
    if ($regradeid == 0) {
        // Update draft correction time
        if ($draft->timecorrectionstarted == null) {
            $draft->timecorrectionstarted = time();
        }
        $draft->timecorrectionended = time();
        $DB->update_record('emarking_draft', $draft);
    }
    $diff = abs($previousbonus - $bonus);
    if ($comment->levelid > 0) {
        if ($diff > 0.01 || $previouslvlid != $levelid || $previouscomment !== $commentrawtext) {
            emarking_set_finalgrade($levelid, $commentrawtext, $submission, $draft, $emarking, $context, null);
        }
    }
    if ($regradeid > 0) {
        $regrade->markercomment = $regrademarkercomment;
        $regrade->timemodified = time();
        $regrade->accepted = $regradeaccepted;
        $DB->update_record('emarking_regrade', $regrade);
        if ($draft->timeregradingstarted == null) {
            $draft->timeregradingstarted = time();
        }
        $draft->timeregradingended = time();
        $DB->update_record("emarking_draft", $draft);
        $remainingregrades = $DB->count_records("emarking_regrade", array("draft" => $draft->id, "accepted" => 0));
        if ($remainingregrades == 0) {
            $draft->status = EMARKING_STATUS_REGRADING_RESPONDED;
            $draft->timemodified = time();
            $DB->update_record("emarking_draft", $draft);
        }
    }
    $results = emarking_get_submission_grade($draft);
    $newgrade = $results->finalgrade;
    return $newgrade;
}
コード例 #12
0
ファイル: actAddMark.php プロジェクト: eduagdo/emarking
$rubriclevel = required_param('level', PARAM_INT);
/** Mark position in the page **/
$posx = required_param('posx', PARAM_INT);
$posy = required_param('posy', PARAM_INT);
/** Page number **/
$pageno = required_param('pageno', PARAM_INT);
/** Comment text **/
$comment = required_param('comment', PARAM_RAW_TRIMMED);
/** Bonus, positive or negative to be added to the level points **/
$bonus = optional_param('bonus', 0, PARAM_FLOAT);
/**  Measures the correction window **/
$winwidth = required_param('windowswidth', PARAM_NUMBER);
$winheight = required_param('windowsheight', PARAM_NUMBER);
// Get the page for the comment
if (!($page = $DB->get_record('emarking_page', array('submission' => $submission->id, 'page' => $pageno)))) {
    emarking_json_error('Invalid page for submission');
}
$rubricinfo = null;
$removeid = 0;
// Get the rubric information so we can get the max score
$rubricinfo = $DB->get_record_sql("\n\t\tSELECT c.definitionid, l.definition, l.criterionid, l.score, c.description\n\t\tFROM {gradingform_rubric_levels} as l\n\t\tINNER JOIN {gradingform_rubric_criteria} as c on (l.criterionid = c.id)\n\t\tWHERE l.id = ?", array($rubriclevel));
// Get the maximum score for the criterion in which we are adding a mark
$maxscorerecord = $DB->get_record_sql("\n\t\tSELECT MAX(l.score) as maxscore\n\t\tFROM {gradingform_rubric_levels} as l\n\t\tWHERE l.criterionid = ?\n\t\tGROUP BY l.criterionid", array($rubricinfo->criterionid));
// Get all the previous comments with the same criterion
$previouscomments = $DB->get_records_sql("SELECT ec.*\n\t\tFROM {emarking_comment} AS ec\n\t\tWHERE draft = ?\n            AND levelid in (\n\t\t\tSELECT id FROM {gradingform_rubric_levels} WHERE criterionid = ?)", array($draft->id, $rubricinfo->criterionid));
// Delete all records from the same criterion
foreach ($previouscomments as $prevcomment) {
    $DB->delete_records('emarking_comment', array('id' => $prevcomment->id));
    $removeid = $prevcomment->id;
}
/** transformation pixels screen to percentages **/
コード例 #13
0
ファイル: locallib.php プロジェクト: sikeze/emarking
/**
 *
 * @param unknown $submission
 * @param unknown $draft
 * @param unknown $emarking
 * @param unknown $context
 * @return unknown
 */
function emarking_update_comment($submission, $draft, $emarking, $context)
{
    global $CFG, $DB;
    require_once "{$CFG->dirroot}/grade/grading/form/rubric/lib.php";
    // Required and optional params for emarking.
    $userid = required_param('markerid', PARAM_INT);
    $commentid = required_param('cid', PARAM_INT);
    $commentrawtext = required_param('comment', PARAM_RAW_TRIMMED);
    $bonus = optional_param('bonus', -1, PARAM_FLOAT);
    $levelid = optional_param('levelid', 0, PARAM_INT);
    $format = optional_param('format', 2, PARAM_INT);
    $regradeid = optional_param('regradeid', 0, PARAM_INT);
    $regrademarkercomment = optional_param('regrademarkercomment', null, PARAM_RAW_TRIMMED);
    $regradeaccepted = optional_param('regradeaccepted', 0, PARAM_INT);
    $posx = required_param('posx', PARAM_INT);
    $posy = required_param('posy', PARAM_INT);
    // Measures the correction window.
    $winwidth = optional_param('windowswidth', '-1', PARAM_NUMBER);
    $winheight = optional_param('windowsheight', '-1', PARAM_NUMBER);
    if (!($comment = $DB->get_record('emarking_comment', array('id' => $commentid)))) {
        emarking_json_error("Invalid comment", array("id" => $commentid));
    }
    if ($regradeid > 0 && !($regrade = $DB->get_record('emarking_regrade', array('id' => $regradeid)))) {
        emarking_json_error("Invalid regrade", array("id" => $regradeid));
    }
    $previousbonus = $comment->bonus;
    $previouslvlid = $comment->levelid;
    $previouscomment = $comment->rawtext;
    if ($bonus < 0) {
        $bonus = $previousbonus;
    }
    if ($commentrawtext === 'delphi') {
        $commentrawtext = $previouscomment;
    }
    if ($previouslvlid > 0 && $levelid <= 0) {
        emarking_json_error("Invalid level id for a rubric id which has a previous level", array("id" => $commentid, "levelid" => $previouslvlid));
    }
    // Transformation pixels screen to percentages.
    if ($winheight != -1 && $winheight != -1) {
        $posx = $posx / $winwidth;
        $posy = $posy / $winheight;
        $comment->posx = $posx;
        $comment->posy = $posy;
    }
    $comment->id = $commentid;
    $comment->rawtext = $commentrawtext;
    $comment->bonus = $bonus;
    $comment->textformat = $format;
    $comment->levelid = $levelid;
    if ($previouslvlid != $levelid) {
        $comment->markerid = $userid;
    }
    $DB->update_record('emarking_comment', $comment);
    if ($regradeid == 0) {
        // Update draft correction time
        if ($draft->timecorrectionstarted == null) {
            $draft->timecorrectionstarted = time();
        }
        $draft->timecorrectionended = time();
        $DB->update_record('emarking_draft', $draft);
    }
    $diff = abs($previousbonus - $bonus);
    if ($comment->levelid > 0) {
        if ($diff > 0.01 || $previouslvlid != $levelid || $previouscomment !== $commentrawtext) {
            emarking_set_finalgrade($levelid, $commentrawtext, $submission, $draft, $emarking, $context, null);
        }
    }
    if ($regradeid > 0) {
        $regrade->markercomment = $regrademarkercomment;
        $regrade->timemodified = time();
        $regrade->accepted = $regradeaccepted;
        $DB->update_record('emarking_regrade', $regrade);
        if ($draft->timeregradingstarted == null) {
            $draft->timeregradingstarted = time();
        }
        $draft->timeregradingended = time();
        $DB->update_record("emarking_draft", $draft);
        $remainingregrades = $DB->count_records("emarking_regrade", array("draft" => $draft->id, "accepted" => 0));
        if ($remainingregrades == 0) {
            $draft->status = EMARKING_STATUS_REGRADING_RESPONDED;
            $draft->timemodified = time();
            $DB->update_record("emarking_draft", $draft);
        }
    }
    $results = emarking_get_submission_grade($draft);
    $newgrade = $results->finalgrade;
    return $newgrade;
}