Passed
Pull Request — master (#10)
by Anton
07:57 queued 04:02
created

Page::getPath()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 34
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 34
rs 8.439
cc 5
eloc 13
nc 5
nop 0
1
<?php
2
3
namespace Handlers\Site {
4
5
	use Frames, Modules\Entitizer, Utils\View, Template;
6
7
	class Page extends Frames\Site\Section {
8
9
		private $page = null, $path = [];
10
11
		# Get contents
12
13
		private function getContents() {
14
15
			$contents = View::get('Blocks\Page');
16
17
			# Set breadcrumbs
18
19
			if (count($this->path) <= 1) $contents->block('breadcrumbs')->disable();
20
21
			else $contents->block('breadcrumbs')->path = $this->path;
22
23
			# Set contents
24
25
			$contents->contents = Template::block($this->page->contents);
26
27
			# ------------------------
28
29
			return $contents;
30
		}
31
32
		# Handle request
33
34
		protected function handle() {
35
36
			# Get page entity
37
38
			$this->page = Entitizer::get(TABLE_PAGES);
39
40
			# Init page by requested url
41
42
			$slug = implode('/', $this->url->path());
43
44
			if ('' !== $slug) $this->page->initBySlug($slug); else $this->page->init(1);
45
46
			# Display error if not found
47
48
			if (0 === $this->page->id) return false;
49
50
			# Get path
51
52
			if (false !== ($path = $this->page->path())) $this->path = $path;
53
54
			# Set data
55
56
			if ($this->page->id !== 1) $this->title = $this->page->title; else $this->layout = 'Index';
57
58
			$this->description      = $this->page->description;
59
			$this->keywords         = $this->page->keywords;
60
			$this->robots_index     = $this->page->robots_index;
61
			$this->robots_follow    = $this->page->robots_follow;
62
			$this->canonical        = $this->page->canonical;
63
64
			# ------------------------
65
66
			return $this->getContents();
67
		}
68
	}
69
}
70