Passed
Push — master ( 3660fa...998d5d )
by Marcel
03:22
created

ThresholdController::floatvalue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
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 2020 Marcel Scherello
10
 */
11
12
namespace OCA\Analytics\Controller;
13
14
use OCA\Analytics\Db\DatasetMapper;
15
use OCA\Analytics\Notification\NotificationManager;
16
use OCA\Analytics\Service\ThresholdService;
17
use OCP\AppFramework\Controller;
18
use OCP\ILogger;
19
use OCP\IRequest;
20
21
class ThresholdController extends Controller
22
{
23
    private $logger;
24
    private $ThresholdService;
25
    private $DatasetMapper;
26
    private $NotificationManager;
27
28
    public function __construct(
29
        $appName,
30
        IRequest $request,
31
        ILogger $logger,
32
        ThresholdService $ThresholdService,
33
        NotificationManager $NotificationManager,
34
        DatasetMapper $DatasetMapper
35
    )
36
    {
37
        parent::__construct($appName, $request);
38
        $this->logger = $logger;
39
        $this->ThresholdService = $ThresholdService;
40
        $this->NotificationManager = $NotificationManager;
41
        $this->DatasetMapper = $DatasetMapper;
42
    }
43
44
    /**
45
     * read all thresholds for a dataset
46
     *
47
     * @NoAdminRequired
48
     * @param int $datasetId
49
     * @return array
50
     */
51
    public function read(int $datasetId)
52
    {
53
        return $this->ThresholdService->read($datasetId);
54
    }
55
56
    /**
57
     * create new threshold for dataset
58
     *
59
     * @NoAdminRequired
60
     * @param int $datasetId
61
     * @param $dimension1
62
     * @param $option
63
     * @param $value
64
     * @param int $severity
65
     * @return int
66
     */
67
    public function create(int $datasetId, $dimension1, $option, $value, int $severity)
68
    {
69
        return $this->ThresholdService->create($datasetId, $dimension1, $value, $option, $severity);
70
    }
71
72
    /**
73
     * Delete threshold for dataset
74
     *
75
     * @NoAdminRequired
76
     * @param int $thresholdId
77
     * @return bool
78
     */
79
    public function delete(int $thresholdId)
80
    {
81
        $this->ThresholdService->delete($thresholdId);
82
        return true;
83
    }
84
85
    /**
86
     * validate threshold
87
     *
88
     * @NoAdminRequired
89
     * @param int $datasetId
90
     * @param $dimension1
91
     * @param $dimension2
92
     * @param $value
93
     * @return string
94
     * @throws \Exception
95
     */
96
    public function validate(int $datasetId, $dimension1, $dimension2, $value)
97
    {
98
        return $this->ThresholdService->validate($datasetId, $dimension1, $dimension2, $value);
99
    }
100
}