| @@ 140-154 (lines=15) @@ | ||
| 137 | * |
|
| 138 | * @return $this |
|
| 139 | */ |
|
| 140 | public function moveOrderDown() |
|
| 141 | { |
|
| 142 | $orderColumnName = $this->determineOrderColumnName(); |
|
| 143 | ||
| 144 | $swapWithModel = $this->buildSortQuery()->limit(1) |
|
| 145 | ->ordered() |
|
| 146 | ->where($orderColumnName, '>', $this->$orderColumnName) |
|
| 147 | ->first(); |
|
| 148 | ||
| 149 | if (! $swapWithModel) { |
|
| 150 | return $this; |
|
| 151 | } |
|
| 152 | ||
| 153 | return $this->swapOrderWithModel($swapWithModel); |
|
| 154 | } |
|
| 155 | ||
| 156 | /** |
|
| 157 | * Swaps the order of this model with the model 'above' this model. |
|
| @@ 161-175 (lines=15) @@ | ||
| 158 | * |
|
| 159 | * @return $this |
|
| 160 | */ |
|
| 161 | public function moveOrderUp() |
|
| 162 | { |
|
| 163 | $orderColumnName = $this->determineOrderColumnName(); |
|
| 164 | ||
| 165 | $swapWithModel = $this->buildSortQuery()->limit(1) |
|
| 166 | ->ordered('desc') |
|
| 167 | ->where($orderColumnName, '<', $this->$orderColumnName) |
|
| 168 | ->first(); |
|
| 169 | ||
| 170 | if (! $swapWithModel) { |
|
| 171 | return $this; |
|
| 172 | } |
|
| 173 | ||
| 174 | return $this->swapOrderWithModel($swapWithModel); |
|
| 175 | } |
|
| 176 | ||
| 177 | /** |
|
| 178 | * Swap the order of this model with the order of another model. |
|