protected function getResponseValue(CMEQuiz $quiz, CMEQuizResponse $response, InquisitionInquisitionQuestionBinding $question_binding, $option_id) { $response_value = null; $question_id = $question_binding->getInternalValue('question'); // make sure option is valid for question $sql = sprintf('select count(1) from InquisitionQuestionOption where question = %s and id = %s', $this->app->db->quote($question_id, 'integer'), $this->app->db->quote($option_id, 'integer')); if (SwatDB::queryOne($this->app->db, $sql) === 1) { // check for existing response $sql = sprintf('select * from InquisitionResponseValue where response = %s and question_binding = %s', $this->app->db->quote($response->id, 'integer'), $this->app->db->quote($question_binding->id, 'integer')); $wrapper = SwatDBClassMap::get('InquisitionResponseValueWrapper'); $response_value = SwatDB::query($this->app->db, $sql, $wrapper)->getFirst(); // if no existing response, make a new one if ($response_value === null) { $class_name = SwatDBClassMap::get('InquisitionResponseValue'); $response_value = new $class_name(); $response_value->setDatabase($this->app->db); } // set question option and question $response_value->question_option = $option_id; $response_value->question_binding = $question_binding->id; } return $response_value; }