Completed
Push — master ( 5dcbd9...ad771e )
by Leo
03:21
created

OrderableBlocks::reorderItems()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 25
rs 8.8571
cc 3
eloc 18
nc 3
nop 3
1
<?php
2
3
class OrderableBlocks extends GridFieldOrderableRows {
4
	protected function reorderItems($list, array $values, array $order) {
5
		$pool = array_values($values);
6
		sort($pool);
7
8
		foreach(array_values($order) as $pos => $id) {
9
			if($values[$id] != $pool[$pos]) {
10
				DB::query(sprintf(
11
					'UPDATE "%s" SET "%s" = %d WHERE %s',
12
					$this->getSortTable($list),
13
					$this->getSortField(),
14
					$pool[$pos],
15
					$this->getSortTableClauseForIds($list, $id)
16
				));
17
				DB::query(sprintf(
18
					'UPDATE "%s_Live" SET "%s" = %d WHERE %s',
19
					$this->getSortTable($list),
20
					$this->getSortField(),
21
					$pool[$pos],
22
					$this->getSortTableClauseForIds($list, $id)
23
				));
24
			}
25
		}
26
27
		$this->extend('onAfterReorderItems', $list);
28
	}
29
}