PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.12.1 5.12.0 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 2 years ago ArchiveInvalidator.php 2 years ago ArchivePurger.php 2 years ago ArchiveQuery.php 2 years ago ArchiveQueryFactory.php 2 years ago Chunk.php 2 years ago DataCollection.php 2 years ago DataTableFactory.php 2 years ago Parameters.php 2 years ago
ArchiveQueryFactory.php
114 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
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 class ArchiveQueryFactory
18 {
19 public function __construct()
20 {
21 // empty
22 }
23 /**
24 * @see \Piwik\Archive::build()
25 */
26 public function build($idSites, $strPeriod, $strDate, $strSegment = false, $_restrictSitesToLogin = false)
27 {
28 list($websiteIds, $timezone, $idSiteIsAll) = $this->getSiteInfoFromQueryParam($idSites, $_restrictSitesToLogin);
29 list($allPeriods, $isMultipleDate) = $this->getPeriodInfoFromQueryParam($strDate, $strPeriod, $timezone);
30 $segment = $this->getSegmentFromQueryParam($strSegment, $websiteIds, $allPeriods);
31 return $this->factory($segment, $allPeriods, $websiteIds, $idSiteIsAll, $isMultipleDate);
32 }
33 /**
34 * @see \Piwik\Archive::factory()
35 */
36 public function factory(Segment $segment, array $periods, array $idSites, $idSiteIsAll = false, $isMultipleDate = false)
37 {
38 $forceIndexedBySite = false;
39 $forceIndexedByDate = false;
40 if ($idSiteIsAll || count($idSites) > 1) {
41 $forceIndexedBySite = true;
42 }
43 if (count($periods) > 1 || $isMultipleDate) {
44 $forceIndexedByDate = true;
45 }
46 $params = new \Piwik\Archive\Parameters($idSites, $periods, $segment);
47 return $this->newInstance($params, $forceIndexedBySite, $forceIndexedByDate);
48 }
49 public function newInstance(\Piwik\Archive\Parameters $params, $forceIndexedBySite, $forceIndexedByDate)
50 {
51 return new Archive($params, $forceIndexedBySite, $forceIndexedByDate);
52 }
53 /**
54 * Parses the site ID string provided in the 'idSite' query parameter to a list of
55 * website IDs.
56 *
57 * @param string $idSites the value of the 'idSite' query parameter
58 * @param bool $_restrictSitesToLogin
59 * @return array an array containing three elements:
60 * - an array of website IDs
61 * - string timezone to use (or false to use no timezone) when creating periods.
62 * - true if the request was for all websites (this forces the archive result to
63 * be indexed by site, even if there is only one site in Piwik)
64 */
65 protected function getSiteInfoFromQueryParam($idSites, $_restrictSitesToLogin)
66 {
67 $websiteIds = Site::getIdSitesFromIdSitesString($idSites, $_restrictSitesToLogin);
68 $timezone = false;
69 if (count($websiteIds) === 1) {
70 $timezone = Site::getTimezoneFor($websiteIds[0]);
71 }
72 $idSiteIsAll = $idSites === Archive::REQUEST_ALL_WEBSITES_FLAG;
73 return [$websiteIds, $timezone, $idSiteIsAll];
74 }
75 /**
76 * Parses the date & period query parameters into a list of periods.
77 *
78 * @param string $strDate the value of the 'date' query parameter
79 * @param string $strPeriod the value of the 'period' query parameter
80 * @param string $timezone the timezone to use when constructing periods.
81 * @return array an array containing two elements:
82 * - the list of period objects to query archive data for
83 * - true if the request was for multiple periods (ie, two months, two weeks, etc.), false if otherwise.
84 * (this forces the archive result to be indexed by period, even if the list of periods
85 * has only one period).
86 */
87 protected function getPeriodInfoFromQueryParam($strDate, $strPeriod, $timezone)
88 {
89 if (Period::isMultiplePeriod($strDate, $strPeriod)) {
90 $oPeriod = PeriodFactory::build($strPeriod, $strDate, $timezone);
91 $allPeriods = $oPeriod->getSubperiods();
92 } else {
93 $oPeriod = PeriodFactory::makePeriodFromQueryParams($timezone, $strPeriod, $strDate);
94 $allPeriods = array($oPeriod);
95 }
96 $isMultipleDate = Period::isMultiplePeriod($strDate, $strPeriod);
97 return [$allPeriods, $isMultipleDate];
98 }
99 /**
100 * Parses the segment query parameter into a Segment object.
101 *
102 * @param string $strSegment the value of the 'segment' query parameter.
103 * @param int[] $websiteIds the list of sites being queried.
104 * @param Period[] $allPeriods list of all periods
105 * @return Segment
106 */
107 protected function getSegmentFromQueryParam($strSegment, $websiteIds, $allPeriods)
108 {
109 // we might have multiple periods, so use the start date of the first one and
110 // the end date of the last one to limit the possible segment subquery
111 return new Segment($strSegment, $websiteIds, reset($allPeriods)->getDateTimeStart(), end($allPeriods)->getDateTimeEnd());
112 }
113 }
114