ChartViewHelper::getShortLabel()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 11
rs 9.2
cc 4
eloc 7
nc 3
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2015 - Arno van Rossum <[email protected]>
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 */
23
namespace OCA\ocUsageCharts\Owncloud\TemplateHelpers;
24
25
use OCA\ocUsageCharts\Entity\ChartConfig;
26
27
28
class ChartViewHelper
29
{
30
    /**
31
     * @var ChartConfig
32
     */
33
    private $chart;
34
35
    /**
36
     * @param ChartConfig $chart
37
     */
38
    public function __construct(ChartConfig $chart)
39
    {
40
        $this->chart = $chart;
41
    }
42
43
    /**
44
     * @param $requestToken
45
     * @return string
46
     */
47
    public function getUrl($requestToken)
48
    {
49
        if ( !$requestToken )
50
        {
51
            throw new \RuntimeException('No request token given');
52
        }
53
        return \OCP\Util::linkToRoute('ocusagecharts.chart_api.load_chart', array('id' => $this->chart->getId(), 'requesttoken' => $requestToken));
54
    }
55
56
    /**
57
     * @param $language
58
     * @return string
59
     */
60
    public function getTitle($language)
61
    {
62
        return $language->t($this->chart->getChartType());
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getShortLabel()
69
    {
70
        if ( strpos($this->chart->getChartType(), 'Storage') !== false ) {
71
            $meta = json_decode($this->chart->getMetaData());
72
            if (!empty($meta) && $meta->size) {
73
                return $meta->size;
74
            }
75
            return 'gb';
76
        }
77
        return '';
78
    }
79
80
    /**
81
     * @param $language
82
     * @return string
83
     */
84
    public function getLabel($language)
85
    {
86
        if ( strpos($this->chart->getChartType(), 'Storage') !== false ) {
87
            $meta = json_decode($this->chart->getMetaData());
88
            if (!empty($meta) && $meta->size) {
89
                return $language->t('sizes_' . $meta->size);
90
            }
91
            return $language->t('sizes_gb');
92
        }
93
        return $language->t('activities');
94
    }
95
96
}
97