Exemple #1
0
 /**
  * Returns array of appreciations for this game
  * @return array of ::Appreciation
  */
 private function fetchAppreciations()
 {
     global $wpdb;
     // Fetch from DB
     $row = $wpdb->get_results($wpdb->prepare('SELECT id FROM ' . WPViralQuiz::getTableName('appreciations') . ' WHERE quizId = %d', $this->id));
     // No appreciations
     if (empty($row)) {
         return array();
     }
     $appreciations = array();
     foreach ($row as $appreciation) {
         $app = new WPVQAppreciation();
         $app->load($appreciation->id);
         $appreciations[] = $app;
     }
     return $appreciations;
 }
 /**
  * Load a question by ID
  * @return [type] [description]
  */
 public function load($id)
 {
     global $wpdb;
     if (!is_numeric($id)) {
         throw new Exception("Need numeric ID on answer load ({$i}).");
     }
     // Fetch from DB
     $row = $wpdb->get_row('SELECT * FROM ' . WPViralQuiz::getTableName('answers') . ' WHERE ID = ' . $id);
     // No appreciations
     if (empty($row)) {
         throw new Exception("No question with ID#{$id}");
     }
     $this->id = $row->ID;
     $this->questionId = $row->questionId;
     $this->content = $row->content;
     $this->label = $row->label;
     $this->pictureId = $row->pictureId;
     // If not "true/false" quiz
     if ($row->weight > 1) {
         if (WPVQAppreciation::exists($row->weight)) {
             $this->weight = $row->weight;
         } else {
             $this->weight = -1;
         }
     } else {
         $this->weight = $row->weight;
     }
     // Fetch multiplier association for personality quiz
     // Useless for Trivia Quiz
     $row = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . WPViralQuiz::getTableName('multipliers') . ' WHERE answerId = %d', $this->id));
     foreach ($row as $multiplier) {
         $this->multipliers[$multiplier->appreciationId] = $multiplier->multiplier;
     }
     return $this;
 }
             // echo "</pre>";
         }
         $i++;
     }
 }
 // end of tab=QUESTIONS
 /**
  * ================================================
  * 		      APPRECIATIONS PROCESS
  * ================================================
  */
 if ($activeTab == 'appreciations') {
     // Delete appreciations if we need to
     $deleteAppreciations = array_filter(explode(',', $_POST['deleteAppreciations']));
     foreach ($deleteAppreciations as $appreciationId) {
         $appreciation = new WPVQAppreciation();
         try {
             $appreciation->load(intval($appreciationId))->delete();
         } catch (Exception $e) {
         }
     }
     // If Personality Quizz
     // => add appreciations
     if ($quizType == 'WPVQGamePersonality' && isset($_POST['vqappreciations'])) {
         foreach ($_POST['vqappreciations'] as $appreciation) {
             // Empty appreciation
             if ($appreciation['content'] == '' && $appreciation['label'] == '') {
                 continue;
             }
             $param = array();
             // Wordpress addslashes to $_POST by default. But in the case of appreciation,
 /**
  * Trigger when player finishes a Trivia Quiz
  * Can be used using the local parameters instead of ajax $_POST
  * @return [type] [description]
  */
 public static function getTrueFalseAppreciation($quizId = NULL, $score = NULL)
 {
     $local = false;
     if (!isset($_POST['score']) || !is_numeric($_POST['score']) || (!isset($_POST['quizId']) || !is_numeric($_POST['quizId']))) {
         if (!$quizId || !$score) {
             die;
         } else {
             $_POST['score'] = $score;
             $_POST['quizId'] = $quizId;
             $local = true;
         }
     }
     // Debug mode : generate virtual lag
     // sleep(2);
     $score = intval($_POST['score']);
     $quizId = intval($_POST['quizId']);
     $appreciation = WPVQAppreciation::getAppreciationByScore($quizId, $score);
     if ($appreciation == NULL) {
         return 0;
         // no appreciation set
     }
     $result = array('scoreCondition' => $appreciation->getScoreCondition(), 'appreciationContent' => do_shortcode(htmlspecialchars_decode(stripslashes($appreciation->getContent()))));
     if ($local) {
         return json_encode($result);
     } else {
         print json_encode($result);
         die;
     }
 }