|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the core-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Model; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Wiki view model. |
|
16
|
|
|
* |
|
17
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
18
|
|
|
* @package WBW\Bundle\CoreBundle\Model |
|
19
|
|
|
*/ |
|
20
|
|
|
class WikiView { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Bundle. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $bundle; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Category. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private $category; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Package. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private $package; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Page. |
|
45
|
|
|
* |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
private $page; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Title. |
|
52
|
|
|
* |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
private $title; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Constructor. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $category The category. |
|
61
|
|
|
* @param string $package The package. |
|
62
|
|
|
* @param string $page The page. |
|
63
|
|
|
* @param string $title The title. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function __construct($category, $package, $page, $title) { |
|
66
|
|
|
$this->setBundle("Core"); |
|
67
|
|
|
$this->setCategory($category); |
|
68
|
|
|
$this->setPackage($package); |
|
69
|
|
|
$this->setPage($page); |
|
70
|
|
|
$this->setTitle($title); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Find. |
|
75
|
|
|
* |
|
76
|
|
|
* @param WikiView[] $wikiViews The wiki views. |
|
77
|
|
|
* @param type $category The category. |
|
78
|
|
|
* @param type $package The package. |
|
79
|
|
|
* @param type $page The page. |
|
80
|
|
|
* @return WikiView Returns the wiki view in case of success, null otherwise. |
|
81
|
|
|
*/ |
|
82
|
|
|
public static function find(array $wikiViews, $category, $package, $page) { |
|
83
|
|
|
$wikiView = null; |
|
84
|
|
|
foreach ($wikiViews as $current) { |
|
85
|
|
|
if ($category !== $current->getCategory() && $package !== $current->getPackage() && $page !== $current->getPage()) { |
|
86
|
|
|
continue; |
|
87
|
|
|
} |
|
88
|
|
|
$wikiView = $current; |
|
89
|
|
|
break; |
|
90
|
|
|
} |
|
91
|
|
|
return $wikiView; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get the bundle. |
|
96
|
|
|
* |
|
97
|
|
|
* @return string Returns the bundle. |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getBundle() { |
|
100
|
|
|
return $this->bundle; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get the category. |
|
105
|
|
|
* |
|
106
|
|
|
* @return string Returns the category. |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getCategory() { |
|
109
|
|
|
return $this->category; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get the package. |
|
114
|
|
|
* |
|
115
|
|
|
* @return string Returns the package. |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getPackage() { |
|
118
|
|
|
return $this->package; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Get the page. |
|
123
|
|
|
* |
|
124
|
|
|
* @return string Returns the page. |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getPage() { |
|
127
|
|
|
return $this->page; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Get the title. |
|
132
|
|
|
* |
|
133
|
|
|
* @return string Returns the title. |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getTitle() { |
|
136
|
|
|
return $this->title; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Get a view. |
|
141
|
|
|
* |
|
142
|
|
|
* @return string Returns the view. |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getView() { |
|
145
|
|
|
$paths = [ |
|
146
|
|
|
"@" . $this->getBundle(), |
|
147
|
|
|
"Wiki", |
|
148
|
|
|
strtolower($this->getCategory()), |
|
149
|
|
|
strtolower($this->getPackage()), |
|
150
|
|
|
strtolower($this->getPage()) . ".html.twig", |
|
151
|
|
|
]; |
|
152
|
|
|
return implode("/", $paths); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Set the bundle. |
|
157
|
|
|
* |
|
158
|
|
|
* @param string $bundle The bundle. |
|
159
|
|
|
* @return WikiView Returns this wiki view. |
|
160
|
|
|
*/ |
|
161
|
|
|
public function setBundle($bundle) { |
|
162
|
|
|
$this->bundle = $bundle; |
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Set the category. |
|
168
|
|
|
* |
|
169
|
|
|
* @param string $category The category. |
|
170
|
|
|
* @return WikiView Returns this wiki view. |
|
171
|
|
|
*/ |
|
172
|
|
|
public function setCategory($category) { |
|
173
|
|
|
$this->category = $category; |
|
174
|
|
|
return $this; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Set the package. |
|
179
|
|
|
* |
|
180
|
|
|
* @param string $package The package. |
|
181
|
|
|
* @return WikiView Returns this wiki view. |
|
182
|
|
|
*/ |
|
183
|
|
|
public function setPackage($package) { |
|
184
|
|
|
$this->package = $package; |
|
185
|
|
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Set the page. |
|
190
|
|
|
* |
|
191
|
|
|
* @param string $page The page. |
|
192
|
|
|
* @return WikiView Returns this wiki view. |
|
193
|
|
|
*/ |
|
194
|
|
|
public function setPage($page) { |
|
195
|
|
|
$this->page = $page; |
|
196
|
|
|
return $this; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Set the title. |
|
201
|
|
|
* |
|
202
|
|
|
* @param string $title The title. |
|
203
|
|
|
* @return WikiView Returns this wiki view. |
|
204
|
|
|
*/ |
|
205
|
|
|
public function setTitle($title) { |
|
206
|
|
|
$this->title = $title; |
|
207
|
|
|
return $this; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
} |
|
211
|
|
|
|