protected function questionViewIsVisible(InquisitionInquisitionQuestionBinding $question_binding) { $question_view_visible = true; // If the question view is dependent on other options, check to make // sure all dependent options are available and selected. if (count($question_binding->getDependentOptions()) > 0) { foreach ($question_binding->getDependentOptions() as $option) { // Check to make sure the dependent view exists. If // InquisitionQuestion.enabled has been set to false, it will // not exist in the available question views. if (isset($this->question_views[$option['binding']])) { $view = $this->question_views[$option['binding']]; $values = $view->getResponseValue(); if (!is_array($values)) { $values = array($values); } // If no dependent option is selected then this will // remain false and the question will not be shown. $option_selected = false; foreach ($values as $value) { $selected = $value->getInternalValue('question_option'); foreach ($option['options'] as $dependent) { // Only one option per question must be selected // for the dependecy to be fulfilled. $option_selected = $selected === $dependent || $option_selected; } } // Each question this question depends on must have one // of its dependent options selected. $question_view_visible = $question_view_visible && $option_selected; } } } return $question_view_visible; }
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; }