[29] | 1 | <?php |
---|
[95] | 2 | |
---|
[29] | 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 | */ |
---|
| 13 | class Survey { |
---|
[56] | 14 | |
---|
[29] | 15 | public $id; |
---|
| 16 | public $title; |
---|
| 17 | public $description; |
---|
| 18 | public $questions; |
---|
[95] | 19 | public $results; |
---|
| 20 | |
---|
| 21 | const DEFAULT_DESCRIPTION = "Write a helpful description for this survey here."; |
---|
[56] | 22 | |
---|
| 23 | public function __construct($id, $title, $description = null) { |
---|
[29] | 24 | $this->id = $id; |
---|
| 25 | $this->title = $title; |
---|
| 26 | $this->description = $description; |
---|
| 27 | $this->questions = array(); |
---|
[95] | 28 | |
---|
| 29 | $this->results = null; |
---|
[29] | 30 | } |
---|
[56] | 31 | |
---|
[95] | 32 | public function addQuestion($question) { |
---|
| 33 | array_push($this->questions, $question); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | public function setResults($surveyResults) { |
---|
| 37 | $this->results = $surveyResults; |
---|
| 38 | } |
---|
| 39 | |
---|
[56] | 40 | public static function getSurvey($info) { |
---|
[29] | 41 | $id = $info['surveyID']; |
---|
| 42 | $title = $info['surveyTitle']; |
---|
| 43 | $description = $info['surveyDescription']; |
---|
[56] | 44 | |
---|
[29] | 45 | $survey = new Survey($id, $title, $description); |
---|
[56] | 46 | |
---|
[29] | 47 | $numQ = 1; //number questions |
---|
[56] | 48 | while (isset($info['questionTitle' . $numQ])) { |
---|
[35] | 49 | $id = $info['questionID' . $numQ]; |
---|
[98] | 50 | $code = $info['questionCode' . $numQ]; |
---|
[29] | 51 | $title = $info['questionTitle' . $numQ]; |
---|
| 52 | $type = $info['questionType' . $numQ]; |
---|
| 53 | $description = $info['questionDescription' . $numQ]; |
---|
[56] | 54 | |
---|
[98] | 55 | $question = new Question($id, $code, $title, $type, $description); |
---|
[29] | 56 | |
---|
| 57 | $numA = 1; //number answers |
---|
[56] | 58 | while (isset($info['q' . $numQ . 'ans' . $numA])) { |
---|
[29] | 59 | $answer = $info['q' . $numQ . 'ans' . $numA]; |
---|
| 60 | $question->answers[$numA] = $answer; |
---|
[56] | 61 | |
---|
[29] | 62 | $numA++; |
---|
| 63 | } |
---|
[56] | 64 | |
---|
| 65 | |
---|
[29] | 66 | $survey->questions[$numQ] = $question; |
---|
[56] | 67 | |
---|
[29] | 68 | $numQ++; |
---|
| 69 | } |
---|
[56] | 70 | |
---|
[29] | 71 | return $survey; |
---|
| 72 | } |
---|
[56] | 73 | |
---|
[95] | 74 | /** |
---|
| 75 | * TODO: Should return Results-object from reading RDF-database |
---|
| 76 | * @param type $surveyID |
---|
| 77 | */ |
---|
| 78 | public static function getResults($surveyID) { |
---|
| 79 | |
---|
| 80 | } |
---|
| 81 | |
---|
[29] | 82 | } |
---|
[95] | 83 | |
---|
[29] | 84 | ?> |
---|