ch_personality.php 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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('Display').'</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('Answer options').'</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. }
  78. /**
  79. * @param FormValidator $form
  80. * @param array $questionData
  81. * @param array $answers
  82. */
  83. public function render(FormValidator $form, $questionData = [], $answers = [])
  84. {
  85. $question = new ch_yesno();
  86. $question->render($form, $questionData, $answers);
  87. }
  88. }