[144] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * To change this template, choose Tools | Templates |
---|
| 4 | * and open the template in the editor. |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | /** |
---|
| 8 | * Description of Sequencer |
---|
| 9 | * |
---|
| 10 | * @author HP |
---|
| 11 | */ |
---|
[146] | 12 | class PipelineSequencer { |
---|
[144] | 13 | |
---|
| 14 | // properties |
---|
[150] | 15 | private $pipeline; |
---|
| 16 | private $name = "empty"; |
---|
[144] | 17 | private $numStepsInArray = 0; |
---|
[146] | 18 | private $maxNumStepsInArray = 10; |
---|
[144] | 19 | private $selectedStep; |
---|
| 20 | |
---|
[150] | 21 | public function __construct($uid) { |
---|
| 22 | $dbi = new DatabaseInterface(); |
---|
| 23 | $this->pipeline = $dbi->get("pipeline", array("uid"=>$uid)); |
---|
[146] | 24 | } |
---|
[144] | 25 | |
---|
[150] | 26 | public function init() { |
---|
[144] | 27 | ?> |
---|
| 28 | <br /><form name="sequencer" action="pipelineEditor.php" method="post"><fieldset id="sequencer"> |
---|
[150] | 29 | <div class="title">Name: <?php echo $this->pipeline->name; ?> </div> |
---|
[144] | 30 | |
---|
| 31 | <div class="seqContent"> |
---|
[146] | 32 | <?php $this->DrawSteps(); ?> |
---|
[144] | 33 | </div> |
---|
| 34 | |
---|
| 35 | <div id="controls"> |
---|
| 36 | <input type="submit" name="moveSelectedLeft" value="< Move" class="surveyButton" /> |
---|
| 37 | <input type="submit" name="moveSelectedRight" value="Move >" class="surveyButton" /> |
---|
| 38 | <input type="submit" name="editSelected" value="Edit step" class="surveyButton" /> |
---|
| 39 | <input type="submit" name="deleteSelected" value="Delete step" class="surveyButton" /> |
---|
[146] | 40 | <input type="submit" name="clearPipeline" value="Clear pipeline" class="surveyButton dis" disabled="true"/> |
---|
| 41 | <input type="checkbox" name="confirmClear" onChange="IsCheckEnabled(this, document.sequencer.clearPipeline);" />Really clear? |
---|
[144] | 42 | <input type="hidden" name="selectedStep" /> |
---|
| 43 | </div> |
---|
| 44 | </fieldset> |
---|
| 45 | </form> |
---|
| 46 | <?php |
---|
| 47 | } |
---|
| 48 | |
---|
[146] | 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); |
---|
[144] | 59 | ?> |
---|
| 60 | <script type="text/javascript"> |
---|
| 61 | document.refresh(); |
---|
| 62 | </script> |
---|
| 63 | <?php |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | public function RemoveStep($targetStep) { |
---|
| 67 | |
---|
[146] | 68 | $tempArray = array(); |
---|
| 69 | $removed = false; |
---|
| 70 | foreach ($this->pipeline as $step) { |
---|
| 71 | if ($step->id != $targetStep) { |
---|
[144] | 72 | $tempArray[] = $step; |
---|
[146] | 73 | if ($removed) { |
---|
| 74 | $step::AdjustID(-1); |
---|
| 75 | } |
---|
| 76 | } else { |
---|
| 77 | $removed = true; |
---|
[144] | 78 | } |
---|
| 79 | } |
---|
[146] | 80 | $this->pipeline = $tempArray; |
---|
[144] | 81 | } |
---|
| 82 | |
---|
[146] | 83 | public function GetPipeline() { |
---|
| 84 | return $this->pipeline; |
---|
[144] | 85 | } |
---|
| 86 | |
---|
[146] | 87 | public function DrawSteps() { |
---|
[144] | 88 | //draw the actual icons in the container div. |
---|
[146] | 89 | if (!empty($this->pipeline)) { |
---|
| 90 | foreach ($this->pipeline as $step) { |
---|
| 91 | if ($this->numStepsInArray < $this->maxNumStepsInArray) { |
---|
| 92 | //var_dump($step); |
---|
[150] | 93 | $step->init(); |
---|
[146] | 94 | $this->numStepsInArray++; |
---|
| 95 | if ($this->numStepsInArray < $this->maxNumStepsInArray && $this->numStepsInArray < count($this->pipeline)) { |
---|
| 96 | echo "<div class='divider'></div>"; |
---|
| 97 | } |
---|
[144] | 98 | } |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
[146] | 103 | public function MoveStep($direction) { |
---|
| 104 | $key = array_search($this->selectedStep, $this->pipeline); |
---|
| 105 | //echo $key; |
---|
[144] | 106 | } |
---|
| 107 | |
---|
[146] | 108 | private function MoveEntry(&$array, $key, $dir) { |
---|
[144] | 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 | |
---|
[146] | 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 | |
---|
[150] | 135 | public function HandlePost() { |
---|
[146] | 136 | |
---|
[150] | 137 | //this doesn't actually work, the sequencer doesn't know what the uid is yet. This data should be POSTed upon refresh! |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | |
---|
[146] | 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; |
---|
| 175 | } |
---|
| 176 | |
---|
[150] | 177 | private function Javascript() { |
---|
| 178 | ?> |
---|
| 179 | <!-- |
---|
| 180 | Add JS code for selecting steps, highlighting them, reordering, etc. |
---|
| 181 | Is a refresh of the page (with subsequent querying of database really necessary? |
---|
| 182 | |
---|
| 183 | --> |
---|
| 184 | <script type="text/javascript"> |
---|
| 185 | function selectStep(step) { |
---|
| 186 | step.addClass("selected"); |
---|
| 187 | document.sequencer.controls.selectedStep.value = step.name; |
---|
| 188 | } |
---|
| 189 | </script> |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | <?php |
---|
| 193 | } |
---|
| 194 | |
---|
[144] | 195 | } |
---|
| 196 | ?> |
---|