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

PrintBlocks::getGivenBlocks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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
}