GalleryController::nestedAction()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 3
Metric Value
c 5
b 0
f 3
dl 0
loc 17
rs 9.4285
cc 3
eloc 10
nc 2
nop 1
1
<?php
2
namespace SKYFILLERS\SfFilecollectionGallery\Controller;
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
use SKYFILLERS\SfFilecollectionGallery\Service\FileCollectionService;
17
18
/**
19
 * GalleryController
20
 *
21
 * @author Jöran Kurschatke <[email protected]>
22
 */
23
class GalleryController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
24
25
	/**
26
	 * File Collection Service
27
	 *
28
	 * @var \SKYFILLERS\SfFilecollectionGallery\Service\FileCollectionService
29
	 */
30
	protected $fileCollectionService;
31
32
	/**
33
	 * Inject the FileCollectionService
34
	 *
35
	 * @param \SKYFILLERS\SfFilecollectionGallery\Service\FileCollectionService $fileCollectionService The service
36
	 *
37
	 * @return void
38
	 */
39
	public function injectFileCollectionService(FileCollectionService $fileCollectionService) {
40
		$this->fileCollectionService = $fileCollectionService;
41
	}
42
43
	/**
44
	 * Initializes the view before invoking an action method.
45
	 * Override this method to solve assign variables common for all actions
46
	 * or prepare the view in another way before the action is called.
47
	 *
48
	 * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view The view to be initialized
49
	 * @return void
50
	 */
51
	protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) {
52
		$view->assign('contentObjectData', $this->configurationManager->getContentObject()->data);
53
	}
54
55
	/**
56
	 * List action
57
	 *
58
	 * @param int $offset The offset
59
	 *
60
	 * @return void
61
	 */
62
	public function listAction($offset = 0) {
63
		if ($this->settings['fileCollection'] !== '' && $this->settings['fileCollection']) {
64
			$collectionUids = explode(',', $this->settings['fileCollection']);
65
			$cObj = $this->configurationManager->getContentObject();
66
			$currentUid = $cObj->data['uid'];
67
			$columnPosition = $cObj->data['colPos'];
68
69
			$showBackToGallerySelectionLink = FALSE;
70
			//if a special gallery is requested
71
			if ($this->request->hasArgument('galleryUID')) {
72
				$gallery = array($this->request->getArgument('galleryUID'));
73
				$imageItems = $this->fileCollectionService->getFileObjectsFromCollection($gallery);
74
				$showBackToGallerySelectionLink = TRUE;
75
			} else {
76
				$imageItems = $this->fileCollectionService->getFileObjectsFromCollection($collectionUids);
77
			}
78
			$this->view->assignMultiple($this->fileCollectionService->buildArrayForAssignToView(
79
				$imageItems, $offset, $this->fileCollectionService->buildPaginationArray($this->settings),
80
				$this->settings, $currentUid, $columnPosition, $showBackToGallerySelectionLink
81
			));
82
		}
83
	}
84
85
	/**
86
	 * Nested action
87
	 *
88
	 * @param int $offset The offset
89
	 *
90
	 * @return void
91
	 */
92
	public function nestedAction($offset = 0) {
93
		if ($this->settings['fileCollection'] !== '' && $this->settings['fileCollection']) {
94
			$cObj = $this->configurationManager->getContentObject();
95
			$currentUid = $cObj->data['uid'];
96
			$columnPosition = $cObj->data['colPos'];
97
98
			$collectionUids = explode(',', $this->settings['fileCollection']);
99
100
			//Get Gallery Covers for Gallery selection page
101
			$imageItems = $this->fileCollectionService->getGalleryCoversFromCollections($collectionUids);
102
103
			$this->view->assignMultiple($this->fileCollectionService->buildArrayForAssignToView(
104
				$imageItems, $offset, $this->fileCollectionService->buildPaginationArray($this->settings),
105
				$this->settings, $currentUid, $columnPosition, FALSE
106
			));
107
		}
108
	}
109
}
110