|
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\Db; |
|
13
|
|
|
|
|
14
|
|
|
use OCP\IDbConnection; |
|
15
|
|
|
use OCP\IL10N; |
|
16
|
|
|
use OCP\ILogger; |
|
17
|
|
|
|
|
18
|
|
|
class ThresholdMapper |
|
19
|
|
|
{ |
|
20
|
|
|
private $userId; |
|
21
|
|
|
private $l10n; |
|
22
|
|
|
private $db; |
|
23
|
|
|
private $logger; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct( |
|
26
|
|
|
$userId, |
|
27
|
|
|
IL10N $l10n, |
|
28
|
|
|
IDbConnection $db, |
|
29
|
|
|
ILogger $logger |
|
30
|
|
|
) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->userId = $userId; |
|
33
|
|
|
$this->l10n = $l10n; |
|
34
|
|
|
$this->db = $db; |
|
35
|
|
|
$this->logger = $logger; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function createThreshold($datasetId, $dimension1, $dimension3, $option, $serverity) |
|
39
|
|
|
{ |
|
40
|
|
|
$SQL = 'INSERT INTO `*PREFIX*analytics_threshold` (`user_id`,`dataset`,`dimension1`,`dimension3`,`option`,`severity`) VALUES(?,?,?,?,?,?)'; |
|
41
|
|
|
//$this->logger->error($SQL); |
|
42
|
|
|
|
|
43
|
|
|
$stmt = $this->db->prepare($SQL); |
|
44
|
|
|
$stmt->execute(array($this->userId, $datasetId, $dimension1, $dimension3, $option, $serverity)); |
|
45
|
|
|
$insertid = $this->db->lastInsertId('*PREFIX*analytics_threashold'); |
|
46
|
|
|
return $insertid; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getThresholdsByDataset($datasetId) |
|
50
|
|
|
{ |
|
51
|
|
|
$SQL = 'SELECT * FROM `*PREFIX*analytics_threshold` WHERE `dataset` = ?'; |
|
52
|
|
|
//$this->logger->error($SQL); |
|
53
|
|
|
$stmt = $this->db->prepare($SQL); |
|
54
|
|
|
$stmt->execute(array($datasetId)); |
|
55
|
|
|
return $stmt->fetchAll(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getSevOneThresholdsByDataset($datasetId) |
|
59
|
|
|
{ |
|
60
|
|
|
$SQL = 'SELECT * FROM `*PREFIX*analytics_threshold` WHERE `dataset` = ? AND `severity` = 1'; |
|
61
|
|
|
//$this->logger->error($SQL); |
|
62
|
|
|
$stmt = $this->db->prepare($SQL); |
|
63
|
|
|
$stmt->execute(array($datasetId)); |
|
64
|
|
|
return $stmt->fetchAll(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function deleteThreshold($thresholdId) |
|
68
|
|
|
{ |
|
69
|
|
|
$SQL = 'DELETE FROM `*PREFIX*analytics_threshold` WHERE `id` = ? AND `user_id` = ?'; |
|
70
|
|
|
$stmt = $this->db->prepare($SQL); |
|
71
|
|
|
$stmt->execute([$thresholdId, $this->userId]); |
|
72
|
|
|
return true; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|