public function fetchById($templateId, $loadData = true)
 {
     $row = $this->_wpdb->get_row($this->_wpdb->prepare("SELECT * FROM {$this->_tableTemplate} WHERE template_id = %d ", $templateId), ARRAY_A);
     if ($row !== null) {
         $data = $row['data'];
         unset($row['data']);
         $template = new WpProQuiz_Model_Template($row);
         if ($loadData && WpProQuiz_Helper_Until::saveUnserialize($data, $into)) {
             $template->setData($into);
         }
         return $template;
     }
     return new WpProQuiz_Model_Template();
 }
 public function getPluginContainer($serialize = false)
 {
     if ($this->_pluginContainer === null) {
         $this->_pluginContainer = new WpProQuiz_Model_PluginContainer();
     }
     if (is_object($this->_pluginContainer) || $this->_pluginContainer instanceof WpProQuiz_Model_PluginContainer) {
         if ($serialize) {
             return @serialize($this->_pluginContainer);
         }
     } else {
         if (!$serialize) {
             if (WpProQuiz_Helper_Until::saveUnserialize($this->_pluginContainer, $into) === false) {
                 return null;
             }
             $this->_pluginContainer = $into;
         }
     }
     return $this->_pluginContainer;
 }
 private static function updateV21()
 {
     global $wpdb;
     $results = $wpdb->get_results("\n\t\t\t\tSELECT id, answer_data, answer_type, answer_points_activated, points\n\t\t\t\tFROM {$wpdb->prefix}wp_pro_quiz_question", ARRAY_A);
     foreach ($results as $row) {
         if ($row['points']) {
             continue;
         }
         if (WpProQuiz_Helper_Until::saveUnserialize($row['answer_data'], $into)) {
             $points = 0;
             if ($row['answer_points_activated']) {
                 $dPoints = 0;
                 foreach ($into as $c) {
                     if ($row['answer_type'] == 'cloze_answer') {
                         preg_match_all('#\\{(.*?)(?:\\|(\\d+))?(?:[\\s]+)?\\}#im', $c->getAnswer(), $matches);
                         foreach ($matches[2] as $match) {
                             if (empty($match)) {
                                 $match = 1;
                             }
                             $dPoints += $match;
                         }
                     } else {
                         $dPoints += $c->getPoints();
                     }
                 }
                 $points = $dPoints;
             } else {
                 $points = 1;
             }
             $wpdb->update($wpdb->prefix . 'wp_pro_quiz_question', array('points' => $points), array('id' => $row['id']));
         }
     }
 }
 public function setQuestionAnswerData($_questionAnswerData)
 {
     $this->_questionAnswerData = null;
     if (WpProQuiz_Helper_Until::saveUnserialize($_questionAnswerData, $into) !== false) {
         $this->_questionAnswerData = $into;
     }
     return $this;
 }
 /**
  * @param bool|false $serialize
  * @return WpProQuiz_Model_AnswerTypes[]|null|string
  */
 public function getAnswerData($serialize = false)
 {
     if ($this->_answerData === null) {
         return null;
     }
     if (is_array($this->_answerData) || $this->_answerData instanceof WpProQuiz_Model_AnswerTypes) {
         if ($serialize) {
             return @serialize($this->_answerData);
         }
     } else {
         if (!$serialize) {
             if (WpProQuiz_Helper_Until::saveUnserialize($this->_answerData, $into) === false) {
                 return null;
             }
             $this->_answerData = $into;
         }
     }
     return $this->_answerData;
 }