$corners = array(); foreach ($dbcorners as $corner) { $corners[] = new oq_point($corner->x, $corner->y); } // Initialize a page scanner. $scanner = new offlinequiz_page_scanner($offlinequiz, $context->id, $maxquestions, $maxanswers); // Load the stored picture file. $sheetloaded = $scanner->load_stored_image($scannedpage->filename, $corners); $pagenumber = $scannedpage->pagenumber; // Make a first check. $scanner->check_deleted(); $scanner->calibrate_and_get_group(); $scanner->get_usernumber(); $scanner->get_page(); // Necessary s.t. we can get the answer hotspots from the scanner. $scanner->set_page($pagenumber); $quba = question_engine::load_questions_usage_by_activity($result->usageid); $slots = $quba->get_slots(); // Determine the slice of slots we are interested in. // We start at the top of the page (e.g. 0, 96, etc). $startindex = min(($pagenumber - 1) * $questionsperpage, count($slots)); // We end on the bottom of the page or when the questions are gone (e.g., 95, 105). $endindex = min($pagenumber * $questionsperpage, count($slots)); // Load the choices made before from the database. There might not be any. $choices = $DB->get_records('offlinequiz_choices', array('scannedpageid' => $scannedpage->id), 'slotnumber, choicenumber'); // Choicesdata contains the choices data from the DB indexed by slotnumber and choicenumber. $choicesdata = array(); if (!empty($choices)) { foreach ($choices as $choice) { if (!isset($choicesdata[$choice->slotnumber]) || !is_array($choicesdata[$choice->slotnumber])) { $choicesdata[$choice->slotnumber] = array();