1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\ScheduledReports;
use Piwik\Common;
use Piwik\Db;
use Piwik\DbHelper;
use Piwik\ReportRenderer;
use Piwik\Translate;
class Model
{
private static $rawPrefix = 'report';
private $table;
public function __construct()
{
$this->table = Common::prefixTable(self::$rawPrefix);
}
public function deleteUserReportForSite($userLogin, $idSite)
{
$query = 'DELETE FROM ' . $this->table . ' WHERE login = ? and idsite = ?';
$bind = array($userLogin, $idSite);
Db::query($query, $bind);
}
public function deleteAllReportForUser($userLogin)
{
Db::query('DELETE FROM ' . $this->table . ' WHERE login = ?', $userLogin);
}
public function updateReport($idReport, $report)
{
$idReport = (int) $idReport;
$this->getDb()->update($this->table, $report, "idreport = " . $idReport);
}
public function createReport($report)
{
$nextId = $this->getNextReportId();
$report['idreport'] = $nextId;
$this->getDb()->insert($this->table, $report);
return $nextId;
}
private function getNextReportId()
{
$db = $this->getDb();
$idReport = $db->fetchOne("SELECT max(idreport) + 1 FROM " . $this->table);
if ($idReport == false) {
$idReport = 1;
}
return $idReport;
}
private function getDb()
{
return Db::get();
}
public static function install()
{
$reportTable = "`idreport` INT(11) NOT NULL AUTO_INCREMENT,
`idsite` INTEGER(11) NOT NULL,
`login` VARCHAR(100) NOT NULL,
`description` VARCHAR(255) NOT NULL,
`idsegment` INT(11),
`period` VARCHAR(10) NOT NULL,
`hour` tinyint NOT NULL default 0,
`type` VARCHAR(10) NOT NULL,
`format` VARCHAR(10) NOT NULL,
`reports` TEXT NOT NULL,
`parameters` TEXT NULL,
`ts_created` TIMESTAMP NULL,
`ts_last_sent` TIMESTAMP NULL,
`deleted` tinyint(4) NOT NULL default 0,
PRIMARY KEY (`idreport`)";
DbHelper::createTable(self::$rawPrefix, $reportTable);
}
}
|