@@ -26,334 +26,334 @@ |
||
| 26 | 26 | class FileCollectionService |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Collection Repository |
|
| 31 | - * |
|
| 32 | - * @var \TYPO3\CMS\Core\Resource\FileCollectionRepository |
|
| 33 | - */ |
|
| 34 | - protected $fileCollectionRepository; |
|
| 29 | + /** |
|
| 30 | + * Collection Repository |
|
| 31 | + * |
|
| 32 | + * @var \TYPO3\CMS\Core\Resource\FileCollectionRepository |
|
| 33 | + */ |
|
| 34 | + protected $fileCollectionRepository; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * The Frontend Configuration |
|
| 38 | - * |
|
| 39 | - * @var \TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager |
|
| 40 | - */ |
|
| 41 | - protected $frontendConfigurationManager; |
|
| 36 | + /** |
|
| 37 | + * The Frontend Configuration |
|
| 38 | + * |
|
| 39 | + * @var \TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager |
|
| 40 | + */ |
|
| 41 | + protected $frontendConfigurationManager; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Inject the fileCollection repository |
|
| 45 | - * |
|
| 46 | - * @param \TYPO3\CMS\Core\Resource\FileCollectionRepository $fileCollectionRepository |
|
| 47 | - * |
|
| 48 | - * @return void |
|
| 49 | - */ |
|
| 50 | - public function injectFileCollectionRepository(FileCollectionRepository $fileCollectionRepository) |
|
| 51 | - { |
|
| 52 | - $this->fileCollectionRepository = $fileCollectionRepository; |
|
| 53 | - } |
|
| 43 | + /** |
|
| 44 | + * Inject the fileCollection repository |
|
| 45 | + * |
|
| 46 | + * @param \TYPO3\CMS\Core\Resource\FileCollectionRepository $fileCollectionRepository |
|
| 47 | + * |
|
| 48 | + * @return void |
|
| 49 | + */ |
|
| 50 | + public function injectFileCollectionRepository(FileCollectionRepository $fileCollectionRepository) |
|
| 51 | + { |
|
| 52 | + $this->fileCollectionRepository = $fileCollectionRepository; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Inject the Frontend Configuration Manager. |
|
| 57 | - * |
|
| 58 | - * @param \TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager $frontendConfigurationManager |
|
| 59 | - * |
|
| 60 | - * @return void |
|
| 61 | - */ |
|
| 62 | - public function injectFrontendConfigurationManager(FrontendConfigurationManager $frontendConfigurationManager) |
|
| 63 | - { |
|
| 64 | - $this->frontendConfigurationManager = $frontendConfigurationManager; |
|
| 65 | - } |
|
| 55 | + /** |
|
| 56 | + * Inject the Frontend Configuration Manager. |
|
| 57 | + * |
|
| 58 | + * @param \TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager $frontendConfigurationManager |
|
| 59 | + * |
|
| 60 | + * @return void |
|
| 61 | + */ |
|
| 62 | + public function injectFrontendConfigurationManager(FrontendConfigurationManager $frontendConfigurationManager) |
|
| 63 | + { |
|
| 64 | + $this->frontendConfigurationManager = $frontendConfigurationManager; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Returns an array of file objects for the given UIDs of fileCollections |
|
| 69 | - * |
|
| 70 | - * @param array $collectionUids The uids |
|
| 71 | - * |
|
| 72 | - * @return array |
|
| 73 | - */ |
|
| 74 | - public function getFileObjectsFromCollection(array $collectionUids) |
|
| 75 | - { |
|
| 76 | - $imageItems = array(); |
|
| 77 | - foreach ($collectionUids as $collectionUid) { |
|
| 78 | - $collection = $this->fileCollectionRepository->findByUid($collectionUid); |
|
| 79 | - $collection->loadContents(); |
|
| 80 | - foreach ($collection->getItems() as $item) { |
|
| 81 | - if (get_class($item) === 'TYPO3\CMS\Core\Resource\FileReference') { |
|
| 82 | - array_push($imageItems, $this->getFileObjectFromFileReference($item)); |
|
| 83 | - } else { |
|
| 84 | - array_push($imageItems, $item); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - return $this->sortFileObjects($imageItems); |
|
| 89 | - } |
|
| 67 | + /** |
|
| 68 | + * Returns an array of file objects for the given UIDs of fileCollections |
|
| 69 | + * |
|
| 70 | + * @param array $collectionUids The uids |
|
| 71 | + * |
|
| 72 | + * @return array |
|
| 73 | + */ |
|
| 74 | + public function getFileObjectsFromCollection(array $collectionUids) |
|
| 75 | + { |
|
| 76 | + $imageItems = array(); |
|
| 77 | + foreach ($collectionUids as $collectionUid) { |
|
| 78 | + $collection = $this->fileCollectionRepository->findByUid($collectionUid); |
|
| 79 | + $collection->loadContents(); |
|
| 80 | + foreach ($collection->getItems() as $item) { |
|
| 81 | + if (get_class($item) === 'TYPO3\CMS\Core\Resource\FileReference') { |
|
| 82 | + array_push($imageItems, $this->getFileObjectFromFileReference($item)); |
|
| 83 | + } else { |
|
| 84 | + array_push($imageItems, $item); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + return $this->sortFileObjects($imageItems); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Returns an array of gallery covers for the given UIDs of fileCollections |
|
| 93 | - * |
|
| 94 | - * @param $collectionUids |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - public function getGalleryCoversFromCollections($collectionUids) |
|
| 98 | - { |
|
| 99 | - $imageItems = array(); |
|
| 100 | - foreach ($collectionUids as $collectionUid) { |
|
| 101 | - $collection = $this->fileCollectionRepository->findByUid($collectionUid); |
|
| 102 | - $collection->loadContents(); |
|
| 103 | - $galleryCover = array(); |
|
| 104 | - foreach ($collection->getItems() as $item) { |
|
| 105 | - if (get_class($item) === 'TYPO3\CMS\Core\Resource\FileReference') { |
|
| 106 | - array_push($galleryCover, $this->getFileObjectFromFileReference($item)); |
|
| 107 | - } else { |
|
| 108 | - array_push($galleryCover, $item); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - $galleryCover = $this->sortFileObjects($galleryCover); |
|
| 91 | + /** |
|
| 92 | + * Returns an array of gallery covers for the given UIDs of fileCollections |
|
| 93 | + * |
|
| 94 | + * @param $collectionUids |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + public function getGalleryCoversFromCollections($collectionUids) |
|
| 98 | + { |
|
| 99 | + $imageItems = array(); |
|
| 100 | + foreach ($collectionUids as $collectionUid) { |
|
| 101 | + $collection = $this->fileCollectionRepository->findByUid($collectionUid); |
|
| 102 | + $collection->loadContents(); |
|
| 103 | + $galleryCover = array(); |
|
| 104 | + foreach ($collection->getItems() as $item) { |
|
| 105 | + if (get_class($item) === 'TYPO3\CMS\Core\Resource\FileReference') { |
|
| 106 | + array_push($galleryCover, $this->getFileObjectFromFileReference($item)); |
|
| 107 | + } else { |
|
| 108 | + array_push($galleryCover, $item); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + $galleryCover = $this->sortFileObjects($galleryCover); |
|
| 112 | 112 | |
| 113 | - $galleryCover[0]->galleryUID = $collectionUid; |
|
| 114 | - $galleryCover[0]->galleryTitle = $collection->getTitle(); |
|
| 115 | - $galleryCover[0]->galleryDescription = $collection->getDescription(); |
|
| 116 | - $galleryCover[0]->gallerySize = sizeof($galleryCover); |
|
| 113 | + $galleryCover[0]->galleryUID = $collectionUid; |
|
| 114 | + $galleryCover[0]->galleryTitle = $collection->getTitle(); |
|
| 115 | + $galleryCover[0]->galleryDescription = $collection->getDescription(); |
|
| 116 | + $galleryCover[0]->gallerySize = sizeof($galleryCover); |
|
| 117 | 117 | |
| 118 | - array_push($imageItems, $galleryCover[0]); |
|
| 119 | - } |
|
| 120 | - return $this->sortFileObjects($imageItems); |
|
| 121 | - } |
|
| 118 | + array_push($imageItems, $galleryCover[0]); |
|
| 119 | + } |
|
| 120 | + return $this->sortFileObjects($imageItems); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Returns an array of gallery covers for the given UIDs of fileCollections |
|
| 125 | - * Use if you have recursive folder collection. |
|
| 126 | - * |
|
| 127 | - * @param $collectionUids |
|
| 128 | - * @return array |
|
| 129 | - */ |
|
| 130 | - public function getGalleryCoversFromNestedFoldersCollection($collectionUids) |
|
| 131 | - { |
|
| 132 | - $configuration = $this->frontendConfigurationManager->getConfiguration(); |
|
| 133 | - $imageItems = array(); |
|
| 123 | + /** |
|
| 124 | + * Returns an array of gallery covers for the given UIDs of fileCollections |
|
| 125 | + * Use if you have recursive folder collection. |
|
| 126 | + * |
|
| 127 | + * @param $collectionUids |
|
| 128 | + * @return array |
|
| 129 | + */ |
|
| 130 | + public function getGalleryCoversFromNestedFoldersCollection($collectionUids) |
|
| 131 | + { |
|
| 132 | + $configuration = $this->frontendConfigurationManager->getConfiguration(); |
|
| 133 | + $imageItems = array(); |
|
| 134 | 134 | |
| 135 | - // Load all images from collection |
|
| 136 | - foreach ($collectionUids as $collectionUid) { |
|
| 137 | - $collection = $this->fileCollectionRepository->findByUid($collectionUid); |
|
| 138 | - $collection->loadContents(); |
|
| 139 | - $galleryCover = array(); |
|
| 135 | + // Load all images from collection |
|
| 136 | + foreach ($collectionUids as $collectionUid) { |
|
| 137 | + $collection = $this->fileCollectionRepository->findByUid($collectionUid); |
|
| 138 | + $collection->loadContents(); |
|
| 139 | + $galleryCover = array(); |
|
| 140 | 140 | |
| 141 | - // Load all image and sort them by folder_hash |
|
| 142 | - foreach ($collection->getItems() as $item) { |
|
| 143 | - if (get_class($item) === 'TYPO3\CMS\Core\Resource\FileReference') { |
|
| 144 | - array_push($galleryCover, $this->getFileObjectFromFileReference($item)); |
|
| 145 | - } else { |
|
| 146 | - array_push($galleryCover, $item); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - $this->sortFileObjectsByFolderHash($galleryCover, SORT_ASC); |
|
| 141 | + // Load all image and sort them by folder_hash |
|
| 142 | + foreach ($collection->getItems() as $item) { |
|
| 143 | + if (get_class($item) === 'TYPO3\CMS\Core\Resource\FileReference') { |
|
| 144 | + array_push($galleryCover, $this->getFileObjectFromFileReference($item)); |
|
| 145 | + } else { |
|
| 146 | + array_push($galleryCover, $item); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + $this->sortFileObjectsByFolderHash($galleryCover, SORT_ASC); |
|
| 150 | 150 | |
| 151 | - // Split all images in separate arrays |
|
| 152 | - $folderHashedGalleryCovers = array(); |
|
| 153 | - $oldFolderHash = ''; |
|
| 154 | - foreach ($galleryCover as $item) { |
|
| 155 | - $getFolderPath = explode(strrchr($item->getIdentifier(), "/"), $item->getIdentifier()); |
|
| 156 | - $itemIdentificatorWithoutFilename = $getFolderPath[0]; |
|
| 157 | - if ($item->getProperty('folder_hash') !== $oldFolderHash) { |
|
| 158 | - $oldFolderHash = $item->getProperty('folder_hash'); |
|
| 159 | - $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename] = array(); |
|
| 160 | - array_push($folderHashedGalleryCovers[$itemIdentificatorWithoutFilename], $item); |
|
| 161 | - } else { |
|
| 162 | - array_push($folderHashedGalleryCovers[$itemIdentificatorWithoutFilename], $item); |
|
| 163 | - } |
|
| 164 | - } |
|
| 151 | + // Split all images in separate arrays |
|
| 152 | + $folderHashedGalleryCovers = array(); |
|
| 153 | + $oldFolderHash = ''; |
|
| 154 | + foreach ($galleryCover as $item) { |
|
| 155 | + $getFolderPath = explode(strrchr($item->getIdentifier(), "/"), $item->getIdentifier()); |
|
| 156 | + $itemIdentificatorWithoutFilename = $getFolderPath[0]; |
|
| 157 | + if ($item->getProperty('folder_hash') !== $oldFolderHash) { |
|
| 158 | + $oldFolderHash = $item->getProperty('folder_hash'); |
|
| 159 | + $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename] = array(); |
|
| 160 | + array_push($folderHashedGalleryCovers[$itemIdentificatorWithoutFilename], $item); |
|
| 161 | + } else { |
|
| 162 | + array_push($folderHashedGalleryCovers[$itemIdentificatorWithoutFilename], $item); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - // Sort the array by key => $itemIdentificatorWithoutFilename |
|
| 167 | - if ($configuration['settings']['orderNestedFolder'] == "asc") { |
|
| 168 | - ksort($folderHashedGalleryCovers); |
|
| 169 | - } else { |
|
| 170 | - krsort($folderHashedGalleryCovers); |
|
| 171 | - } |
|
| 166 | + // Sort the array by key => $itemIdentificatorWithoutFilename |
|
| 167 | + if ($configuration['settings']['orderNestedFolder'] == "asc") { |
|
| 168 | + ksort($folderHashedGalleryCovers); |
|
| 169 | + } else { |
|
| 170 | + krsort($folderHashedGalleryCovers); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - // Sort all subarrays depending on the current settings |
|
| 174 | - foreach ($folderHashedGalleryCovers as $itemIdentificatorWithoutFilename => $folderHashedGalleryCoversArray) { |
|
| 175 | - $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename] = $this->sortFileObjects($folderHashedGalleryCoversArray); |
|
| 176 | - $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]->galleryFolder = $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]->getProperty('folder_hash'); |
|
| 173 | + // Sort all subarrays depending on the current settings |
|
| 174 | + foreach ($folderHashedGalleryCovers as $itemIdentificatorWithoutFilename => $folderHashedGalleryCoversArray) { |
|
| 175 | + $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename] = $this->sortFileObjects($folderHashedGalleryCoversArray); |
|
| 176 | + $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]->galleryFolder = $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]->getProperty('folder_hash'); |
|
| 177 | 177 | |
| 178 | - $getFolderPath = explode("/", $itemIdentificatorWithoutFilename); |
|
| 179 | - $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]->galleryFolderName = end($getFolderPath); |
|
| 180 | - $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]->galleryUID = $collectionUid; |
|
| 181 | - $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]->gallerySize = sizeof($folderHashedGalleryCovers[$itemIdentificatorWithoutFilename]); |
|
| 182 | - array_push($imageItems, $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - return $imageItems; |
|
| 186 | - } |
|
| 178 | + $getFolderPath = explode("/", $itemIdentificatorWithoutFilename); |
|
| 179 | + $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]->galleryFolderName = end($getFolderPath); |
|
| 180 | + $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]->galleryUID = $collectionUid; |
|
| 181 | + $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]->gallerySize = sizeof($folderHashedGalleryCovers[$itemIdentificatorWithoutFilename]); |
|
| 182 | + array_push($imageItems, $folderHashedGalleryCovers[$itemIdentificatorWithoutFilename][0]); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + return $imageItems; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Returns an array of gallery covers for the given UIDs of fileCollections |
|
| 190 | - * Use if you have recursive folder collection. |
|
| 191 | - * |
|
| 192 | - * @param $collectionUids |
|
| 193 | - * @param $galleryFolder |
|
| 194 | - * @return array |
|
| 195 | - */ |
|
| 196 | - public function getGalleryItemsByFolderHash($collectionUids, $galleryFolderHash) |
|
| 197 | - { |
|
| 198 | - $imageItems = array(); |
|
| 188 | + /** |
|
| 189 | + * Returns an array of gallery covers for the given UIDs of fileCollections |
|
| 190 | + * Use if you have recursive folder collection. |
|
| 191 | + * |
|
| 192 | + * @param $collectionUids |
|
| 193 | + * @param $galleryFolder |
|
| 194 | + * @return array |
|
| 195 | + */ |
|
| 196 | + public function getGalleryItemsByFolderHash($collectionUids, $galleryFolderHash) |
|
| 197 | + { |
|
| 198 | + $imageItems = array(); |
|
| 199 | 199 | |
| 200 | - // Load all images from collection |
|
| 201 | - foreach ($collectionUids as $collectionUid) { |
|
| 202 | - $collection = $this->fileCollectionRepository->findByUid($collectionUid); |
|
| 203 | - $collection->loadContents(); |
|
| 204 | - $allItems = array(); |
|
| 200 | + // Load all images from collection |
|
| 201 | + foreach ($collectionUids as $collectionUid) { |
|
| 202 | + $collection = $this->fileCollectionRepository->findByUid($collectionUid); |
|
| 203 | + $collection->loadContents(); |
|
| 204 | + $allItems = array(); |
|
| 205 | 205 | |
| 206 | - // Load all image and sort them by folder_hash |
|
| 207 | - foreach ($collection->getItems() as $item) { |
|
| 208 | - if($item->getProperty('folder_hash') === $galleryFolderHash) { |
|
| 209 | - if (get_class($item) === 'TYPO3\CMS\Core\Resource\FileReference') { |
|
| 210 | - array_push($allItems, $this->getFileObjectFromFileReference($item)); |
|
| 211 | - } else { |
|
| 212 | - array_push($allItems, $item); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - $imageItems = $this->sortFileObjects($allItems); |
|
| 217 | - } |
|
| 218 | - return $imageItems; |
|
| 219 | - } |
|
| 206 | + // Load all image and sort them by folder_hash |
|
| 207 | + foreach ($collection->getItems() as $item) { |
|
| 208 | + if($item->getProperty('folder_hash') === $galleryFolderHash) { |
|
| 209 | + if (get_class($item) === 'TYPO3\CMS\Core\Resource\FileReference') { |
|
| 210 | + array_push($allItems, $this->getFileObjectFromFileReference($item)); |
|
| 211 | + } else { |
|
| 212 | + array_push($allItems, $item); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + $imageItems = $this->sortFileObjects($allItems); |
|
| 217 | + } |
|
| 218 | + return $imageItems; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Returns the array including pagination settings |
|
| 223 | - * |
|
| 224 | - * @param array $settings The current settings |
|
| 225 | - * @return array |
|
| 226 | - */ |
|
| 227 | - public function buildPaginationArray($settings) |
|
| 228 | - { |
|
| 229 | - $paginationArray = array(); |
|
| 230 | - if (!empty($settings)) { |
|
| 231 | - $paginationArray = array( |
|
| 232 | - 'itemsPerPage' => $settings['imagesPerPage'], |
|
| 233 | - 'maximumVisiblePages' => $settings['numberOfPages'], |
|
| 234 | - 'insertAbove' => $settings['insertAbove'], |
|
| 235 | - 'insertBelow' => $settings['insertBelow'] |
|
| 236 | - ); |
|
| 237 | - } |
|
| 238 | - return $paginationArray; |
|
| 239 | - } |
|
| 221 | + /** |
|
| 222 | + * Returns the array including pagination settings |
|
| 223 | + * |
|
| 224 | + * @param array $settings The current settings |
|
| 225 | + * @return array |
|
| 226 | + */ |
|
| 227 | + public function buildPaginationArray($settings) |
|
| 228 | + { |
|
| 229 | + $paginationArray = array(); |
|
| 230 | + if (!empty($settings)) { |
|
| 231 | + $paginationArray = array( |
|
| 232 | + 'itemsPerPage' => $settings['imagesPerPage'], |
|
| 233 | + 'maximumVisiblePages' => $settings['numberOfPages'], |
|
| 234 | + 'insertAbove' => $settings['insertAbove'], |
|
| 235 | + 'insertBelow' => $settings['insertBelow'] |
|
| 236 | + ); |
|
| 237 | + } |
|
| 238 | + return $paginationArray; |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Returns the array for assign to view in controller |
|
| 243 | - * |
|
| 244 | - * @param array $imageItems The imageItems to show |
|
| 245 | - * @param int $offset The offset in gallery |
|
| 246 | - * @param array $paginationConfiguration The pagination config |
|
| 247 | - * @param array $settings The settings array |
|
| 248 | - * @param int $currentUid The current uid |
|
| 249 | - * @param int $columnPosition The column position |
|
| 250 | - * @param bool $showBackToGallerySelectionLink If back link should be shown |
|
| 251 | - * |
|
| 252 | - * @return array |
|
| 253 | - */ |
|
| 254 | - public function buildArrayForAssignToView($imageItems, $offset, $paginationConfiguration, $settings, |
|
| 255 | - $currentUid, $columnPosition, $showBackToGallerySelectionLink) |
|
| 256 | - { |
|
| 257 | - $assign = array( |
|
| 258 | - 'imageItems' => $imageItems, |
|
| 259 | - 'offset' => $offset, |
|
| 260 | - 'paginationConfiguration' => $paginationConfiguration, |
|
| 261 | - 'settings' => $settings, |
|
| 262 | - 'currentUid' => $currentUid, |
|
| 263 | - 'columnPosition' => $columnPosition, |
|
| 264 | - 'showBackToGallerySelectionLink' => $showBackToGallerySelectionLink |
|
| 265 | - ); |
|
| 266 | - return $assign; |
|
| 267 | - } |
|
| 241 | + /** |
|
| 242 | + * Returns the array for assign to view in controller |
|
| 243 | + * |
|
| 244 | + * @param array $imageItems The imageItems to show |
|
| 245 | + * @param int $offset The offset in gallery |
|
| 246 | + * @param array $paginationConfiguration The pagination config |
|
| 247 | + * @param array $settings The settings array |
|
| 248 | + * @param int $currentUid The current uid |
|
| 249 | + * @param int $columnPosition The column position |
|
| 250 | + * @param bool $showBackToGallerySelectionLink If back link should be shown |
|
| 251 | + * |
|
| 252 | + * @return array |
|
| 253 | + */ |
|
| 254 | + public function buildArrayForAssignToView($imageItems, $offset, $paginationConfiguration, $settings, |
|
| 255 | + $currentUid, $columnPosition, $showBackToGallerySelectionLink) |
|
| 256 | + { |
|
| 257 | + $assign = array( |
|
| 258 | + 'imageItems' => $imageItems, |
|
| 259 | + 'offset' => $offset, |
|
| 260 | + 'paginationConfiguration' => $paginationConfiguration, |
|
| 261 | + 'settings' => $settings, |
|
| 262 | + 'currentUid' => $currentUid, |
|
| 263 | + 'columnPosition' => $columnPosition, |
|
| 264 | + 'showBackToGallerySelectionLink' => $showBackToGallerySelectionLink |
|
| 265 | + ); |
|
| 266 | + return $assign; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * @param array $items The items to sort |
|
| 271 | - * @param $direction the direction. SORT_DESC or SORT_ASC |
|
| 272 | - * @return bool |
|
| 273 | - */ |
|
| 274 | - protected function sortFileObjectsByName(&$items, $direction) |
|
| 275 | - { |
|
| 276 | - $lowercaseNames = array_map(function ($n) { |
|
| 277 | - return strtolower($n->getName()); |
|
| 278 | - }, $items); |
|
| 269 | + /** |
|
| 270 | + * @param array $items The items to sort |
|
| 271 | + * @param $direction the direction. SORT_DESC or SORT_ASC |
|
| 272 | + * @return bool |
|
| 273 | + */ |
|
| 274 | + protected function sortFileObjectsByName(&$items, $direction) |
|
| 275 | + { |
|
| 276 | + $lowercaseNames = array_map(function ($n) { |
|
| 277 | + return strtolower($n->getName()); |
|
| 278 | + }, $items); |
|
| 279 | 279 | |
| 280 | - array_multisort($lowercaseNames, $direction, SORT_STRING, $items); |
|
| 281 | - } |
|
| 280 | + array_multisort($lowercaseNames, $direction, SORT_STRING, $items); |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * @param array $items The items to sort |
|
| 285 | - * @param $direction the direction. SORT_DESC or SORT_ASC |
|
| 286 | - * @return bool |
|
| 287 | - */ |
|
| 288 | - protected function sortFileObjectsByDate(&$items, $direction) |
|
| 289 | - { |
|
| 290 | - $dates = array_map(function ($n) { |
|
| 291 | - return strtolower($n->getCreationTime()); |
|
| 292 | - }, $items); |
|
| 283 | + /** |
|
| 284 | + * @param array $items The items to sort |
|
| 285 | + * @param $direction the direction. SORT_DESC or SORT_ASC |
|
| 286 | + * @return bool |
|
| 287 | + */ |
|
| 288 | + protected function sortFileObjectsByDate(&$items, $direction) |
|
| 289 | + { |
|
| 290 | + $dates = array_map(function ($n) { |
|
| 291 | + return strtolower($n->getCreationTime()); |
|
| 292 | + }, $items); |
|
| 293 | 293 | |
| 294 | - array_multisort($dates, $direction, SORT_NUMERIC, $items); |
|
| 295 | - } |
|
| 294 | + array_multisort($dates, $direction, SORT_NUMERIC, $items); |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - /** |
|
| 298 | - * @param array $items The items to sort |
|
| 299 | - * @param $direction the direction. SORT_DESC or SORT_ASC |
|
| 300 | - * @return bool |
|
| 301 | - */ |
|
| 302 | - protected function sortFileObjectsByFolderHash(&$items, $direction) |
|
| 303 | - { |
|
| 304 | - $folderhashes = array_map(function ($n) { |
|
| 305 | - return strtolower($n->getProperty('folder_hash')); |
|
| 306 | - }, $items); |
|
| 297 | + /** |
|
| 298 | + * @param array $items The items to sort |
|
| 299 | + * @param $direction the direction. SORT_DESC or SORT_ASC |
|
| 300 | + * @return bool |
|
| 301 | + */ |
|
| 302 | + protected function sortFileObjectsByFolderHash(&$items, $direction) |
|
| 303 | + { |
|
| 304 | + $folderhashes = array_map(function ($n) { |
|
| 305 | + return strtolower($n->getProperty('folder_hash')); |
|
| 306 | + }, $items); |
|
| 307 | 307 | |
| 308 | - array_multisort($folderhashes, $direction, SORT_NUMERIC, $items); |
|
| 309 | - } |
|
| 308 | + array_multisort($folderhashes, $direction, SORT_NUMERIC, $items); |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - /** |
|
| 312 | - * Sorts the Result Array according to the Flexform Settings |
|
| 313 | - * |
|
| 314 | - * @param array $imageItems The image items |
|
| 315 | - * |
|
| 316 | - * @return array |
|
| 317 | - */ |
|
| 318 | - protected function sortFileObjects($imageItems) |
|
| 319 | - { |
|
| 320 | - $configuration = $this->frontendConfigurationManager->getConfiguration(); |
|
| 321 | - switch ($configuration['settings']['order']) { |
|
| 322 | - case 'desc': |
|
| 323 | - $this->sortFileObjectsByName($imageItems, SORT_DESC); |
|
| 324 | - break; |
|
| 325 | - case 'date-desc': |
|
| 326 | - $this->sortFileObjectsByDate($imageItems, SORT_DESC); |
|
| 327 | - break; |
|
| 328 | - case 'date-asc': |
|
| 329 | - $this->sortFileObjectsByDate($imageItems, SORT_ASC); |
|
| 330 | - break; |
|
| 331 | - case 'manual': |
|
| 332 | - // Do not sort. This could be default, but could be breaking, since default was ASC before. |
|
| 333 | - break; |
|
| 334 | - default: |
|
| 335 | - $this->sortFileObjectsByName($imageItems, SORT_ASC); |
|
| 336 | - break; |
|
| 337 | - } |
|
| 338 | - return $imageItems; |
|
| 339 | - } |
|
| 311 | + /** |
|
| 312 | + * Sorts the Result Array according to the Flexform Settings |
|
| 313 | + * |
|
| 314 | + * @param array $imageItems The image items |
|
| 315 | + * |
|
| 316 | + * @return array |
|
| 317 | + */ |
|
| 318 | + protected function sortFileObjects($imageItems) |
|
| 319 | + { |
|
| 320 | + $configuration = $this->frontendConfigurationManager->getConfiguration(); |
|
| 321 | + switch ($configuration['settings']['order']) { |
|
| 322 | + case 'desc': |
|
| 323 | + $this->sortFileObjectsByName($imageItems, SORT_DESC); |
|
| 324 | + break; |
|
| 325 | + case 'date-desc': |
|
| 326 | + $this->sortFileObjectsByDate($imageItems, SORT_DESC); |
|
| 327 | + break; |
|
| 328 | + case 'date-asc': |
|
| 329 | + $this->sortFileObjectsByDate($imageItems, SORT_ASC); |
|
| 330 | + break; |
|
| 331 | + case 'manual': |
|
| 332 | + // Do not sort. This could be default, but could be breaking, since default was ASC before. |
|
| 333 | + break; |
|
| 334 | + default: |
|
| 335 | + $this->sortFileObjectsByName($imageItems, SORT_ASC); |
|
| 336 | + break; |
|
| 337 | + } |
|
| 338 | + return $imageItems; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * Returns an FileObject from a given FileReference |
|
| 343 | - * |
|
| 344 | - * @param \TYPO3\CMS\Core\Resource\FileReference $item The item |
|
| 345 | - * |
|
| 346 | - * @return \TYPO3\CMS\Core\Resource\File |
|
| 347 | - */ |
|
| 348 | - protected function getFileObjectFromFileReference(FileReference $item) |
|
| 349 | - { |
|
| 350 | - /** |
|
| 351 | - * The item to return |
|
| 352 | - * |
|
| 353 | - * @var \TYPO3\CMS\Core\Resource\File $returnItem |
|
| 354 | - */ |
|
| 355 | - $returnItem = $item->getOriginalFile(); |
|
| 356 | - $returnItem->updateProperties($item->getProperties()); |
|
| 357 | - return $returnItem; |
|
| 358 | - } |
|
| 341 | + /** |
|
| 342 | + * Returns an FileObject from a given FileReference |
|
| 343 | + * |
|
| 344 | + * @param \TYPO3\CMS\Core\Resource\FileReference $item The item |
|
| 345 | + * |
|
| 346 | + * @return \TYPO3\CMS\Core\Resource\File |
|
| 347 | + */ |
|
| 348 | + protected function getFileObjectFromFileReference(FileReference $item) |
|
| 349 | + { |
|
| 350 | + /** |
|
| 351 | + * The item to return |
|
| 352 | + * |
|
| 353 | + * @var \TYPO3\CMS\Core\Resource\File $returnItem |
|
| 354 | + */ |
|
| 355 | + $returnItem = $item->getOriginalFile(); |
|
| 356 | + $returnItem->updateProperties($item->getProperties()); |
|
| 357 | + return $returnItem; |
|
| 358 | + } |
|
| 359 | 359 | } |