public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $valid_steps = $this->Section()->Report()->Template()->Steps()->column();
     $entity_survey_temp = $this->Section()->Report()->Template()->EntitySurveys();
     foreach ($entity_survey_temp as $est) {
         $est_steps = $est->Steps()->column();
         $valid_steps = array_merge($valid_steps, $est_steps);
     }
     $questionList = SurveyQuestionTemplate::get()->filter(array('StepID' => $valid_steps))->sort('Label')->map('ID', 'Label')->toArray();
     $questionSelect = DropdownField::create('QuestionID', 'Question')->setSource($questionList);
     $fields->replaceField('QuestionID', $questionSelect);
     return $fields;
 }
 /**
  * @return DataList
  */
 private function getAllowedDependants()
 {
     $steps_query = new SQLQuery();
     $steps_query->setSelect("ID");
     $steps_query->setFrom("SurveyStepTemplate");
     $high_order = $this->Step()->order();
     $current_survey_id = $this->Step()->SurveyTemplateID;
     $steps_query->setWhere("SurveyTemplateID = {$current_survey_id} AND `Order` <= {$high_order} ");
     $steps_query->setOrderBy('`Order`', 'ASC');
     $current_step_ids = $steps_query->execute()->keyedColumn();
     return SurveyQuestionTemplate::get()->filter(array('StepID' => $current_step_ids));
 }