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/Session.php

    r174 r186  
    3737        }
    3838
     39        /*
     40         * function evaluate(()
     41         * Evaluates all the references of this object.
     42         */
     43        public function evaluate()
     44        {
     45                $dbi = new DatabaseInterface();
     46                if(is_string($this->creator))
     47                {
     48                        $result = $dbi->get("user", array("uid" => $this->creator));
     49                        if(!isset($result[0]))
     50                                return false;
     51                        $this->creator = $result[0];
     52                }
     53                if(!empty($this->pipeline) && is_string($this->pipeline[0]))
     54                {
     55                        $newPipeline = array();
     56                        foreach($this->pipeline as $element)
     57                        {
     58                                //Check if the element's UID can be found in surveys, if not:
     59                                //Check applications. If it isn't in either: invalid reference.
     60                                $result = $dbi->get("survey", array("uid" => $element));
     61                                if(!isset($result[0]))
     62                                        $result = $dbi->get("application", array("uid" => $element));
     63                                if(!isset($result[0]))
     64                                        return false;
     65                                $newPipeline[] = $result[0];
     66                        }
     67                        $this->pipeline = $newPipeline;
     68                }
     69                if(!empty($this->answersets) && is_string($this->answersets[0]))
     70                {
     71                        $newAnswerSets = array();
     72                        foreach($this->answersets as $element)
     73                        {
     74                                $result = $dbi->get("answerset", array("uid" => $element));
     75                                if(!isset($result[0]))
     76                                        return false;
     77                                $newAnswerSets[] = $result[0];
     78                        }
     79                        $this->answersets = $newAnswerSets;
     80                }
     81                return true;
     82        }
     83
    3984        /**
    4085         * function toSPSS
    4186         * @param type $location
    4287         * Writes an SPSS parseable file at the given location, named '$datetime_$title.txt'
     88         * One big note about toSPSS: If this session contains multiple instances of THE SAME Survey,
     89         * the world burns, people die, etcetera. (or, in a more fortunate case, the latest values
     90         * are written to the file whilst the others get lost.
    4391         */
    4492        public function toSPSS($location)
    4593        {
     94                $this->evaluate();
    4695                if(!is_dir($location))
    4796                {
     
    58107                        if(get_class($element) == "Survey")
    59108                        {
     109                                $element->evaluate();
    60110                                foreach($element->questions as $question)
    61111                                {
     112                                        //TODO: This might need fixing after lazy initialization refactoring.
    62113                                        $headers[] = $element->title . '_' . $question->uid;
    63114                                }
Note: See TracChangeset for help on using the changeset viewer.