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

    r173 r186  
    5959                                $pipeline = $this->getPipeline($result['?uid']->label);
    6060                                $answersets = $this->getAnswerSets($result['?uid']->label);
    61                                 $creator = $this->db->get("User", array("uid" => $result['?creator']->label));
     61                                $creator = $result['?creator']->label;
    6262                                $datetime = new DateTime();
    6363                                $datetime->setTimestamp(intval($result['?datetime']->label));
    64                                 $sessions[] = new Session($result['?uid']->label, $result['?title']->label, $creator[0], $datetime, $pipeline, $answersets);
     64                                $sessions[] = new Session($result['?uid']->label, $result['?title']->label, $creator, $datetime, $pipeline, $answersets);
    6565                        }
    6666                }
     
    7979                {
    8080                        $element = $iterator->next();
    81                         if(strpos($element->getLabelPredicate(), "has_application") != false)
    82                         {
    83                                 $applications = $this->db->get("application", array("uid" => $element->getLabelObject()));
    84                                 $pipeline[] = $applications[0];
    85                         }
    86                         else
    87                         {
    88                                 $surveys = $this->db->get("survey", array("uid" => $element->getLabelObject()));
    89                                 $pipeline[] = $surveys[0];
    90                         }
     81                        $pipeline[] = $element->getLabelObject();
    9182                }
    9283                return $pipeline;
     
    10596                {
    10697                        $element = $iterator->next();
    107                         $resultsets = $this->db->get("answerset", array("uid" => $element->getLabelObject()));
    108                         $answersets[] = $resultsets[0];
     98                        $answersets[] = $element->getLabelObject();
    10999                }
    110100                return $answersets;
     
    118108        {
    119109                $this->load();
     110                //If evaluation fails, some references are incorrect.
     111                //We shouldn't save in this case. Instead - let the user know. This function returns false if the evaluation has failed.
     112                //TODO: Decide how to fix invalid references graciously.
     113                if(!$rToolObject->evaluate())
     114                        return false;
     115
    120116                $resourceSession = new Resource(SESSION . '/' . $rToolObject->uid);
    121117                //Remove the old value stored with the given id
     
    171167
    172168                $this->save();
     169                return true;
    173170        }
    174171}
Note: See TracChangeset for help on using the changeset viewer.