Passed
Push — master ( 0b1a33...6372a5 )
by Marcel
06:49
created

ReportController::export()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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\ReportService;
15
use OCP\AppFramework\Controller;
16
use OCP\AppFramework\Http\DataResponse;
17
use OCP\IRequest;
18
use Psr\Log\LoggerInterface;
19
20
class ReportController extends Controller
21
{
22
    private $logger;
23
    private $ReportService;
24
25
    public function __construct(
26
        $appName,
27
        IRequest $request,
28
        LoggerInterface $logger,
29
        ReportService $ReportService
30
    )
31
    {
32
        parent::__construct($appName, $request);
33
        $this->logger = $logger;
34
        $this->ReportService = $ReportService;
35
    }
36
37
    /**
38
     * get all reports
39
     *
40
     * @NoAdminRequired
41
     * @return DataResponse
42
     */
43
    public function index()
44
    {
45
        return $this->ReportService->index();
46
    }
47
48
    /**
49
     * create new blank report
50
     *
51
     * @NoAdminRequired
52
     * @return int
53
     */
54
    public function create()
55
    {
56
        return $this->ReportService->create();
57
    }
58
59
    /**
60
     * copy an existing report with the current navigation status
61
     *
62
     * @NoAdminRequired
63
     * @param int $reportId
64
     * @param $chartoptions
65
     * @param $dataoptions
66
     * @param $filteroptions
67
     * @return int
68
     */
69
    public function createCopy(int $reportId, $chartoptions, $dataoptions, $filteroptions)
70
    {
71
        return $this->ReportService->createCopy($reportId, $chartoptions, $dataoptions, $filteroptions);
72
    }
73
74
    /**
75
     * create new report from file
76
     *
77
     * @NoAdminRequired
78
     * @param string $file
79
     * @return int
80
     */
81
    public function createFromFile($file = '')
82
    {
83
        //**todo**//
84
        //still needed?
85
        return $this->ReportService->create($file);
0 ignored issues
show
Unused Code introduced by
The call to OCA\Analytics\Service\ReportService::create() has too many arguments starting with $file. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
        return $this->ReportService->/** @scrutinizer ignore-call */ create($file);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
86
    }
87
88
    /**
89
     * get own report details
90
     *
91
     * @NoAdminRequired
92
     * @param int $reportId
93
     * @return array
94
     */
95
    public function read(int $reportId)
96
    {
97
        return $this->ReportService->read($reportId);
98
    }
99
100
    /**
101
     * Delete report and all depending objects
102
     *
103
     * @NoAdminRequired
104
     * @param int $reportId
105
     * @return bool
106
     */
107
    public function delete(int $reportId)
108
    {
109
        return $this->ReportService->delete($reportId);
110
    }
111
112
    /**
113
     * get report details
114
     *
115
     * @NoAdminRequired
116
     * @param int $reportId
117
     * @param $name
118
     * @param $subheader
119
     * @param int $parent
120
     * @param int $type
121
     * @param int $dataset
122
     * @param $link
123
     * @param $visualization
124
     * @param $chart
125
     * @param $chartoptions
126
     * @param $dataoptions
127
     * @param null $dimension1
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dimension1 is correct as it would always require null to be passed?
Loading history...
128
     * @param null $dimension2
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dimension2 is correct as it would always require null to be passed?
Loading history...
129
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
130
     * @return bool
131
     * @throws \OCP\DB\Exception
132
     */
133
    public function update(int $reportId, $name, $subheader, int $parent, int $type, int $dataset, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1 = null, $dimension2 = null, $value = null)
134
    {
135
        return $this->ReportService->update($reportId, $name, $subheader, $parent, $type, $dataset, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1, $dimension2, $value);
136
    }
137
138
    /**
139
     * update report options
140
     *
141
     * @NoAdminRequired
142
     * @param int $reportId
143
     * @param $chartoptions
144
     * @param $dataoptions
145
     * @param $filteroptions
146
     * @return bool
147
     */
148
    public function updateOptions(int $reportId, $chartoptions, $dataoptions, $filteroptions)
149
    {
150
        return $this->ReportService->updateOptions($reportId, $chartoptions, $dataoptions, $filteroptions);
151
    }
152
153
    /**
154
     * update report refresh details
155
     *
156
     * @NoAdminRequired
157
     * @param int $reportId
158
     * @param $refresh
159
     * @return bool
160
     */
161
    public function updateRefresh(int $reportId, $refresh)
162
    {
163
        return $this->ReportService->updateRefresh($reportId, $refresh);
164
    }
165
166
    /**
167
     * get own reports which are marked as favorites
168
     *
169
     * @NoAdminRequired
170
     * @return array|bool
171
     */
172
    public function getOwnFavoriteReports()
173
    {
174
        return $this->ReportService->getOwnFavoriteReports();
175
    }
176
177
    /**
178
     * set/remove the favorite flag for a report
179
     *
180
     * @NoAdminRequired
181
     * @param int $reportId
182
     * @param string $favorite
183
     * @return bool
184
     */
185
    public function setFavorite(int $reportId, string $favorite)
186
    {
187
        return $this->ReportService->setFavorite($reportId, $favorite);
188
    }
189
190
    /**
191
     * Export report
192
     *
193
     * @NoCSRFRequired
194
     * @NoAdminRequired
195
     * @param int $reportId
196
     * @return \OCP\AppFramework\Http\DataDownloadResponse
197
     */
198
    public function export(int $reportId)
199
    {
200
        return $this->ReportService->export($reportId);
201
    }
202
203
    /**
204
     * Import report
205
     *
206
     * @NoAdminRequired
207
     * @param string|null $path
208
     * @param string|null $raw
209
     * @return DataResponse
210
     * @throws \OCP\Files\NotFoundException
211
     * @throws \OCP\Files\NotPermittedException
212
     */
213
    public function import(string $path = null, string $raw = null)
214
    {
215
        return new DataResponse($this->ReportService->import($path, $raw));
216
    }
217
218
}