Пример #1
0
/**
 * Removes all grades from gradebook
 *
 * @param int $courseid
 *            The ID of the course to reset
 * @param string $type
 *            Optional type of assignment to limit the reset to a particular assignment type
 */
function emarking_reset_gradebook($courseid, $type = '')
{
    global $CFG, $DB;
    $params = array('moduletype' => 'emarking', 'courseid' => $courseid);
    $sql = 'SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid
            FROM {assign} a, {course_modules} cm, {modules} m
            WHERE m.name=:moduletype AND m.id=cm.module AND cm.instance=a.id AND a.course=:courseid';
    if ($emarkings = $DB->get_records_sql($sql, $params)) {
        foreach ($emarkings as $emarking) {
            emarking_grade_item_update($emarking, 'reset');
        }
    }
}
Пример #2
0
 private function create_marker_module($markerid)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/lib/phpunit/classes/util.php';
     // Start transaction.
     $transaction = $DB->start_delegated_transaction();
     try {
         // Get generator.
         $generator = phpunit_util::get_data_generator();
         /**@var mod_emarking_generator $emarking_generator*/
         $emarking_generator = $generator->get_plugin_generator('mod_emarking');
         $blueprint = $DB->get_record('emarking', array("id" => $this->cm->instance));
         $blueprint->timecreated = time();
         $originalname = $blueprint->name;
         $markers = get_users_by_capability($this->context, 'mod/emarking:grade', 'u.id,u.username');
         $marker = $markers[$markerid];
         if (!$marker) {
             throw new Exception("Marker not found");
         }
         $previous = $DB->get_record('emarking_markers', array('masteractivity' => $this->parentcm->instance, 'markerid' => $markerid));
         if ($previous) {
             throw new Exception("Delete previous marker record before assigning a new one");
         }
         $submissions = $DB->get_records('emarking_submission', array("emarking" => $this->cm->instance));
         $pages = array();
         foreach ($submissions as $sub) {
             $pages[$sub->id] = $DB->get_records('emarking_page', array("submission" => $sub->id));
         }
         unset($blueprint->id);
         $blueprint->name = $originalname . " -- " . $marker->username;
         $inserted = $emarking_generator->create_instance($blueprint, array("visible" => 0));
         $markermap = new stdClass();
         $markermap->masteractivity = $this->parentcm->instance;
         $markermap->markerid = $marker->id;
         $markermap->activityid = $inserted->id;
         $DB->insert_record('emarking_markers', $markermap);
         // se agrega el grading method correcto.
         require_once $CFG->dirroot . '/grade/grading/lib.php';
         $gradingman = get_grading_manager(context_module::instance($inserted->cmid), 'mod_emarking');
         $gradingman->set_area("attempt");
         $gradingman->set_active_method("rubric");
         emarking_grade_item_update($inserted);
         //Now replicate submissions
         foreach ($submissions as $sub) {
             $insertable = clone $sub;
             unset($insertable->id);
             $insertable->emarking = $inserted->id;
             $id = $DB->insert_record('emarking_submission', $insertable);
             foreach ($pages[$sub->id] as $subpage) {
                 $insertablepage = clone $subpage;
                 unset($insertablepage->id);
                 $insertablepage->submission = $id;
                 $DB->insert_record('emarking_page', $insertablepage);
             }
             // Update the raw grade of the user
             $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'emarking', 'iteminstance' => $inserted->id));
             $grade = $grade_item->get_grade($insertable->student, true);
             $grade_item->update_final_grade($insertable->student, null, 'upload', '', FORMAT_HTML, $marker->id);
             // grade
         }
         $transaction->allow_commit();
     } catch (Exception $e) {
         $transaction->rollback($e);
     }
 }
Пример #3
0
/**
 * Saves a new instance of the emarking into the database
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will create a new instance and return the id number
 * of the new instance.
 *
 * @param object $emarking
 *        	An object from the form in mod_form.php
 * @param mod_emarking_mod_form $mform        	
 * @return int The id of the newly inserted emarking record
 */
