| 1 | <?php |
||
| 19 | class CollectionManager extends TrackingManager |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * A copy of the collection definitions to be available for later usage. |
||
| 23 | * |
||
| 24 | * @var string[][] |
||
| 25 | */ |
||
| 26 | private $collectionDefinitions; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Get all of the ContentItems grouped by Collection name. |
||
| 30 | * |
||
| 31 | * @return ContentItem[][] |
||
| 32 | */ |
||
| 33 | 16 | public function &getCollections() |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Get a ContentItem from a Collection pased on it's path. |
||
| 40 | * |
||
| 41 | * @param string $filePath |
||
| 42 | * |
||
| 43 | * @throws TrackedItemNotFoundException |
||
| 44 | * |
||
| 45 | * @return ContentItem |
||
| 46 | */ |
||
| 47 | 1 | public function &getContentItem($filePath) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * A jailed representation of CollectionManager::getCollections(). |
||
| 59 | * |
||
| 60 | * @return JailedDocument[][] |
||
| 61 | */ |
||
| 62 | 19 | public function getJailedCollections() |
|
| 63 | { |
||
| 64 | 19 | $jailItems = array(); |
|
| 65 | |||
| 66 | /** |
||
| 67 | * @var string $key |
||
| 68 | * @var ContentItem $item |
||
| 69 | */ |
||
| 70 | 19 | foreach ($this->trackedItemsFlattened as &$item) |
|
| 71 | { |
||
| 72 | 19 | if (!Service::getParameter(BuildableCommand::USE_DRAFTS) && $item['draft']) { continue; } |
|
| 73 | |||
| 74 | 19 | $jailItems[$item->getNamespace()][$item->getName()] = $item->createJail(); |
|
| 75 | } |
||
| 76 | |||
| 77 | 19 | return $jailItems; |
|
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Parse every collection and store them in the manager. |
||
| 82 | * |
||
| 83 | * @param string[][] $collections An array of definitions for collections |
||
| 84 | */ |
||
| 85 | 37 | public function parseCollections($collections) |
|
| 86 | { |
||
| 87 | 37 | if ($collections === null) |
|
| 88 | { |
||
| 89 | $this->output->debug('No collections found, nothing to parse.'); |
||
| 90 | |||
| 91 | return; |
||
| 92 | } |
||
| 93 | |||
| 94 | 37 | $this->collectionDefinitions = $collections; |
|
| 95 | |||
| 96 | /** |
||
| 97 | * The information which each collection has taken from the configuration file. |
||
| 98 | * |
||
| 99 | * $collection['name'] string The name of the collection |
||
| 100 | * ['folder'] string The folder where this collection has its ContentItems |
||
| 101 | * |
||
| 102 | * @var array |
||
| 103 | */ |
||
| 104 | 37 | foreach ($collections as $collection) |
|
| 105 | { |
||
| 106 | 37 | $this->output->notice("Loading '{$collection['name']}' collection..."); |
|
|
1 ignored issue
–
show
|
|||
| 107 | |||
| 108 | 37 | $collectionFolder = $this->fs->absolutePath($collection['folder']); |
|
| 109 | |||
| 110 | 37 | if (!$this->fs->exists($collectionFolder)) |
|
| 111 | { |
||
| 112 | $this->output->warning("The folder '{$collection['folder']}' could not be found for the '{$collection['name']}' collection"); |
||
|
1 ignored issue
–
show
|
|||
| 113 | continue; |
||
| 114 | } |
||
| 115 | |||
| 116 | 37 | $this->saveFolderDefinition($collection['folder'], $collection); |
|
| 117 | 37 | $this->scanTrackableItems($collectionFolder, array( |
|
| 118 | 37 | 'namespace' => $collection['name'], |
|
| 119 | )); |
||
| 120 | } |
||
| 121 | 37 | } |
|
| 122 | |||
| 123 | /** |
||
| 124 | * {@inheritdoc} |
||
| 125 | */ |
||
| 126 | public function createNewItem($filePath) |
||
| 127 | { |
||
| 128 | $collection = $this->getTentativeCollectionName($filePath); |
||
| 129 | |||
| 130 | return $this->handleTrackableItem($filePath, array( |
||
| 131 | 'namespace' => $collection, |
||
| 132 | )); |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * {@inheritdoc} |
||
| 137 | */ |
||
| 138 | public function refreshItem($filePath) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * {@inheritdoc} |
||
| 144 | */ |
||
| 145 | 37 | protected function handleTrackableItem($filePath, $options = array()) |
|
| 162 | |||
| 163 | /** |
||
| 164 | * Get the name of the Collection this Content Item belongs to. |
||
| 165 | * |
||
| 166 | * @param string $filePath |
||
| 167 | * |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | private function getTentativeCollectionName($filePath) |
||
| 182 | } |
||
| 183 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.