ChartDataProvider::getChartUsage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
/**
3
 * Copyright (c) 2014 - 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
24
namespace OCA\ocUsageCharts\Service;
25
26
use OCA\ocUsageCharts\ChartTypeAdapterFactory;
27
use OCA\ocUsageCharts\DataProviderFactory;
28
use OCA\ocUsageCharts\Entity\ChartConfig;
29
30
/**
31
 * @author Arno van Rossum <[email protected]>
32
 */
33
class ChartDataProvider
34
{
35
    /**
36
     * @var DataProviderFactory
37
     */
38
    private $dataProviderFactory;
39
40
    /**
41
     * @var ChartTypeAdapterFactory
42
     */
43
    private $chartTypeAdapterFactory;
44
45
    /**
46
     * @param DataProviderFactory $dataProviderFactory
47
     * @param ChartTypeAdapterFactory $chartTypeAdapterFactory
48
     */
49
    public function __construct(DataProviderFactory $dataProviderFactory, ChartTypeAdapterFactory $chartTypeAdapterFactory)
50
    {
51
        $this->dataProviderFactory = $dataProviderFactory;
52
        $this->chartTypeAdapterFactory = $chartTypeAdapterFactory;
53
    }
54
55
    /**
56
     * Get the current usage for a chart given
57
     *
58
     * @param ChartConfig $chartConfig
59
     * @return boolean
60
     */
61
    public function isAllowedToUpdate(ChartConfig $chartConfig)
62
    {
63
        $provider = $this->dataProviderFactory->getDataProviderByConfig($chartConfig);
64
        return $provider->isAllowedToUpdate();
65
    }
66
67
    /**
68
     * Get the current usage for a chart given
69
     *
70
     * @param ChartConfig $chartConfig
71
     * @return mixed
72
     */
73
    public function getChartUsageForUpdate(ChartConfig $chartConfig)
74
    {
75
        $provider = $this->dataProviderFactory->getDataProviderByConfig($chartConfig);
76
        return $provider->getChartUsageForUpdate();
77
    }
78
79
    /**
80
     * Save a particular usage
81
     *
82
     * @param ChartConfig $chartConfig
83
     * @param mixed $usage
84
     * @return boolean
85
     */
86
    public function save(ChartConfig $chartConfig, $usage)
87
    {
88
        $provider = $this->dataProviderFactory->getDataProviderByConfig($chartConfig);
89
        return $provider->save($usage);
90
    }
91
92
    /**
93
     * This method returns all usage for a chart based on the chartconfig given
94
     *
95
     * @param ChartConfig $chartConfig
96
     * @return array
97
     */
98
    public function getChartUsage(ChartConfig $chartConfig)
99
    {
100
        $provider = $this->dataProviderFactory->getDataProviderByConfig($chartConfig);
101
        $data = $provider->getChartUsage();
102
103
        $adapter = $this->chartTypeAdapterFactory->getChartTypeAdapterByConfig($chartConfig);
104
        return $adapter->formatData($data);
105
    }
106
}
107