1 | <?php |
||
17 | class CollectionManager extends TrackingManager |
||
18 | { |
||
19 | /** |
||
20 | * A copy of the collection definitions to be available for later usage |
||
21 | * |
||
22 | * @var string[][] |
||
23 | */ |
||
24 | private $collectionDefinitions; |
||
25 | |||
26 | /** |
||
27 | * @param string $filePath |
||
28 | * |
||
29 | * @return ContentItem |
||
30 | */ |
||
31 | 1 | public function &getContentItem ($filePath) |
|
35 | |||
36 | /** |
||
37 | * Get all of the Content Items grouped by Collection |
||
38 | * |
||
39 | * @return ContentItem[][] |
||
40 | */ |
||
41 | 2 | public function &getCollections () |
|
45 | |||
46 | /** |
||
47 | * Get the name of the Collection this Content Item belongs to |
||
48 | * |
||
49 | * @param string $filePath |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getTentativeCollectionName ($filePath) |
||
54 | { |
||
55 | foreach ($this->collectionDefinitions as $collection) |
||
56 | { |
||
57 | if (strpos($filePath, $collection['folder']) === 0) |
||
58 | { |
||
59 | return $collection['name']; |
||
60 | } |
||
61 | } |
||
62 | |||
63 | return ''; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Parse every collection and store them in the manager |
||
68 | * |
||
69 | * @param string[][] $collections An array of definitions for collections |
||
70 | */ |
||
71 | 4 | public function parseCollections ($collections) |
|
72 | { |
||
73 | 4 | if ($collections === null) |
|
74 | { |
||
75 | $this->output->debug("No collections found, nothing to parse."); |
||
76 | return; |
||
77 | } |
||
78 | |||
79 | 4 | $this->collectionDefinitions = $collections; |
|
80 | |||
81 | /** |
||
82 | * The information which each collection has taken from the configuration file |
||
83 | * |
||
84 | * $collection['name'] string The name of the collection |
||
85 | * ['folder'] string The folder where this collection has its ContentItems |
||
86 | * |
||
87 | * @var $collection array |
||
88 | */ |
||
89 | 4 | foreach ($collections as $collection) |
|
90 | { |
||
91 | 4 | $this->output->notice("Loading '{$collection['name']}' collection..."); |
|
92 | |||
93 | 4 | $collectionFolder = $this->fs->absolutePath($collection['folder']); |
|
94 | |||
95 | 4 | if (!$this->fs->exists($collectionFolder)) |
|
96 | { |
||
97 | $this->output->warning("The folder '{$collection['folder']}' could not be found for the '{$collection['name']}' collection"); |
||
98 | continue; |
||
99 | } |
||
100 | |||
101 | 4 | $this->saveFolderDefinition($collection['folder'], $collection); |
|
102 | 4 | $this->scanTrackableItems($collectionFolder, array( |
|
103 | 4 | 'namespace' => $collection['name'] |
|
104 | )); |
||
105 | } |
||
106 | 4 | } |
|
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | public function createNewItem($filePath) |
||
112 | { |
||
113 | $collection = $this->getTentativeCollectionName($filePath); |
||
114 | |||
115 | return $this->handleTrackableItem($filePath, array( |
||
116 | 'namespace' => $collection |
||
117 | )); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | public function refreshItem($filePath) |
||
127 | |||
128 | /** |
||
129 | * {@inheritdoc} |
||
130 | */ |
||
131 | 4 | protected function handleTrackableItem($filePath, $options = array()) |
|
148 | } |