コード例 #1
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;
}
コード例 #2
0
ファイル: a.php プロジェクト: hansnok/emarking
     $nextsubmission = emarking_get_next_submission($emarking, $draft, $context, $user, $issupervisor);
     emarking_json_array(array('nextsubmission' => $nextsubmission));
     break;
 case 'setanswerkey':
     $status = required_param('status', PARAM_INT);
     $newvalue = emarking_set_answer_key($submission, $status);
     emarking_json_array(array('newvalue' => $newvalue));
     break;
 case 'getmoodleresources':
     break;
 case 'getrubric':
     $results = emarking_get_rubric_submission($submission, $draft, $cm, $readonly, $issupervisor);
     emarking_json_resultset($results);
     break;
 case 'getsubmission':
     $results = emarking_get_submission_grade($draft);
     $output = $results;
     $output->coursemodule = $cm->id;
     $output->markerfirstname = $USER->firstname;
     $output->markerlastname = $USER->lastname;
     $output->markeremail = $USER->email;
     $output->markerid = $USER->id;
     $results = emarking_get_rubric_submission($submission, $draft, $cm, $readonly, $issupervisor);
     $output->rubric = $results;
     $results = emarking_get_answerkeys_submission($submission);
     $output->answerkeys = $results;
     emarking_json_array($output);
     break;
 case 'getchathistory':
     $output = emarking_get_chat_history();
     emarking_json_array($output);
コード例 #3
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;
}