source: Dev/trunk/classes/Answer.php @ 186

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

Implemented lazy evaluation.

  • Initially, references to other database objects are now given as an ID rather than an object.
  • Every model class now has an evaluate() function, which gets all the objects that object has references to. Returns true if it got all the values correctly, false if there are invalid references.
  • Every connector now first evaluates an object before storing, to make sure only objects with valid references get stored.
File size: 1.0 KB
Line 
1<?php
2
3/**
4 * Description of Answer
5 *
6 * @author jkraaijeveld
7 */
8class Answer extends ResearchToolObject {
9    public $question;
10        public $values;
11   
12    /**
13     * Constructor for an Answer object
14     * @param type $uid : The uid of the Answer object.
15     * @param type $question : The Question object this Answer answers.
16     * @param type $values : An array of strings, containing the answers.
17     */
18    public function __construct($uid = null, $question = null, $values = null) {
19      if(!isset($uid))
20      {
21            $uid = md5(uniqid(rand(), true));
22      }
23      $this->uid = $uid;
24      $this->question = $question;
25      $this->values = $values;
26        }
27       
28        /**
29         * function evaluate()
30         * Evaluates the references and fills in the objects for them instead.
31         */
32        public function evaluate()
33        {
34                if(is_string($this->question))
35                {
36                        $dbi = new DatabaseInterface();
37                        $result = $dbi->get("question", array("code" => $this->question));
38                        if(!isset($result[0]))
39                                return false;
40                        $this->question = $result[0];
41                }
42                return true;
43
44        }
45}
46
47?>
Note: See TracBrowser for help on using the repository browser.