diff options
author | Benaka <diosmosis@users.noreply.github.com> | 2017-11-24 03:58:22 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2017-11-24 03:58:22 +0300 |
commit | f092d3b20289e8f6844674779b7b8b475e553cd1 (patch) | |
tree | b2374f6db41f9309f2ba19d4dc4d9c6cd9260262 /core | |
parent | 1f12b54962e58a893aa211b931b5e231c217df64 (diff) |
Use consistent HTML email body for all scheduled reports (HTML, PDF & CSV) (#12233)
* Extract mail configuring parts of sendReport method & write tests for them.
* Use twig in AttachedFileReportEmailGenerator.
* Extract header/footer of html scheduled report email into re-usable View subclasses & use for PDF/CSV emails.
* Fixing test failures.
* Integrationt est
Diffstat (limited to 'core')
-rw-r--r-- | core/ReportRenderer/Html.php | 67 | ||||
-rw-r--r-- | core/View/HtmlEmailFooterView.php | 25 | ||||
-rw-r--r-- | core/View/HtmlReportEmailHeaderView.php | 92 |
3 files changed, 121 insertions, 63 deletions
diff --git a/core/ReportRenderer/Html.php b/core/ReportRenderer/Html.php index 3240a8ad94..b447cdf8e6 100644 --- a/core/ReportRenderer/Html.php +++ b/core/ReportRenderer/Html.php @@ -9,15 +9,8 @@ namespace Piwik\ReportRenderer; use Piwik\Piwik; -use Piwik\Plugin; -use Piwik\Plugins\API\API; -use Piwik\Plugins\CoreAdminHome\CustomLogo; use Piwik\ReportRenderer; -use Piwik\SettingsPiwik; -use Piwik\Site; -use Piwik\Date; use Piwik\View; -use Piwik\Plugins\ScheduledReports\ScheduledReports; /** * HTML report renderer @@ -27,11 +20,6 @@ class Html extends ReportRenderer const IMAGE_GRAPH_WIDTH = 700; const IMAGE_GRAPH_HEIGHT = 200; - const REPORT_TITLE_TEXT_SIZE = 24; - const REPORT_TABLE_HEADER_TEXT_SIZE = 11; - const REPORT_TABLE_ROW_TEXT_SIZE = '13px'; - const REPORT_BACK_TO_TOP_TEXT_SIZE = 9; - const HTML_CONTENT_TYPE = 'text/html'; const HTML_FILE_EXTENSION = 'html'; @@ -86,68 +74,21 @@ class Html extends ReportRenderer private function epilogue() { - $view = new View('@CoreHome/ReportRenderer/_htmlReportFooter'); - $view->hasWhiteLabel = Plugin\Manager::getInstance()->isPluginLoaded('WhiteLabel'); + $view = new View\HtmlEmailFooterView(); $this->rendering .= $view->render(); } public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment) { - $frontPageView = new View('@CoreHome/ReportRenderer/_htmlReportHeader'); - $this->assignCommonParameters($frontPageView); - - $period = $this->report['period']; - - $periods = ScheduledReports::getPeriodToFrequencyAsAdjective(); - $frontPageView->assign("period", $periods[$period]); - $frontPageView->assign("reportTitle", $reportTitle); - $frontPageView->assign("prettyDate", $prettyDate); - $frontPageView->assign("description", $description); - $frontPageView->assign("reportMetadata", $reportMetadata); - $frontPageView->assign("websiteName", Site::getNameFor($this->idSite)); - $frontPageView->assign("idSite", $this->idSite); - $frontPageView->assign("period", $period); - - $customLogo = new CustomLogo(); - $frontPageView->assign("isCustomLogo", $customLogo->isEnabled() && CustomLogo::hasUserLogo()); - $frontPageView->assign("logoHeader", $customLogo->getHeaderLogoUrl($pathOnly = false)); - - $date = Date::now()->setTimezone(Site::getTimezoneFor($this->idSite))->toString(); - $frontPageView->assign("date", $date); - - // segment - $displaySegment = ($segment != null); - $frontPageView->assign("displaySegment", $displaySegment); - if ($displaySegment) { - $frontPageView->assign("segmentName", $segment['name']); - } - + $frontPageView = new View\HtmlReportEmailHeaderView($reportTitle, $prettyDate, $description, $reportMetadata, + $segment, $this->idSite, $this->report['period']); $this->rendering .= $frontPageView->render(); } - private function assignCommonParameters(View $view) - { - $view->assign("reportFontFamily", ReportRenderer::DEFAULT_REPORT_FONT_FAMILY); - $view->assign("reportTitleTextColor", ReportRenderer::REPORT_TITLE_TEXT_COLOR); - $view->assign("reportTitleTextSize", self::REPORT_TITLE_TEXT_SIZE); - $view->assign("reportTextColor", ReportRenderer::REPORT_TEXT_COLOR); - $view->assign("tableHeaderBgColor", ReportRenderer::TABLE_HEADER_BG_COLOR); - $view->assign("tableHeaderTextColor", ReportRenderer::TABLE_HEADER_TEXT_COLOR); - $view->assign("tableCellBorderColor", ReportRenderer::TABLE_CELL_BORDER_COLOR); - $view->assign("tableBgColor", ReportRenderer::TABLE_BG_COLOR); - $view->assign("reportTableHeaderTextWeight", self::TABLE_HEADER_TEXT_WEIGHT); - $view->assign("reportTableHeaderTextSize", self::REPORT_TABLE_HEADER_TEXT_SIZE); - $view->assign("reportTableHeaderTextTransform", ReportRenderer::TABLE_HEADER_TEXT_TRANSFORM); - $view->assign("reportTableRowTextSize", self::REPORT_TABLE_ROW_TEXT_SIZE); - $view->assign("reportBackToTopTextSize", self::REPORT_BACK_TO_TOP_TEXT_SIZE); - $view->assign("currentPath", SettingsPiwik::getPiwikUrl()); - $view->assign("logoHeader", API::getInstance()->getHeaderLogoUrl()); - } - public function renderReport($processedReport) { $reportView = new View('@CoreHome/ReportRenderer/_htmlReportBody'); - $this->assignCommonParameters($reportView); + View\HtmlReportEmailHeaderView::assignCommonParameters($reportView); $reportMetadata = $processedReport['metadata']; $reportData = $processedReport['reportData']; diff --git a/core/View/HtmlEmailFooterView.php b/core/View/HtmlEmailFooterView.php new file mode 100644 index 0000000000..123736a0df --- /dev/null +++ b/core/View/HtmlEmailFooterView.php @@ -0,0 +1,25 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\View; + + +use Piwik\View; + +class HtmlEmailFooterView extends View +{ + const TEMPLATE_FILE = '@CoreHome/ReportRenderer/_htmlReportFooter'; + + public function __construct() + { + parent::__construct(self::TEMPLATE_FILE); + + $this->hasWhiteLabel = \Piwik\Plugin\Manager::getInstance()->isPluginLoaded('WhiteLabel'); + } +}
\ No newline at end of file diff --git a/core/View/HtmlReportEmailHeaderView.php b/core/View/HtmlReportEmailHeaderView.php new file mode 100644 index 0000000000..d27b20ad43 --- /dev/null +++ b/core/View/HtmlReportEmailHeaderView.php @@ -0,0 +1,92 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\View; + +use Piwik\Date; +use Piwik\Plugins\API\API; +use Piwik\Plugins\CoreAdminHome\CustomLogo; +use Piwik\ReportRenderer; +use Piwik\Scheduler\Schedule\Schedule; +use Piwik\SettingsPiwik; +use Piwik\Site; +use Piwik\View; + +class HtmlReportEmailHeaderView extends View +{ + const TEMPLATE_FILE = '@CoreHome/ReportRenderer/_htmlReportHeader'; + + const REPORT_TITLE_TEXT_SIZE = 24; + const REPORT_TABLE_HEADER_TEXT_SIZE = 11; + const REPORT_TABLE_ROW_TEXT_SIZE = '13px'; + const REPORT_BACK_TO_TOP_TEXT_SIZE = 9; + + private static $reportFrequencyTranslationByPeriod = [ + Schedule::PERIOD_DAY => 'General_DailyReport', + Schedule::PERIOD_WEEK => 'General_WeeklyReport', + Schedule::PERIOD_MONTH => 'General_MonthlyReport', + Schedule::PERIOD_YEAR => 'General_YearlyReport', + Schedule::PERIOD_RANGE => 'General_RangeReports', + ]; + + public function __construct($reportTitle, $prettyDate, $description, $reportMetadata, $segment, $idSite, $period) + { + parent::__construct(self::TEMPLATE_FILE); + + self::assignCommonParameters($this); + + $periods = self::getPeriodToFrequencyAsAdjective(); + $this->assign("frequency", $periods[$period]); + $this->assign("reportTitle", $reportTitle); + $this->assign("prettyDate", $prettyDate); + $this->assign("description", $description); + $this->assign("reportMetadata", $reportMetadata); + $this->assign("websiteName", Site::getNameFor($idSite)); + $this->assign("idSite", $idSite); + $this->assign("period", $period); + + $customLogo = new CustomLogo(); + $this->assign("isCustomLogo", $customLogo->isEnabled() && CustomLogo::hasUserLogo()); + $this->assign("logoHeader", $customLogo->getHeaderLogoUrl($pathOnly = false)); + + $date = Date::now()->setTimezone(Site::getTimezoneFor($idSite))->toString(); + $this->assign("date", $date); + + // segment + $displaySegment = ($segment != null); + $this->assign("displaySegment", $displaySegment); + if ($displaySegment) { + $this->assign("segmentName", $segment['name']); + } + } + + public static function assignCommonParameters(View $view) + { + $view->assign("reportFontFamily", ReportRenderer::DEFAULT_REPORT_FONT_FAMILY); + $view->assign("reportTitleTextColor", ReportRenderer::REPORT_TITLE_TEXT_COLOR); + $view->assign("reportTitleTextSize", self::REPORT_TITLE_TEXT_SIZE); + $view->assign("reportTextColor", ReportRenderer::REPORT_TEXT_COLOR); + $view->assign("tableHeaderBgColor", ReportRenderer::TABLE_HEADER_BG_COLOR); + $view->assign("tableHeaderTextColor", ReportRenderer::TABLE_HEADER_TEXT_COLOR); + $view->assign("tableCellBorderColor", ReportRenderer::TABLE_CELL_BORDER_COLOR); + $view->assign("tableBgColor", ReportRenderer::TABLE_BG_COLOR); + $view->assign("reportTableHeaderTextWeight", ReportRenderer::TABLE_HEADER_TEXT_WEIGHT); + $view->assign("reportTableHeaderTextSize", self::REPORT_TABLE_HEADER_TEXT_SIZE); + $view->assign("reportTableHeaderTextTransform", ReportRenderer::TABLE_HEADER_TEXT_TRANSFORM); + $view->assign("reportTableRowTextSize", self::REPORT_TABLE_ROW_TEXT_SIZE); + $view->assign("reportBackToTopTextSize", self::REPORT_BACK_TO_TOP_TEXT_SIZE); + $view->assign("currentPath", SettingsPiwik::getPiwikUrl()); + $view->assign("logoHeader", API::getInstance()->getHeaderLogoUrl()); + } + + private static function getPeriodToFrequencyAsAdjective() + { + return array_map(['\Piwik\Piwik', 'translate'], self::$reportFrequencyTranslationByPeriod); + } +} |