Example #1
0
 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;
 }