Completed
Push — master ( 720fed...5dcbd9 )
by Leo
02:39
created

PrintBlocks::getDockedBlocks()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 18
rs 8.8571
cc 5
eloc 12
nc 9
nop 0
1
<?php
2
class PrintBlocks extends Extension {
3
	
4
	public function getAllBlocks() {
5
		$blocks = new ArrayList();
6
		$blocks->merge($this->getMyBlocks());
7
		$blocks->merge($this->getDockedBlocks());
8
		return $blocks;
9
	}
10
		
11
	public function getMyBlocks() {
12
		$blocks = $this->owner->Blocks()->sort(array('SortOrder' => 'ASC', 'ID' => 'DESC'));
13
		$published_blocks = new ArrayList();
14
		foreach ($blocks as $block) {
15
			if ($block->isPublished()) {
16
				$published_blocks->push($block);
17
			}
18
		}
19
		
20
		return $published_blocks;
21
	}
22
	
23
	public function getDockedBlocks() {
24
		$blocks = Block::get()->filter(array('showBlockbyClass' => true));
25
		$blocks_map = $blocks->map('ID', 'shownInClass');
26
		foreach ($blocks_map as $blockID => $Classes) {
27
			$Classes = explode(',', $Classes);
28
			if (!in_array($this->owner->ClassName, $Classes)) {
29
				$blocks = $blocks->exclude('ID', $blockID);
30
			}
31
		}
32
		$published_blocks = new ArrayList();
33
		foreach ($blocks as $block) {
34
			if ($block->isPublished()) {
35
				$published_blocks->push($block);
36
			}
37
		}
38
		
39
		return $published_blocks->sort('SortOrder', 'ASC');
40
	}
41
}