public function save($option_number = 0) { if ($this->_question->get_max_experts() == 0) { $this->set_marks_correct(0); } else { $this->set_marks_correct($this->correct / $this->_question->get_max_experts()); } return parent::save($option_number); }
function save_options($question, $userObject, $db) { $unified_part_names = $question->get_unified_fields(); for ($option_no = 1; $option_no <= $question->max_options; $option_no++) { $option = null; if (isset($_POST["optionid{$option_no}"]) and $_POST["optionid{$option_no}"] != -1) { // Editing existing option $option = $question->options[$_POST["optionid{$option_no}"]]; $part_names = $option->get_editable_fields(); // Build arrays for compound fields $compound_fields = $option->get_compound_fields(); if (!isset($existing_values)) { $existing_values = array(); } $option->populate_compound(array_keys($compound_fields), $_POST, $existing_values, 'option_'); // Save editable fields that aren't unified $option->populate($part_names, $option_no, $_POST, array_merge(array_keys($unified_part_names), array_keys($compound_fields)), 'option_'); // Save fields that are the same across options $option->populate_unified($unified_part_names, $_POST, array_keys($compound_fields), 'option_'); } else { // Create new option if have required data $option = OptionEdit::option_factory($db, $userObject->get_user_ID(), $question, $option_no, $string, array('marks' => 1)); if ($option->minimum_fields_exist($_POST, $_FILES, $option_no)) { $correct_fb = isset($_POST["option_correct_fback{$option_no}"]) ? $_POST["option_correct_fback{$option_no}"] : ''; $incorrect_fb = isset($_POST["option_incorrect_fback{$option_no}"]) ? $_POST["option_incorrect_fback{$option_no}"] : ''; $part_names = $option->get_editable_fields(); // Build arrays for compound fields $compound_fields = $option->get_compound_fields(); if (!isset($existing_values)) { $existing_values = array(); } $option->populate_compound(array_keys($compound_fields), $_POST, $existing_values, 'option_'); // Save editable fields that aren't unified $option->populate($part_names, $option_no, $_POST, array_merge(array_keys($unified_part_names), array_keys($compound_fields)), 'option_'); // Save fields that are the same across options $option->populate_unified($unified_part_names, $_POST, array_keys($compound_fields), 'option_', false); $question->options[] = $option; } } if ($option != null and !in_array('media', $question->get_compound_fields())) { // Handle changes in media $old_media = $option->get_media(); if (isset($_FILES["option_media{$option_no}"]) and $_FILES["option_media{$option_no}"]['name'] != $old_media['filename'] and ($_FILES["option_media{$option_no}"]['name'] != 'none' and $_FILES["option_media{$option_no}"]['name'] != '')) { if ($old_media['filename'] != '') { deleteMedia($old_media['filename']); } $option->set_media(uploadFile("option_media{$option_no}")); } else { // Delete existing media if asked if (isset($_POST["delete_media{$option_no}"]) and $_POST["delete_media{$option_no}"] == 'on') { deleteMedia($old_media['filename']); $option->set_media(array('filename' => '', 'width' => 0, 'height' => 0)); } } } } }
/** * @param string $value */ public function set_correct($value) { if (strpos($value, ';') !== false) { $tmp = explode(';', $value); $value = $tmp[1]; } $value = rtrim($value, ', '); parent::set_correct($value); }
<tr> <th colspan="2"> </th> <th class="small align-centre"><strong><?php echo $string['answer']; ?> </strong></th> </tr> </thead> <?php $index = 1; foreach ($question->options as $o_id => $option) { include 'options/opt_dichotomous.php'; $index++; } for ($index = $num_options + 1; $index <= $question->max_options; $index++) { $option = OptionEdit::option_factory($mysqli, $userObject->get_user_ID(), $question, $index, $string); include 'options/opt_dichotomous.php'; } if ($question->get_locked() == '') { ?> <tbody class="add-option-holder"> <tr> <th> </th> <td colspan="2"> <input class="next-option" value="<?php echo $string['addoptions']; ?> " type="button" /> </td> </tr> </tbody>
/** * Get the actual data for the question and its options */ private function get_question() { // Get the question $found = 0; $success = false; $q_query = <<<QUERY SELECT q_type, theme, scenario, scenario_plain, leadin, leadin_plain, notes, correct_fback, incorrect_fback, score_method, display_method, q_option_order, std, bloom, ownerID, q_media, q_media_width, q_media_height, checkout_time, checkout_authorID, creation_date, last_edited, locked, deleted, status, settings, guid FROM questions WHERE q_id = ? QUERY; $result = $this->_mysqli->prepare($q_query); $result->bind_param('i', $this->id); $result->execute(); $result->store_result(); call_user_func_array(array($result, 'bind_result'), $this->_data); if ($result->fetch()) { $success = true; $found = $result->num_rows; } $result->close(); $this->unserialize_settings(); if ($found > 0) { //get the question modules $t_query = <<<QUERY SELECT idMod, moduleId FROM questions_modules, modules WHERE q_id = ? AND questions_modules.idMod = modules.id QUERY; $result = $this->_mysqli->prepare($t_query); $result->bind_param('i', $this->id); $result->execute(); $result->store_result(); $result->bind_result($idMod, $moduleId); while ($success = $result->fetch()) { $this->teams[$idMod] = $moduleId; } $result->close(); // Build array of references to option data for use in call_user_func_array $opt_fields = OptionEdit::get_field_array(); $opt_data = array(); $params = array(); $params[] =& $opt_data['id']; foreach ($opt_fields as $field) { $params[] =& $opt_data[$field]; } // Get the options $o_query = <<<QUERY SELECT id_num, o_id, option_text, o_media, o_media_width, o_media_height, feedback_right, feedback_wrong, correct, marks_correct, marks_incorrect, marks_partial FROM options WHERE o_id = ? ORDER BY id_num ASC QUERY; $result = $this->_mysqli->prepare($o_query); $result->bind_param('i', $this->id); $result->execute(); $result->store_result(); call_user_func_array(array($result, 'bind_result'), $opt_data); // TODO: handle 'correctness' more nicely $i = 1; while ($success = $result->fetch()) { $this->options[$opt_data['id']] = OptionEdit::option_factory($this->_mysqli, $this->_user_id, $this, $i, $this->_lang_strings, $opt_data); $i++; } $result->close(); } else { throw new RecordNotFoundException(sprintf($this->_lang_strings['norecorderror'], $this->id)); } return $success !== false; }
/** * Ensure that text is in correct format before calling parent save() function * @return integer */ public function save($option_number = 0) { $this->set_text('dummy'); return parent::save($option_number); }