blob: 68b3fcff53dfea18a982947be089a26ec655a187 (
plain)
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
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\SegmentEditor;
use Piwik\Common;
use Piwik\Db;
/**
* The SegmentEditor Model lets you persist and read custom Segments from the backend without handling any logic.
*/
class Model
{
/**
* Returns all stored segments.
*
* @param bool|int $idSite Whether to return stored segments for a specific idSite, or segments that are available
* for all sites. If supplied, must be a valid site ID.
* @return array
*/
public function getSegmentsToAutoArchive($idSite = false)
{
$bind = array();
$whereIdSite = '';
if (!empty($idSite)) {
$whereIdSite = 'enable_only_idsite = ? OR ';
$bind[] = $idSite;
}
$sql = $this->buildQuerySortedByName("($whereIdSite enable_only_idsite = 0)
AND deleted = 0 AND auto_archive = 1");
$segments = Db::get()->fetchAll($sql, $bind);
return $segments;
}
/**
* Returns all stored segments that are available to the given login.
*
* @param string $userLogin
* @return array
*/
public function getAllSegments($userLogin)
{
$bind = array($userLogin);
$sql = $this->buildQuerySortedByName('deleted = 0 AND (enable_all_users = 1 OR login = ?)');
$segments = Db::get()->fetchAll($sql, $bind);
return $segments;
}
/**
* Returns all stored segments that are available for the given site and login.
*
* @param string $userLogin
* @param int $idSite Whether to return stored segments for a specific idSite, or all of them. If supplied, must be a valid site ID.
* @return array
*/
public function getAllSegmentsForSite($idSite, $userLogin)
{
$bind = array($idSite, $userLogin);
$sql = $this->buildQuerySortedByName('(enable_only_idsite = ? OR enable_only_idsite = 0)
AND deleted = 0
AND (enable_all_users = 1 OR login = ?)');
$segments = Db::get()->fetchAll($sql, $bind);
return $segments;
}
private function buildQuerySortedByName($where)
{
$sql = "SELECT * FROM " . Common::prefixTable("segment") .
" WHERE $where ORDER BY name ASC";
return $sql;
}
}
|