ch_dropdown.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class ch_dropdown.
  5. */
  6. class ch_dropdown extends survey_question
  7. {
  8. /**
  9. * @param array $survey_data
  10. * @param $formData
  11. */
  12. public function createForm($survey_data, $formData)
  13. {
  14. parent::createForm($survey_data, $formData);
  15. if (is_array($formData['answers'])) {
  16. foreach ($formData['answers'] as $key => $value) {
  17. $this->getForm()->addText('answers['.$key.']', $key + 1);
  18. }
  19. }
  20. parent::addRemoveButtons($formData);
  21. }
  22. /**
  23. * @param FormValidator $form
  24. * @param array $questionData
  25. * @param array $answers
  26. */
  27. public function render(FormValidator $form, $questionData = [], $answers = [])
  28. {
  29. $name = 'question'.$questionData['question_id'];
  30. $data = [0 => '--'] + $questionData['options'];
  31. $form->addSelect($name, null, $data);
  32. if (!empty($answers)) {
  33. $form->setDefaults([$name => $answers]);
  34. }
  35. }
  36. }