Passed
Push — master ( 222752...4454ce )
by Marcel
02:38
created

StorageController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
c 0
b 0
f 0
dl 0
loc 83
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 14 3
A read() 0 16 4
A delete() 0 4 1
A __construct() 0 10 1
1
<?php
2
/**
3
 * Data Analytics
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @copyright 2019 Marcel Scherello
10
 */
11
12
namespace OCA\Analytics\Controller;
13
14
use OCP\AppFramework\Controller;
15
use OCP\ILogger;
16
use OCP\IRequest;
17
18
class StorageController extends Controller
19
{
20
    private $logger;
21
    private $DBController;
22
23
    public function __construct(
24
        string $AppName,
25
        IRequest $request,
26
        ILogger $logger,
27
        DbController $DBController
28
    )
29
    {
30
        parent::__construct($AppName, $request);
31
        $this->logger = $logger;
32
        $this->DBController = $DBController;
33
    }
34
35
    /**
36
     * Get the items for the selected category
37
     *
38
     * @NoAdminRequired
39
     * @param $datasetMetadata
40
     * @param $objectDrilldown
41
     * @param $dateDrilldown
42
     * @return array
43
     */
44
    public function read($datasetMetadata, $objectDrilldown, $dateDrilldown)
45
    {
46
        $header = array();
47
        if ($objectDrilldown === 'true') $header['dimension1'] = $datasetMetadata['dimension1'];
48
        if ($dateDrilldown === 'true') $header['dimension2'] = $datasetMetadata['dimension2'];
49
        $header['dimension3'] = $datasetMetadata['dimension3'];
50
51
        $data = $this->DBController->getData($datasetMetadata['id'], $objectDrilldown, $dateDrilldown);
52
53
        $result = empty($data) ? [
54
            'status' => 'nodata'
55
        ] : [
56
            'header' => $header,
57
            'data' => $data
58
        ];
59
        return $result;
60
    }
61
62
    /**
63
     * Get the items for the selected category
64
     *
65
     * @NoAdminRequired
66
     * @param int $datasetId
67
     * @param $dimension1
68
     * @param $dimension2
69
     * @param $dimension3
70
     * @return array
71
     */
72
    public function update(int $datasetId, $dimension1, $dimension2, $dimension3)
73
    {
74
        $dimension3 = str_replace(',', '.', $dimension3);
75
        $action = $this->DBController->createData($datasetId, $dimension1, $dimension2, $dimension3);
76
77
        $insert = $update = 0;
78
        if ($action === 'insert') $insert = 1;
79
        elseif ($action === 'update') $update = 1;
80
81
        $result = [
82
            'insert' => $insert,
83
            'update' => $update
84
        ];
85
        return $result;
86
    }
87
88
    /**
89
     * delete data
90
     *
91
     * @NoAdminRequired
92
     * @param int $datasetId
93
     * @param $dimension1
94
     * @param $dimension2
95
     * @return bool
96
     */
97
    public function delete(int $datasetId, $dimension1, $dimension2)
98
    {
99
        $result = $this->DBController->deleteData($datasetId, $dimension1, $dimension2);
100
        return $result;
101
    }
102
}