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

    r171 r186  
    5050                        foreach($results as $result)
    5151                        {
    52                                 $survey = $this->db->get("survey", array("uid" => $result['?for_survey']->label));
    53                                 $respondent = $this->db->get("respondent", array("uid" => $result['?by_respondent']->label));
     52                                $survey = $result['?for_survey']->label;
     53                                $respondent = $result['?by_respondent']->label;
    5454                                $answers =      $this->getAnswers($result['?uid']->label);
    5555                                $answerSets[] = new AnswerSet($result['?uid']->label, $survey[0], $respondent[0], $answers);
     
    7171                {
    7272                        $element = $iterator->next();
    73                         $answersR = $this->db->get("answer", array("uid" => $element->getLabelObject()));
    74                         $answers[] = $answersR[0];
     73                        $answers[] = $element->getLabelObject();
    7574                }
    7675                return $answers;
     
    8483        {
    8584                $this->load();
     85                //If evaluation fails, some references are incorrect.
     86                //We shouldn't save in this case. Instead - let the user know. This function returns false if the evaluation has failed.
     87                //TODO: Decide how to fix invalid references graciously.
     88                if(!$rToolObject->evaluate())
     89                        return false;
     90
    8691                $resourceAnswerSet = new Resource(ANSWERSET . '/' . $rToolObject->uid);
    8792                //Remove the old value stored with the given id
     
    115120                }
    116121                $this->save();
     122                return true;
    117123        }
    118124}
Note: See TracChangeset for help on using the changeset viewer.