OrderableBlocks   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 27
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B reorderItems() 0 25 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
}