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