function emarking_add_instance(stdClass $data, $itemid, mod_emarking_mod_form $mform = null)
{
    global $DB, $CFG, $COURSE, $USER;
    $data->timecreated = time();
    $id = $DB->insert_record('emarking', $data);
    $data->id = $id;
    $course = $data->course;
    emarking_grade_item_update($data);
    foreach ($data as $k => $v) {
        $parts = explode('-', $k);
        if (count($parts) > 1 && $parts[0] === 'marker') {
            $markerid = intval($parts[1]);
            $marker = new stdClass();
            $marker->emarking = $id;
            $marker->marker = $markerid;
            $marker->qualitycontrol = 1;
            $DB->insert_record('emarking_markers', $marker);
        }
    }
    // entregar id del curso
    $context = context_course::instance($course);
    $examid = 0;
    // If there's no previous exam to associate, and we are creating a new
    // EMarking, we need the PDF file.
    if ($data->exam == 0) {
        $examfiles = emarking_validate_exam_files_from_draft($itemid);
        if (count($examfiles) == 0) {
            throw new Exception('Invalid PDF exam files');
        }
        $numpages = $examfiles[0]['numpages'];
    } else {
        $examid = $data->exam;
    }
    $studentsnumber = emarking_get_students_count_for_printing($course);
    // A new exam object is created and its attributes filled from form data.
    if ($examid == 0) {
        $exam = new stdClass();
        $exam->course = $course;
        $exam->courseshortname = $COURSE->shortname;
        $exam->name = "a";
        $exam->examdate = time();
        $exam->emarking = $id;
        $exam->headerqr = 1;
        $exam->printrandom = 0;
        $exam->printlist = 0;
        $exam->extrasheets = 0;
        $exam->extraexams = 0;
        $exam->usebackside = 0;
        if ($examid == 0) {
            $exam->timecreated = time();
        }
        $exam->timemodified = time();
        $exam->requestedby = $USER->id;
        $exam->totalstudents = $studentsnumber;
        $exam->comment = "comment";
        // Get the enrolments as a comma separated values.
        $exam->enrolments = "manual";
        $exam->printdate = 0;
        $exam->status = 10;
        // Calculate total pages for exam.
        $exam->totalpages = 2;
        $exam->printingcost = emarking_get_category_cost($course);
        $exam->id = $DB->insert_record('emarking_exams', $exam);
        $fs = get_file_storage();
        foreach ($examfiles as $exampdf) {
            // Save the submitted file to check if it's a PDF.
            $filerecord = array('component' => 'mod_emarking', 'filearea' => 'exams', 'contextid' => $context->id, 'itemid' => $exam->id, 'filepath' => '/', 'filename' => $exampdf['filename']);
            $file = $fs->create_file_from_pathname($filerecord, $exampdf['pathname']);
        }
        // Update exam object to store the PDF's file id.
        $exam->file = $file->get_id();
        if (!$DB->update_record('emarking_exams', $exam)) {
            $fs->delete_area_files($contextid, 'emarking', 'exams', $exam->id);
            print_error(get_string('errorsavingpdf', 'mod_emarking'));
        }
    } else {
        $exam = $DB->get_record("emarking_exams", array("id" => $examid));
        $exam->emarking = $id;
        $exam->timemodified = time();
        $DB->update_record('emarking_exams', $exam);
    }
    $headerqr = 1;
    setcookie("emarking_headerqr", $headerqr, time() + 3600 * 24 * 365 * 10, '/');
    $defaultexam = new stdClass();
    $defaultexam->headerqr = $exam->headerqr;
    $defaultexam->printrandom = $exam->printrandom;
    $defaultexam->printlist = $exam->printlist;
    $defaultexam->extrasheets = $exam->extrasheets;
    $defaultexam->extraexams = $exam->extraexams;
    $defaultexam->usebackside = $exam->usebackside;
    $defaultexam->enrolments = $exam->enrolments;
    setcookie("emarking_exam_defaults", json_encode($defaultexam), time() + 3600 * 24 * 365 * 10, '/');
    return $id;
}