1 | <?php |
||
27 | class PageManager extends TrackingManager |
||
28 | { |
||
29 | /** |
||
30 | * A reference to the collections available to this website. |
||
31 | * |
||
32 | * @var ContentItem[][] |
||
33 | */ |
||
34 | private $collections; |
||
35 | |||
36 | /** |
||
37 | * A place to store a reference to static PageViews with titles. |
||
38 | * |
||
39 | * @var PageView[] |
||
40 | */ |
||
41 | private $staticPages; |
||
42 | |||
43 | /** |
||
44 | * @var DataItem[]|array |
||
45 | */ |
||
46 | private $datasets; |
||
47 | |||
48 | /** |
||
49 | * PageManager constructor. |
||
50 | */ |
||
51 | 7 | public function __construct() |
|
52 | { |
||
53 | 7 | parent::__construct(); |
|
54 | |||
55 | 7 | $this->trackedItems = array( |
|
56 | 7 | PageView::STATIC_TYPE => array(), |
|
57 | 7 | PageView::DYNAMIC_TYPE => array(), |
|
58 | 7 | PageView::REPEATER_TYPE => array(), |
|
59 | ); |
||
60 | 7 | $this->collections = array(); |
|
61 | 7 | $this->staticPages = array(); |
|
62 | 7 | } |
|
63 | |||
64 | /** |
||
65 | * Give this manager the collections we'll be using for dynamic PageViews. |
||
66 | * |
||
67 | * @param ContentItem[][] $collections |
||
68 | * |
||
69 | * @since 0.1.0 |
||
70 | */ |
||
71 | 4 | public function setCollections(&$collections) |
|
72 | { |
||
73 | 4 | $this->collections = &$collections; |
|
74 | 4 | } |
|
75 | |||
76 | public function setDatasets($datasets) |
||
77 | { |
||
78 | $this->datasets = $datasets; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Get all of the PageViews tracked by this manager. |
||
83 | * |
||
84 | * @todo Remove this function |
||
85 | * |
||
86 | * @deprecated Been replaced by getPageViewsFlattened() |
||
87 | * @since 0.1.0 |
||
88 | * |
||
89 | * @return PageView[][] |
||
90 | */ |
||
91 | public function getAllPageViews() |
||
95 | |||
96 | /** |
||
97 | * Get all of the PageViews in an associative array with PageView types as the keys. |
||
98 | * |
||
99 | * @since 0.1.1 |
||
100 | * |
||
101 | * @return PageView[][] |
||
102 | */ |
||
103 | public function &getPageViews() |
||
104 | { |
||
105 | return $this->trackedItems; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Get all of the PageViews in flat array. |
||
110 | * |
||
111 | * @since 0.1.1 |
||
112 | * |
||
113 | * @return PageView[] |
||
114 | */ |
||
115 | 7 | public function &getPageViewsFlattened() |
|
119 | |||
120 | /** |
||
121 | * Get the static PageViews tracked by this manager indexed by their title. |
||
122 | * |
||
123 | * @since 0.1.0 |
||
124 | * |
||
125 | * @return PageView[] |
||
126 | */ |
||
127 | 1 | public function getStaticPageViews() |
|
131 | |||
132 | /** |
||
133 | * Get the jailed version of the static PageViews indexed by their title. |
||
134 | * |
||
135 | * @since 0.1.0 |
||
136 | * |
||
137 | * @return JailedDocument[] |
||
138 | */ |
||
139 | 1 | public function getJailedStaticPageViews() |
|
150 | |||
151 | /** |
||
152 | * Go through all of the PageView directories and create a respective PageView for each and classify them as a |
||
153 | * dynamic or static PageView. |
||
154 | * |
||
155 | * @param string[] $pageViewFolders |
||
156 | * |
||
157 | * @since 0.1.0 |
||
158 | */ |
||
159 | 7 | public function parsePageViews($pageViewFolders) |
|
182 | |||
183 | /** |
||
184 | * Add a new ContentItem to the respective parent PageView of the ContentItem. |
||
185 | * |
||
186 | * @param ContentItem $contentItem |
||
187 | * |
||
188 | * @since 0.1.0 |
||
189 | */ |
||
190 | 1 | public function trackNewContentItem(&$contentItem) |
|
191 | { |
||
192 | 1 | $collection = $contentItem->getNamespace(); |
|
193 | 1 | $this->trackedItems[PageView::DYNAMIC_TYPE][$collection]->addRepeatableItem($contentItem); |
|
194 | 1 | } |
|
195 | |||
196 | /** |
||
197 | * {@inheritdoc} |
||
198 | */ |
||
199 | 6 | protected function &handleTrackableItem($filePath, $options = array()) |
|
200 | { |
||
201 | 6 | $pageView = PageView::create($filePath); |
|
202 | 6 | $namespace = $pageView->getType(); |
|
203 | 6 | $storageKey = $pageView->getRelativeFilePath(); |
|
204 | |||
205 | switch ($namespace) |
||
206 | { |
||
207 | 6 | case PageView::STATIC_TYPE: |
|
208 | 2 | $this->handleTrackableStaticPageView($pageView); |
|
209 | 2 | break; |
|
210 | |||
211 | 4 | case PageView::DYNAMIC_TYPE: |
|
212 | 4 | $this->handleTrackableDynamicPageView($pageView); |
|
213 | 3 | $storageKey = $pageView->getRepeatableName(); |
|
214 | 3 | break; |
|
215 | |||
216 | default: |
||
217 | break; |
||
218 | } |
||
219 | |||
220 | 5 | $this->addObjectToTracker($pageView, $storageKey, $namespace); |
|
221 | |||
222 | 5 | return $pageView; |
|
223 | } |
||
224 | |||
225 | /** |
||
226 | * Handle special behavior and treatment for static PageViews while we're iterating through them. |
||
227 | * |
||
228 | * @param PageView $pageView |
||
229 | * |
||
230 | * @since 0.1.0 |
||
231 | */ |
||
232 | 2 | private function handleTrackableStaticPageView(&$pageView) |
|
241 | |||
242 | /** |
||
243 | * Handle special behavior and treatment for dynamic PageViews while we're iterating through them. |
||
244 | * |
||
245 | * @param DynamicPageView $pageView |
||
246 | * |
||
247 | * @since 0.1.0 |
||
248 | */ |
||
249 | 4 | private function handleTrackableDynamicPageView(&$pageView) |
|
268 | } |
||
269 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.