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; }
public function getCMSFields() { $fields = parent::getCMSFields(); $fields->add(new TextField('InitialValue', 'Initial Value')); if ($this->ID > 0) { //validation rules $config = GridFieldConfig_RelationEditor::create(); $config->removeComponentsByType('GridFieldAddNewButton'); $gridField = new GridField('ValidationRules', 'ValidationRules', $this->ValidationRules(), $config); $fields->add($gridField); } $fields->removeByName('ShowOnSangriaStatistics'); $fields->removeByName('ShowOnPublicStatistics'); return $fields; }
/** * @param int $question_id * @param ArrayList $answers * @return ArrayList */ public function mapAnswers($question_id, $answers) { $answer_values = new ArrayList(); $question_values = SurveyQuestionValueTemplate::get()->where('OwnerID = ' . $question_id)->map('ID', 'Value')->toArray(); $question = SurveyQuestionTemplate::get_by_id('SurveyQuestionTemplate', $question_id); foreach ($answers as $answer) { $multi_answer = explode(',', $answer['Value']); foreach ($multi_answer as $single_answer) { if (!$single_answer) { continue; } if ($question->ClassName == 'SurveyRadioButtonMatrixTemplateQuestion') { $matrix = explode(':', $single_answer); $col = $matrix[0]; $row = $matrix[1]; if (!$col || !$row) { continue; } $answer_value = array('col' => $question_values[$col], 'row' => $question_values[$row]); $answer_values->push($answer_value); } else { if ($question->Name == 'NetPromoter') { $answer_value = $question_values[$single_answer]; if ($answer_value < 7) { $answer_value = 'Detractor'; } else { if ($answer_value < 9) { $answer_value = 'Neutral'; } else { $answer_value = 'Promoter'; } } $answer_values->push($answer_value); } else { if (isset($question_values[$single_answer])) { $answer_value = $question_values[$single_answer]; $answer_values->push($answer_value); } else { $answer_values->push($single_answer); } } } } } return $answer_values; }
protected function onBeforeDelete() { parent::onBeforeDelete(); foreach ($this->Values() as $v) { $v->delete(); } }
/** * @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)); }