source: Dev/trunk/classes/Survey.php @ 56

Last change on this file since 56 was 56, checked in by fpvanagthoven, 14 years ago

Stubs and some refactoring

File size: 2.3 KB
RevLine 
[29]1<?php
2/*
3 * To change this template, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7/**
8 * Description of Survey
9 *
10 * @author fpvanagthoven
11 */
12class Survey {
[56]13
[29]14    public $id;
15    public $title;
16    public $description;
17    public $questions;
[56]18
19    public function __construct($id, $title, $description = null) {
[29]20        $this->id = $id;
21        $this->title = $title;
22        $this->description = $description;
23        $this->questions = array();
24    }
[56]25
26    public static function getSurvey($info) {
[29]27        $id = $info['surveyID'];
28        $title = $info['surveyTitle'];
29        $description = $info['surveyDescription'];
[56]30
[29]31        $survey = new Survey($id, $title, $description);
[56]32
[29]33        $numQ = 1; //number questions
[56]34        while (isset($info['questionTitle' . $numQ])) {
[35]35            $id = $info['questionID' . $numQ];
[29]36            $title = $info['questionTitle' . $numQ];
37            $type = $info['questionType' . $numQ];
38            $description = $info['questionDescription' . $numQ];
[56]39
[35]40            $question = new Question($id, $title, $type, $description);
[29]41
42            $numA = 1; //number answers
[56]43            while (isset($info['q' . $numQ . 'ans' . $numA])) {
[29]44                $answer = $info['q' . $numQ . 'ans' . $numA];
45                $question->answers[$numA] = $answer;
[56]46
[29]47                $numA++;
48            }
[56]49
50
[29]51            $survey->questions[$numQ] = $question;
[56]52
[29]53            $numQ++;
54        }
[56]55
[29]56        return $survey;
57    }
[56]58
59    public static function newSurveyButton() {
60        ?>
61
62        <form action="surveycreation.php" method="post">
63
64            <input type="submit" value="Create new survey" class="surveyButton bigSurveyButton" />
65
66        </form>
67
68        <?php
69    }
70
71    /**
72     *
73     * @param Survey $surveys An array of surveys
74     */
75    public static function loadSurveyButton($surveys) {
76        ?>
77        <form id="loadForm" action="surveycreation.php" method="post">
78            <input type="button" onclick="loadSurvey()" value="Load survey" class="surveyButton bigSurveyButton" />
79        </form>
80        <br/>
81        <select id="surveysToLoad" size="1000">
82            <?php
83            foreach ($surveys as $survey) {
84                ?><option value='<?php echo $survey->id; ?>'><?php echo $survey->title; ?></option><?php
85        }
86            ?>
87        </select>
88        <?php
89    }
90
[29]91}
92?>
Note: See TracBrowser for help on using the repository browser.