PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Archive / ArchiveQueryFactory.php
matomo / app / core / Archive Last commit date
ArchiveInvalidator 6 years ago ArchiveInvalidator.php 6 years ago ArchivePurger.php 6 years ago ArchiveQuery.php 6 years ago ArchiveQueryFactory.php 6 years ago Chunk.php 6 years ago DataCollection.php 6 years ago DataTableFactory.php 6 years ago Parameters.php 6 years ago
ArchiveQueryFactory.php
127 lines
1 <?php
2 /**
3 * Piwik - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9
10 namespace Piwik\Archive;
11
12 use Piwik\Archive;
13 use Piwik\Period;
14 use Piwik\Segment;
15 use Piwik\Site;
16 use Piwik\Period\Factory as PeriodFactory;
17
18 class ArchiveQueryFactory
19 {
20 public function __construct()
21 {
22 // empty
23 }
24
25 /**
26 * @see \Piwik\Archive::build()
27 */
28 public function build($idSites, $strPeriod, $strDate, $strSegment = false, $_restrictSitesToLogin = false)
29 {
30 list($websiteIds, $timezone, $idSiteIsAll) = $this->getSiteInfoFromQueryParam($idSites, $_restrictSitesToLogin);
31 list($allPeriods, $isMultipleDate) = $this->getPeriodInfoFromQueryParam($strDate, $strPeriod, $timezone);
32 $segment = $this->getSegmentFromQueryParam($strSegment, $websiteIds);
33
34 return $this->factory($segment, $allPeriods, $websiteIds, $idSiteIsAll, $isMultipleDate);
35 }
36
37 /**
38 * @see \Piwik\Archive::factory()
39 */
40 public function factory(Segment $segment, array $periods, array $idSites, $idSiteIsAll = false, $isMultipleDate = false)
41 {
42 $forceIndexedBySite = false;
43 $forceIndexedByDate = false;
44
45 if ($idSiteIsAll || count($idSites) > 1) {
46 $forceIndexedBySite = true;
47 }
48
49 if (count($periods) > 1 || $isMultipleDate) {
50 $forceIndexedByDate = true;
51 }
52
53 $params = new Parameters($idSites, $periods, $segment);
54
55 return $this->newInstance($params, $forceIndexedBySite, $forceIndexedByDate);
56 }
57
58 public function newInstance(Parameters $params, $forceIndexedBySite, $forceIndexedByDate)
59 {
60 return new Archive($params, $forceIndexedBySite, $forceIndexedByDate);
61 }
62
63 /**
64 * Parses the site ID string provided in the 'idSite' query parameter to a list of
65 * website IDs.
66 *
67 * @param string $idSites the value of the 'idSite' query parameter
68 * @param bool $_restrictSitesToLogin
69 * @return array an array containing three elements:
70 * - an array of website IDs
71 * - string timezone to use (or false to use no timezone) when creating periods.
72 * - true if the request was for all websites (this forces the archive result to
73 * be indexed by site, even if there is only one site in Piwik)
74 */
75 protected function getSiteInfoFromQueryParam($idSites, $_restrictSitesToLogin)
76 {
77 $websiteIds = Site::getIdSitesFromIdSitesString($idSites, $_restrictSitesToLogin);
78
79 $timezone = false;
80 if (count($websiteIds) == 1) {
81 $timezone = Site::getTimezoneFor($websiteIds[0]);
82 }
83
84 $idSiteIsAll = $idSites == Archive::REQUEST_ALL_WEBSITES_FLAG;
85
86 return [$websiteIds, $timezone, $idSiteIsAll];
87 }
88
89 /**
90 * Parses the date & period query parameters into a list of periods.
91 *
92 * @param string $strDate the value of the 'date' query parameter
93 * @param string $strPeriod the value of the 'period' query parameter
94 * @param string $timezone the timezone to use when constructing periods.
95 * @return array an array containing two elements:
96 * - the list of period objects to query archive data for
97 * - true if the request was for multiple periods (ie, two months, two weeks, etc.), false if otherwise.
98 * (this forces the archive result to be indexed by period, even if the list of periods
99 * has only one period).
100 */
101 protected function getPeriodInfoFromQueryParam($strDate, $strPeriod, $timezone)
102 {
103 if (Period::isMultiplePeriod($strDate, $strPeriod)) {
104 $oPeriod = PeriodFactory::build($strPeriod, $strDate, $timezone);
105 $allPeriods = $oPeriod->getSubperiods();
106 } else {
107 $oPeriod = PeriodFactory::makePeriodFromQueryParams($timezone, $strPeriod, $strDate);
108 $allPeriods = array($oPeriod);
109 }
110
111 $isMultipleDate = Period::isMultiplePeriod($strDate, $strPeriod);
112
113 return [$allPeriods, $isMultipleDate];
114 }
115
116 /**
117 * Parses the segment query parameter into a Segment object.
118 *
119 * @param string $strSegment the value of the 'segment' query parameter.
120 * @param int[] $websiteIds the list of sites being queried.
121 * @return Segment
122 */
123 protected function getSegmentFromQueryParam($strSegment, $websiteIds)
124 {
125 return new Segment($strSegment, $websiteIds);
126 }
127 }