-
Notifications
You must be signed in to change notification settings - Fork 18
/
Page.php
123 lines (123 loc) · 2.86 KB
/
Page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* This file is part of Notadd.
* @author TwilRoad <269044570@qq.com>
* @copyright (c) 2015, iBenchu.org
* @datetime 2015-10-30 17:16
*/
namespace Notadd\Page;
use Illuminate\Support\Collection;
use Notadd\Page\Models\Page as PageModel;
/**
* Class Page
* @package Notadd\Page
*/
class Page {
/**
* @var int
*/
private $id;
/**
* @var \Notadd\Page\Models\Page
*/
protected $model;
/**
* Page constructor.
* @param $id
*/
public function __construct($id) {
$this->id = $id;
$this->model = PageModel::findOrFail($id);
}
/**
* @return mixed
*/
public function getAlias() {
return $this->model->getAttribute('alias');
}
/**
* @return mixed
*/
public function getContent() {
return $this->model->getAttribute('content');
}
/**
* @return mixed
*/
public function getDescription() {
return $this->model->getAttribute('description');
}
/**
* @return mixed
*/
public function getId() {
return $this->id;
}
/**
* @return mixed
*/
public function getKeywords() {
return $this->model->getAttribute('keyword');
}
/**
* @param \Illuminate\Support\Collection $list
* @param \Notadd\Page\Models\Page|null $model
*/
public function getLoopParent(Collection &$list, PageModel $model = null) {
if ($model === null) {
$model = $this->model;
}
if ($model->hasParent()) {
$parent = $model->getAttribute('parent');
$list->prepend($parent);
$this->getLoopParent($list, $parent);
}
}
/**
* @return mixed
*/
public function getModel() {
return $this->model;
}
/**
* @return mixed
*/
public function getPageId() {
return $this->id;
}
/**
* @return string
*/
public function getRouting() {
$loopParent = Collection::make([$this->model]);
$this->getLoopParent($loopParent);
$routingString = Collection::make();
foreach ($loopParent as $model) {
$model->getAttribute('alias') && $routingString->push($model->getAttribute('alias'));
}
return $routingString->implode('/');
}
/**
* @return static
*/
public function getSubPages() {
$list = Collection::make();
$data = $this->model->whereParentId($this->model->getAttribute('id'))->get();
foreach($data as $value) {
$list->push(new Page($value->getAttribute('id')));
}
return $list;
}
/**
* @return mixed
*/
public function getTemplate() {
return $this->model->getAttribute('template');
}
/**
* @return mixed
*/
public function getTitle() {
return $this->model->getAttribute('title');
}
}