Changeset 163


Ignore:
Timestamp:
11/18/11 15:28:51 (13 years ago)
Author:
fpvanagthoven
Message:
  • Basically alles gefixt om te werken met een local copy van de session, opgeslagen in $_SESSIONlocalSessionCopy?.
  • Flag $_SESSIONupdateNeeded? toegevoegd om aan te geven wanneer er een update uit de database nodig is in plaats van gewoon verder werken met de local copy.
  • '123'/'456' placeholder routine weggehaald uit returnStep.php
  • CreateObject? doet nog niets, maar dat komt volgende week! (AJAX-aangestuurd object creation, met als doel: pipeline editing zonder constante page refreshes).
Location:
Dev/trunk
Files:
1 added
6 edited

Legend:

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

    r156 r163  
    1515    private $loadedSession;
    1616    private $selectedStep;
     17    private $dbi;
    1718
    1819    public function __construct() {
    19         //nothing yet
     20        $this->dbi = new DatabaseInterface();
    2021    }
    2122
    2223    public function init() {
    2324        $stringPipeline = "";
    24         if (is_array($this->loadedSession->pipeline)){
    25         foreach ($this->loadedSession->pipeline as $object) {
    26             $stringPipeline .= "$object->uid,";
    27         }
    28         $stringPipeline = rtrim($stringPipeline, ",");
    29         }
    30         else {
     25        if (is_array($this->loadedSession->pipeline)) {
     26            foreach ($this->loadedSession->pipeline as $object) {
     27                $stringPipeline .= "$object->uid,";
     28            }
     29            $stringPipeline = rtrim($stringPipeline, ",");
     30        } else {
    3131            $stringPipeline = $this->loadedSession->pipeline;
    3232        }
     
    8383    }
    8484
    85     public function GetFromDB($currentSession) {   // Initialize variables on page load.
    86         $dbi = new DatabaseInterface();
     85    public function LoadSession($currentSession) {   // Initialize variables on page load.
    8786        if (!isset($currentSession)) {
    88             $_SESSION['message'] = "No session set!";
    8987            redirect("selectSession.php");
    9088        }
    91 
    92         $sessionResults = $dbi->get("Session", array("uid" => $currentSession));
    93         if (count($sessionResults) > 0) {
    94             $this->loadedSession = $sessionResults[0];
    95         } else {        //No session with that UID found in database!
    96             die("Invalid session!");
     89        if (isset($_SESSION['updateNeeded'])) {    // user has performed an operation that flags session to be reloaded from DB, or is first load of page for that session
     90            $sessionResults = $this->dbi->get("Session", array("uid" => $currentSession));
     91           
     92            if (count($sessionResults) > 0) {
     93                $_SESSION['localSessionCopy'] = $sessionResults[0];
     94            } else {
     95                die("No session with that UID found!");
     96            }
    9797        }
    98         var_dump($this->loadedSession->pipeline);
     98            var_dump($_SESSION['localSessionCopy']);   
     99       
     100        if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) {
     101           
     102            $this->loadedSession = $_SESSION['localSessionCopy'];
     103            unset($_SESSION['updateNeeded']);
     104        }
     105       
    99106    }
    100107
     
    152159    }
    153160
     161    public function StoreToDb() {
     162        if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) {
     163            $this->dbi->set($_SESSION['localSessionCopy']);
     164            unset($_SESSION['updateNeeded']);
     165        }
     166    }
     167
    154168}
    155169?>
  • Dev/trunk/createapplication.php

    r156 r163  
    99
    1010$dbi = new DatabaseInterface();
    11 $session_results = $dbi->get("session", array("uid" => $_SESSION['currentSession']));
    12 
    13 if (count($session_results) > 0) {
    14     $session = $session_results[0];
    15 }
    1611
    1712$newApplication = new Application(null, "New application", "Default application", "Default style");
    1813$dbi->set($newApplication);
    19 $session->pipeline[] = $newApplication->uid;
    20 //$dbi->set($session);
     14
     15if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) {
     16    $session = $_SESSION['localSessionCopy'];
     17    $session->pipeline[] = $newApplication;
     18    $_SESSION['localSessionCopy'] = $session;
     19}
    2120
    2221redirect("pipelineEditor.php");
  • Dev/trunk/createsurvey.php

    r156 r163  
    88
    99$dbi = new DatabaseInterface();
    10 $creator_results = $dbi->get("user", array("name" => $_SESSION['username']));
     10$creator_results = $dbi->get("user", array("name" => $_SESSION['username']));   // Determine if user exists, so we can add him/her as creator of the new survey
    1111if (count($creator_results) > 0) {
    1212    $creator = $creator_results[0];
     
    1818
    1919// Optional part, for when the session needs to be set in pipelineEditor
    20 $session_results = $dbi->get("session", array("uid" => $_SESSION['currentSession']));
    21 if (count($session_results) > 0) {
    22     $session = $session_results[0];
     20// For now, store in local copy, only upload local copy to db when needed (page change, etc...)
     21if (isset($_SESSION['localSessionCopy']) && !empty($_SESSION['localSessionCopy'])) {
     22    $session = $_SESSION['localSessionCopy'];
    2323    $session->pipeline[] = $newSurvey;
    24     $dbi->set($session);
     24    $_SESSION['localSessionCopy'] = $session;
    2525}
    2626
  • Dev/trunk/pipelineEditor.php

    r154 r163  
    77
    88$sequencer = new PipelineSequencer();
    9 $sequencer->GetFromDB($_SESSION['currentSession']); //load session into php part of the sequencer
     9$sequencer->LoadSession($_SESSION['currentSession']); //load session into php part of the sequencer
    1010$sequencer->HandlePostData();
    1111?>
  • Dev/trunk/returnStep.php

    r157 r163  
    4040function processUid($uid) {
    4141        $dbi = new DatabaseInterface();
    42     if ($uid == "123") {        // test case for when steps aren't actually working
    43         $imageURL = "images/icons/unknowntype.png";
    44         $responsePart = '<div class="displayStep" id="' . "123" . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . "123" . '</div>';
    45         return $responsePart;
    46     } else if ($uid == '456') {
    47         $imageURL = "images/icons/unknowntype.png";
    48         $responsePart = '<div class="displayStep" id="' . "456" . '" onClick="selectStep(this.id);"><div class="displayStepIcon"><img src="' . $imageURL . '" /></div>' . "456" . '</div>';
    49         return $responsePart;
    50     } else {
    51 
    52 
    5342        if ($uid == "divider") {    //a divider has been requested instead of a displaystep
    5443            $responsePart = '<div class="divider"></div>';
     
    6857            }
    6958
    70             if ($result != null) {
     59            if ($result == null) {
    7160                $applications = $dbi->get("Application", array("uid" => $uid));
    7261                if (count($applications) > 0) {
     
    7968            }
    8069
    81             if ($result != null) {
     70            if ($result == null) {
    8271                $dashboards = $dbi->get("Dashboard", array("uid" => $uid));
    8372                if (count($dashboards) > 0) {
     
    116105            }
    117106        }
    118     }
     107   
    119108}
    120109
  • Dev/trunk/selectSession.php

    r156 r163  
    2222                // make new session!
    2323                unset($matching);
    24                 $session = new Session(null, $_POST['newSessionName'], null, null, null);
     24                $session = new Session(null, $_POST['newSessionName'], $_SESSION['username'], new DateTime(), null, null);
    2525                $dbi->set($session);
    2626            } else {
     
    4444        if (count($matching) == 1 && $matching[0] != null) {
    4545            $_SESSION['currentSession'] = $_POST['sessionUID'];
     46            $_SESSION['updateNeeded'] = "true";
    4647            redirect("pipelineEditor.php");
    4748        }
     
    7778            <?php
    7879                        foreach ($sessions as $session) {
    79                             echo '<option value="' . $session->uid . '">' . $session->title . '</option>' . "\n";
     80                            $selected = "";
     81                            if ($session->title == $_POST['newSessionName']) {
     82                                $selected = ' selected="true"';
     83                            }
     84                           
     85                            echo '<option value="' . $session->uid . '"' . $selected . '>' . $session->title . '</option>' . "\n";
    8086                        }
    8187                        ?>                   
    8288                    </select>
    8389                    <br /><br />
     90                    <input type="hidden" name="updateNeeded" value="true" />
    8491                    <input type="text" name="newSessionName" value="Name..." style="float: left;" /><br />
    8592                    <input type="submit" name="createSession" value="Create new session" class="surveybutton" style="float: left;" />
Note: See TracChangeset for help on using the changeset viewer.