ch_multiplechoice.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class ch_multiplechoice.
  5. */
  6. class ch_multiplechoice extends survey_question
  7. {
  8. /**
  9. * @param array $survey_data
  10. * @param array $formData
  11. *
  12. * @return FormValidator
  13. */
  14. public function createForm($survey_data, $formData)
  15. {
  16. parent::createForm($survey_data, $formData);
  17. $options = [
  18. 'horizontal' => get_lang('Horizontal'),
  19. 'vertical' => get_lang('Vertical'),
  20. ];
  21. $this->getForm()->addRadio('horizontalvertical', get_lang('Display'), $options);
  22. $formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal';
  23. $this->getForm()->setDefaults($formData);
  24. $config = ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'];
  25. $total = count($formData['answers']);
  26. if (is_array($formData['answers'])) {
  27. foreach ($formData['answers'] as $key => $value) {
  28. $this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config);
  29. if ($total > 2) {
  30. $this->getForm()->addButton("delete_answer[$key]", get_lang('Delete'), 'trash', 'danger');
  31. }
  32. }
  33. }
  34. parent::addRemoveButtons($formData);
  35. }
  36. /**
  37. * @param FormValidator $form
  38. * @param array $questionData
  39. * @param array $answers
  40. */
  41. public function render(FormValidator $form, $questionData = [], $answers = [])
  42. {
  43. $question = new ch_yesno();
  44. $question->render($form, $questionData, $answers);
  45. }
  46. }