diff options
author | m.kurzeja <m.kurzeja@clearcode.cc> | 2014-06-09 17:51:04 +0400 |
---|---|---|
committer | m.kurzeja <m.kurzeja@clearcode.cc> | 2014-06-09 17:52:11 +0400 |
commit | f27939a57634a7c2290d7dcef6e6ed0fd007e510 (patch) | |
tree | 4a67764ff4c5ebc703c3aecbfb7c62c9dca8f95d /core | |
parent | 09fdbeb98dc16cb42c1f1ad1337ac3b44df24ffc (diff) |
Moved attachment generation to report renderer
Diffstat (limited to 'core')
-rw-r--r-- | core/ReportRenderer.php | 10 | ||||
-rw-r--r-- | core/ReportRenderer/Csv.php | 13 | ||||
-rw-r--r-- | core/ReportRenderer/Html.php | 55 | ||||
-rw-r--r-- | core/ReportRenderer/Pdf.php | 13 |
4 files changed, 91 insertions, 0 deletions
diff --git a/core/ReportRenderer.php b/core/ReportRenderer.php index 42a5f72570..893fc3e6d7 100644 --- a/core/ReportRenderer.php +++ b/core/ReportRenderer.php @@ -122,6 +122,16 @@ abstract class ReportRenderer abstract public function renderReport($processedReport); /** + * Get report attachments, ex. graph images + * + * @param $report + * @param $processedReports + * @param $prettyDate + * @return array + */ + abstract public function getAttachments($report, $processedReports, $prettyDate); + + /** * Append $extension to $filename * * @static diff --git a/core/ReportRenderer/Csv.php b/core/ReportRenderer/Csv.php index 6262a1cd6d..23ace2ac4d 100644 --- a/core/ReportRenderer/Csv.php +++ b/core/ReportRenderer/Csv.php @@ -148,4 +148,17 @@ class Csv extends ReportRenderer { return str_replace("_", ".", $uniqueId); } + + /** + * Get report attachments, ex. graph images + * + * @param $report + * @param $processedReports + * @param $prettyDate + * @return array + */ + public function getAttachments($report, $processedReports, $prettyDate) + { + return array(); + } } diff --git a/core/ReportRenderer/Html.php b/core/ReportRenderer/Html.php index 53fbe90a68..e6d0b90e8c 100644 --- a/core/ReportRenderer/Html.php +++ b/core/ReportRenderer/Html.php @@ -8,6 +8,7 @@ */ namespace Piwik\ReportRenderer; +use Piwik\Piwik; use Piwik\Plugins\API\API; use Piwik\ReportRenderer; use Piwik\SettingsPiwik; @@ -161,4 +162,58 @@ class Html extends ReportRenderer $this->rendering .= $reportView->render(); } + + public function getAttachments($report, $processedReports, $prettyDate) + { + $additionalFiles = array(); + + foreach ($processedReports as $processedReport) { + if ($processedReport['displayGraph']) { + + $additionalFiles[] = $this->getAttachment($report, $processedReport, $prettyDate); + } + } + + return $additionalFiles; + } + + protected function getAttachment($report, $processedReport, $prettyDate) + { + $additionalFile = array(); + + $segment = \Piwik\Plugins\ScheduledReports\API::getSegment($report['idsegment']); + + $segmentName = $segment != null ? sprintf(' (%s)', $segment['name']) : ''; + + $processedReportMetadata = $processedReport['metadata']; + + $additionalFile['filename'] = + sprintf( + '%s - %s - %s %d - %s %d%s.png', + $processedReportMetadata['name'], + $prettyDate, + Piwik::translate('General_Website'), + $report['idsite'], + Piwik::translate('General_Report'), + $report['idreport'], + $segmentName + ); + + $additionalFile['cid'] = $processedReportMetadata['uniqueId']; + + $additionalFile['content'] = + ReportRenderer::getStaticGraph( + $processedReportMetadata, + Html::IMAGE_GRAPH_WIDTH, + Html::IMAGE_GRAPH_HEIGHT, + $processedReport['evolutionGraph'], + $segment + ); + + $additionalFile['mimeType'] = 'image/png'; + + $additionalFile['encoding'] = \Zend_Mime::ENCODING_BASE64; + + return $additionalFile; + } } diff --git a/core/ReportRenderer/Pdf.php b/core/ReportRenderer/Pdf.php index 66f47df27b..a0a4a85278 100644 --- a/core/ReportRenderer/Pdf.php +++ b/core/ReportRenderer/Pdf.php @@ -523,4 +523,17 @@ class Pdf extends ReportRenderer $this->TCPDF->Write("1em", $message); $this->TCPDF->Ln(); } + + /** + * Get report attachments, ex. graph images + * + * @param $report + * @param $processedReports + * @param $prettyDate + * @return array + */ + public function getAttachments($report, $processedReports, $prettyDate) + { + return array(); + } } |