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

    r171 r186  
    1111 */
    1212class AnswerConnector extends Connector{
    13         protected $db;
    1413   
    1514    /**
     
    5150                if(!empty($results))
    5251                {
    53             $this->db = new DatabaseInterface();
    5452                        foreach($results as $result)
    5553                        {
    56                                 $questionResult = $this->db->get("question", array("code" => $result['?question_code']->label));
    57                                 $answers[] = new Answer($result['?uid']->label, $questionResult[0], $this->getValues($result['?uid']->label));
     54                                $answers[] = new Answer($result['?uid']->label, $result['?question_code']->label, $this->getValues($result['?uid']->label));
    5855                        }
    5956                }
     
    8481    public function set($rToolObject)
    8582    {
    86         $this->load();
    87        
     83                $this->load();
     84                //If evaluation fails, some references are incorrect.
     85                //We shouldn't save in this case. Instead - let the user know. This function returns false if the evaluation has failed.
     86                //TODO: Decide how to fix invalid references graciously.
     87                if(!$rToolObject->evaluate())
     88                        return false;
    8889        $resourceAnswer = new Resource(ANSWER.'/'.$rToolObject->uid);       
    8990        //Remove the old value stored with the given id
     
    112113                        }
    113114                }
    114         $this->save();
     115                $this->save();
     116                return true;
    115117    }
    116118}
Note: See TracChangeset for help on using the changeset viewer.