ch_personality.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class ch_personality.
  5. */
  6. class ch_personality extends survey_question
  7. {
  8. /**
  9. * This function creates the form elements for the multiple response questions.
  10. *
  11. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  12. *
  13. * @version January 2007
  14. */
  15. public function createForm($survey_data, $form_content)
  16. {
  17. parent::createForm($survey_data, $form_content);
  18. $this->html .= ' <tr>';
  19. $this->html .= ' <td colspan="2"><strong>'.get_lang('DisplayAnswersHorVert').'</strong></td>';
  20. $this->html .= ' </tr>';
  21. // Horizontal or vertical
  22. $this->html .= ' <tr>';
  23. $this->html .= ' <td align="right" valign="top">&nbsp;</td>';
  24. $this->html .= ' <td>';
  25. $this->html .= ' <input name="horizontalvertical" type="radio" value="horizontal" ';
  26. if (empty($form_content['horizontalvertical']) || $form_content['horizontalvertical'] == 'horizontal') {
  27. $this->html .= 'checked="checked"';
  28. }
  29. $this->html .= '/>'.get_lang('Horizontal').'</label><br />';
  30. $this->html .= ' <input name="horizontalvertical" type="radio" value="vertical" ';
  31. if (isset($form_content['horizontalvertical']) && $form_content['horizontalvertical'] == 'vertical') {
  32. $this->html .= 'checked="checked"';
  33. }
  34. $this->html .= ' />'.get_lang('Vertical').'</label>';
  35. $this->html .= ' </td>';
  36. $this->html .= ' <td>&nbsp;</td>';
  37. $this->html .= ' </tr>';
  38. $this->html .= ' <tr>
  39. <td colspan="">&nbsp;</td>
  40. </tr>';
  41. // The options
  42. $this->html .= ' <tr>';
  43. $this->html .= ' <td colspan="3"><strong>'.get_lang('AnswerOptions').'</strong></td>';
  44. $this->html .= ' </tr>';
  45. $total_number_of_answers = count($form_content['answers']);
  46. $question_values = [];
  47. // Values of question options
  48. if (is_array($form_content['values'])) { // Check if data is correct
  49. foreach ($form_content['values'] as $key => &$value) {
  50. $question_values[] = '<input size="3" type="text" id="values['.$key.']" name="values['.$key.']" value="'.$value.'" />';
  51. }
  52. }
  53. $count = 0;
  54. if (is_array($form_content['answers'])) {
  55. foreach ($form_content['answers'] as $key => &$value) {
  56. $this->html .= '<tr>';
  57. $this->html .= '<td align="right"><label for="answers['.$key.']">'.($key + 1).'</label></td>';
  58. $this->html .= '<td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key])), '', '', null, ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120']).'</td>';
  59. $this->html .= '<td>';
  60. if ($total_number_of_answers > 2) {
  61. $this->html .= $question_values[$count];
  62. }
  63. if ($key < $total_number_of_answers - 1) {
  64. $this->html .= '<input type="image" style="width:22px" src="'.Display::returnIconPath('down.png').'" value="move_down['.$key.']" name="move_down['.$key.']"/>';
  65. }
  66. if ($key > 0) {
  67. $this->html .= '<input type="image" style="width:22px" src="'.Display::returnIconPath('up.png').'" value="move_up['.$key.']" name="move_up['.$key.']"/>';
  68. }
  69. if ($total_number_of_answers > 2) {
  70. $this->html .= '<input type="image" style="width:22px" src="'.Display::returnIconPath('delete.png').'" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
  71. }
  72. $this->html .= '</td>';
  73. $this->html .= '</tr>';
  74. $count++;
  75. }
  76. }
  77. // The buttons for adding or removing
  78. //$this->html .= parent :: add_remove_buttons($form_content);
  79. }
  80. /**
  81. * @param FormValidator $form
  82. * @param array $questionData
  83. * @param array $answers
  84. */
  85. public function render(FormValidator $form, $questionData = [], $answers = [])
  86. {
  87. $question = new ch_yesno();
  88. $question->render($form, $questionData, $answers);
  89. }
  90. }