ch_yesno.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class ch_yesno
  5. */
  6. class ch_yesno extends survey_question
  7. {
  8. /**
  9. * @param array $surveyData
  10. * @param array $formData
  11. */
  12. public function createForm($surveyData, $formData)
  13. {
  14. parent::createForm($surveyData, $formData);
  15. $options = array(
  16. 'horizontal' => get_lang('Horizontal'),
  17. 'vertical' => get_lang('Vertical')
  18. );
  19. $this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options);
  20. $formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal';
  21. $this->getForm()->setDefaults($formData);
  22. // The options
  23. $config = array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120');
  24. $this->getForm()->addHtmlEditor('answers[0]', get_lang('AnswerOptions'), true, false, $config);
  25. $this->getForm()->addHtmlEditor('answers[1]', null, true, false, $config);
  26. }
  27. /**
  28. * @param FormValidator $form
  29. * @param array $questionData
  30. * @param array $answers
  31. */
  32. public function render(FormValidator $form, $questionData = array(), $answers = null)
  33. {
  34. if (is_array($questionData['options'])) {
  35. if ($questionData['display'] == 'vertical') {
  36. $class = 'radio';
  37. } else {
  38. $class = 'radio-inline';
  39. }
  40. $name = 'question'.$questionData['question_id'];
  41. $form->addRadio(
  42. $name,
  43. null,
  44. $questionData['options'],
  45. ['radio-class' => $class, 'label-class' => $class]
  46. );
  47. if (!empty($answers)) {
  48. $form->setDefaults([$name => $answers]);
  49. }
  50. }
  51. }
  52. }