| @@ 107-121 (lines=15) @@ | ||
| 104 | * |
|
| 105 | * @return $this |
|
| 106 | */ |
|
| 107 | public function moveOrderDown() |
|
| 108 | { |
|
| 109 | $orderColumnName = $this->determineOrderColumnName(); |
|
| 110 | ||
| 111 | $swapWithModel = $this->buildSortQuery()->limit(1) |
|
| 112 | ->ordered() |
|
| 113 | ->where($orderColumnName, '>', $this->$orderColumnName) |
|
| 114 | ->first(); |
|
| 115 | ||
| 116 | if (! $swapWithModel) { |
|
| 117 | return $this; |
|
| 118 | } |
|
| 119 | ||
| 120 | return $this->swapOrderWithModel($swapWithModel); |
|
| 121 | } |
|
| 122 | ||
| 123 | /** |
|
| 124 | * Swaps the order of this model with the model 'above' this model. |
|
| @@ 128-142 (lines=15) @@ | ||
| 125 | * |
|
| 126 | * @return $this |
|
| 127 | */ |
|
| 128 | public function moveOrderUp() |
|
| 129 | { |
|
| 130 | $orderColumnName = $this->determineOrderColumnName(); |
|
| 131 | ||
| 132 | $swapWithModel = $this->buildSortQuery()->limit(1) |
|
| 133 | ->ordered('desc') |
|
| 134 | ->where($orderColumnName, '<', $this->$orderColumnName) |
|
| 135 | ->first(); |
|
| 136 | ||
| 137 | if (! $swapWithModel) { |
|
| 138 | return $this; |
|
| 139 | } |
|
| 140 | ||
| 141 | return $this->swapOrderWithModel($swapWithModel); |
|
| 142 | } |
|
| 143 | ||
| 144 | /** |
|
| 145 | * Swap the order of this model with the order of another model. |
|