1 | <?php |
||
81 | trait SortableTrait |
||
82 | { |
||
83 | use ActiveRecordTrait; |
||
84 | |||
85 | /** |
||
86 | * Returns the table name |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | abstract public static function tableName(); |
||
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | * |
||
95 | * @return ActiveQuery |
||
96 | */ |
||
97 | abstract public static function find(); |
||
98 | |||
99 | /** |
||
100 | * Ensure a sort order is set. If a sort order is not provided, it will be added to the end. |
||
101 | * |
||
102 | * @param array $sortOrderCondition |
||
103 | * @param string $sortOrderAttribute |
||
104 | */ |
||
105 | protected function ensureSortOrder( |
||
119 | |||
120 | /** |
||
121 | * Ensure all sort order's following this record are in sequential order. As an |
||
122 | * example, a record may update the sort order from '4' to '1' which would result in all records after |
||
123 | * this one to be altered in sequential order. |
||
124 | * |
||
125 | * @param string $targetAttribute |
||
126 | * @param array $sortOrderCondition |
||
127 | * @param string $sortOrderAttribute |
||
128 | * @throws \yii\db\Exception |
||
129 | */ |
||
130 | protected function sequentialOrder( |
||
153 | |||
154 | /** |
||
155 | * Ensure all sort order's following this record are in sequential order. As an |
||
156 | * example, a record may update the sort order from '4' to '1' which would result in all records after |
||
157 | * this one to be altered in sequential order. |
||
158 | * |
||
159 | * @param string $targetAttribute |
||
160 | * @param array $sortOrderCondition |
||
161 | * @param string $sortOrderAttribute |
||
162 | * @throws \yii\db\Exception |
||
163 | */ |
||
164 | protected function autoReOrder( |
||
192 | |||
193 | /** |
||
194 | * Get the next available sort order available |
||
195 | * |
||
196 | * @param array $sortOrderCondition |
||
197 | * @param string $sortOrderAttribute |
||
198 | * @return int |
||
199 | */ |
||
200 | protected function nextSortOrder( |
||
211 | |||
212 | |||
213 | /** |
||
214 | * Creates a sort order query which will display all siblings ordered by their sort order |
||
215 | * |
||
216 | * @param array $sortOrderCondition |
||
217 | * @param string $sortOrderAttribute |
||
218 | * @return ActiveQuery |
||
219 | */ |
||
220 | protected function sortOrderQuery( |
||
231 | |||
232 | /** |
||
233 | * Saves a new sort order. |
||
234 | * |
||
235 | * @param array $sortOrder The new sort order that needs to be saved. The 'key' represents the target value and |
||
236 | * the 'value' represent the sort order. |
||
237 | * @param string $targetAttribute The target attribute that the new order is keyed on. |
||
238 | * @param array $sortOrderCondition Additional condition params used to accurately identify the sort order that |
||
239 | * need to be changed. For example, some sort orders may be site specific, therefore passing a 'siteId' condition |
||
240 | * would only apply the re-ordering to the specified site. |
||
241 | * @param string $sortOrderAttribute The sort order attribute that needs to be updated |
||
242 | * @return bool |
||
243 | * @throws \yii\db\Exception |
||
244 | */ |
||
245 | protected function saveNewOrder( |
||
268 | } |
||
269 |