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 | 2 | 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) |
|
48 | { |
||
49 | 1 | if (!isset($this->trackedItemsFlattened[$filePath])) |
|
50 | { |
||
51 | throw new TrackedItemNotFoundException("The ContentItem at '$filePath' was not found."); |
||
52 | } |
||
53 | |||
54 | 1 | return $this->trackedItemsFlattened[$filePath]; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * A jailed representation of CollectionManager::getCollections() |
||
59 | * |
||
60 | * @return JailObject[][] |
||
61 | */ |
||
62 | 26 | public function getJailedCollections () |
|
63 | { |
||
64 | 26 | $jailItems = array(); |
|
65 | |||
66 | 26 | foreach ($this->trackedItems as $key => $items) |
|
67 | { |
||
68 | 26 | foreach ($items as $name => $contentItem) |
|
69 | { |
||
70 | 26 | $jailItems[$key][$name] = $contentItem->createJail(); |
|
71 | } |
||
72 | } |
||
73 | |||
74 | 26 | return $jailItems; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * Parse every collection and store them in the manager |
||
79 | * |
||
80 | * @param string[][] $collections An array of definitions for collections |
||
81 | */ |
||
82 | 30 | public function parseCollections ($collections) |
|
83 | { |
||
84 | 30 | if ($collections === null) |
|
85 | { |
||
86 | $this->output->debug("No collections found, nothing to parse."); |
||
87 | return; |
||
88 | } |
||
89 | |||
90 | 30 | $this->collectionDefinitions = $collections; |
|
91 | |||
92 | /** |
||
93 | * The information which each collection has taken from the configuration file |
||
94 | * |
||
95 | * $collection['name'] string The name of the collection |
||
96 | * ['folder'] string The folder where this collection has its ContentItems |
||
97 | * |
||
98 | * @var $collection array |
||
99 | */ |
||
100 | 30 | foreach ($collections as $collection) |
|
101 | { |
||
102 | 30 | $this->output->notice("Loading '{$collection['name']}' collection..."); |
|
103 | |||
104 | 30 | $collectionFolder = $this->fs->absolutePath($collection['folder']); |
|
105 | |||
106 | 30 | if (!$this->fs->exists($collectionFolder)) |
|
107 | { |
||
108 | $this->output->warning("The folder '{$collection['folder']}' could not be found for the '{$collection['name']}' collection"); |
||
109 | continue; |
||
110 | } |
||
111 | |||
112 | 30 | $this->saveFolderDefinition($collection['folder'], $collection); |
|
113 | 30 | $this->scanTrackableItems($collectionFolder, array( |
|
114 | 30 | 'namespace' => $collection['name'] |
|
115 | )); |
||
116 | } |
||
117 | 30 | } |
|
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | public function createNewItem($filePath) |
||
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | public function refreshItem($filePath) |
||
138 | |||
139 | /** |
||
140 | * {@inheritdoc} |
||
141 | */ |
||
142 | 30 | protected function handleTrackableItem($filePath, $options = array()) |
|
159 | |||
160 | /** |
||
161 | * Get the name of the Collection this Content Item belongs to |
||
162 | * |
||
163 | * @param string $filePath |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | private function getTentativeCollectionName ($filePath) |
||
179 | |||
180 | } |