/** * * @package mod * @subpackage emarking * @copyright 2015 Jorge Villalon <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function emarking_upload_answers($emarking, $filepath, $course, $cm) { global $CFG, $DB; require_once $CFG->dirroot . '/mod/emarking/lib/qrextractor/config.php'; $context = context_module::instance($cm->id); $exam = $DB->get_record('emarking_exams', array('emarking' => $emarking->id)); // Setup de directorios temporales. $tempdir = emarking_get_temp_dir_path($emarking->id); emarking_initialize_directory($tempdir, true); $extension = pathinfo($filepath, PATHINFO_EXTENSION); $filename = pathinfo($filepath, PATHINFO_FILENAME); if ($extension === 'zip') { if (!emarking_unzip($filepath, $tempdir . "/") || !$exam) { return array(false, get_string('errorprocessingextraction', 'mod_emarking'), 0, 0); } } elseif ($extension === 'pdf') { $command = 'java -jar ' . $CFG->dirroot . '/mod/emarking/lib/qrextractor/emarking.jar ' . $CFG->wwwroot . '/ ' . $CFG->emarking_qr_user . ' ' . $CFG->emarking_qr_password . ' ' . $filepath . ' ' . $tempdir . ' ' . $CFG->dirroot . '/mod/emarking/lib/qrextractor/log4j.properties'; if (isset($CFG->debug) && $CFG->debug >= 32767) { mtrace($command); } $lastline = exec($command, $output, $return_var); if ($return_var != 0) { $errormsg = $lastline; return array(false, $errormsg, 0, 0); } } $totaldocumentsprocessed = 0; $totaldocumentsignored = 0; // Read full directory, then start processing. clearstatcache(); $files = scandir($tempdir, SCANDIR_SORT_ASCENDING); $doubleside = false; $pngfiles = array(); foreach ($files as $fileintemp) { if (!is_dir($fileintemp) && strtolower(substr($fileintemp, -4, 4)) === ".jpg") { $pngfiles[] = $fileintemp; if (strtolower(substr($fileintemp, -5, 5)) === "b.jpg") { $doubleside = true; } } } $total = count($pngfiles); if ($total == 0) { return array(false, get_string('nopagestoprocess', 'mod_emarking'), 0, 0); } // Process files. for ($current = 0; $current < $total; $current++) { $file = $pngfiles[$current]; $filename = explode(".", $file); $updatemessage = $filename; $parts = explode("-", $filename[0]); $orphanpage = false; if (count($parts) != 3) { if ($CFG->debug) { echo "Ignoring {$file} as it has invalid name"; } $totaldocumentsignored++; continue; } $studentid = $parts[0]; $courseid = $parts[1]; $pagenumber = $parts[2]; // Now we process the files according to the emarking type. if ($emarking->type == EMARKING_TYPE_PRINT_ONLY || $emarking->type == EMARKING_TYPE_ON_SCREEN_MARKING || $emarking->type == EMARKING_TYPE_PRINT_SCAN || $emarking->type == EMARKING_TYPE_PEER_REVIEW) { if ($studentid === 'ERROR') { $orphanpage = true; } if ($courseid != $course->id) { $orphanpage = true; } $student = $DB->get_record('user', array('id' => $studentid)); if (!$student) { $orphanpage = true; } else { if ($student->deleted) { $orphanpage = true; } if (!is_enrolled($context, $student, "mod/emarking:submit")) { $orphanpage = true; } } if ($orphanpage) { emarking_submit_error_page($emarking, $context, $tempdir, $file, $pagenumber); $totaldocumentsignored++; continue; } } else { if ($emarking->type == EMARKING_TYPE_MARKER_TRAINING) { $student = new stdClass(); $student->id = $studentid; } else { $student = new stdClass(); $student->id = $studentid; } } // 1 pasa a 1 1 * 2 - 1 = 1. // 1b pasa a 2 1 * 2. // 2 pasa a 3 2 * 2 -1 = 3. // 2b pasa a 4 2 * 2. $anonymouspage = false; // First clean the page number if it's anonymous. if (substr($pagenumber, -2) === "_a") { $pagenumber = substr($pagenumber, 0, strlen($pagenumber) - 2); $anonymouspage = true; } if ($doubleside) { if (substr($pagenumber, -1) === "b") { // Detecta b. $pagenumber = intval($pagenumber) * 2; } else { $pagenumber = intval($pagenumber) * 2 - 1; } } if ($anonymouspage) { continue; } if (!is_numeric($pagenumber)) { if ($CFG->debug) { echo "Ignored file: {$filename['0']} page: {$pagenumber} student id: {$studentid} course id: {$courseid}"; } $totaldocumentsignored++; continue; } if (emarking_submit($emarking, $context, $tempdir, $file, $student, $pagenumber, NULL)) { $totaldocumentsprocessed++; } else { return array(false, get_string('invalidzipnoanonymous', 'mod_emarking'), $totaldocumentsprocessed, $totaldocumentsignored); } } if ($emarking->type == EMARKING_TYPE_PEER_REVIEW) { if (!emarking_assign_peers($emarking, 10)) { echo "Error assigning peers"; } } if ($exam->usebackside == 0 && $doubleside) { $exam->usebackside = 1; $result = $DB->update_record('emarking_exams', $exam); } emarking_send_processanswers_notification($emarking, $course); return array(true, get_string('invalidpdfnopages', 'mod_emarking'), $totaldocumentsprocessed, $totaldocumentsignored); }
// Check drafts being graded for reassigning peers. $sqlnumdraftsgrading = "\n\t SELECT COUNT(DISTINCT d.id) AS numdrafts\n\t\tFROM {emarking_draft} d\n\t\tINNER JOIN {emarking_submission} s ON (s.emarking = :emarking AND d.submissionid = s.id)\n \tWHERE d.status >= " . EMARKING_STATUS_GRADING; $numdraftsgrading = $DB->count_records_sql($sqlnumdraftsgrading, array("emarking" => $cm->instance)); } // Get all user which can mark in this activity. $markers = get_enrolled_users($context, 'mod/emarking:grade'); // Show header and heading. echo $OUTPUT->header(); // Heading and tabs if we are within a course module. echo $OUTPUT->heading($emarking->name); // Navigation tabs. $tabname = $scan ? "scanlist" : "mark"; echo $OUTPUT->tabtree(emarking_tabs($context, $cm, $emarking), $tabname); // Reassign peers if everything is ok with it. if ($reassignpeers && $usercangrade && $issupervisor && $numdraftsgrading == 0) { if (emarking_assign_peers($emarking)) { echo $OUTPUT->notification(get_string('transactionsuccessfull', 'mod_emarking'), 'notifysuccess'); } else { echo $OUTPUT->notification(get_string('fatalerror', 'mod_emarking'), 'notifyproblem'); } } // Get rubric instance. list($gradingmanager, $gradingmethod, $rubriccriteria, $rubriccontroller) = emarking_validate_rubric($context, $emarking->type == EMARKING_TYPE_MARKER_TRAINING || $emarking->type == EMARKING_TYPE_PEER_REVIEW, !$scan); // Show rubric creation button. // User filter checking capabilities. If user can not grade, then she can not. // see other users. $userfilter = 'WHERE 1=1 '; if (!$usercangrade) { $userfilter .= 'AND (u.id = ' . $USER->id . ' OR NM.answerkey = ' . EMARKING_ANSWERKEY_ACCEPTED . ')'; } else { if ($emarking->type == EMARKING_TYPE_MARKER_TRAINING && !is_siteadmin($USER->id) && !$issupervisor) {
function emarking_copy_peer_review($emarkingsrc, $emarkingdst) { global $DB, $OUTPUT; // This goes at the end as the emarking object is left unusable. echo $OUTPUT->box("Copying emarking settings, submission, pages and rubric"); $transaction = $DB->start_delegated_transaction(); try { emarking_copy_exam($emarkingsrc, $emarkingdst); emarking_match_rubrics($emarkingsrc, $emarkingdst, true); emarking_copy_predefined_comments($emarkingsrc, $emarkingdst); emarking_copy_submissions_drafts($emarkingsrc, $emarkingdst); emarking_assign_peers($emarkingdst); } catch (moodle_exception $exception) { $DB->rollback_delegated_transaction($transaction, $exception); return false; } $emarkingdst->copiedfromparent = 1; if (!$DB->update_record('emarking', $emarkingdst)) { $DB->rollback_delegated_transaction($transaction, new moodle_exception("Could not update emarking destination")); return false; } $DB->commit_delegated_transaction($transaction); echo $OUTPUT->box("Success!"); return true; }