/** * 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; }