static function load_question_settings() { $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; $question_id = isset($_REQUEST['question_id']) ? $_REQUEST['question_id'] : null; $options = array('ID' => $question_id); $question = LP_Question::instance($type, $options); $options = $question->get('options'); if (isset($options['type']) && $options['type'] == $type) { } else { unset($options['answer']); $question->set('options', $options); } $post_options = !empty($_REQUEST['options']) ? $_REQUEST['options'] : null; if ($type == 'single_choice') { $selected = -1; if ($post_options && $post_options['answer']) { foreach ($post_options['answer'] as $k => $option) { if (!empty($option['is_true'])) { $selected = $k; } $post_options['answer'][$k]['is_true'] = 0; } } if ($selected > -1) { $post_options['answer'][$selected]['is_true'] = 1; } } if ($post_options) { $question->set('options', $post_options); } $question->admin_interface(); die; }
function admin_script() { parent::admin_script(); ?> <script type="text/html" id="tmpl-dropdown-question-answer"> <tr> <td class="lpr-sortable-handle"> <i class="dashicons dashicons-sort"></i> </td> <td> <input type="hidden" name="lpr_question[{{data.question_id}}][answer][is_true][__INDEX__]" value="0" /> <input type="radio" data-group="lpr-question-answer-{{data.question_id}}" name="lpr_question[{{data.question_id}}][answer][is_true][__INDEX__]" value="1" /> </td> <td><input type="text" name="lpr_question[{{data.question_id}}][answer][text][__INDEX__]" value="" /></td> <td align="center"><span class=""><i class="dashicons dashicons-trash"></i></span> </td> </tr> </script> <?php }
function admin_script() { parent::admin_script(); ?> <script type="text/html" id="tmpl-multi-choice-question-answer"> <tr class="lpr-disabled"> <td class="lpr-sortable-handle"> <i class="dashicons dashicons-sort"></i> </td> <td class="lpr-is-true-answer"> <input type="hidden" name="lpr_question[{{data.question_id}}][answer][is_true][__INDEX__]" value="0" /> <input type="checkbox" name="lpr_question[{{data.question_id}}][answer][is_true][__INDEX__]" value="1" /> </td> <td> <input class="lpr-answer-text" type="text" name="lpr_question[{{data.question_id}}][answer][text][__INDEX__]" value="" /> </td> <td align="center" class="lpr-remove-answer"> <span class=""><i class="dashicons dashicons-trash"></i></span></td> </tr> </script> <?php }
static function save_quiz_questions($post_id) { learn_press_debug($_POST); die; static $has_updated; $questions = isset($_POST[LP()->question_post_type]) ? $_POST[LP()->question_post_type] : null; if (!$questions) { return; } $postmeta = array(); // prevent infinite loop with save_post action if ($has_updated) { return; } $has_updated = true; foreach ($questions as $question_id => $options) { $question = LP_Question::instance($question_id); if ($question) { $question_id = $question->save_post_action(); if ($question_id) { $postmeta[$question_id] = array('toggle' => $options['toggle']); if (!empty($options['type'])) { $post_data = get_post_meta($question_id, '_lpr_question', true); $post_data['type'] = $options['type']; update_post_meta($question_id, '_lpr_question', $post_data); } } } } update_post_meta($post_id, '_lpr_quiz_questions', $postmeta); }
function save($post_data = null) { parent::save($post_data); }
/** * Construct * @param mixed * @param array */ function __construct($the_question = null, $options = null) { parent::__construct($the_question, $options); }