ch_yesno.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 = '';
  37. } else {
  38. $class = 'inline';
  39. }
  40. $name = 'question' . $questionData['question_id'];
  41. $form->addRadio(
  42. $name ,
  43. null,
  44. $questionData['options'],
  45. array('label-class' => $class)
  46. );
  47. if (!empty($answers)) {
  48. $form->setDefaults([$name => $answers]);
  49. }
  50. }
  51. }
  52. }