Passed
Pull Request — master (#166)
by
unknown
17:57
created

ShowDocumentCounterViewHelper::render()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 6
nop 3
dl 0
loc 18
rs 9.8666
1
<?php
2
namespace EWW\Dpf\ViewHelpers;
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
class ShowDocumentCounterViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
18
{
19
    /**
20
     * @param int $documentCount
21
     * @param int $currentPage
22
     * @param int $itemsPerPage
23
     * @return string
24
     */
25
    public function render($documentCount, $currentPage, $itemsPerPage)
26
    {
27
        $from = ($currentPage > 1)? (($currentPage-1) * $itemsPerPage) + 1 : $currentPage;
28
29
        if ($currentPage >= 1) {
30
            if ($currentPage * $itemsPerPage > $documentCount) {
31
                $to = $documentCount;
32
            } else {
33
                $to = $currentPage * $itemsPerPage;
34
            }
35
        } else {
36
            $to = $documentCount;
37
        }
38
39
        return \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
40
            'manager.workspace.documentCounter',
41
            'dpf',
42
            [$from, $to, $documentCount]
43
        );
44
45
    }
46
}
47