本文整理汇总了PHP中Piwik\Period::makePeriodFromQueryParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Period::makePeriodFromQueryParams方法的具体用法?PHP Period::makePeriodFromQueryParams怎么用?PHP Period::makePeriodFromQueryParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Period
的用法示例。
在下文中一共展示了Period::makePeriodFromQueryParams方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getByDayOfWeek
/**
* Returns datatable describing the number of visits for each day of the week.
*
* @param string $idSite The site ID. Cannot refer to multiple sites.
* @param string $period The period type: day, week, year, range...
* @param string $date The start date of the period. Cannot refer to multiple dates.
* @param bool|string $segment The segment.
* @throws Exception
* @return DataTable
*/
public function getByDayOfWeek($idSite, $period, $date, $segment = false)
{
Piwik::checkUserHasViewAccess($idSite);
// metrics to query
$metrics = Metrics::getVisitsMetricNames();
unset($metrics[Metrics::INDEX_MAX_ACTIONS]);
// disabled for multiple dates
if (Period::isMultiplePeriod($date, $period)) {
throw new Exception("VisitTime.getByDayOfWeek does not support multiple dates.");
}
// get metric data for every day within the supplied period
$oPeriod = Period::makePeriodFromQueryParams(Site::getTimezoneFor($idSite), $period, $date);
$dateRange = $oPeriod->getDateStart()->toString() . ',' . $oPeriod->getDateEnd()->toString();
$archive = Archive::build($idSite, 'day', $dateRange, $segment);
// disabled for multiple sites
if (count($archive->getParams()->getIdSites()) > 1) {
throw new Exception("VisitTime.getByDayOfWeek does not support multiple sites.");
}
$dataTable = $archive->getDataTableFromNumeric($metrics)->mergeChildren();
// if there's no data for this report, don't bother w/ anything else
if ($dataTable->getRowsCount() == 0) {
return $dataTable;
}
// group by the day of the week (see below for dayOfWeekFromDate function)
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\\dayOfWeekFromDate'));
// create new datatable w/ empty rows, then add calculated datatable
$rows = array();
foreach (array(1, 2, 3, 4, 5, 6, 7) as $day) {
$rows[] = array('label' => $day, 'nb_visits' => 0);
}
$result = new DataTable();
$result->addRowsFromSimpleArray($rows);
$result->addDataTable($dataTable);
// set day of week integer as metadata
$result->filter('ColumnCallbackAddMetadata', array('label', 'day_of_week'));
// translate labels
$result->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\\translateDayOfWeek'));
// set datatable metadata for period start & finish
$result->setMetadata('date_start', $oPeriod->getDateStart());
$result->setMetadata('date_end', $oPeriod->getDateEnd());
return $result;
}
示例2: getDateRangeForFooterMessage
private static function getDateRangeForFooterMessage()
{
// get query params
$idSite = Common::getRequestVar('idSite', false);
$date = Common::getRequestVar('date', false);
$period = Common::getRequestVar('period', false);
// create a period instance
try {
$oPeriod = Period::makePeriodFromQueryParams(Site::getTimezoneFor($idSite), $period, $date);
} catch (Exception $ex) {
return '';
// if query params are incorrect, forget about the footer message
}
// set the footer message using the period start & end date
$start = $oPeriod->getDateStart()->toString();
$end = $oPeriod->getDateEnd()->toString();
if ($start == $end) {
$dateRange = $start;
} else {
$dateRange = $start . " – " . $end;
}
return $dateRange;
}
示例3: build
/**
* Returns a new Archive instance that will query archive data for the given set of
* sites and periods, using an optional Segment.
*
* This method uses data that is found in query parameters, so the parameters to this
* function can be string values.
*
* If you want to create an Archive instance with an array of Period instances, use
* {@link Archive::factory()}.
*
* @param string|int|array $idSites A single ID (eg, `'1'`), multiple IDs (eg, `'1,2,3'` or `array(1, 2, 3)`),
* or `'all'`.
* @param string $period 'day', `'week'`, `'month'`, `'year'` or `'range'`
* @param Date|string $strDate 'YYYY-MM-DD', magic keywords (ie, 'today'; {@link Date::factory()}
* or date range (ie, 'YYYY-MM-DD,YYYY-MM-DD').
* @param bool|false|string $segment Segment definition or false if no segment should be used. {@link Piwik\Segment}
* @param bool|false|string $_restrictSitesToLogin Used only when running as a scheduled task.
* @return Archive
*/
public static function build($idSites, $period, $strDate, $segment = false, $_restrictSitesToLogin = false)
{
$websiteIds = Site::getIdSitesFromIdSitesString($idSites, $_restrictSitesToLogin);
if (Period::isMultiplePeriod($strDate, $period)) {
$oPeriod = new Range($period, $strDate);
$allPeriods = $oPeriod->getSubperiods();
} else {
$timezone = count($websiteIds) == 1 ? Site::getTimezoneFor($websiteIds[0]) : false;
$oPeriod = Period::makePeriodFromQueryParams($timezone, $period, $strDate);
$allPeriods = array($oPeriod);
}
$segment = new Segment($segment, $websiteIds);
$idSiteIsAll = $idSites == self::REQUEST_ALL_WEBSITES_FLAG;
$isMultipleDate = Period::isMultiplePeriod($strDate, $period);
return Archive::factory($segment, $allPeriods, $websiteIds, $idSiteIsAll, $isMultipleDate);
}