本文整理汇总了PHP中question_engine::load_questions_usage_by_activity方法的典型用法代码示例。如果您正苦于以下问题:PHP question_engine::load_questions_usage_by_activity方法的具体用法?PHP question_engine::load_questions_usage_by_activity怎么用?PHP question_engine::load_questions_usage_by_activity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类question_engine
的用法示例。
在下文中一共展示了question_engine::load_questions_usage_by_activity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: print_error
if (!($course = $DB->get_record("course", array('id' => $offlinequiz->course)))) {
print_error("The course with id {$offlinequiz->course} that the offlinequiz with id {$offlinequiz->id} belongs to is missing");
}
if (!($cm = get_coursemodule_from_instance("offlinequiz", $offlinequiz->id, $course->id))) {
print_error("The course module for the offlinequiz with id {$offlinequiz->id} is missing");
}
// Can only grade finished results.
if ($result->status != 'complete') {
print_error('resultnotcomplete', 'offlinequiz');
}
// Check login and permissions.
require_login($course->id, false, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/offlinequiz:grade', $context);
// Load the questions needed by page.
if (!($quba = question_engine::load_questions_usage_by_activity($result->usageid))) {
print_error('Could not load question usage');
}
$slotquestion = $quba->get_question($slot);
// Print the page header.
$PAGE->set_pagelayout('popup');
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($slotquestion->name));
// Process any data that was submitted.
if (data_submitted() && confirm_sesskey()) {
if (optional_param('submit', false, PARAM_BOOL)) {
// Set the mark in the quba's slot.
$transaction = $DB->start_delegated_transaction();
$quba->process_all_actions(time());
question_engine::save_questions_usage_by_activity($quba);
$transaction->allow_commit();
示例2: display_grading_interface
protected function display_grading_interface($slot, $questionid, $grade, $pagesize, $page, $shownames, $showidnumbers, $order, $counts)
{
global $OUTPUT;
if ($pagesize * $page >= $counts->{$grade}) {
$page = 0;
}
list($qubaids, $count) = $this->get_usage_ids_where_question_in_state($grade, $slot, $questionid, $order, $page, $pagesize);
$attempts = $this->load_attempts_by_usage_ids($qubaids);
// Prepare the form.
$hidden = array('id' => $this->cm->id, 'mode' => 'grading', 'slot' => $slot, 'qid' => $questionid, 'page' => $page);
if (array_key_exists('includeauto', $this->viewoptions)) {
$hidden['includeauto'] = $this->viewoptions['includeauto'];
}
$mform = new quiz_grading_settings_form($hidden, $counts, $shownames, $showidnumbers);
// Tell the form the current settings.
$settings = new stdClass();
$settings->grade = $grade;
$settings->pagesize = $pagesize;
$settings->order = $order;
$mform->set_data($settings);
// Print the heading and form.
echo question_engine::initialise_js();
$a = new stdClass();
$a->number = $this->questions[$slot]->number;
$a->questionname = format_string($counts->name);
echo $OUTPUT->heading(get_string('gradingquestionx', 'quiz_grading', $a), 3);
echo html_writer::tag('p', html_writer::link($this->list_questions_url(), get_string('backtothelistofquestions', 'quiz_grading')), array('class' => 'mdl-align'));
$mform->display();
// Paging info.
$a = new stdClass();
$a->from = $page * $pagesize + 1;
$a->to = min(($page + 1) * $pagesize, $count);
$a->of = $count;
echo $OUTPUT->heading(get_string('gradingattemptsxtoyofz', 'quiz_grading', $a), 3);
if ($count > $pagesize && $order != 'random') {
echo $OUTPUT->paging_bar($count, $page, $pagesize, $this->grade_question_url($slot, $questionid, $grade, false));
}
// Display the form with one section for each attempt.
$sesskey = sesskey();
$qubaidlist = implode(',', $qubaids);
echo html_writer::start_tag('form', array('method' => 'post', 'action' => $this->grade_question_url($slot, $questionid, $grade, $page), 'class' => 'mform', 'id' => 'manualgradingform')) . html_writer::start_tag('div') . html_writer::input_hidden_params(new moodle_url('', array('qubaids' => $qubaidlist, 'slots' => $slot, 'sesskey' => $sesskey)));
foreach ($qubaids as $qubaid) {
$attempt = $attempts[$qubaid];
$quba = question_engine::load_questions_usage_by_activity($qubaid);
$displayoptions = quiz_get_review_options($this->quiz, $attempt, $this->context);
$displayoptions->hide_all_feedback();
$displayoptions->history = question_display_options::HIDDEN;
$displayoptions->manualcomment = question_display_options::EDITABLE;
$heading = $this->get_question_heading($attempt, $shownames, $showidnumbers);
if ($heading) {
echo $OUTPUT->heading($heading, 4);
}
echo $quba->render_question($slot, $displayoptions, $this->questions[$slot]->number);
}
echo html_writer::tag('div', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('saveandnext', 'quiz_grading'))), array('class' => 'mdl-align')) . html_writer::end_tag('div') . html_writer::end_tag('form');
}
示例3: __construct
/**
* Constructor assuming we already have the necessary data loaded.
*
* @param object $attempt the row of the quiz_attempts table.
* @param object $quiz the quiz object for this attempt and user.
* @param object $cm the course_module object for this quiz.
* @param object $course the row from the course table for the course we belong to.
* @param bool $loadquestions (optional) if true, the default, load all the details
* of the state of each question. Else just set up the basic details of the attempt.
*/
public function __construct($attempt, $quiz, $cm, $course, $loadquestions = true)
{
$this->attempt = $attempt;
$this->quizobj = new quiz($quiz, $cm, $course);
if (!$loadquestions) {
return;
}
$this->quba = question_engine::load_questions_usage_by_activity($this->attempt->uniqueid);
$this->determine_layout();
$this->number_questions();
}
示例4: __construct
/**
* Constructor assuming we already have the necessary data loaded.
*
* @param object $attempt the row of the quiz_attempts table.
* @param object $quiz the quiz object for this attempt and user.
* @param object $cm the course_module object for this quiz.
* @param object $course the row from the course table for the course we belong to.
* @param bool $loadquestions (optional) if true, the default, load all the details
* of the state of each question. Else just set up the basic details of the attempt.
*/
public function __construct($attempt, $quiz, $cm, $course, $loadquestions = true)
{
global $DB;
$this->attempt = $attempt;
$this->quizobj = new quiz($quiz, $cm, $course);
if (!$loadquestions) {
return;
}
$this->quba = question_engine::load_questions_usage_by_activity($this->attempt->uniqueid);
$this->slots = $DB->get_records('quiz_slots', array('quizid' => $this->get_quizid()), 'slot', 'slot, requireprevious, questionid');
$this->sections = array_values($DB->get_records('quiz_sections', array('quizid' => $this->get_quizid()), 'firstslot'));
$this->link_sections_and_slots();
$this->determine_layout();
$this->number_questions();
}
示例5: __construct
/**
* Constructor assuming we already have the necessary data loaded.
*
* @param object $attempt the row of the reader_attempts table.
* @param object $reader the reader object for this attempt and user.
* @param object $cm the course_module object for this reader.
* @param object $course the row from the course table for the course we belong to.
*/
public function __construct($attempt, $reader, $cm, $course)
{
$this->attempt = $attempt;
$this->readerobj = reader::create($reader->id, $attempt->userid, $attempt->quizid);
$this->quba = question_engine::load_questions_usage_by_activity($this->attempt->uniqueid);
$this->determine_layout();
$this->number_questions();
}
示例6: display
//.........这里部分代码省略.........
header("Content-Type: text/csv; charset=utf-8");
header("Content-Disposition: attachment; filename=\"{$filename}\"");
header("Expires: 0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Pragma: public");
echo "";
// UTF-8 BOM.
$headers = get_string($offlinequizconfig->ID_field) . ", " . get_string('fullname') . ", " . get_string('importedon', 'offlinequiz') . ", " . get_string('group') . ", " . get_string('grade', 'offlinequiz');
if (!empty($withparticipants)) {
$headers .= ", " . get_string('present', 'offlinequiz');
}
echo $headers . " \n";
} else {
if ($download == 'CSVplus1' || $download == 'CSVpluspoints') {
$filename .= ".csv";
header("Content-Encoding: UTF-8");
header("Content-Type: text/csv; charset=utf-8");
header("Content-Disposition: attachment; filename=\"{$filename}\"");
header("Expires: 0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Pragma: public");
echo "";
// UTF-8 BOM.
// Print the table headers.
echo get_string('firstname') . ',' . get_string('lastname') . ',' . get_string($offlinequizconfig->ID_field) . ',' . get_string('group');
$maxquestions = offlinequiz_get_maxquestions($offlinequiz, $groups);
for ($i = 0; $i < $maxquestions; $i++) {
echo ', ' . get_string('question') . ' ' . ($i + 1);
}
echo "\n";
// Print the correct answer bit-strings.
foreach ($groups as $group) {
if ($group->templateusageid) {
$quba = question_engine::load_questions_usage_by_activity($group->templateusageid);
$slots = $quba->get_slots();
echo ', ,' . get_string('correct', 'offlinequiz');
echo ',' . $group->number;
foreach ($slots as $slot) {
$slotquestion = $quba->get_question($slot);
$qtype = $slotquestion->get_type_name();
if ($qtype == 'multichoice' || $qtype == 'multichoiceset') {
$attempt = $quba->get_question_attempt($slot);
$order = $slotquestion->get_order($attempt);
// Order of the answers.
$tempstr = ",";
$letters = array();
$counter = 0;
foreach ($order as $key => $answerid) {
$fraction = $DB->get_field('question_answers', 'fraction', array('id' => $answerid));
if ($fraction > 0) {
$letters[] = $answerletters[$counter];
}
$counter++;
}
if (empty($letters)) {
$tempstr .= '99';
} else {
$tempstr .= implode('/', $letters);
}
echo $tempstr;
}
}
echo "\n";
}
}
}
示例7: question_preview_question_pluginfile
/**
* Called via pluginfile.php -> question_pluginfile to serve files belonging to
* a question in a question_attempt when that attempt is a preview.
*
* @param object $course course settings object
* @param object $context context object
* @param string $component the name of the component we are serving files for.
* @param string $filearea the name of the file area.
* @param int $qubaid the question_usage this image belongs to.
* @param int $slot the relevant slot within the usage.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @return bool false if file not found, does not return if found - justsend the file
*/
function question_preview_question_pluginfile($course, $context, $component, $filearea, $qubaid, $slot, $args, $forcedownload)
{
global $USER, $DB, $CFG;
$quba = question_engine::load_questions_usage_by_activity($qubaid);
if (!question_has_capability_on($quba->get_question($slot), 'use')) {
send_file_not_found();
}
$options = new question_display_options();
$options->feedback = question_display_options::VISIBLE;
$options->numpartscorrect = question_display_options::VISIBLE;
$options->generalfeedback = question_display_options::VISIBLE;
$options->rightanswer = question_display_options::VISIBLE;
$options->manualcomment = question_display_options::VISIBLE;
$options->history = question_display_options::VISIBLE;
if (!$quba->check_file_access($slot, $options, $component, $filearea, $args, $forcedownload)) {
send_file_not_found();
}
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/{$context->id}/{$component}/{$filearea}/{$relativepath}";
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
send_file_not_found();
}
send_stored_file($file, 0, 0, $forcedownload);
}
示例8: regrade_result
/**
* Regrade a particular offlinequiz result. Either for real ($dryrun = false), or
* as a pretend regrade to see which fractions would change. The outcome is
* stored in the offlinequiz_overview_regrades table.
*
* Note, $result is not upgraded in the database. The caller needs to do that.
* However, $result->sumgrades is updated, if this is not a dry run.
*
* @param object $result the offlinequiz result to regrade.
* @param bool $dryrun if true, do a pretend regrade, otherwise do it for real.
* @param array $slots if null, regrade all questions, otherwise, just regrade
* the quetsions with those slots.
*/
protected function regrade_result($result, $questions, $dryrun = false, $slots = null)
{
global $DB;
$transaction = $DB->start_delegated_transaction();
$quba = question_engine::load_questions_usage_by_activity($result->usageid);
if (is_null($slots)) {
$slots = $quba->get_slots();
}
$changed = false;
$finished = true;
foreach ($slots as $slot) {
$qqr = new stdClass();
$qqr->oldfraction = $quba->get_question_fraction($slot);
$slotquestion = $quba->get_question($slot);
$newmaxmark = $questions[$slotquestion->id]->maxmark;
$quba->regrade_question($slot, $finished, $newmaxmark);
$qqr->newfraction = $quba->get_question_fraction($slot);
if (abs($qqr->oldfraction - $qqr->newfraction) > 1.0E-7) {
$changed = true;
}
}
if (!$dryrun) {
question_engine::save_questions_usage_by_activity($quba);
}
$transaction->allow_commit();
return $changed;
}
示例9: enter_scantron_responses
/**
* Processes a set of Scantron-formatted responses, creating a quiz attempt, as though the user had entered these answers into Moodle directly.
*
* @param array $set An associative array of data read off of a Scantron form. Known to work for the scantron form 223127; likely works for others.
* @param bool $overwrite If set, imported responses will be allowed to overwrite existsing quiz attempts with the same unique id (QUBA id).
* @param bool $allow_cross_user If set, allows a quiz attempt to move from one user to another (i.e. if the student had entered in the wrong ID number.)
*/
protected function enter_scantron_responses($set, $overwrite = false, $allow_cross_user = false, $finish = true, $error_if_not_first = false, $force_first = false)
{
global $DB;
//if no usage ID has been specified, throw an exception
if (!array_key_exists('Special Codes', $set)) {
if (array_key_exists('Student Name', $set) || array_key_exists('ID', $set)) {
throw new quiz_papercopy_invalid_usage_id_exception();
} else {
throw new quiz_papercopy_benign_row_exception();
}
}
//get the usage ID from the Special Codes field on the scantron
$usage_id = intval($set['Special Codes']);
//get the ID for the attempt that would be created
$new_id = $this->user_id_from_scantron($set);
//if we need this to be the first attempt, check for an existing attempt by this user at the current quiz
if ($error_if_not_first || $force_first) {
//if an attempt exists with both this user_id and quiz ID
$existing_attempt = $DB->get_record('quiz_attempts', array('userid' => $new_id, 'quiz' => $this->quiz->id));
//if this isn't allowed to be a subsequent attempt, throw an exception
if ($error_if_not_first) {
throw new quiz_papercopy_not_first_attempt_when_required();
} elseif ($force_first) {
$DB->delete_records('quiz_attempts', array('userid' => $new_id, 'quiz' => $this->quiz->id));
}
}
//check for any attempt that uses this usage
$existing_record = $DB->get_record('quiz_attempts', array('uniqueid' => $usage_id), 'userid', IGNORE_MISSING);
//if one exists, handle the overwrite cases
if ($existing_record) {
//if we're trying to assign the same record to a different usage, and we haven't explicitly allowed cross-user overwrites, throw an exception
if ($new_id != $existing_record->userid && !$allow_cross_user) {
throw new quiz_papercopy_conflicting_users_exception();
}
//if overwrite is enabled, remove the existing attempt
if ($overwrite) {
$DB->delete_records('quiz_attempts', array('uniqueid' => $usage_id));
} else {
throw new quiz_papercopy_attempt_exists_exception();
}
}
try {
//get a usage object from the Special Codes usage ID
$usage = question_engine::load_questions_usage_by_activity($usage_id);
} catch (coding_exception $e) {
//if we couldn't load that usage, throw an "invalid usage id" error
throw new quiz_papercopy_invalid_usage_id_exception();
}
//get an associative array, which indicates the order in which questions were
$slots = $usage->get_slots();
//enter the student's answers for each of the questions
foreach ($slots as $slot) {
$letter2number = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4);
if (array_key_exists($set['Question' . $slot], $letter2number)) {
$set['Question' . $slot] = $letter2number[$set['Question' . $slot]];
}
$usage->process_action($slot, array('answer' => $set['Question' . $slot] - 1));
}
//set the attempt's owner to reflect the student who filled out the scantron
$target_user = $this->user_id_from_scantron($set);
//create a new attempt object, if requested, immediately close it, grading the attempt
// $attempt = $this->build_attempt_from_usage($usage, $target_user, $finish, true);
$attempt = $this->build_attempt_from_usage($usage, $target_user, true, true);
//return the user's grade and id, on success
return array('grade' => $attempt->sumgrades, 'user' => $attempt->userid);
}
示例10: offlinequiz_get_group_template_usage
/**
* Retrieves a template question usage for an offline group. Creates a new template if there is none.
* While creating question usage it shuffles the group questions if shuffleanswers is created.
*
* @param object $offlinequiz
* @param object $group
* @param object $context
* @return question_usage_by_activity
*/
function offlinequiz_get_group_template_usage($offlinequiz, $group, $context)
{
global $CFG, $DB;
if (!empty($group->templateusageid) && $group->templateusageid > 0) {
$templateusage = question_engine::load_questions_usage_by_activity($group->templateusageid);
} else {
$questionids = offlinequiz_get_group_question_ids($offlinequiz, $group->id);
if ($offlinequiz->shufflequestions) {
$offlinequiz->groupid = $group->id;
$questionids = offlinequiz_shuffle_questions($questionids);
}
// We have to use our own class s.t. we can use the clone function to create results.
$templateusage = offlinequiz_make_questions_usage_by_activity('mod_offlinequiz', $context);
$templateusage->set_preferred_behaviour('immediatefeedback');
if (!$questionids) {
print_error(get_string('noquestionsfound', 'offlinequiz'), 'view.php?q=' . $offlinequiz->id);
}
// Gets database raw data for the questions.
$questiondata = question_load_questions($questionids);
// Get the question instances for initial markmarks.
$sql = "SELECT questionid, maxmark\n FROM {offlinequiz_group_questions}\n WHERE offlinequizid = :offlinequizid\n AND offlinegroupid = :offlinegroupid ";
$groupquestions = $DB->get_records_sql($sql, array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $group->id));
foreach ($questionids as $questionid) {
if ($questionid) {
// Convert the raw data of multichoice questions to a real question definition object.
if (!$offlinequiz->shuffleanswers) {
$questiondata[$questionid]->options->shuffleanswers = false;
}
$question = question_bank::make_question($questiondata[$questionid]);
// We only add multichoice questions which are needed for grading.
if ($question->get_type_name() == 'multichoice' || $question->get_type_name() == 'multichoiceset') {
$templateusage->add_question($question, $groupquestions[$question->id]->maxmark);
}
}
}
// Create attempts for all questions (fixes order of the answers if shuffleanswers is active).
$templateusage->start_all_questions();
// Save the template question usage to the DB.
question_engine::save_questions_usage_by_activity($templateusage);
// Save the templateusage-ID in the offlinequiz_groups table.
$group->templateusageid = $templateusage->get_id();
$DB->set_field('offlinequiz_groups', 'templateusageid', $group->templateusageid, array('id' => $group->id));
}
// End else.
return $templateusage;
}
示例11: __construct
/**
* Construct the class. if a dbattempt object is passed in set it, otherwise initialize empty class
*
* @param questionmanager $questionmanager
* @param \stdClass
* @param \context_module $context
*/
public function __construct($questionmanager, $dbattempt = null, $context = null)
{
$this->questionmanager = $questionmanager;
$this->context = $context;
// if empty create new attempt
if (empty($dbattempt)) {
$this->attempt = new \stdClass();
// create a new quba since we're creating a new attempt
$this->quba = \question_engine::make_questions_usage_by_activity('mod_activequiz', $this->questionmanager->getRTQ()->getContext());
$this->quba->set_preferred_behaviour('immediatefeedback');
$attemptlayout = $this->questionmanager->add_questions_to_quba($this->quba);
// add the attempt layout to this instance
$this->attempt->qubalayout = implode(',', $attemptlayout);
} else {
// else load it up in this class instance
$this->attempt = $dbattempt;
$this->quba = \question_engine::load_questions_usage_by_activity($this->attempt->questionengid);
}
}
示例12: offlinequiz_check_result_completed
/**
* Checks whether a given result is complete, i.e. all contributing scanned pages have been submitted.
* Updates the result in the DB if it is complete. Also updates the scanned pages that were duplicates from
* 'doublepage' to 'resultexists'
*
* @param object $offlinequiz
* @param object $group
* @param object $result
* @return boolean
*/
function offlinequiz_check_result_completed($offlinequiz, $group, $result)
{
global $DB;
$resultpages = $DB->get_records_sql("SELECT *\n FROM {offlinequiz_scanned_pages}\n WHERE resultid = :resultid\n AND status = 'submitted'", array('resultid' => $result->id));
if (count($resultpages) == $group->numberofpages) {
$transaction = $DB->start_delegated_transaction();
$quba = question_engine::load_questions_usage_by_activity($result->usageid);
$quba->finish_all_questions(time());
$totalmark = $quba->get_total_mark();
question_engine::save_questions_usage_by_activity($quba);
$result->sumgrades = $totalmark;
$result->status = 'complete';
$result->timestart = time();
$result->timefinish = time();
$result->timemodified = time();
$DB->update_record('offlinequiz_results', $result);
$transaction->allow_commit();
offlinequiz_update_grades($offlinequiz, $result->userid);
// Change the error of all submitted pages of the result to '' (was 'missingpages' before).
foreach ($resultpages as $page) {
$DB->set_field('offlinequiz_scanned_pages', 'error', '', array('id' => $page->id));
}
// Change the status of all double pages of the user to 'resultexists'.
$offlinequizconfig = get_config('offlinequiz');
$user = $DB->get_record('user', array('id' => $result->userid));
$sql = "SELECT id\n FROM {offlinequiz_scanned_pages}\n WHERE offlinequizid = :offlinequizid\n AND userkey = :userkey\n AND groupnumber = :groupnumber\n AND error = 'doublepage'";
$params = array('offlinequizid' => $offlinequiz->id, 'userkey' => $user->{$offlinequizconfig->ID_field}, 'groupnumber' => $group->number);
$doublepages = $DB->get_records_sql($sql, $params);
foreach ($doublepages as $page) {
$DB->set_field('offlinequiz_scanned_pages', 'error', 'resultexists', array('id' => $page->id));
$DB->set_field('offlinequiz_scanned_pages', 'resultid', 0, array('id' => $page->id));
}
return true;
}
return false;
}
示例13: update_all_results_and_logs
public function update_all_results_and_logs($offlinequiz)
{
global $DB, $CFG;
$this->prevent_timeout();
// Now we have to migrate offlinequiz_attempts to offlinequiz_results because
// we need the new result IDs for the scannedpages.
// Get all attempts that have already been migrated to the new question engine.
$attempts = $DB->get_records('offlinequiz_attempts', array('offlinequiz' => $offlinequiz->id, 'needsupgradetonewqe' => 0, 'sheet' => 0));
$groups = $DB->get_records('offlinequiz_groups', array('offlinequizid' => $offlinequiz->id), 'number', '*', 0, $offlinequiz->numgroups);
list($maxquestions, $maxanswers, $formtype, $questionsperpage) = offlinequiz_get_question_numbers($offlinequiz, $groups);
$transaction = $DB->start_delegated_transaction();
foreach ($attempts as $attempt) {
$group = $DB->get_record('offlinequiz_groups', array('offlinequizid' => $offlinequiz->id, 'number' => $attempt->groupid));
$attemptlog = $DB->get_record('offlinequiz_i_log', array('offlinequiz' => $offlinequiz->id, 'attempt' => $attempt->id, 'page' => 0));
$result = new StdClass();
$result->offlinequizid = $offlinequiz->id;
if ($group) {
$result->offlinegroupid = $group->id;
}
$teacherid = $attemptlog->importadmin;
if (empty($teacherid)) {
$teacherid = 2;
}
$result->userid = $attempt->userid;
$result->sumgrades = $attempt->sumgrades;
$result->usageid = $attempt->uniqueid;
$result->teacherid = $teacherid;
$result->offlinegroupid = $group->id;
$result->status = 'complete';
$result->timestart = $attempt->timestart;
$result->timefinish = $attempt->timefinish;
$result->timemodified = $attempt->timemodified;
if (!($oldresult = $DB->get_record('offlinequiz_results', array('offlinequizid' => $result->offlinequizid, 'userid' => $result->userid)))) {
$result->id = $DB->insert_record('offlinequiz_results', $result);
} else {
$result->id = $oldresult->id;
$DB->update_record('offlinequiz_results', $result);
}
// Save the resultid, s.t. we can still reconstruct the data later.
$DB->set_field('offlinequiz_attempts', 'resultid', $result->id, array('id' => $attempt->id));
if ($quba = question_engine::load_questions_usage_by_activity($result->usageid)) {
$quba->finish_all_questions();
$slots = $quba->get_slots();
// Get all the page logs that have contributed to the attempt.
if ($group->numberofpages == 1) {
$pagelogs = array($attemptlog);
} else {
$sql = "SELECT *\n FROM {offlinequiz_i_log}\n WHERE offlinequiz = :offlinequizid\n AND attempt = :attemptid\n AND page > 0";
$params = array('offlinequizid' => $offlinequiz->id, 'attemptid' => $attempt->id);
$pagelogs = $DB->get_records_sql($sql, $params);
}
foreach ($pagelogs as $pagelog) {
$rawdata = $pagelog->rawdata;
$scannedpage = new StdClass();
$scannedpage->offlinequizid = $offlinequiz->id;
$scannedpage->resultid = $result->id;
$scannedpage->filename = $this->get_pic_name($rawdata);
$scannedpage->groupnumber = $this->get_group($rawdata);
$scannedpage->userkey = $this->get_user_name($rawdata);
if ($group->numberofpages == 1) {
$scannedpage->pagenumber = 1;
} else {
$scannedpage->pagenumber = $pagelog->page;
}
$scannedpage->time = $pagelog->time ? $pagelog->time : time();
$scannedpage->status = 'submitted';
$scannedpage->error = '';
$scannedpage->id = $DB->insert_record('offlinequiz_scanned_pages', $scannedpage);
$itemdata = $this->get_item_data($rawdata);
$items = explode(',', $itemdata);
if (!empty($items)) {
// Determine the slice of slots we are interested in.
// we start at the top of the page (e.g. 0, 96, etc).
$startindex = min(($scannedpage->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($scannedpage->pagenumber * $questionsperpage, count($slots));
$questioncounter = 0;
for ($slotindex = $startindex; $slotindex < $endindex; $slotindex++) {
$slot = $slots[$slotindex];
if (array_key_exists($questioncounter, $items)) {
$item = $items[$questioncounter];
for ($key = 0; $key < strlen($item); $key++) {
$itemchoice = substr($item, $key, 1);
$choice = new stdClass();
$choice->scannedpageid = $scannedpage->id;
$choice->slotnumber = $slot;
$choice->choicenumber = $key;
if ($itemchoice == '1') {
$choice->value = 1;
} else {
if ($itemchoice == '0') {
$choice->value = 0;
} else {
$choice->value = -1;
}
}
$choice->id = $DB->insert_record('offlinequiz_choices', $choice);
}
}
$questioncounter++;
//.........这里部分代码省略.........
示例14: quiz_attempt_stepone
private static function quiz_attempt_stepone($attempt, $lastattempt, $quizobj, $timenow, $quba, $attemptnumber)
{
//global $CFG, $DB;
if (!($quizobj->get_quiz()->attemptonlast && $lastattempt)) {
// Starting a normal, new, quiz attempt.
// Fully load all the questions in this quiz.
$quizobj->preload_questions();
$quizobj->load_questions();
// Add them all to the $quba.
$questionsinuse = array_keys($quizobj->get_questions());
self::quiz_question_process($attempt, $quizobj, $quba, $questionsinuse, $attemptnumber, $timenow);
} else {
// Starting a subsequent attempt in each attempt builds on last mode.
$oldquba = question_engine::load_questions_usage_by_activity($lastattempt->uniqueid);
$oldnumberstonew = array();
foreach ($oldquba->get_attempt_iterator() as $oldslot => $oldqa) {
$newslot = $quba->add_question($oldqa->get_question(), $oldqa->get_max_mark());
$quba->start_question_based_on($newslot, $oldqa);
$oldnumberstonew[$oldslot] = $newslot;
}
}
}
示例15: question_preview_options
// Get and validate display options.
$maxvariant = $question->get_num_variants();
$options = new question_preview_options($question);
$options->load_user_defaults();
$options->set_from_request();
$PAGE->set_url(question_preview_url($id, $options->behaviour, $options->maxmark, $options));
// Get and validate exitsing preview, or start a new one.
$previewid = optional_param('previewid', 0, PARAM_INT);
if ($previewid) {
if (!isset($SESSION->question_previews[$previewid])) {
print_error('notyourpreview', 'question');
}
try {
$quba = question_engine::load_questions_usage_by_activity($previewid);
} catch (Exception $e) {
print_error('submissionoutofsequencefriendlymessage', 'question',
question_preview_url($question->id, $options->behaviour,
$options->maxmark, $options), null, $e);
}
$slot = $quba->get_first_question_number();
$usedquestion = $quba->get_question($slot);
if ($usedquestion->id != $question->id) {
print_error('questionidmismatch', 'question');
}
$question = $usedquestion;
$options->variant = $quba->get_variant($slot);
} else {
$quba = question_engine::make_questions_usage_by_activity('core_question_preview',