get_var( $wpdb->prepare( "SELECT quiz_name FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id=%d LIMIT 1", $quiz_id ) ); if ( is_null( $quiz_name ) ) { return false; } global $mlwQuizMasterNext; $mlwQuizMasterNext->quizCreator->set_id( $quiz_id ); $mlwQuizMasterNext->quiz_settings->prepare_quiz( $quiz_id ); return True; } /** * Retrieves all quizzes. * * @param bool $include_deleted If set to true, returned array will include all deleted quizzes * @param string $order_by The column the quizzes should be ordered by * @param string $order whether the $order_by should be ordered as ascending or decending. Can be "ASC" or "DESC" * @return array All of the quizzes as a numerical array of objects */ public function get_quizzes( $include_deleted = false, $order_by = 'quiz_id', $order = 'DESC' ) { global $wpdb; // Set order direction $order_direction = 'DESC'; if ( 'ASC' == $order ) { $order_direction = 'ASC'; } // Set field to sort by switch ( $order_by ) { case 'last_activity': $order_field = 'last_activity'; break; case 'quiz_views': $order_field = 'quiz_views'; break; case 'quiz_taken': $order_field = 'quiz_taken'; break; default: $order_field = 'quiz_id'; break; } // Should we include deleted? $delete = "WHERE deleted='0'"; if ( $include_deleted ) { $delete = ''; } // Get quizzes and return them $quizzes = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}mlw_quizzes $delete ORDER BY $order_field $order_direction" ); return $quizzes; } /** * Registers a quiz setting * * @since 5.0.0 * @param array $field_array An array of the components for the settings field */ public function register_quiz_setting( $field_array, $section = 'quiz_options' ) { global $mlwQuizMasterNext; $mlwQuizMasterNext->quiz_settings->register_setting( $field_array, $section ); } /** * Retrieves a setting value from a section based on name of section and setting * * @since 5.0.0 * @param string $section The name of the section the setting is registered in * @param string $setting The name of the setting whose value we need to retrieve * @param mixed $default What we need to return if no setting exists with given $setting * @return $mixed Value set for $setting or $default if setting does not exist */ public function get_section_setting( $section, $setting, $default = false ) { global $mlwQuizMasterNext; return $mlwQuizMasterNext->quiz_settings->get_section_setting( $section, $setting, $default ); } /** * Retrieves setting value based on name of setting * * @since 4.0.0 * @param string $setting The name of the setting whose value we need to retrieve * @param mixed $default What we need to return if no setting exists with given $setting * @return $mixed Value set for $setting or $default if setting does not exist */ public function get_quiz_setting( $setting, $default = false ) { global $mlwQuizMasterNext; return $mlwQuizMasterNext->quiz_settings->get_setting( $setting, $default ); } /** * Updates a settings value, adding it if it didn't already exist * * @since 4.0.0 * @param string $setting The name of the setting whose value we need to retrieve * @param mixed $value The value that needs to be stored for the setting * @return bool True if successful or false if fails */ public function update_quiz_setting( $setting, $value ) { global $mlwQuizMasterNext; return $mlwQuizMasterNext->quiz_settings->update_setting( $setting, $value ); } /** * Outputs the section of input fields * * @since 5.0.0 * @param string $section The section that the settings were registered with */ public function generate_settings_section( $section = 'quiz_options' ) { global $mlwQuizMasterNext; QSM_Fields::generate_section( $mlwQuizMasterNext->quiz_settings->load_setting_fields( $section ), $section ); } /** * Registers Quiz Templates * * @since 4.5.0 * @param $name String of the name of the template * @param $file_path String of the path to the css file */ public function register_quiz_template( $name, $file_path ) { $slug = strtolower(str_replace( " ", "-", $name)); $this->quiz_templates[$slug] = array( "name" => $name, "path" => $file_path ); } /** * Returns Template Array * * @since 4.5.0 * @param $name String of the name of the template. If left empty, will return all templates * @return array The array of quiz templates */ public function get_quiz_templates( $slug = null ) { if ( is_null( $slug ) ) { return $this->quiz_templates; } elseif ( isset( $this->quiz_templates[$slug] ) ) { return $this->quiz_templates[$slug]; } else { return false; } } /** * Register Question Types * * Adds a question type to the question type array using the parameters given * * @since 4.0.0 * @param string $name The name of the Question Type which will be shown when selecting type * @param string $display_function The name of the function to call when displaying the question * @param bool $graded Tells the plugin if this question is graded or not. This will affect scoring. * @param string $review_function The name of the function to call when scoring the question * @param string $slug The slug of the question type to be stored with question in database * @return void */ public function register_question_type($name, $display_function, $graded, $review_function = null, $edit_args = null, $save_edit_function = null, $slug = null) { if (is_null($slug)) { $slug = strtolower(str_replace( " ", "-", $name)); } else { $slug = strtolower(str_replace( " ", "-", $slug)); } if ( is_null( $edit_args ) || !is_array( $edit_args ) ) { $validated_edit_function = array( 'inputs' => array( 'question', 'answer', 'hint', 'correct_info', 'comments', 'category', 'required' ), 'information' => '', 'extra_inputs' => array(), 'function' => '' ); } else { $validated_edit_function = array( 'inputs' => $edit_args['inputs'], 'information' => $edit_args['information'], 'extra_inputs' => $edit_args['extra_inputs'], 'function' => $edit_args['function'] ); } if ( is_null( $save_edit_function ) ) { $save_edit_function = ''; } $new_type = array( 'name' => $name, 'display' => $display_function, 'review' => $review_function, 'graded' => $graded, 'edit' => $validated_edit_function, 'save' => $save_edit_function, 'slug' => $slug ); $this->question_types[] = $new_type; } /** * Retrieves List Of Question Types * * retrieves a list of the slugs and names of the question types * * @since 4.0.0 * @return array An array which contains the slug and name of question types that have been registered */ public function get_question_type_options() { $type_array = array(); foreach($this->question_types as $type) { $type_array[] = array( 'slug' => $type["slug"], 'name' => $type["name"] ); } return $type_array; } public function get_question_type_edit_fields() { $type_array = array(); foreach($this->question_types as $type) { $type_array[$type["slug"]] = $type["edit"]; } return $type_array; } /** * Displays A Question * * Retrieves the question types display function and creates the HTML for the question * * @since 4.0.0 * @param string $slug The slug of the question type that the question is * @param int $question_id The id of the question * @param array $quiz_options An array of the columns of the quiz row from the database * @return string The HTML for the question */ public function display_question($slug, $question_id, $quiz_options) { $display = ''; global $wpdb; global $qmn_total_questions; $question = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."mlw_questions WHERE question_id=%d", intval($question_id))); $answers = array(); if (is_serialized($question->answer_array) && is_array(@unserialize($question->answer_array))) { $answers = @unserialize($question->answer_array); } else { $mlw_answer_array_correct = array(0, 0, 0, 0, 0, 0); $mlw_answer_array_correct[$question->correct_answer-1] = 1; $answers = array( array($question->answer_one, $question->answer_one_points, $mlw_answer_array_correct[0]), array($question->answer_two, $question->answer_two_points, $mlw_answer_array_correct[1]), array($question->answer_three, $question->answer_three_points, $mlw_answer_array_correct[2]), array($question->answer_four, $question->answer_four_points, $mlw_answer_array_correct[3]), array($question->answer_five, $question->answer_five_points, $mlw_answer_array_correct[4]), array($question->answer_six, $question->answer_six_points, $mlw_answer_array_correct[5])); } if ( 2 == $quiz_options->randomness_order || 3 == $quiz_options->randomness_order ) { shuffle( $answers ); } foreach($this->question_types as $type) { if ($type["slug"] == strtolower(str_replace( " ", "-", $slug))) { if ($type["graded"]) { $qmn_total_questions += 1; if ($quiz_options->question_numbering == 1) { $display .= "$qmn_total_questions. "; } } if($quiz_options->show_category_on_front && $question->category != ''){ $display .= '