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 | ?> |
---|
39 | <p class='centerBoxed'><?php echo $this->survey->description; ?></p> |
---|
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) { |
---|
51 | echo "<fieldset>"; |
---|
52 | $this->displayQuestionTitle($question); |
---|
53 | $this->displayQuestionDescription($question); |
---|
54 | $this->displayAnswerBox($question, $numQ); |
---|
55 | echo "</fieldset>"; |
---|
56 | } |
---|
57 | |
---|
58 | private function displayQuestionTitle($question) { |
---|
59 | ?> |
---|
60 | <?php echo "<legend><h2>" . $question->title . "</h2></legend>"; ?> |
---|
61 | <?php |
---|
62 | } |
---|
63 | |
---|
64 | private function displayQuestionDescription($question) { |
---|
65 | ?> |
---|
66 | <p><?php echo "<div class='questionDescription noPadding'>" . $question->description . "</div>"; ?></p> |
---|
67 | <?php |
---|
68 | } |
---|
69 | |
---|
70 | private function displayAnswerBox($question, $numQ) { |
---|
71 | echo "<div class='answerBox'>"; |
---|
72 | switch ($question->type) { |
---|
73 | case 'text': |
---|
74 | ?> |
---|
75 | <input type="text" name="<?php echo 'q' . $numQ . 'ans1' ?>" value="" class="textBox"/> |
---|
76 | <?php |
---|
77 | break; |
---|
78 | case 'int': |
---|
79 | ?> |
---|
80 | <input type="text" name="<?php echo 'q' . $numQ . 'ans1' ?>" value="" class="intBox"/> |
---|
81 | <?php |
---|
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': |
---|
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 |
---|
106 | break; |
---|
107 | default: |
---|
108 | break; |
---|
109 | } |
---|
110 | echo "</div>"; |
---|
111 | } |
---|
112 | |
---|
113 | private function submitSurvey() { |
---|
114 | ?> |
---|
115 | <input type="submit" value="Submit survey!" class="topMargin surveyButton bigSurveyButton"/> |
---|
116 | <?php |
---|
117 | } |
---|
118 | |
---|
119 | } |
---|
120 | ?> |
---|