public function process()
 {
     global $wpdb;
     if (!isset($_GET['id'])) {
         // do some redirection here.
         // TODO add redirect function in code.
     }
     if (isset($_GET['marked']) && $_GET['marked'] == "true") {
         $this->_pageVars['message'] = "Result successfully marked!";
     }
     if (isset($_GET['deleted']) && $_GET['deleted'] == "true") {
         $this->_pageVars['message'] = "Result successfully deleted!";
     }
     $unviewed = $wpdb->get_results($wpdb->prepare("SELECT * \n\t\t\t\t\t\t                 FROM `" . WPSQT_TABLE_RESULTS . "` \n\t\t\t\t\t\t                 WHERE item_id = %d \n\t\t\t\t\t\t                 AND LCASE(status) = 'unviewed'\n\t\t\t\t\t\t                 ORDER BY ID DESC", array($_GET['id'])), ARRAY_A);
     $accepted = $wpdb->get_results($wpdb->prepare("SELECT * \n\t\t\t\t\t\t                 FROM `" . WPSQT_TABLE_RESULTS . "` \n\t\t\t\t\t\t                 WHERE item_id = %d \n\t\t\t\t\t\t                 AND LCASE(status) = 'accepted'\n\t\t\t\t\t\t                 ORDER BY ID DESC", array($_GET['id'])), ARRAY_A);
     $rejected = $wpdb->get_results($wpdb->prepare("SELECT * \n\t\t\t\t\t\t                 FROM `" . WPSQT_TABLE_RESULTS . "` \n\t\t\t\t\t\t                 WHERE item_id = %d \n\t\t\t\t\t\t                 AND LCASE(status) = 'rejected'\n\t\t\t\t\t\t                 ORDER BY ID DESC", array($_GET['id'])), ARRAY_A);
     if (!isset($_GET['status']) || !isset(${$_GET['status']})) {
         $rawResults = array_merge($unviewed, $accepted, $rejected);
     } else {
         $rawResults = ${$_GET['status']};
     }
     $itemsPerPage = get_option('wpsqt_number_of_items');
     $currentPage = Wpsqt_Core::getCurrentPageNumber();
     $startNumber = ($currentPage - 1) * $itemsPerPage;
     $this->_pageVars['results'] = array_slice($rawResults, $startNumber, $itemsPerPage);
     $this->_pageVars['counts'] = array('unviewed_count' => sizeof($unviewed), 'accepted_count' => sizeof($accepted), 'rejected_count' => sizeof($rejected));
     $this->_pageVars['numberOfPages'] = Wpsqt_Core::getPaginationCount(sizeof($rawResults), $itemsPerPage);
     $this->_pageVars['currentPage'] = Wpsqt_Core::getCurrentPageNumber();
     return false;
 }
Ejemplo n.º 2
0
 /**
  * (non-PHPdoc)
  * @see Wpsqt_Page::process()
  */
 public function process()
 {
     global $wpdb;
     if (isset($_GET['order'])) {
         $this->_updateQuestionOrder($_GET['order'], $_GET['id']);
     }
     $questions = Wpsqt_System::getQuizQuestionTypes();
     // Builds the query for the question counts.
     $sql = "SELECT count(id) as `all_count`,";
     $questionCounts = array();
     $questionTypes = array('all');
     $itemId = $wpdb->prepare("%d", array($_GET['id']));
     foreach ($questions as $questionType => $description) {
         // Part of the query which fetches the query count for the singl
         $sqlFriendlyType = str_replace(' ', '', $questionType);
         $questionCounts[] = " (SELECT count(id) FROM " . WPSQT_TABLE_QUESTIONS . " WHERE item_id = " . $itemId . " and type = '" . $questionType . "') as `" . $sqlFriendlyType . "_count` ";
         $questionTypes[] = $questionType;
     }
     // Finishes off the query for the question counts.
     $sql .= implode(',', $questionCounts);
     $sql .= "FROM " . WPSQT_TABLE_QUESTIONS . " WHERE item_id = " . $itemId;
     $itemsPerPage = get_option('wpsqt_number_of_items');
     $questions = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSQT_TABLE_QUESTIONS . "` WHERE item_id = %d ORDER BY `order` ASC", array($_GET['id'])), ARRAY_A);
     $questions = apply_filters("wpsqt_list_questions", $questions);
     $currentPage = Wpsqt_Core::getCurrentPageNumber();
     $startNumber = ($currentPage - 1) * $itemsPerPage;
     $pageQuestions = array_slice($questions, $startNumber, $itemsPerPage);
     $this->_pageVars['questions'] = $pageQuestions;
     $this->_pageVars['currentPage'] = $currentPage;
     $this->_pageVars['numberOfPages'] = Wpsqt_Core::getPaginationCount(sizeof($questions), $itemsPerPage);
     $this->_pageVars['question_counts'] = $wpdb->get_row($sql, ARRAY_A);
     $this->_pageVars['question_types'] = $questionTypes;
     $this->_pageView = "admin/questions/index.php";
 }