|
1
|
|
|
<?php |
|
2
|
|
|
namespace Bookdown\Bookdown\Content; |
|
3
|
|
|
|
|
4
|
|
|
class Page |
|
5
|
|
|
{ |
|
6
|
|
|
protected $name; |
|
7
|
|
|
protected $origin; |
|
8
|
|
|
protected $parent; |
|
9
|
|
|
protected $count; |
|
10
|
|
|
protected $prev; |
|
11
|
|
|
protected $next; |
|
12
|
|
|
protected $title; |
|
13
|
|
|
protected $headings = array(); |
|
14
|
|
|
protected $copyright; |
|
15
|
|
|
|
|
16
|
22 |
|
public function __construct( |
|
17
|
|
|
$origin, |
|
18
|
|
|
$name, |
|
19
|
|
|
IndexPage $parent, |
|
20
|
|
|
$count |
|
21
|
|
|
) { |
|
22
|
22 |
|
$this->origin = $origin; |
|
23
|
22 |
|
$this->name = $name; |
|
24
|
22 |
|
$this->parent = $parent; |
|
25
|
22 |
|
$this->count = $count; |
|
26
|
22 |
|
} |
|
27
|
|
|
|
|
28
|
19 |
|
public function getName() |
|
29
|
|
|
{ |
|
30
|
19 |
|
return $this->name; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
21 |
|
public function getOrigin() |
|
34
|
|
|
{ |
|
35
|
21 |
|
return $this->origin; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
22 |
|
public function setTitle($title) |
|
39
|
|
|
{ |
|
40
|
22 |
|
$this->title = $title; |
|
41
|
22 |
|
} |
|
42
|
|
|
|
|
43
|
17 |
|
public function getTitle() |
|
44
|
|
|
{ |
|
45
|
17 |
|
return $this->title; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
4 |
|
public function hasParent() |
|
49
|
|
|
{ |
|
50
|
4 |
|
return (bool) $this->parent; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
20 |
|
public function getParent() |
|
54
|
|
|
{ |
|
55
|
20 |
|
return $this->parent; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
16 |
|
public function getCount() |
|
59
|
|
|
{ |
|
60
|
16 |
|
return $this->count; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
22 |
|
public function setPrev($prev) |
|
64
|
|
|
{ |
|
65
|
22 |
|
$this->prev = $prev; |
|
66
|
22 |
|
} |
|
67
|
|
|
|
|
68
|
4 |
|
public function hasPrev() |
|
69
|
|
|
{ |
|
70
|
4 |
|
return (bool) $this->prev; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
6 |
|
public function getPrev() |
|
74
|
|
|
{ |
|
75
|
6 |
|
return $this->prev; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
22 |
|
public function setNext($next) |
|
79
|
|
|
{ |
|
80
|
22 |
|
$this->next = $next; |
|
81
|
22 |
|
} |
|
82
|
|
|
|
|
83
|
4 |
|
public function hasNext() |
|
84
|
|
|
{ |
|
85
|
4 |
|
return (bool) $this->next; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
7 |
|
public function getNext() |
|
89
|
|
|
{ |
|
90
|
7 |
|
return $this->next; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
14 |
|
public function getHref() |
|
94
|
|
|
{ |
|
95
|
14 |
|
$base = $this->getParent()->getHref(); |
|
96
|
14 |
|
return $base . $this->getName() . '.html'; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
16 |
|
public function getNumber() |
|
100
|
|
|
{ |
|
101
|
16 |
|
$base = $this->getParent()->getNumber(); |
|
102
|
16 |
|
$count = $this->getCount(); |
|
103
|
16 |
|
return "{$base}{$count}."; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
6 |
|
public function getNumberAndTitle() |
|
107
|
|
|
{ |
|
108
|
6 |
|
return trim($this->getNumber() . ' ' . $this->getTitle()); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
18 |
|
public function getTarget() |
|
112
|
|
|
{ |
|
113
|
18 |
|
$base = rtrim( |
|
114
|
18 |
|
dirname($this->getParent()->getTarget()), |
|
115
|
|
|
DIRECTORY_SEPARATOR |
|
116
|
18 |
|
); |
|
117
|
18 |
|
return $base . DIRECTORY_SEPARATOR . $this->getName() . '.html'; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
2 |
|
public function getCopyright() |
|
124
|
|
|
{ |
|
125
|
2 |
|
return $this->copyright; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param string $copyright |
|
130
|
|
|
*/ |
|
131
|
2 |
|
public function setCopyright($copyright) |
|
132
|
|
|
{ |
|
133
|
2 |
|
$this->copyright = $copyright; |
|
134
|
2 |
|
} |
|
135
|
|
|
|
|
136
|
16 |
|
public function setHeadings(array $headings) |
|
137
|
|
|
{ |
|
138
|
16 |
|
$this->headings = $headings; |
|
139
|
16 |
|
} |
|
140
|
|
|
|
|
141
|
4 |
|
public function hasHeadings() |
|
142
|
|
|
{ |
|
143
|
4 |
|
return (bool) $this->headings; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
15 |
|
public function getHeadings() |
|
147
|
|
|
{ |
|
148
|
15 |
|
return $this->headings; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
14 |
|
public function isIndex() |
|
152
|
|
|
{ |
|
153
|
14 |
|
return false; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
11 |
|
public function isRoot() |
|
157
|
|
|
{ |
|
158
|
11 |
|
return false; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
4 |
|
public function getRoot() |
|
162
|
|
|
{ |
|
163
|
4 |
|
$page = $this; |
|
164
|
4 |
|
while (! $page->isRoot()) { |
|
165
|
3 |
|
$page = $page->getParent(); |
|
166
|
3 |
|
} |
|
167
|
4 |
|
return $page; |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|