/** * Check the tags that have been provided, and get the details for each tag. * * @param unknown_type $dataToDecode The data to decode. * * @return Array The validated tags as tag_[number] => array (count => $count, 'name' => $name). */ static function decodeTagSelection($dataToDecode) { $decodedData = json_decode($dataToDecode, true); $newDataToReturn = false; // Validate that the data is indeed JSON encoded. if (json_last_error() === JSON_ERROR_NONE) { if (!empty($decodedData)) { foreach ($decodedData as $key => $value) { // Have we got the whole pool tag? If so, process and abort. // Should be no further tags in this section. if ('whole_pool' == $key) { $newDataToReturn[$key] = array('count' => $value, 'name' => __('Entire Question Pool', 'wp_courseware'), 'tag_id' => false, 'tag_usage' => WPCW_questions_getQuestionCount()); break; } else { if (preg_match('/^tag_([0-9]+)$/', $key, $matches)) { // Extract details for this tag. $tagDetails = WPCW_questions_tags_getTagDetails($matches[1]); if ($tagDetails) { $newDataToReturn[$key] = array('count' => $value, 'name' => $tagDetails->question_tag_name, 'tag_id' => $tagDetails->question_tag_id, 'tag_usage' => $tagDetails->question_tag_usage); } // end tag detail check } // end preg_match } // end if whole_pool } // end foreach } // end if (!empty($decodedData)) } return $newDataToReturn; }
/** * Render the placeholder for the AJAX-loading Thickbox that allows the user to add * a selection of random questions using a tag. */ function WPCW_showPage_thickbox_randomQuestion() { $defaultQuestions = 10; printf('<div id="wpcw_tb_random_question" style="display: none">'); printf('<div id="wpcw_tb_random_question_inner">'); // ### Choice A - Whole Quiz Pool printf('<div class="wpcw_tb_option_wrap" id="wpcw_tb_option_wrap_whole_pool">'); // Label printf('<label class="wpcw_bold"><input type="radio" name="wpcw_tb_random_question_type" value="whole_pool" /> %s</label>', __('Randomly Select from Entire Quiz Pool', 'wp_courseware')); printf('<div class="wpcw_tb_description">%s</div>', __('If this option is selected, then number of questions you choose wil be randomly chosen from the entire quiz pool, regardless of question tag.', 'wp_courseware')); // How many questions are there? $questionCount = WPCW_questions_getQuestionCount(); // Wraps the selection in a grey box printf('<div class="wpcw_tb_option_selection">'); printf('<label>%s </label>', __('Show a total of ', 'wp_courseware')); printf('<input type="text" class="wpcw_spinner" value="%d" data-wpcw-max="%d"/>', $defaultQuestions, $questionCount); printf('<label> %s</label>', __('questions', 'wp_courseware')); // Shows how many questions are available. printf('<div class="wpcw_tb_random_question_count">%s <b>%d</b> %s</div>', __('There are a total of ', 'wp_courseware'), $questionCount, __('questions available in the question pool.', 'wp_courseware')); printf('</div>'); printf('</div>'); // .wpcw_tb_option_wrap // ### Choice B - Select using question tags... printf('<div class="wpcw_tb_option_wrap wpcw_tb_option_wrap_active" id="wpcw_tb_option_wrap_question_tags">'); // Label printf('<label class="wpcw_bold"><input type="radio" name="wpcw_tb_random_question_type" value="question_tags" checked/> %s</label>', __('Randomly Select using Question Tags', 'wp_courseware')); printf('<div class="wpcw_tb_description">%s</div>', __('If this option is selected, then number of questions you choose for each tag will be randomly displayed.', 'wp_courseware')); // Wraps the selection in a grey box printf('<div class="wpcw_tb_option_selection">'); // List the main ones. printf('<div id="wpcw_tb_option_wrap_question_tags_list">'); WPCW_showPage_thickbox_randomQuestion_tagSelectionLine(10, true); printf('</div>'); // Create the add new line printf('<hr/>'); printf('<a href="#" id="wpcw_tb_option_wrap_question_tags_add">%s</a>', __('+ Add Another', 'wp_courseware')); printf('</div>'); printf('</div>'); // .wpcw_tb_option_wrap // Insert button printf('<br/><div class="wpcw_button_group">'); printf('<a href="#new_question" class="button-primary" id="wpcw_tb_random_question_inner_insert">%s</a>', __('Insert Random Question Selection', 'wp_courseware')); printf('</div>'); printf('</div>'); // #wpcw_tb_random_question_inner printf('</div>'); // #wpcw_tb_random_question }