protected function MatomoBase::getDateTranslated in Dashboards with Layout Builder 8
Same name and namespace in other branches
- 2.0.x modules/dashboards_matomo/src/Plugin/Dashboard/MatomoBase.php \Drupal\dashboards_matomo\Plugin\Dashboard\MatomoBase::getDateTranslated()
Translate date matomo string.
Parameters
string $period: Period to translated.
Return value
string Translated date.
File
- modules/
dashboards_matomo/ src/ Plugin/ Dashboard/ MatomoBase.php, line 67
Class
- MatomoBase
- Base class for matomo plugins.
Namespace
Drupal\dashboards_matomo\Plugin\DashboardCode
protected function getDateTranslated(string $period) : string {
$format = 'Y-m-d';
$start = time();
$time = time();
switch ($period) {
case 'last_seven_days':
$start = strtotime('-7 days');
break;
case 'this_week':
$start = strtotime('monday this week');
$time = strtotime('sunday this week');
break;
case 'this_month':
$start = strtotime('first day of this month');
$time = strtotime('last day of this month');
break;
case 'last_three_months':
$start = strtotime('first day of this month -2 months');
$time = strtotime('last day of this month');
break;
case 'last_six_months':
$start = strtotime('first day of this month -5 months');
$time = strtotime('last day of this month');
break;
case 'year':
$start = strtotime('first day of this year');
$time = strtotime('last day of this year');
break;
default:
return $period;
}
$date = new \DateTime();
$date
->setTimestamp($time);
$startDateTime = new \DateTime();
$startDateTime
->setTimestamp($start);
return implode(',', [
$startDateTime
->format($format),
$date
->format($format),
]);
}