ch_dropdown.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. * @return void
  13. */
  14. public function createForm($survey_data, $formData)
  15. {
  16. parent::createForm($survey_data, $formData);
  17. if (is_array($formData['answers'])) {
  18. foreach ($formData['answers'] as $key => $value) {
  19. $this->getForm()->addText('answers['.$key.']', $key + 1);
  20. }
  21. }
  22. parent::addRemoveButtons($formData);
  23. }
  24. /**
  25. * @param FormValidator $form
  26. * @param array $questionData
  27. * @param array $answers
  28. * @return void
  29. */
  30. public function render(FormValidator $form, $questionData = array(), $answers = array())
  31. {
  32. $name = 'question'.$questionData['question_id'];
  33. $data = array(0 => '--') + $questionData['options'];
  34. $form->addSelect($name, null, $data);
  35. if (!empty($answers)) {
  36. $form->setDefaults([$name => $answers]);
  37. }
  38. }
  39. }