DocumentController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 43
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 28 5
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