[51] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * Description of SurveyTool |
---|
| 5 | * |
---|
| 6 | * @author fpvanagthoven |
---|
| 7 | */ |
---|
| 8 | class SurveyTool { |
---|
| 9 | |
---|
| 10 | private $survey; |
---|
| 11 | |
---|
| 12 | public function __construct($survey) { |
---|
| 13 | $this->survey = $survey; |
---|
| 14 | |
---|
| 15 | $this->init(); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | private function init() { |
---|
| 19 | ?> |
---|
| 20 | <form action="" method="post"> |
---|
| 21 | <?php |
---|
| 22 | $this->displayTitle(); |
---|
| 23 | $this->displayDescription(); |
---|
| 24 | $this->displayQuestions(); |
---|
| 25 | $this->submitSurvey(); |
---|
| 26 | ?> |
---|
| 27 | </form> |
---|
| 28 | <?php |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | private function displayTitle() { |
---|
| 32 | ?> |
---|
| 33 | <h1><?php echo $this->survey->title; ?></h1> |
---|
| 34 | <?php |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | private function displayDescription() { |
---|
| 38 | ?> |
---|
[52] | 39 | <p class='centerBoxed'><?php echo $this->survey->description; ?></p> |
---|
[51] | 40 | <?php |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | private function displayQuestions() { |
---|
| 44 | foreach ($this->survey->questions as $numQ => $question) { |
---|
| 45 | |
---|
| 46 | $this->displayQuestion($question, $numQ); |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | private function displayQuestion($question, $numQ) { |
---|
[52] | 51 | echo "<fieldset>"; |
---|
[51] | 52 | $this->displayQuestionTitle($question); |
---|
| 53 | $this->displayQuestionDescription($question); |
---|
| 54 | $this->displayAnswerBox($question, $numQ); |
---|
[52] | 55 | echo "</fieldset>"; |
---|
[51] | 56 | } |
---|
| 57 | |
---|
| 58 | private function displayQuestionTitle($question) { |
---|
| 59 | ?> |
---|
[52] | 60 | <?php echo "<legend><h2>" . $question->title . "</h2></legend>"; ?> |
---|
[51] | 61 | <?php |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | private function displayQuestionDescription($question) { |
---|
| 65 | ?> |
---|
[52] | 66 | <p><?php echo "<div class='questionDescription noPadding'>" . $question->description . "</div>"; ?></p> |
---|
[51] | 67 | <?php |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | private function displayAnswerBox($question, $numQ) { |
---|
[52] | 71 | echo "<div class='answerBox'>"; |
---|
[51] | 72 | switch ($question->type) { |
---|
| 73 | case 'text': |
---|
[52] | 74 | ?> |
---|
| 75 | <input type="text" name="<?php echo 'q' . $numQ . 'ans1' ?>" value="" class="textBox"/> |
---|
| 76 | <?php |
---|
[51] | 77 | break; |
---|
| 78 | case 'int': |
---|
[52] | 79 | ?> |
---|
| 80 | <input type="text" name="<?php echo 'q' . $numQ . 'ans1' ?>" value="" class="intBox"/> |
---|
| 81 | <?php |
---|
[51] | 82 | break; |
---|
| 83 | case 'mc': |
---|
| 84 | foreach ($question->answers as $answer) { |
---|
| 85 | ?> |
---|
| 86 | <input type="radio" name="<?php echo 'q' . $numQ . 'ans1' ?>" value="<?php echo $answer; ?>" /><?php echo $answer; ?><br /> |
---|
| 87 | <?php |
---|
| 88 | } |
---|
| 89 | break; |
---|
| 90 | case 'checkboxes': |
---|
| 91 | foreach ($question->answers as $numA => $answer) { |
---|
| 92 | ?> |
---|
| 93 | <input type="checkbox" name="<?php echo 'q' . $numQ . 'ans' . $numA; ?>" value="<?php echo $answer; ?>" /><?php echo $answer; ?><br /> |
---|
| 94 | <?php |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | break; |
---|
| 98 | case 'scale': |
---|
[52] | 99 | ?> |
---|
| 100 | <div class="scaleLabel"><?php echo $question->answers[1]; ?></div> |
---|
| 101 | <?php |
---|
| 102 | for ($i = 1; $i < $question->answers[3] + 1; $i++) { |
---|
| 103 | ?><input type="radio" class="scaleRadio" name="<?php echo 'q' . $numQ . 'ans1' ?>" value="<?php echo $i;?>"/><?php } ?> |
---|
| 104 | <div class="scaleLabel"><?php echo $question->answers[2]; ?></div> |
---|
| 105 | <?php |
---|
[51] | 106 | break; |
---|
| 107 | default: |
---|
| 108 | break; |
---|
| 109 | } |
---|
[52] | 110 | echo "</div>"; |
---|
[51] | 111 | } |
---|
| 112 | |
---|
| 113 | private function submitSurvey() { |
---|
| 114 | ?> |
---|
[52] | 115 | <input type="submit" value="Submit survey!" class="topMargin surveyButton bigSurveyButton"/> |
---|
[51] | 116 | <?php |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | } |
---|
| 120 | ?> |
---|