Ignore:
Timestamp:
12/16/11 11:19:54 (13 years ago)
Author:
jkraaijeveld
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/classes/AnswerSet.php

    r149 r186  
    1313         * Constructor for an AnswerSet object
    1414         * @param type $uid
    15          * @param type $question
    16          * @param type $values
     15         * @param type $survey
     16         * @param type $respondent
     17         * @param type $answers
    1718         */
    1819        public function __construct($uid=null, $survey=null, $respondent=null, $answers=null)
     
    2728                $this->answers = $answers;
    2829        }
     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        }
    2966}
    3067
Note: See TracChangeset for help on using the changeset viewer.