DocumentController::indexAction()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 9.1608
c 0
b 0
f 0
cc 5
nc 6
nop 0
1
<?php
2
/**
3
 * Document controller
4
 *
5
 * @author Tim Lochmüller
6
 */
7
8
namespace FRUIT\GoogleServices\Controller;
9
10
use TYPO3\CMS\Core\Resource\FileReference;
11
use TYPO3\CMS\Core\Utility\GeneralUtility;
12
use TYPO3\CMS\Core\Utility\MathUtility;
13
14
/**
15
 * Document controller
16
 */
17
class DocumentController extends AbstractController
18
{
19
20
    /**
21
     * File repository
22
     *
23
     * @var \TYPO3\CMS\Core\Resource\FileRepository
24
     * @inject
25
     */
26
    protected $fileRepository;
27
28
    /**
29
     * Base view
30
     */
31
    public function indexAction()
32
    {
33
        if (!$this->settings['file']) {
34
            throw new \Exception('You have to select a valid FAL reference file', 12372183723);
35
        }
36
37
        $images = $this->fileRepository->findByRelation(
38
            'tt_content',
39
            'pdf',
40
            $this->configurationManager->getContentObject()->data['uid']
41
        );
42
        if (!sizeof($images)) {
43
            throw new \Exception('You have to select a valid FAL reference file', 12372183723);
44
        }
45
        /** @var FileReference $image */
46
        $image = current($images);
47
48
        $width = MathUtility::canBeInterpretedAsInteger($this->settings['width']) ? $this->settings['width'] . 'px' : $this->settings['width'];
49
        $height = MathUtility::canBeInterpretedAsInteger($this->settings['height']) ? $this->settings['height'] . 'px' : $this->settings['height'];
50
        $fileUrl = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST') . '/' . $image->getPublicUrl();
51
52
        $this->view->assignMultiple([
53
            'fileUrl'  => urlencode($fileUrl),
54
            'language' => $GLOBALS['TSFE']->config['config']['language'],
55
            'width'    => $width,
56
            'height'   => $height,
57
        ]);
58
    }
59
}
60