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

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

QuestionID now gets passed.

File size: 1.6 KB
Line 
1<?php
2
3/*
4 * To change this template, choose Tools | Templates
5 * and open the template in the editor.
6 */
7
8/**
9 * Description of Survey
10 *
11 * @author fpvanagthoven
12 */
13class Survey {
14    public $id;
15    public $title;
16    public $description;
17    public $questions;
18   
19    public function __construct($id, $title, $description = null)
20    {
21        $this->id = $id;
22        $this->title = $title;
23        $this->description = $description;
24        $this->questions = array();
25    }
26   
27    public static function getSurvey($info)
28    {
29        $id = $info['surveyID'];
30        $title = $info['surveyTitle'];
31        $description = $info['surveyDescription'];
32       
33        $survey = new Survey($id, $title, $description);
34       
35        $numQ = 1; //number questions
36        while (isset($info['questionTitle' . $numQ]))
37        {
38            $id = $info['questionID' . $numQ];
39            $title = $info['questionTitle' . $numQ];
40            $type = $info['questionType' . $numQ];
41            $description = $info['questionDescription' . $numQ];
42                   
43            $question = new Question($id, $title, $type, $description);
44
45            $numA = 1; //number answers
46            while (isset($info['q' . $numQ . 'ans' . $numA]))
47            {
48                $answer = $info['q' . $numQ . 'ans' . $numA];
49                $question->answers[$numA] = $answer;
50               
51                $numA++;
52            }
53           
54           
55            $survey->questions[$numQ] = $question;
56           
57            $numQ++;
58        }
59       
60        return $survey;
61    }
62   
63}
64
65?>
Note: See TracBrowser for help on using the repository browser.