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

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

ID passed. Simple Question and Survey php data classes.

File size: 1.5 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            $title = $info['questionTitle' . $numQ];
39            $type = $info['questionType' . $numQ];
40            $description = $info['questionDescription' . $numQ];
41                   
42            $question = new Question($title, $type, $description);
43
44            $numA = 1; //number answers
45            while (isset($info['q' . $numQ . 'ans' . $numA]))
46            {
47                $answer = $info['q' . $numQ . 'ans' . $numA];
48                $question->answers[$numA] = $answer;
49               
50                $numA++;
51            }
52           
53           
54            $survey->questions[$numQ] = $question;
55           
56            $numQ++;
57        }
58       
59        return $survey;
60    }
61   
62}
63
64?>
Note: See TracBrowser for help on using the repository browser.