本文整理汇总了PHP中Piwik\Period\Range::getLastDate方法的典型用法代码示例。如果您正苦于以下问题:PHP Range::getLastDate方法的具体用法?PHP Range::getLastDate怎么用?PHP Range::getLastDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Period\Range
的用法示例。
在下文中一共展示了Range::getLastDate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
$view = new View('@Referrers/index');
$view->graphEvolutionReferrers = $this->getEvolutionGraph(Common::REFERRER_TYPE_DIRECT_ENTRY, array(), array('nb_visits'));
$view->nameGraphEvolutionReferrers = 'Referrers.getEvolutionGraph';
// building the referrers summary report
$view->dataTableReferrerType = $this->renderReport(new GetReferrerType());
$nameValues = $this->getReferrersVisitorsByType();
$totalVisits = array_sum($nameValues);
foreach ($nameValues as $name => $value) {
$view->{$name} = $value;
// calculate percent of total, if there were any visits
if ($value != 0 && $totalVisits != 0) {
$percentName = $name . 'Percent';
$view->{$percentName} = round($value / $totalVisits * 100, 0);
}
}
// set distinct metrics
$distinctMetrics = $this->getDistinctReferrersMetrics();
foreach ($distinctMetrics as $name => $value) {
$view->{$name} = $value;
}
// calculate evolution for visit metrics & distinct metrics
list($lastPeriodDate, $ignore) = Range::getLastDate();
if ($lastPeriodDate !== false) {
$date = Common::getRequestVar('date');
$period = Common::getRequestVar('period');
$prettyDate = self::getPrettyDate($date, $period);
$prettyLastPeriodDate = self::getPrettyDate($lastPeriodDate, $period);
// visit metrics
$previousValues = $this->getReferrersVisitorsByType($lastPeriodDate);
$this->addEvolutionPropertiesToView($view, $prettyDate, $nameValues, $prettyLastPeriodDate, $previousValues);
// distinct metrics
$previousValues = $this->getDistinctReferrersMetrics($lastPeriodDate);
$this->addEvolutionPropertiesToView($view, $prettyDate, $distinctMetrics, $prettyLastPeriodDate, $previousValues);
}
// sparkline for the historical data of the above values
$view->urlSparklineSearchEngines = $this->getReferrerUrlSparkline(Common::REFERRER_TYPE_SEARCH_ENGINE);
$view->urlSparklineDirectEntry = $this->getReferrerUrlSparkline(Common::REFERRER_TYPE_DIRECT_ENTRY);
$view->urlSparklineWebsites = $this->getReferrerUrlSparkline(Common::REFERRER_TYPE_WEBSITE);
$view->urlSparklineCampaigns = $this->getReferrerUrlSparkline(Common::REFERRER_TYPE_CAMPAIGN);
// sparklines for the evolution of the distinct keywords count/websites count/ etc
$view->urlSparklineDistinctSearchEngines = $this->getUrlSparkline('getLastDistinctSearchEnginesGraph');
$view->urlSparklineDistinctKeywords = $this->getUrlSparkline('getLastDistinctKeywordsGraph');
$view->urlSparklineDistinctWebsites = $this->getUrlSparkline('getLastDistinctWebsitesGraph');
$view->urlSparklineDistinctCampaigns = $this->getUrlSparkline('getLastDistinctCampaignsGraph');
$view->totalVisits = $totalVisits;
$view->referrersReportsByDimension = $this->getReferrersReportsByDimensionView($totalVisits);
return $view->render();
}
示例2: buildDataTable
private function buildDataTable($sitesToProblablyAdd, $period, $date, $segment, $_restrictSitesToLogin, $enhanced, $multipleWebsitesRequested, $showColumns)
{
$idSites = array();
if (!empty($sitesToProblablyAdd)) {
foreach ($sitesToProblablyAdd as $site) {
$idSites[] = $site['idsite'];
}
}
// build the archive type used to query archive data
$archive = Archive::build($idSites, $period, $date, $segment, $_restrictSitesToLogin);
// determine what data will be displayed
$fieldsToGet = array();
$columnNameRewrites = array();
$apiECommerceMetrics = array();
$apiMetrics = API::getApiMetrics($enhanced);
foreach ($apiMetrics as $metricName => $metricSettings) {
if (!empty($showColumns) && !in_array($metricName, $showColumns)) {
unset($apiMetrics[$metricName]);
continue;
}
$fieldsToGet[] = $metricSettings[self::METRIC_RECORD_NAME_KEY];
$columnNameRewrites[$metricSettings[self::METRIC_RECORD_NAME_KEY]] = $metricName;
if ($metricSettings[self::METRIC_IS_ECOMMERCE_KEY]) {
$apiECommerceMetrics[$metricName] = $metricSettings;
}
}
$dataTable = $archive->getDataTableFromNumericAndMergeChildren($fieldsToGet);
$this->populateLabel($dataTable);
$totalMetrics = $this->preformatApiMetricsForTotalsCalculation($apiMetrics);
$this->setMetricsTotalsMetadata($dataTable, $totalMetrics);
// if the period isn't a range & a lastN/previousN date isn't used, we get the same
// data for the last period to show the evolution of visits/actions/revenue
list($strLastDate, $lastPeriod) = Range::getLastDate($date, $period);
if ($strLastDate !== false) {
if ($lastPeriod !== false) {
// NOTE: no easy way to set last period date metadata when range of dates is requested.
// will be easier if DataTable\Map::metadata is removed, and metadata that is
// put there is put directly in DataTable::metadata.
$dataTable->setMetadata(self::getLastPeriodMetadataName('date'), $lastPeriod);
}
$pastArchive = Archive::build($idSites, $period, $strLastDate, $segment, $_restrictSitesToLogin);
$pastData = $pastArchive->getDataTableFromNumericAndMergeChildren($fieldsToGet);
$this->populateLabel($pastData);
// labels are needed to calculate evolution
$this->calculateEvolutionPercentages($dataTable, $pastData, $apiMetrics);
$this->setPastTotalVisitsMetadata($dataTable, $pastData);
if ($dataTable instanceof DataTable) {
// needed for MultiSites\Dashboard
$dataTable->setMetadata('pastData', $pastData);
}
}
// move the site id to a metadata column
$dataTable->queueFilter('MetadataCallbackAddMetadata', array('idsite', 'group', array('\\Piwik\\Site', 'getGroupFor'), array()));
$dataTable->queueFilter('MetadataCallbackAddMetadata', array('idsite', 'main_url', array('\\Piwik\\Site', 'getMainUrlFor'), array()));
// set the label of each row to the site name
if ($multipleWebsitesRequested) {
$dataTable->queueFilter('ColumnCallbackReplace', array('label', '\\Piwik\\Site::getNameFor'));
} else {
$dataTable->queueFilter('ColumnDelete', array('label'));
}
// replace record names with user friendly metric names
$dataTable->queueFilter('ReplaceColumnNames', array($columnNameRewrites));
// filter rows without visits
// note: if only one website is queried and there are no visits, we can not remove the row otherwise
// ResponseBuilder throws 'Call to a member function getColumns() on a non-object'
if ($multipleWebsitesRequested && !$enhanced) {
$dataTable->filter('ColumnCallbackDeleteRow', array(self::NB_VISITS_METRIC, function ($value) {
return $value == 0;
}));
}
if ($multipleWebsitesRequested && $dataTable->getRowsCount() === 1 && $dataTable instanceof DataTable\Simple) {
$simpleTable = $dataTable;
$dataTable = $simpleTable->getEmptyClone();
$dataTable->addRow($simpleTable->getFirstRow());
unset($simpleTable);
}
return $dataTable;
}
示例3: getSparklines
public function getSparklines()
{
$metrics = $this->getReferrersVisitorsByType();
$distinctMetrics = $this->getDistinctReferrersMetrics();
$numberFormatter = NumberFormatter::getInstance();
$totalVisits = array_sum($metrics);
foreach ($metrics as $name => $value) {
// calculate percent of total, if there were any visits
if ($value != 0 && $totalVisits != 0) {
$percentName = $name . 'Percent';
$metrics[$percentName] = round($value / $totalVisits * 100, 0);
}
}
// calculate evolution for visit metrics & distinct metrics
list($lastPeriodDate, $ignore) = Range::getLastDate();
if ($lastPeriodDate !== false) {
$date = Common::getRequestVar('date');
$period = Common::getRequestVar('period');
$prettyDate = self::getPrettyDate($date, $period);
$prettyLastPeriodDate = self::getPrettyDate($lastPeriodDate, $period);
// visit metrics
$previousValues = $this->getReferrersVisitorsByType($lastPeriodDate);
$metrics = $this->addEvolutionPropertiesToView($prettyDate, $metrics, $prettyLastPeriodDate, $previousValues);
// distinct metrics
$previousValues = $this->getDistinctReferrersMetrics($lastPeriodDate);
$distinctMetrics = $this->addEvolutionPropertiesToView($prettyDate, $distinctMetrics, $prettyLastPeriodDate, $previousValues);
}
/** @var Sparklines $view */
$view = ViewDataTable\Factory::build(Sparklines::ID, $api = '', $controller = '', $force = true, $loadUserParams = false);
// DIRECT ENTRY
$metrics['visitorsFromDirectEntry'] = $numberFormatter->formatNumber($metrics['visitorsFromDirectEntry']);
$values = array($metrics['visitorsFromDirectEntry']);
$descriptions = array(Piwik::translate('Referrers_TypeDirectEntries'));
if (!empty($metrics['visitorsFromDirectEntryPercent'])) {
$metrics['visitorsFromDirectEntryPercent'] = $numberFormatter->formatPercent($metrics['visitorsFromDirectEntryPercent'], $precision = 1);
$values[] = $metrics['visitorsFromDirectEntryPercent'];
$descriptions[] = Piwik::translate('Referrers_XPercentOfVisits');
}
$directEntryParams = $this->getReferrerSparklineParams(Common::REFERRER_TYPE_DIRECT_ENTRY);
$view->config->addSparkline($directEntryParams, $values, $descriptions, @$metrics['visitorsFromDirectEntryEvolution']);
// WEBSITES
$metrics['visitorsFromWebsites'] = $numberFormatter->formatNumber($metrics['visitorsFromWebsites']);
$values = array($metrics['visitorsFromWebsites']);
$descriptions = array(Piwik::translate('Referrers_TypeWebsites'));
if (!empty($metrics['visitorsFromWebsitesPercent'])) {
$metrics['visitorsFromWebsitesPercent'] = $numberFormatter->formatPercent($metrics['visitorsFromWebsitesPercent'], $precision = 1);
$values[] = $metrics['visitorsFromWebsitesPercent'];
$descriptions[] = Piwik::translate('Referrers_XPercentOfVisits');
}
$searchEngineParams = $this->getReferrerSparklineParams(Common::REFERRER_TYPE_WEBSITE);
$view->config->addSparkline($searchEngineParams, $values, $descriptions, @$metrics['visitorsFromWebsitesEvolution']);
// SEARCH ENGINES
$metrics['visitorsFromSearchEngines'] = $numberFormatter->formatNumber($metrics['visitorsFromSearchEngines']);
$values = array($metrics['visitorsFromSearchEngines']);
$descriptions = array(Piwik::translate('Referrers_TypeSearchEngines'));
if (!empty($metrics['visitorsFromSearchEnginesPercent'])) {
$metrics['visitorsFromSearchEnginesPercent'] = $numberFormatter->formatPercent($metrics['visitorsFromSearchEnginesPercent'], $precision = 1);
$values[] = $metrics['visitorsFromSearchEnginesPercent'];
$descriptions[] = Piwik::translate('Referrers_XPercentOfVisits');
}
$searchEngineParams = $this->getReferrerSparklineParams(Common::REFERRER_TYPE_SEARCH_ENGINE);
$view->config->addSparkline($searchEngineParams, $values, $descriptions, @$metrics['visitorsFromSearchEnginesEvolution']);
// CAMPAIGNS
$metrics['visitorsFromCampaigns'] = $numberFormatter->formatNumber($metrics['visitorsFromCampaigns']);
$values = array($metrics['visitorsFromCampaigns']);
$descriptions = array(Piwik::translate('Referrers_TypeCampaigns'));
if (!empty($metrics['visitorsFromCampaignsPercent'])) {
$metrics['visitorsFromCampaignsPercent'] = $numberFormatter->formatPercent($metrics['visitorsFromCampaignsPercent'], $precision = 1);
$values[] = $metrics['visitorsFromCampaignsPercent'];
$descriptions[] = Piwik::translate('Referrers_XPercentOfVisits');
}
$searchEngineParams = $this->getReferrerSparklineParams(Common::REFERRER_TYPE_CAMPAIGN);
$view->config->addSparkline($searchEngineParams, $values, $descriptions, @$metrics['visitorsFromCampaignsEvolution']);
// DISTINCT SEARCH ENGINES
$sparklineParams = $this->getDistinctSparklineUrlParams('getLastDistinctSearchEnginesGraph');
$value = $distinctMetrics['numberDistinctSearchEngines'];
$value = $numberFormatter->formatNumber($value);
$description = Piwik::translate('Referrers_DistinctSearchEngines');
$view->config->addSparkline($sparklineParams, $value, $description, @$distinctMetrics['numberDistinctSearchEnginesEvolution']);
// DISTINCT WEBSITES
$sparklineParams = $this->getDistinctSparklineUrlParams('getLastDistinctWebsitesGraph');
$distinctMetrics['numberDistinctWebsites'] = $numberFormatter->formatNumber($distinctMetrics['numberDistinctWebsites']);
$distinctMetrics['numberDistinctWebsitesUrls'] = $numberFormatter->formatNumber($distinctMetrics['numberDistinctWebsitesUrls']);
$values = array($distinctMetrics['numberDistinctWebsites'], $distinctMetrics['numberDistinctWebsitesUrls']);
$descriptions = array(Piwik::translate('Referrers_DistinctWebsites'), Piwik::translate('Referrers_UsingNDistinctUrls'));
$view->config->addSparkline($sparklineParams, $values, $descriptions, @$distinctMetrics['numberDistinctWebsitesEvolution']);
// DISTINCT KEYWORDS
$sparklineParams = $this->getDistinctSparklineUrlParams('getLastDistinctKeywordsGraph');
$value = $distinctMetrics['numberDistinctKeywords'];
$value = $numberFormatter->formatNumber($value);
$description = Piwik::translate('Referrers_DistinctKeywords');
$view->config->addSparkline($sparklineParams, $value, $description, @$distinctMetrics['numberDistinctKeywordsEvolution']);
// DISTINCT CAMPAIGNS
$sparklineParams = $this->getDistinctSparklineUrlParams('getLastDistinctCampaignsGraph');
$value = $distinctMetrics['numberDistinctCampaigns'];
$value = $numberFormatter->formatNumber($value);
$description = Piwik::translate('Referrers_DistinctCampaigns');
$view->config->addSparkline($sparklineParams, $value, $description, @$distinctMetrics['numberDistinctCampaignsEvolution']);
return $view->render();
}
示例4: buildDataTable
private function buildDataTable($idSitesOrIdSite, $period, $date, $segment, $_restrictSitesToLogin, $enhanced, $multipleWebsitesRequested)
{
$allWebsitesRequested = $idSitesOrIdSite == 'all';
if ($allWebsitesRequested) {
// First clear cache
Site::clearCache();
// Then, warm the cache with only the data we should have access to
if (Piwik::isUserIsSuperUser() && !TaskScheduler::isTaskBeingExecuted()) {
$sites = APISitesManager::getInstance()->getAllSites();
} else {
$sites = APISitesManager::getInstance()->getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin);
}
// Both calls above have called Site::setSitesFromArray. We now get these sites:
$sitesToProblablyAdd = Site::getSites();
} else {
$sitesToProblablyAdd = array(APISitesManager::getInstance()->getSiteFromId($idSitesOrIdSite));
}
// build the archive type used to query archive data
$archive = Archive::build($idSitesOrIdSite, $period, $date, $segment, $_restrictSitesToLogin);
// determine what data will be displayed
$fieldsToGet = array();
$columnNameRewrites = array();
$apiECommerceMetrics = array();
$apiMetrics = API::getApiMetrics($enhanced);
foreach ($apiMetrics as $metricName => $metricSettings) {
$fieldsToGet[] = $metricSettings[self::METRIC_RECORD_NAME_KEY];
$columnNameRewrites[$metricSettings[self::METRIC_RECORD_NAME_KEY]] = $metricName;
if ($metricSettings[self::METRIC_IS_ECOMMERCE_KEY]) {
$apiECommerceMetrics[$metricName] = $metricSettings;
}
}
// get the data
// $dataTable instanceOf Set
$dataTable = $archive->getDataTableFromNumeric($fieldsToGet);
$dataTable = $this->mergeDataTableMapAndPopulateLabel($idSitesOrIdSite, $multipleWebsitesRequested, $dataTable);
if ($dataTable instanceof DataTable\Map) {
foreach ($dataTable->getDataTables() as $table) {
$this->addMissingWebsites($table, $fieldsToGet, $sitesToProblablyAdd);
}
} else {
$this->addMissingWebsites($dataTable, $fieldsToGet, $sitesToProblablyAdd);
}
// calculate total visits/actions/revenue
$this->setMetricsTotalsMetadata($dataTable, $apiMetrics);
// if the period isn't a range & a lastN/previousN date isn't used, we get the same
// data for the last period to show the evolution of visits/actions/revenue
list($strLastDate, $lastPeriod) = Range::getLastDate($date, $period);
if ($strLastDate !== false) {
if ($lastPeriod !== false) {
// NOTE: no easy way to set last period date metadata when range of dates is requested.
// will be easier if DataTable\Map::metadata is removed, and metadata that is
// put there is put directly in DataTable::metadata.
$dataTable->setMetadata(self::getLastPeriodMetadataName('date'), $lastPeriod);
}
$pastArchive = Archive::build($idSitesOrIdSite, $period, $strLastDate, $segment, $_restrictSitesToLogin);
$pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet);
$pastData = $this->mergeDataTableMapAndPopulateLabel($idSitesOrIdSite, $multipleWebsitesRequested, $pastData);
// use past data to calculate evolution percentages
$this->calculateEvolutionPercentages($dataTable, $pastData, $apiMetrics);
$this->setPastDataMetadata($dataTable, $pastData, $apiMetrics);
}
// remove eCommerce related metrics on non eCommerce Piwik sites
// note: this is not optimal in terms of performance: those metrics should not be retrieved in the first place
if ($enhanced) {
if ($dataTable instanceof DataTable\Map) {
foreach ($dataTable->getDataTables() as $table) {
$this->removeEcommerceRelatedMetricsOnNonEcommercePiwikSites($table, $apiECommerceMetrics);
}
} else {
$this->removeEcommerceRelatedMetricsOnNonEcommercePiwikSites($dataTable, $apiECommerceMetrics);
}
}
// move the site id to a metadata column
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'idsite'));
// set the label of each row to the site name
if ($multipleWebsitesRequested) {
$dataTable->filter('ColumnCallbackReplace', array('label', '\\Piwik\\Site::getNameFor'));
} else {
$dataTable->filter('ColumnDelete', array('label'));
}
// replace record names with user friendly metric names
$dataTable->filter('ReplaceColumnNames', array($columnNameRewrites));
// Ensures data set sorted, for Metadata output
$dataTable->filter('Sort', array(self::NB_VISITS_METRIC, 'desc', $naturalSort = false));
// filter rows without visits
// note: if only one website is queried and there are no visits, we can not remove the row otherwise
// ResponseBuilder throws 'Call to a member function getColumns() on a non-object'
if ($multipleWebsitesRequested && !$enhanced) {
$dataTable->filter('ColumnCallbackDeleteRow', array(self::NB_VISITS_METRIC, function ($value) {
return $value == 0;
}));
}
return $dataTable;
}
示例5: getLastDate
/**
* @deprecated
*/
public function getLastDate($date, $period)
{
$lastDate = Range::getLastDate($date, $period);
return array_shift($lastDate);
}