Ignore:
Timestamp:
11/08/11 17:02:55 (13 years ago)
Author:
fpvanagthoven
Message:
 
File:
1 edited

Legend:

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

    r150 r151  
    66
    77/**
    8  * Description of Sequencer
     8 * A visual interface object for editing and viewing a session's pipeline.
    99 *
    10  * @author HP
     10 * @author Tschipper
    1111 */
    1212class PipelineSequencer {
    1313
    1414    // properties
    15     private $pipeline;
     15    private $pipeline;      // array of UID strings.
    1616    private $name = "empty";
    1717    private $numStepsInArray = 0;
     
    2121    public function __construct($uid) {
    2222        $dbi = new DatabaseInterface();
    23         $this->pipeline = $dbi->get("pipeline", array("uid"=>$uid));
     23        $this->pipeline = $dbi->get("pipeline", array("uid" => $uid));
    2424    }
    2525
    2626    public function init() {
    2727        ?>
    28         <br /><form name="sequencer" action="pipelineEditor.php" method="post"><fieldset id="sequencer">
     28        <br /><form name="sequencer" action="pipelineEditor.php" method="post">
     29            <fieldset id="sequencer">
    2930                <div class="title">Name: <?php echo $this->pipeline->name; ?> </div>
    3031
    31                 <div class="seqContent">
     32                <div id="seqContent">
    3233                    <?php $this->DrawSteps(); ?>         
    3334                </div>
     
    4142                    <input type="checkbox" name="confirmClear" onChange="IsCheckEnabled(this, document.sequencer.clearPipeline);" />Really clear?
    4243                    <input type="hidden" name="selectedStep" />
     44                    <input type="hidden" name="numSteps" />
     45                    <input type="hidden" name="pipeline" />
    4346                </div>
    4447            </fieldset>
     
    4750    }
    4851
    49     public function AddStep($newStep) {
    50         $n = 1;
    51         foreach ($this->pipeline as $existingStep) {
    52             if ($existingStep->name == $newStep . " $n") {
    53                 $n++;
    54             }
    55         }
    56 
    57         $this->pipeline[] = new Step($newStep, $newStep . " " . $n, count($this->pipeline) + 1);
    58         //var_dump($this->pipeline);
    59         ?>
    60         <script type="text/javascript">
    61             document.refresh();
    62         </script>
    63         <?php
    64     }
    65 
    66     public function RemoveStep($targetStep) {
    67 
    68         $tempArray = array();
    69         $removed = false;
    70         foreach ($this->pipeline as $step) {
    71             if ($step->id != $targetStep) {
    72                 $tempArray[] = $step;
    73                 if ($removed) {
    74                     $step::AdjustID(-1);
    75                 }
    76             } else {
    77                 $removed = true;
    78             }
    79         }
    80         $this->pipeline = $tempArray;
    81     }
    82 
    83     public function GetPipeline() {
    84         return $this->pipeline;
    85     }
    86 
    8752    public function DrawSteps() {
    88         //draw the actual icons in the container div.
    89         if (!empty($this->pipeline)) {
    90             foreach ($this->pipeline as $step) {
    91                 if ($this->numStepsInArray < $this->maxNumStepsInArray) {
    92                     //var_dump($step);
    93                     $step->init();
    94                     $this->numStepsInArray++;
    95                     if ($this->numStepsInArray < $this->maxNumStepsInArray && $this->numStepsInArray < count($this->pipeline)) {
    96                         echo "<div class='divider'></div>";
    97                     }
    98                 }
    99             }
    100         }
    101     }
    102 
    103     public function MoveStep($direction) {
    104         $key = array_search($this->selectedStep, $this->pipeline);
    105         //echo $key;
    106     }
    107 
    108     private function MoveEntry(&$array, $key, $dir) {
    109         if ($dir == -1) {   // move up
    110             if ($key > 0) {
    111                 $reverseArray = array_reverse(array_slice($array, $key - 1, 2, true));   // make a reversed array of the two entries, preserving keys
    112                 array_splice($array, $key - 1, 2, $reverseArray);    // replace the given range in the oldArray with the reversed Array
    113             }
    114         } else if ($dir == 1) {   // move down
    115             if ($key < count($array) - 1) {
    116                 $reverseArray = array_reverse(array_slice($array, $key, 2, true));   // make a reversed array of the two entries, preserving keys
    117                 array_splice($array, $key, 2, $reverseArray);    // replace the given range in the oldArray with the reversed Array
    118             }
    119         }
    120     }
    121 
    122     public function SetSelected($key) {
    123 
    124         if ($key > 0 && $key < count($this->pipeline)) {
    125             $this->selectedStep = $key;
    126         }
    127     }
    128 
    129     public function GetName($name) {
    130         if ($name && $name != "") {
    131             $this->name = $name;
    132         }
    133     }
    134 
    135     public function HandlePost() {
    136 
    137         //this doesn't actually work, the sequencer doesn't know what the uid is yet. This data should be POSTed upon refresh!
    13853       
    139        
    140        
    141         if (isset($_POST['destroy'])) {
    142             unset($_POST['destroy']);
    143             unset($_SESSION['currentPipeline']);
    144         }
    145 
    146         if (isset($_POST['clearPipeline'])) {
    147             $this->pipeline = array();
    148             $_SESSION['currentPipeline'] = $this->pipeline;
    149         }
    150 
    151         if (isset($_SESSION['currentPipeline']) && !empty($_SESSION['currentPipeline'])) {      // take pipeline from session data
    152             $this->pipeline = $_SESSION['currentPipeline'];
    153         } else {
    154             $pipeline = array();
    155         }
    156 
    157         if (isset($_POST['objectToCreate'])) {      // user clicked a button in the toolbox.
    158             //$this->pipeline[] = new Step($_POST['objectToCreate'], $_POST['objectToCreate'] . " NEW", null);
    159             $this::AddStep($_POST['objectToCreate']);
    160         }
    161 
    162         if (isset($_POST['deleteSelected'])) {
    163             if (isset($_POST['selectedStep'])) {
    164                 $this->RemoveStep($_POST['selectedStep']);
    165             }
    166         }
    167 
    168         //var_dump($_POST);
    169 
    170         if (isset($_POST['selectedStep'])) {
    171             $this::SetSelected($_POST['selectedStep']);
    172         }
    173 
    174         $_SESSION['currentPipeline'] = $this->pipeline;
    17554    }
    17655
     
    18059        Add JS code for selecting steps, highlighting them, reordering, etc.
    18160        Is a refresh of the page (with subsequent querying of database really necessary?
    182        
     61
    18362        -->
    18463        <script type="text/javascript">
    185             function selectStep(step) {
    186                 step.addClass("selected");
    187                 document.sequencer.controls.selectedStep.value = step.name;
     64            function selectStep(uid) {
     65                document.getElementById(uid).addClass("selected");
     66                document.sequencer.controls.selectedStep.value = uid;
    18867            }
     68                                                                           
     69                                                                           
     70            /*
     71             * ajaxStepRequest gets  the markup for displaying a step in the sequencer from returnStep.php
     72             * Using ajax principle allows for editing of pipeline without constantly refreshing the page.
     73             */
     74                                                                           
     75            function ajaxStepRequest(uid) {     
     76                var xmlhttp;
     77                if (window.XMLHttpRequest) {    // IE7+, FF, Chrome, Opera, Safari
     78                    xmlhttp = new XMLHttpRequest();
     79                }
     80                else {  //IE 5, 6
     81                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     82                }
     83                                                                               
     84                xmlhttp.onreadystatechange = function () {
     85                    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
     86                        if (xmlhttp.responseText.length > 0) {
     87                            var newDiv = xmlhttp.responseText;
     88                            document.getElementById("seqContent").appendChild(newDiv);
     89                        }   
     90                    }
     91                }
     92                                       
     93                xmlhttp.open("POST", "returnStep.php", true);
     94                xmlhttp.send();
     95            }
     96                           
     97            function drawSteps() {
     98                var sequencer = document.getElementById("sequencer");
     99                var seqContent = document.getElementById("seqContent");
     100               
     101                // first delete all current children of seqContent (to reset the sequencer).
     102                while (seqContent.childNodes.length > 0) {
     103                    var step = seqContent.childNodes[0];
     104                    step.parentNode.removeChild(step);
     105                }
     106               
     107                // get pipeline contents from hidden form inputs.
     108                var pipeline = sequencer.controls.pipeline.value;
     109                var pipeline = pipeline.split(", ");
     110               
     111                // then do an xmlhttp request for each step to be added to the sequencer
     112                var numberOfSteps = pipeline.length;
     113                for (var i = 0; i > numberOfSteps; i++) {
     114                    ajaxStepRequest(pipeline[i]);
     115                }
     116               
     117            }
     118                                                                               
     119                                               
    189120        </script>
    190121
     
    193124    }
    194125
     126    public function GetDromDB() {   // Initialize variables on page load.
     127        $dbi = new DatabaseInterface();
     128        if (isset($_POST['currentSession'])) {
     129            $currentSession = $dbi->get("Session", array("UID" => $uid));
     130            $this->pipeline = $currentSession->pipeline;
     131        }
     132    }
     133
    195134}
    196135?>
Note: See TracChangeset for help on using the changeset viewer.