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