Completed
Push — master ( 093a3a...44d378 )
by Leo
02:17
created

PrintBlocks   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllBlocks() 0 9 3
A getMyBlocks() 0 11 3
A getGivenBlocks() 0 6 1
1
<?php
2
class PrintBlocks extends Extension {
3
	
4
	public function getAllBlocks() {
5
		$blocks = Block::get();
6
		foreach ($blocks as $block) {
7
			if ($block->forTemplate() === false) {
8
				$blocks->exclude(array('ID' => $block->ID));
9
			}
10
		}
11
		return $blocks;
12
	}
13
		
14
	public function getMyBlocks() {
15
		$mySegment = ltrim($this->owner->Link(), '/' );
16
		$mySegment = rtrim($mySegment, '/');
17
		$mySegment = strlen($mySegment) == 0 || $mySegment == 'home' ? '<home>' : $mySegment;
18
		$blocks = Block::get()->filter(array(
19
			'ExcludeListed'		=>	false,
20
			'UrlsRegExps'		=>	$mySegment
21
		))->sort('SortOrder', 'ASC');
22
		
23
		return $blocks;
24
	}
25
	
26
	public function getGivenBlocks() {
27
		$blocks = $this->getAllBlocks();
28
		$myBlocksID = $this->getMyBlocks()->column('ID');
29
		
30
		return $blocks->exclude(array('ID' => $myBlocksID));
31
	}
32
}