ch_multiplechoice.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 = array(
  18. 'horizontal' => get_lang('Horizontal'),
  19. 'vertical' => get_lang('Vertical')
  20. );
  21. $this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options);
  22. $formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal';
  23. $this->getForm()->setDefaults($formData);
  24. $config = array('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 ($key < $total-1) {
  30. //$this->getForm()->addButton("move_down[$key]", get_lang('Down'));
  31. }
  32. if ($key > 0) {
  33. //$this->getForm()->addButton("move_up[$key]", get_lang('Up'));
  34. }
  35. if ($total> 2) {
  36. $this->getForm()->addButton("delete_answer[$key]", get_lang('Delete'), 'trash', 'danger');
  37. }
  38. }
  39. }
  40. parent :: addRemoveButtons($formData);
  41. }
  42. /**
  43. * @param FormValidator $form
  44. * @param array $questionData
  45. * @param array $answers
  46. */
  47. public function render(FormValidator $form, $questionData = array(), $answers = array())
  48. {
  49. $question = new ch_yesno();
  50. $question->render($form, $questionData, $answers);
  51. }
  52. }