ch_multiplechoice.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * @return FormValidator
  12. */
  13. public function createForm($survey_data, $formData)
  14. {
  15. parent::createForm($survey_data, $formData);
  16. $options = array(
  17. 'horizontal' => get_lang('Horizontal'),
  18. 'vertical' => get_lang('Vertical')
  19. );
  20. $this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options);
  21. $formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal';
  22. $this->getForm()->setDefaults($formData);
  23. $config = array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120');
  24. $total = count($formData['answers']);
  25. if (is_array($formData['answers'])) {
  26. foreach ($formData['answers'] as $key => $value) {
  27. $this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config);
  28. if ($key < $total-1) {
  29. //$this->getForm()->addButton("move_down[$key]", get_lang('Down'));
  30. }
  31. if ($key > 0) {
  32. //$this->getForm()->addButton("move_up[$key]", get_lang('Up'));
  33. }
  34. if ($total> 2) {
  35. $this->getForm()->addButton("delete_answer[$key]", get_lang('Delete'), 'trash', 'danger');
  36. }
  37. }
  38. }
  39. parent :: addRemoveButtons($formData);
  40. }
  41. /**
  42. * @param FormValidator $form
  43. * @param array $questionData
  44. * @param array $answers
  45. */
  46. public function render(FormValidator $form, $questionData = array(), $answers = array())
  47. {
  48. $question = new ch_yesno();
  49. $question->render($form, $questionData, $answers);
  50. }
  51. }