/** * Handle the question deletion from the question pool page. * @param PageBuilder $page The page rendering object. */ function WPCW_quizzes_handleQuestionDeletion($page) { global $wpcwdb, $wpdb; $wpdb->show_errors(); // Check that the question exists and deletion has been requested if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['question_id'])) { $questionID = $_GET['question_id']; $questionDetails = WPCW_questions_getQuestionDetails($questionID); // Only do deletion if question details are valid. if ($questionDetails) { // Get tags for questions $question_tags = WPCW_questions_getQuestionDetails($questionID, $getTagsToo = true); // Remove tags for each question foreach ($question_tags->tags as $question_tag) { WPCW_questions_tags_removeTag($questionID, $question_tag->question_tag_id); } // Delete question from question map $wpdb->query($wpdb->prepare("\n\t\t\t\tDELETE FROM {$wpcwdb->quiz_qs_mapping}\n\t\t\t\tWHERE question_id = %d\n\t\t\t", $questionDetails->question_id)); // Finally delete question itself $wpdb->query($wpdb->prepare("\n\t\t\t\tDELETE FROM {$wpcwdb->quiz_qs} \n\t\t\t\tWHERE question_id = %d\n\t\t\t", $questionDetails->question_id)); $page->showMessage(sprintf(__('The question \'%s\' was successfully deleted.', 'wp_courseware'), $questionDetails->question_question)); } // end of if $questionDetails } // end of check for deletion action }
/** * Function called when a question tag needs to be removed. */ function WPCW_AJAX_handleQuestionRemoveTag() { $ajaxResults = array('success' => true); $tagID = intval(WPCW_arrays_getValue($_POST, 'tagid')); $questionID = intval(WPCW_arrays_getValue($_POST, 'questionid')); WPCW_questions_tags_removeTag($questionID, $tagID); header('Content-Type: application/json'); echo json_encode($ajaxResults); die; }
function wpcw_tag_cleanup() { global $wpdb, $wpcwdb; $wpcwdb = new WPCW_Database(); $tags = array(); $SQL = "SELECT *\n\t\t\tFROM {$wpcwdb->question_tag_mapping}"; $tags = $wpdb->get_results($SQL); foreach ($tags as $tag) { $questionDetails = WPCW_questions_getQuestionDetails($tag->question_id); if (!$questionDetails) { WPCW_questions_tags_removeTag($tag->question_id, $tag->tag_id); } WPCW_questions_tags_updatePopularity($tag->tag_id); } }