Passed
Push — master ( 7cb5a0...7ee6da )
by Marcel
03:06
created

DatasetController::getOwnFavoriteDatasets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * 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 2021 Marcel Scherello
10
 */
11
12
namespace OCA\Analytics\Controller;
13
14
use OCA\Analytics\Service\DatasetService;
15
use OCP\AppFramework\Controller;
16
use OCP\AppFramework\Http\DataResponse;
17
use OCP\IRequest;
18
use Psr\Log\LoggerInterface;
19
20
class DatasetController extends Controller
21
{
22
    private $logger;
23
    private $DatasetService;
24
25
    public function __construct(
26
        $appName,
27
        IRequest $request,
28
        LoggerInterface $logger,
29
        DatasetService $DatasetService
30
    )
31
    {
32
        parent::__construct($appName, $request);
33
        $this->logger = $logger;
34
        $this->DatasetService = $DatasetService;
35
    }
36
37
    /**
38
     * get all datasets
39
     *
40
     * @NoAdminRequired
41
     * @return DataResponse
42
     */
43
    public function index()
44
    {
45
        return $this->DatasetService->index();
46
    }
47
48
    /**
49
     * create new dataset
50
     *
51
     * @NoAdminRequired
52
     * @param string $file
53
     * @return int
54
     */
55
    public function create($file = '')
56
    {
57
        return $this->DatasetService->create($file);
58
    }
59
60
    /**
61
     * get own dataset details
62
     *
63
     * @NoAdminRequired
64
     * @param int $datasetId
65
     * @return array
66
     */
67
    public function read(int $datasetId)
68
    {
69
        return $this->DatasetService->read($datasetId);
70
    }
71
72
    /**
73
     * Delete Dataset and all depending objects
74
     *
75
     * @NoAdminRequired
76
     * @param int $datasetId
77
     * @return bool
78
     */
79
    public function delete(int $datasetId)
80
    {
81
        return $this->DatasetService->delete($datasetId);
82
    }
83
84
    /**
85
     * get dataset details
86
     *
87
     * @NoAdminRequired
88
     * @param int $datasetId
89
     * @param $name
90
     * @param $subheader
91
     * @param int $parent
92
     * @param int $type
93
     * @param $link
94
     * @param $visualization
95
     * @param $chart
96
     * @param $chartoptions
97
     * @param $dataoptions
98
     * @param $dimension1
99
     * @param $dimension2
100
     * @param $value
101
     * @return bool
102
     */
103
    public function update(int $datasetId, $name, $subheader, int $parent, int $type, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1 = null, $dimension2 = null, $value = null)
104
    {
105
        return $this->DatasetService->update($datasetId, $name, $subheader, $parent, $type, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1, $dimension2, $value);
106
    }
107
108
    /**
109
     * get dataset details
110
     *
111
     * @NoAdminRequired
112
     * @param int $datasetId
113
     * @param $chartoptions
114
     * @param $dataoptions
115
     * @param $filteroptions
116
     * @return bool
117
     */
118
    public function updateOptions(int $datasetId, $chartoptions, $dataoptions, $filteroptions)
119
    {
120
        return $this->DatasetService->updateOptions($datasetId, $chartoptions, $dataoptions, $filteroptions);
121
    }
122
123
    /**
124
     * get dataset details
125
     *
126
     * @NoAdminRequired
127
     * @param int $datasetId
128
     * @param $refresh
129
     * @return bool
130
     */
131
    public function updateRefresh(int $datasetId, $refresh)
132
    {
133
        return $this->DatasetService->updateRefresh($datasetId, $refresh);
134
    }
135
136
    /**
137
     * get own datasets which are marked as favorites
138
     *
139
     * @NoAdminRequired
140
     * @return array|bool
141
     */
142
    public function getOwnFavoriteDatasets()
143
    {
144
        return $this->DatasetService->getOwnFavoriteDatasets();
145
    }
146
147
    /**
148
     * set/remove the favorite flag for a report
149
     *
150
     * @NoAdminRequired
151
     * @param int $datasetId
152
     * @param string $favorite
153
     * @return bool
154
     */
155
    public function setFavorite(int $datasetId, string $favorite)
156
    {
157
        return $this->DatasetService->setFavorite($datasetId, $favorite);
158
    }
159
160
    /**
161
     * Export Dataset
162
     *
163
     * @NoCSRFRequired
164
     * @NoAdminRequired
165
     * @param int $datasetId
166
     * @return \OCP\AppFramework\Http\DataDownloadResponse
167
     */
168
    public function export(int $datasetId)
169
    {
170
        return $this->DatasetService->export($datasetId);
171
    }
172
173
    /**
174
     * Import Dataset
175
     *
176
     * @NoAdminRequired
177
     * @param string|null $path
178
     * @param string|null $raw
179
     * @return DataResponse
180
     * @throws \OCP\Files\NotFoundException
181
     * @throws \OCP\Files\NotPermittedException
182
     */
183
    public function import(string $path = null, string $raw = null)
184
    {
185
        return new DataResponse($this->DatasetService->import($path, $raw));
186
    }
187
188
}