/** * Shows the row where you can add tags for this question. * * @param Integer $columnCount The number of columns that are being rendered to show the question. * @param Boolean $questionNotSavedYet If true, then there's limited save capability as the question is not saved yet. * * @return String The HTML to show the tags. */ function getSection_questionTags($columnCount, $questionNotSavedYet = false) { $html = sprintf('<tr data-questionsaved="%s">', $questionNotSavedYet ? 'no' : 'yes'); $html .= sprintf('<th>%s<span class="wpcw_inner_hint">%s</span></th>', __('Question Tags', 'wp_courseware'), __('(Optional) Add tags to this question to add it to your pool of questions to reuse in other quizzes.', 'wp_courseware')); // For new questions, to ensure they get replaced with IDs, we need to add an _ to the question ID, but without // changing the field for normal numbers. $extraPrefix = false; if ('new' == substr($this->quizItem->question_id, 0, 3)) { $extraPrefix = '_'; } $html .= sprintf('<td class="wpcw_quiz_details_question_tags" colspan="%s" data-questionid="%s%s" id="wpcw_quiz_details_question_tags_%s">', $columnCount - 1, $extraPrefix, $this->quizItem->question_id, $this->quizItem->question_id); // The input box and add button. $html .= sprintf('<input class="wpcw_question_add_tag_input" name="wpcw_question_add_tag_input" type="text" value="">'); $html .= sprintf('<input class="button-secondary wpcw_question_add_tag_btn" type="submit" value="%s" >', __('Add', 'wp_courseware')); // Now need to have a list of the tags currently being used, all with X to allow them to be removed.] $tagsToShow = false; if (!empty($this->quizItem->tags)) { $tagsToShow = $this->quizItem->tags; } // Use this so we always create a tag wrapper. $html .= WPCW_questions_tags_render($this->quizItem->question_id, $tagsToShow); $html .= '</td>'; $html .= '</tr>'; return $html; }
/** * Function to show a list of questions in the question pool for use by a standard page or the AJAX thickbox. * * @param Integer $itemsPerPage The number of items to show on each table page. * @param Array $paramSrc The array of parameters to use for filtering/searching the question pool. * @param String $actionMode The type of mode we're in (ajax or std). * @param PageBuilder $page The current page object (optional). */ function WPCW_questionPool_showPoolTable($itemsPerPage, $paramSrc, $actionMode = 'std', $page = false) { global $wpcwdb, $wpdb; $wpdb->show_errors(); // AJAX loader if ('ajax' == $actionMode) { printf('<img src="%simg/ajax_loader.gif" class="wpcw_loader" style="display: none;" />', WPCW_plugin_getPluginPath()); } // Check to see if we've got questions to process if ('std' == $actionMode) { WPCW_showPage_QuestionPool_processActionForm($page); } $paging_pageWanted = WPCW_arrays_getValue($paramSrc, 'pagenum') + 0; if ($paging_pageWanted == 0) { $paging_pageWanted = 1; } // Handle the sorting and filtering $orderBy = WPCW_arrays_getValue($paramSrc, 'orderby'); $ordering = WPCW_arrays_getValue($paramSrc, 'order'); // Validate ordering switch ($orderBy) { case 'question_question': case 'question_type': break; // Default and question_id //case 'question_id': // Default and question_id //case 'question_id': default: $orderBy = 'qs.question_id'; break; } // Create opposite ordering for reversing it. $ordering_opposite = false; switch ($ordering) { case 'desc': $ordering_opposite = 'asc'; break; case 'asc': $ordering_opposite = 'desc'; break; default: $ordering = 'desc'; $ordering_opposite = 'asc'; break; } // Was a search string specified? Or a specific item? $searchString = WPCW_arrays_getValue($paramSrc, 's'); // Create WHERE string based search - Title or Description of Quiz $SQL_WHERE = false; if ($searchString) { $SQL_WHERE = $wpdb->prepare(" AND question_question LIKE %s", '%' . $searchString . '%'); } $summaryPageURL = admin_url('admin.php?page=WPCW_showPage_QuestionPool'); // Show the form for searching ?> <form id="wpcw_questions_search_box" method="get" action="<?php echo $summaryPageURL; ?> "> <p class="search-box"> <label class="screen-reader-text" for="wpcw_questions_search_input"><?php _e('Search Questions', 'wp_courseware'); ?> </label> <input id="wpcw_questions_search_input" type="text" value="<?php echo $searchString; ?> " name="s"/> <input class="button" type="submit" value="<?php _e('Search Questions', 'wp_courseware'); ?> "/> <input type="hidden" name="page" value="WPCW_showPage_QuestionPool" /> </p> </form> <?php $SQL_TAG_FILTER = false; $tagFilter = intval(WPCW_arrays_getValue($paramSrc, 'filter', false)); // See if we have any tag filtering to do. if ($tagFilter > 0) { // Ensure we add the tag mapping table to the query $SQL_TAG_FILTER = "\n\t\t\tLEFT JOIN {$wpcwdb->question_tag_mapping} qtm ON qtm.question_id = qs.question_id\t\n\t\t"; $SQL_WHERE .= $wpdb->prepare("\n\t\t\tAND qtm.tag_id = %d\n\t\t\tAND qs.question_question IS NOT NULL \n\t\t", $tagFilter); // } $SQL_PAGING = "\n\t\t\tSELECT COUNT(*) as question_count \n\t\t\tFROM {$wpcwdb->quiz_qs} qs\n\t\t\t{$SQL_TAG_FILTER}\n\t\t\tWHERE question_type <> 'random_selection'\n\t\t\t{$SQL_WHERE} \n\t\t"; $paging_resultsPerPage = $itemsPerPage; $paging_totalCount = $wpdb->get_var($SQL_PAGING); $paging_recordStart = ($paging_pageWanted - 1) * $paging_resultsPerPage + 1; $paging_recordEnd = $paging_pageWanted * $paging_resultsPerPage; $paging_pageCount = ceil($paging_totalCount / $paging_resultsPerPage); $paging_sqlStart = $paging_recordStart - 1; // Show search message - that a search has been tried. if ($searchString) { printf('<div class="wpcw_search_count">%s "%s" (%s %s) (<a href="%s">%s</a>)</div>', __('Search results for', 'wp_courseware'), htmlentities($searchString), $paging_totalCount, _n('result', 'results', $paging_totalCount, 'wp_courseware'), $summaryPageURL, __('reset', 'wp_courseware')); } // Do main query $SQL = "SELECT * \n\t\t\tFROM {$wpcwdb->quiz_qs} qs\t\t\t\n\t\t\t{$SQL_TAG_FILTER}\t\t\t\n\t\t\tWHERE question_type <> 'random_selection'\n\t\t\t{$SQL_WHERE}\n\t\t\tORDER BY {$orderBy} {$ordering}\n\t\t\tLIMIT {$paging_sqlStart}, {$paging_resultsPerPage}\t\t\t \n\t\t\t"; // These are already checked, so they are safe, hence no prepare() // Generate paging code $baseURL = WPCW_urls_getURLWithParams($summaryPageURL, 'pagenum') . "&pagenum="; $questions = $wpdb->get_results($SQL); $tbl = new TableBuilder(); $tbl->attributes = array('id' => 'wpcw_tbl_question_pool', 'class' => 'widefat wpcw_tbl'); // Checkbox Col //$tblCol = new TableColumn(false, 'question_selection'); //$tblCol->cellClass = "question_selection wpcw_center"; //$tbl->addColumn($tblCol); // Wanting sorting links... in standard mode if ('std' == $actionMode) { // Checkbox field (no name, as we'll use jQuery to do a check all) $tblCol = new TableColumn('<input type="checkbox" />', 'question_id_cb'); $tblCol->cellClass = "wpcw_center wpcw_select_cb"; $tblCol->headerClass = "wpcw_center wpcw_select_cb"; $tbl->addColumn($tblCol); // ID - sortable $sortableLink = sprintf('<a href="%s&order=%s&orderby=question_id"><span>%s</span><span class="sorting-indicator"></span></a>', $baseURL, 'question_id' == $orderBy ? $ordering_opposite : 'asc', __('ID', 'wp_courseware')); // ID - render $tblCol = new TableColumn($sortableLink, 'question_id'); $tblCol->headerClass = 'question_id' == $orderBy ? 'sorted ' . $ordering : 'sortable'; $tblCol->cellClass = "question_id"; $tbl->addColumn($tblCol); // Question - sortable $sortableLink = sprintf('<a href="%s&order=%s&orderby=question_question"><span>%s</span><span class="sorting-indicator"></span></a>', $baseURL, 'question_question' == $orderBy ? $ordering_opposite : 'asc', __('Question', 'wp_courseware')); // Question - render $tblCol = new TableColumn($sortableLink, 'question_question'); $tblCol->headerClass = 'question_question' == $orderBy ? 'sorted ' . $ordering : 'sortable'; $tblCol->cellClass = "question_question"; $tbl->addColumn($tblCol); // Question Type - sortable $sortableLink = sprintf('<a href="%s&order=%s&orderby=question_type"><span>%s</span><span class="sorting-indicator"></span></a>', $baseURL, 'question_type' == $orderBy ? $ordering_opposite : 'asc', __('Question Type', 'wp_courseware')); // Question Type - render $tblCol = new TableColumn($sortableLink, 'question_type'); $tblCol->headerClass = ('question_type' == $orderBy ? 'sorted ' . $ordering : 'sortable') . ' wpcw_center'; $tblCol->cellClass = "question_type"; $tbl->addColumn($tblCol); } else { $tblCol = new TableColumn(__('ID', 'wp_courseware'), 'question_id'); $tblCol->cellClass = "question_id"; $tbl->addColumn($tblCol); $tblCol = new TableColumn(__('Question', 'wp_courseware'), 'question_question'); $tblCol->cellClass = "question_question"; $tbl->addColumn($tblCol); $tblCol = new TableColumn(__('Question Type', 'wp_courseware'), 'question_type'); $tblCol->cellClass = "question_type"; $tbl->addColumn($tblCol); } $tblCol = new TableColumn(__('Associated Quizzes', 'wp_courseware'), 'associated_quizzes'); $tblCol->headerClass = "wpcw_center"; $tblCol->cellClass = "associated_quizzes wpcw_center"; $tbl->addColumn($tblCol); $tblCol = new TableColumn(__('Tags', 'wp_courseware'), 'question_tags'); $tblCol->cellClass = "question_tags wpcw_center"; $tbl->addColumn($tblCol); // Actions $tblCol = new TableColumn(__('Actions', 'wp_courseware'), 'actions'); $tblCol->cellClass = "actions actions_right"; $tblCol->headerClass = "actions_right"; $tbl->addColumn($tblCol); // Stores course details in a mini cache to save lots of MySQL lookups. $miniCourseDetailCache = array(); // Format row data and show it. if ($questions) { $odd = false; foreach ($questions as $singleQuestion) { $data = array(); // URLs $editURL = admin_url('admin.php?page=WPCW_showPage_ModifyQuestion&question_id=' . $singleQuestion->question_id); // Maintain paging where possible. $deleteURL = $baseURL . '&action=delete&question_id=' . $singleQuestion->question_id; // Basic Details $data['question_id'] = $singleQuestion->question_id; $data['question_type'] = WPCW_quizzes_getQuestionTypeName($singleQuestion->question_type); $data['question_id_cb'] = sprintf('<input type="checkbox" name="question_%d" />', $singleQuestion->question_id); // Association Count $data['associated_quizzes'] = $singleQuestion->question_usage_count; // Actions - Std mode if ('std' == $actionMode) { // Edit by clicking $data['question_question'] = sprintf('<a href="%s">%s</a>', $editURL, $singleQuestion->question_question); $data['actions'] = '<ul class="wpcw_action_link_list">'; $data['actions'] .= sprintf('<li><a href="%s" class="button-primary">%s</a></li>', $editURL, __('Edit', 'wp_courseware')); $data['actions'] .= sprintf('<li><a href="%s" class="button-secondary wpcw_action_link_delete_question wpcw_action_link_delete" rel="%s">%s</a></li>', $deleteURL, __('Are you sure you wish to delete this question? This cannot be undone.', 'wp_courseware'), __('Delete', 'wp_courseware')); $data['actions'] .= '</ul>'; } else { if ('ajax' == $actionMode) { // No Edit by clicking $data['question_question'] = $singleQuestion->question_question . sprintf('<span class="wpcw_action_status wpcw_action_status_added">%s</span>', __('Added', 'wp_courseware')); $data['actions'] = '<ul class="wpcw_action_link_list">'; $data['actions'] .= sprintf('<li><a href="#" class="button-primary wpcw_tb_action_add" data-questionnum="%d">%s</a></li>', $singleQuestion->question_id, __('Add To Quiz', 'wp_courseware')); $data['actions'] .= '</ul>'; } } // Tags $data['question_tags'] = sprintf('<span class="wpcw_quiz_details_question_tags" data-questionid="%d" id="wpcw_quiz_details_question_tags_%d">', $singleQuestion->question_id, $singleQuestion->question_id); $data['question_tags'] .= WPCW_questions_tags_render($singleQuestion->question_id, WPCW_questions_tags_getTagsForQuestion($singleQuestion->question_id)); $data['question_tags'] .= '</span>'; // Odd/Even row colouring. $odd = !$odd; $tbl->addRow($data, $odd ? 'alternate' : ''); } } else { // No questions - show error in table. $tbl->addRowObj(new RowDataSimple('wpcw_center wpcw_none_found', __('There are currently no questions to show.', 'wp_courseware'), 7)); } // Add the form for the start of the multiple-add $formWrapper_start = false; if ('std' == $actionMode) { // Set the action URL to preserve parameters that we have. $formWrapper_start = sprintf('<form method="POST" action="%s">', WPCW_urls_getURLWithParams($summaryPageURL, 'pagenum')); } // Create tag filter (uses a form) $tagFilter = WPCW_questions_tags_createTagFilter($tagFilter, 'WPCW_showPage_QuestionPool'); // Work out paging and filtering $paging = WPCW_tables_showPagination($baseURL, $paging_pageWanted, $paging_pageCount, $paging_totalCount, $paging_recordStart, $paging_recordEnd, $tagFilter); // Show the actions $formWrapper_end = false; if ('std' == $actionMode) { $formWrapper_end = WPCW_showPage_QuestionPool_actionForm(); // Form tag - needed for processing $formWrapper_end .= '</form>'; } // Finally show table return $paging . $formWrapper_start . $tbl->toString() . $formWrapper_end . $paging; }