| @@ 105-119 (lines=15) @@ | ||
| 102 | * |
|
| 103 | * @throws SortableException |
|
| 104 | */ |
|
| 105 | public function moveOrderDown() |
|
| 106 | { |
|
| 107 | $orderColumnName = $this->determineOrderColumnName(); |
|
| 108 | ||
| 109 | $swapWithModel = static::limit(1) |
|
| 110 | ->ordered() |
|
| 111 | ->where($orderColumnName, '>', $this->$orderColumnName) |
|
| 112 | ->first(); |
|
| 113 | ||
| 114 | if (!$swapWithModel) { |
|
| 115 | throw new SortableException('The model you try to move down has already the lowest order'); |
|
| 116 | } |
|
| 117 | ||
| 118 | return $this->swapOrderWithModel($swapWithModel); |
|
| 119 | } |
|
| 120 | ||
| 121 | /** |
|
| 122 | * Swaps the order of this model with the model 'above' this model |
|
| @@ 128-142 (lines=15) @@ | ||
| 125 | * |
|
| 126 | * @throws SortableException |
|
| 127 | */ |
|
| 128 | public function moveOrderUp() |
|
| 129 | { |
|
| 130 | $orderColumnName = $this->determineOrderColumnName(); |
|
| 131 | ||
| 132 | $swapWithModel = static::limit(1) |
|
| 133 | ->ordered() |
|
| 134 | ->where($orderColumnName, '<', $this->$orderColumnName) |
|
| 135 | ->first(); |
|
| 136 | ||
| 137 | if (!$swapWithModel) { |
|
| 138 | throw new SortableException('The model you try to move up has already the highest order'); |
|
| 139 | } |
|
| 140 | ||
| 141 | return $this->swapOrderWithModel($swapWithModel); |
|
| 142 | } |
|
| 143 | ||
| 144 | /** |
|
| 145 | * Swap the order of this model with the order of another model |
|