/** * (non-PHPdoc) * @see moodleform_mod::data_preprocessing() */ public function data_preprocessing(&$toform) { if (!empty($this->_feedbacks)) { $key = 0; foreach ($this->_feedbacks as $feedback) { $toform['feedbacktext[' . $key . ']'] = $feedback->feedbacktext; if ($feedback->mingrade > 0) { $toform['feedbackboundaries[' . $key . ']'] = 100.0 * $feedback->mingrade / $toform['grade'] . '%'; } $key++; } } // Set the pdfintro text. if ($this->current->instance) { if (!$toform['docscreated']) { // Editing an existing pdfintro - let us prepare the added editor elements (intro done automatically). $draftitemid = file_get_submitted_draft_itemid('pdfintro'); $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_offlinequiz', 'pdfintro', false, offlinequiz_get_editor_options($this->context), $toform['pdfintro']); // $default_values['pdfintro']['format'] = $default_values['pdfintro']; $toform['pdfintro'] = array(); $toform['pdfintro']['text'] = $text; $toform['pdfintro']['format'] = editors_get_preferred_format(); $toform['pdfintro']['itemid'] = $draftitemid; } } else { // Adding a new feedback instance. $draftitemid = file_get_submitted_draft_itemid('pdfintro'); // No context yet, itemid not used. file_prepare_draft_area($draftitemid, null, 'mod_offlinequiz', 'pdfintro', false); $toform['pdfintro'] = array(); $toform['pdfintro']['text'] = get_string('pdfintrotext', 'offlinequiz'); $toform['pdfintro']['format'] = editors_get_preferred_format(); $toform['pdfintro']['itemid'] = $draftitemid; } if (empty($toform['timelimit'])) { $toform['timelimitenable'] = 0; } else { $toform['timelimitenable'] = 1; } if (isset($toform['review'])) { $review = (int) $toform['review']; unset($toform['review']); $toform['attemptclosed'] = $review & OFFLINEQUIZ_REVIEW_ATTEMPT; $toform['correctnessclosed'] = $review & OFFLINEQUIZ_REVIEW_CORRECTNESS; $toform['marksclosed'] = $review & OFFLINEQUIZ_REVIEW_MARKS; $toform['specificfeedbackclosed'] = $review & OFFLINEQUIZ_REVIEW_SPECIFICFEEDBACK; $toform['generalfeedbackclosed'] = $review & OFFLINEQUIZ_REVIEW_GENERALFEEDBACK; $toform['rightanswerclosed'] = $review & OFFLINEQUIZ_REVIEW_RIGHTANSWER; $toform['sheetclosed'] = $review & OFFLINEQUIZ_REVIEW_SHEET; $toform['gradedsheetclosed'] = $review & OFFLINEQUIZ_REVIEW_GRADEDSHEET; } }
/** * Given an object containing all the necessary data, * (defined by the form in mod_form.php) this function * will update an existing instance with new data. * * @param object $offlinequiz An object from the form in mod_form.php * @return boolean Success/Fail */ function offlinequiz_update_instance($offlinequiz) { global $DB, $CFG; require_once $CFG->dirroot . '/mod/offlinequiz/locallib.php'; $offlinequiz->timemodified = time(); $offlinequiz->id = $offlinequiz->instance; // Remember the old values of the shuffle settings. $shufflequestions = $DB->get_field('offlinequiz', 'shufflequestions', array('id' => $offlinequiz->id)); $shuffleanswers = $DB->get_field('offlinequiz', 'shuffleanswers', array('id' => $offlinequiz->id)); // Process the options from the form. $result = offlinequiz_process_options($offlinequiz); if ($result && is_string($result)) { return $result; } $context = context_module::instance($offlinequiz->coursemodule); // Process the HTML editor data in pdfintro. if (property_exists($offlinequiz, 'pdfintro') && is_array($offlinequiz->pdfintro) && array_key_exists('text', $offlinequiz->pdfintro)) { if ($draftitemid = $offlinequiz->pdfintro['itemid']) { $editoroptions = offlinequiz_get_editor_options(); $offlinequiz->pdfintro = file_save_draft_area_files($draftitemid, $context->id, 'mod_offlinequiz', 'pdfintro', 0, $editoroptions, $offlinequiz->pdfintro['text']); } // $offlinequiz->pdfintro = $feedback->pdfintro['format']; } // Update the database. if (!$DB->update_record('offlinequiz', $offlinequiz)) { return false; // Some error occurred. } // Do the processing required after an add or an update. offlinequiz_after_add_or_update($offlinequiz); // We also need the docscreated and the numgroups field. $offlinequiz = $DB->get_record('offlinequiz', array('id' => $offlinequiz->id)); // Delete the question usage templates if no documents have been created and no answer forms have been scanned. if (!$offlinequiz->docscreated && !offlinequiz_has_scanned_pages($offlinequiz->id)) { offlinequiz_delete_template_usages($offlinequiz); } return true; }