Completed
Push — master ( e1e23b...70f5e9 )
by Ralf
15s queued 13s
created

PreviewViewHelper::getViewIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 5
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace EWW\Dpf\ViewHelpers\Link;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Core\Utility\GeneralUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use TYPO3\CMS\Core\Utility\MathUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Core\Utility\MathUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use TYPO3\CMS\Backend\Utility\BackendUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Utility\BackendUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Fluid\ViewHelp...stractBackendViewHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
22
class PreviewViewHelper extends AbstractBackendViewHelper
23
{
24
25
    /**
26
     * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Config...urationManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
     */
28
    protected $configurationManager;
29
30
    /**
31
     * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
32
     * @return void
33
     */
34
    public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
35
    {
36
        $this->configurationManager = $configurationManager;
37
    }
38
39
    /**
40
     * documentRepository
41
     *
42
     * @var \EWW\Dpf\Domain\Repository\DocumentRepository
43
     * @inject
44
     */
45
    protected $documentRepository;
46
47
    /**
48
     * Returns the View Icon with link
49
     *
50
     * @param array $row Data row
51
     * @param integer $viewPage Detail View page id
52
     * @param  integer $apiPid
53
     * @param  string $insideText
54
     * @param  string $class
55
     * @return string html output
56
     */
57
    protected function getViewIcon(array $row, $pageUid, $apiPid, $insideText, $class)
58
    {
59
60
        $previewMets = BackendUtility::getViewDomain($pageUid) . '/index.php?id='.$apiPid.'&tx_dpf[qid]=' . $row['uid'] . '&tx_dpf[action]=' . $row['action'];
61
62
        $additionalGetVars = '&tx_dlf[id]=' . urlencode($previewMets) . '&no_cache=1';
63
        $title = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('manager.tooltip.preview', 'dpf', $arguments = null);
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Utility\LocalizationUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
64
        $icon = '<a href="#" data-toggle="tooltip" class="' . $class . '" onclick="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($pageUid, $this->backPath, '', '', '', $additionalGetVars)) . '" title="' . $title . '">' .
65
                          $insideText . '</a>';
66
67
        return $icon;
68
69
    }
70
71
    /**
72
     * Renders a record list as known from the TYPO3 list module
73
     * Note: This feature is experimental!
74
     *
75
     * @param array() $arguments
76
     * @param  integer $pageUid
77
     * @param  integer $apiPid
78
     * @param  string $class
79
     * @return string the rendered record list
80
     */
81
    public function render(array $arguments, $pageUid, $apiPid, $class)
82
    {
83
84
        if ($arguments['document']) {
85
86
            // it's already a document object?
87
            if ($arguments['document'] instanceof \EWW\Dpf\Domain\Model\Document) {
88
89
                $document = $arguments['document'];
90
91
            } else if (MathUtility::canBeInterpretedAsInteger($arguments['document'])) {
92
93
                $document = $this->documentRepository->findByUid($arguments['document']);
94
95
            }
96
97
            // we found a valid document
98
            if ($document) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $document does not seem to be defined for all execution paths leading up to this point.
Loading history...
99
100
                $row['uid'] = $document->getUid();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$row was never initialized. Although not strictly required by PHP, it is generally a good practice to add $row = array(); before regardless.
Loading history...
101
102
                $row['title'] = $document->getTitle();
103
104
                $row['action'] = 'preview';
105
106
            } else {
107
108
                // ok, nothing to render. So return empty content.
109
                return '';
110
111
            }
112
113
        } else if ($arguments['documentObjectIdentifier']) {
114
115
            $row['action'] = 'mets';
116
117
            $row['uid'] = $arguments['documentObjectIdentifier'];
118
119
        }
120
121
        $insideText = $this->renderChildren();
122
123
        $content = $this->getViewIcon($row, $pageUid, $apiPid, $insideText, $class);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $row does not seem to be defined for all execution paths leading up to this point.
Loading history...
124
125
        return $content;
126
127
    }
128
}
129