source: Dev/branches/jos-branch/classes_old/AnswerSet.php @ 210

Last change on this file since 210 was 210, checked in by jkraaijeveld, 13 years ago

Moved all classes into classes_old

File size: 1.5 KB
RevLine 
[149]1<?php
2
3/**
4 * AnswerSet is a collection of answers corresponding to a Session
5 *
6 */
7class AnswerSet extends ResearchToolObject{
8        public $survey;
9        public $respondent;
10        public $answers;
11
12        /**
13         * Constructor for an AnswerSet object
14         * @param type $uid
[186]15         * @param type $survey
16         * @param type $respondent
17         * @param type $answers
[149]18         */
19        public function __construct($uid=null, $survey=null, $respondent=null, $answers=null)
20        {
21                if(!isset($uid))
22                {
23                        $uid = md5(uniqid(rand(), true));
24                }
25                $this->uid = $uid;
26                $this->survey = $survey;
27                $this->respondent = $respondent;
28                $this->answers = $answers;
29        }
[186]30
31        /**
32         * function evaluate()
33         * evaluates the references of survey, respondent and answers.
34         */
35        public function evaluate()
36        {
37                $dbi = new DatabaseInterface();
38                if(is_string($this->survey))
39                {
40                        $result = $dbi->get("survey", array("uid" => $this->survey));
41                        if(!isset($result[0]))
42                                return false;
43                        $this->survey = $result[0];
44                }
45                if(is_string($this->respondent))
46                {
47                        $result = $dbi->get("respondent", array("uid" => $this->respondent));
48                        if(!isset($result[0]))
49                                return false;
50                        $this->respondent = $result[0];
51                }
52                if(!empty($this->answers) && is_string($this->answers[0]))
53                {
54                        $newanswers = array();
55                        foreach($this->answers as $answer)
56                        {
57                                $result = $dbi->get("answer", array("uid" => $answer));
58                                if(!isset($result[0]))
59                                        return false;
60                                $newanswers[] = $result[0];
61                        }
62                        $this->answers = $newanswers;
63                }
64                return true;
65        }
[149]66}
67
Note: See TracBrowser for help on using the repository browser.