| @@ 131-151 (lines=21) @@ | ||
| 128 | * |
|
| 129 | * @return $this |
|
| 130 | */ |
|
| 131 | public function moveOrderDown() |
|
| 132 | { |
|
| 133 | $orderColumnName = $this->determineOrderColumnName(); |
|
| 134 | ||
| 135 | $swapWithModel = static::limit(1) |
|
| 136 | ->ordered() |
|
| 137 | ->where($orderColumnName, '>', $this->$orderColumnName); |
|
| 138 | ||
| 139 | if ($this->hasSortScope()) { |
|
| 140 | $swapWithModel = $swapWithModel->where($this->determineSortScope(), $this->{$this->determineSortScope()}); |
|
| 141 | } |
|
| 142 | ||
| 143 | $swapWithModel = $swapWithModel->first(); |
|
| 144 | ||
| 145 | if (! $swapWithModel) { |
|
| 146 | return $this; |
|
| 147 | } |
|
| 148 | ||
| 149 | return $this->swapOrderWithModel($swapWithModel); |
|
| 150 | } |
|
| 151 | ||
| 152 | /** |
|
| 153 | * Swaps the order of this model with the model 'above' this model. |
|
| 154 | * |
|
| @@ 157-176 (lines=20) @@ | ||
| 154 | * |
|
| 155 | * @return $this |
|
| 156 | */ |
|
| 157 | public function moveOrderUp() |
|
| 158 | { |
|
| 159 | $orderColumnName = $this->determineOrderColumnName(); |
|
| 160 | ||
| 161 | $swapWithModel = static::limit(1) |
|
| 162 | ->ordered('desc') |
|
| 163 | ->where($orderColumnName, '<', $this->$orderColumnName); |
|
| 164 | if ($this->hasSortScope()) { |
|
| 165 | $swapWithModel = $swapWithModel->where($this->determineSortScope(), $this->{$this->determineSortScope()}); |
|
| 166 | } |
|
| 167 | ||
| 168 | $swapWithModel = $swapWithModel->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. |
|
| 179 | * |
|