| 1 | <?php | ||
| 25 | class PageManager extends TrackingManager | ||
| 26 | { | ||
| 27 | /** | ||
| 28 | * A reference to the collections available to this website. | ||
| 29 | * | ||
| 30 | * @var ContentItem[][] | ||
| 31 | */ | ||
| 32 | private $collections; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * A place to store a reference to static PageViews with titles. | ||
| 36 | * | ||
| 37 | * @var PageView[] | ||
| 38 | */ | ||
| 39 | private $staticPages; | ||
| 40 | |||
| 41 | /** | ||
| 42 | * PageManager constructor. | ||
| 43 | */ | ||
| 44 | 7 | public function __construct() | |
| 56 | |||
| 57 | /** | ||
| 58 | * Give this manager the collections we'll be using for dynamic PageViews. | ||
| 59 | * | ||
| 60 | * @param ContentItem[][] $collections | ||
| 61 | * | ||
| 62 | * @since 0.1.0 | ||
| 63 | */ | ||
| 64 | 4 | public function setCollections(&$collections) | |
| 68 | |||
| 69 | /** | ||
| 70 | * Get all of the PageViews tracked by this manager. | ||
| 71 | * | ||
| 72 | * @todo Remove this function | ||
| 73 | * | ||
| 74 | * @deprecated Been replaced by getPageViewsFlattened() | ||
| 75 | * @since 0.1.0 | ||
| 76 | * | ||
| 77 | * @return PageView[][] | ||
| 78 | */ | ||
| 79 | public function getAllPageViews() | ||
| 83 | |||
| 84 | /** | ||
| 85 | * Get all of the PageViews in an associative array with PageView types as the keys. | ||
| 86 | * | ||
| 87 | * @since 0.1.1 | ||
| 88 | * | ||
| 89 | * @return PageView[][] | ||
| 90 | */ | ||
| 91 | public function &getPageViews() | ||
| 92 |     { | ||
| 93 | return $this->trackedItems; | ||
| 94 | } | ||
| 95 | |||
| 96 | /** | ||
| 97 | * Get all of the PageViews in flat array. | ||
| 98 | * | ||
| 99 | * @since 0.1.1 | ||
| 100 | * | ||
| 101 | * @return PageView[] | ||
| 102 | */ | ||
| 103 | public function &getPageViewsFlattened() | ||
| 104 |     { | ||
| 105 | return $this->trackedItemsFlattened; | ||
| 106 | } | ||
| 107 | |||
| 108 | /** | ||
| 109 | * Get the static PageViews tracked by this manager indexed by their title. | ||
| 110 | * | ||
| 111 | * @since 0.1.0 | ||
| 112 | * | ||
| 113 | * @return PageView[] | ||
| 114 | */ | ||
| 115 | 7 | public function getStaticPageViews() | |
| 119 | |||
| 120 | /** | ||
| 121 | * Get the jailed version of the static PageViews indexed by their title. | ||
| 122 | * | ||
| 123 | * @since 0.1.0 | ||
| 124 | * | ||
| 125 | * @return JailedDocument[] | ||
| 126 | */ | ||
| 127 | 1 | public function getJailedStaticPageViews() | |
| 128 |     { | ||
| 129 | 1 | $jailedObjects = array(); | |
| 130 | |||
| 131 | 1 | foreach ($this->staticPages as $key => $value) | |
| 132 |         { | ||
| 133 | 1 | $jailedObjects[$key] = $value->createJail(); | |
| 134 | 1 | } | |
| 135 | |||
| 136 | 1 | return $jailedObjects; | |
| 137 | } | ||
| 138 | |||
| 139 | /** | ||
| 140 | * Go through all of the PageView directories and create a respective PageView for each and classify them as a | ||
| 141 | * dynamic or static PageView. | ||
| 142 | * | ||
| 143 | * @param string[] $pageViewFolders | ||
| 144 | * | ||
| 145 | * @since 0.1.0 | ||
| 146 | */ | ||
| 147 | 7 | public function parsePageViews($pageViewFolders) | |
| 148 |     { | ||
| 149 | 7 | if (empty($pageViewFolders)) | |
| 150 | 7 |         { | |
| 151 | return; | ||
| 152 | } | ||
| 153 | |||
| 154 | 7 | foreach ($pageViewFolders as $pageViewFolderName) | |
| 155 |         { | ||
| 156 | /** @var string $pageViewFolderPath */ | ||
| 157 | 7 | $pageViewFolderPath = $this->fs->absolutePath($pageViewFolderName); | |
| 158 | |||
| 159 | 7 | if (!$this->fs->exists($pageViewFolderPath)) | |
| 160 | 7 |             { | |
| 161 | 1 |                 $this->output->warning("The '$pageViewFolderName' folder could not be found"); | |
| 1 ignored issue–
                            show | |||
| 162 | 1 | continue; | |
| 163 | } | ||
| 164 | |||
| 165 | 6 | $this->scanTrackableItems($pageViewFolderPath, array( | |
| 166 | 6 | 'fileExplorer' => FileExplorer::INCLUDE_ONLY_FILES, | |
| 167 | 6 |             ), array('/.html$/', '/.twig$/')); | |
| 168 | 6 | } | |
| 169 | 6 | } | |
| 170 | |||
| 171 | /** | ||
| 172 | * Add a new ContentItem to the respective parent PageView of the ContentItem. | ||
| 173 | * | ||
| 174 | * @param ContentItem $contentItem | ||
| 175 | * | ||
| 176 | * @since 0.1.0 | ||
| 177 | */ | ||
| 178 | 1 | public function trackNewContentItem(&$contentItem) | |
| 183 | |||
| 184 | /** | ||
| 185 |      * {@inheritdoc} | ||
| 186 | */ | ||
| 187 | 6 | protected function &handleTrackableItem($filePath, $options = array()) | |
| 212 | |||
| 213 | /** | ||
| 214 | * Handle special behavior and treatment for static PageViews while we're iterating through them. | ||
| 215 | * | ||
| 216 | * @param PageView $pageView | ||
| 217 | * | ||
| 218 | 2 | * @since 0.1.0 | |
| 219 | */ | ||
| 220 | 2 | private function handleTrackableStaticPageView(&$pageView) | |
| 229 | |||
| 230 | /** | ||
| 231 | * Handle special behavior and treatment for dynamic PageViews while we're iterating through them. | ||
| 232 | * | ||
| 233 | * @param DynamicPageView $pageView | ||
| 234 | * | ||
| 235 | 4 | * @since 0.1.0 | |
| 236 | */ | ||
| 237 | 4 | private function handleTrackableDynamicPageView(&$pageView) | |
| 253 | } | ||
| 254 | 
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.