ch_multipleresponse.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class ch_multipleresponse
  5. */
  6. class ch_multipleresponse 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. $config = array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120');
  23. if (is_array($formData['answers'])) {
  24. foreach ($formData['answers'] as $key => $value) {
  25. $this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config);
  26. }
  27. }
  28. parent :: addRemoveButtons($formData);
  29. }
  30. /**
  31. * @param FormValidator $form
  32. * @param array $questionData
  33. * @param array $answers
  34. */
  35. public function render(FormValidator $form, $questionData = array(), $answers = array())
  36. {
  37. if ($questionData['display'] == 'vertical') {
  38. $class = '';
  39. } else {
  40. $class = 'inline';
  41. }
  42. $name = 'question'.$questionData['question_id'];
  43. $form->addCheckBoxGroup(
  44. $name,
  45. null,
  46. $questionData['options'],
  47. array('label-class' => $class)
  48. );
  49. $defaults = [];
  50. if (!empty($answers)) {
  51. foreach ($answers as $answer) {
  52. $defaults[$name.'['.$answer.']'] = true;
  53. }
  54. }
  55. $form->setDefaults($defaults);
  56. }
  57. }