Advertisement
Strider64

OutputQA.php (Class)

Sep 25th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2.  
  3. namespace website_project\trivia_game;
  4.  
  5. use website_project\database\Database as DB;
  6. use PDO;
  7. use DateTime;
  8. use DateTimeZone;
  9.  
  10. class OutputQA {
  11.  
  12.     public $result = \NULL;
  13.     protected $pdo = \NULL;
  14.     protected $q_num = \NULL;
  15.     protected $query = \NULL;
  16.     protected $stmt = \NULL;
  17.  
  18.     public function __construct() {
  19.        
  20.     }
  21.  
  22.     protected function buildQuizTables(array $categories) {
  23.         $db = DB::getInstance();
  24.         $this->pdo = $db->getConnection();
  25.         $this->query = "SELECT 1 FROM trivia_questions WHERE id > 0";
  26.         $this->stmt = $this->pdo->prepare($this->query);
  27.         $this->stmt->bindParam(':player', $this->player);
  28.         $this->stmt->execute();
  29.         $this->result = $this->stmt->fetch();
  30.     }
  31.  
  32.     public function readQA($q_num) {
  33.         $db = DB::getInstance();
  34.         $this->pdo = $db->getConnection();
  35.         $this->q_num = $q_num;
  36.         $this->query = "SELECT id, q_num, question, answer1, answer2, answer3, answer4, play_date FROM the_daily_ten WHERE q_num=:q_num";
  37.         $this->stmt = $this->pdo->prepare($this->query);
  38.         $this->stmt->execute([':q_num' => $this->q_num]);
  39.         $this->data = $this->stmt->fetchAll(PDO::FETCH_OBJ);
  40.         if ($this->data) {
  41.             return $this->data;
  42.         } else {
  43.             return NULL;
  44.         }
  45.     }
  46.  
  47.     public function checkDailyTen($id, $answer) {
  48.         $db = DB::getInstance();
  49.         $this->pdo = $db->getConnection();
  50.         $this->today = new DateTime("Now", new DateTimeZone("America/Detroit"));
  51.         $this->today->modify("Midnight");
  52.         $query = "SELECT  id, correct, play_date FROM the_daily_ten WHERE id =:id";
  53.         $this->stmt = $this->pdo->prepare($query);
  54.         $this->stmt->execute([':id' => $id]);
  55.         $this->row = $this->stmt->fetch(PDO::FETCH_ASSOC);
  56.  
  57.         if ($this->row) {
  58.             if ($this->row['correct'] === (int) $answer) {
  59.                 $this->data['correct'] = TRUE;
  60.                 $this->data['right_answer'] = $this->row['correct'];
  61.                 $this->data['user_answer'] = (int) $answer;
  62.             } else {
  63.                 $this->data['correct'] = FALSE;
  64.                 $this->data['right_answer'] = $this->row['correct'];
  65.                 $this->data['user_answer'] = (int) $answer;
  66.             }
  67.             return $this->data;
  68.         } else {
  69.             return NULL;
  70.         }
  71.     }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement