hide map for Character groups Quest Stations when there are no stations
This commit is contained in:
commit
df14dfafc3
4371 changed files with 1220224 additions and 0 deletions
151
www/analytics/core/ReportRenderer/Csv.php
Normal file
151
www/analytics/core/ReportRenderer/Csv.php
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
namespace Piwik\ReportRenderer;
|
||||
|
||||
use Piwik\Piwik;
|
||||
use Piwik\ReportRenderer;
|
||||
use Piwik\DataTable\Renderer\Csv as CsvDataTableRenderer;
|
||||
use Piwik\DataTable\DataTableInterface;
|
||||
|
||||
class Csv extends ReportRenderer
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $rendered;
|
||||
|
||||
/**
|
||||
* Initialize locale settings.
|
||||
* If not called, locale settings defaults to 'en'
|
||||
*
|
||||
* @param string $locale
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save rendering to disk
|
||||
*
|
||||
* @param string $filename without path & without format extension
|
||||
* @return string path of file
|
||||
*/
|
||||
public function sendToDisk($filename)
|
||||
{
|
||||
return ReportRenderer::writeFile(
|
||||
$filename,
|
||||
ReportRenderer::CSV_FORMAT,
|
||||
$this->getRenderedReport()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send rendering to browser with a 'download file' prompt
|
||||
*
|
||||
* @param string $filename without path & without format extension
|
||||
*/
|
||||
public function sendToBrowserDownload($filename)
|
||||
{
|
||||
ReportRenderer::sendToBrowser(
|
||||
$filename,
|
||||
ReportRenderer::CSV_FORMAT,
|
||||
"text/" . ReportRenderer::CSV_FORMAT,
|
||||
$this->getRenderedReport()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output rendering to browser
|
||||
*
|
||||
* @param string $filename without path & without format extension
|
||||
*/
|
||||
public function sendToBrowserInline($filename)
|
||||
{
|
||||
ReportRenderer::sendToBrowser(
|
||||
$filename,
|
||||
ReportRenderer::CSV_FORMAT,
|
||||
"application/" . ReportRenderer::CSV_FORMAT,
|
||||
$this->getRenderedReport()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rendered report
|
||||
*/
|
||||
public function getRenderedReport()
|
||||
{
|
||||
return $this->rendered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the first page.
|
||||
*
|
||||
* @param string $reportTitle
|
||||
* @param string $prettyDate formatted date
|
||||
* @param string $description
|
||||
* @param array $reportMetadata metadata for all reports
|
||||
* @param array $segment segment applied to all reports
|
||||
*/
|
||||
public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the provided report.
|
||||
* Multiple calls to this method before calling outputRendering appends each report content.
|
||||
*
|
||||
* @param array $processedReport @see API::getProcessedReport()
|
||||
*/
|
||||
public function renderReport($processedReport)
|
||||
{
|
||||
$csvRenderer = $this->getRenderer(
|
||||
$processedReport['reportData'],
|
||||
$processedReport['metadata']['uniqueId']
|
||||
);
|
||||
|
||||
$reportData = $csvRenderer->render($processedReport);
|
||||
if(empty($reportData)) {
|
||||
$reportData = Piwik::translate('CoreHome_ThereIsNoDataForThisReport');
|
||||
}
|
||||
|
||||
$replaceBySpace = array( $csvRenderer->separator, ";");
|
||||
$reportName = str_replace($replaceBySpace, " ", $processedReport['metadata']['name']);
|
||||
$this->rendered .= implode(
|
||||
'',
|
||||
array(
|
||||
$reportName,
|
||||
$csvRenderer->lineEnd,
|
||||
$reportData,
|
||||
$csvRenderer->lineEnd,
|
||||
$csvRenderer->lineEnd,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataTableInterface $table
|
||||
* @param string $uniqueId
|
||||
* @return \Piwik\DataTable\Renderer\Csv
|
||||
*/
|
||||
protected function getRenderer(DataTableInterface $table, $uniqueId)
|
||||
{
|
||||
$csvRenderer = new CsvDataTableRenderer();
|
||||
$csvRenderer->setTable($table);
|
||||
$csvRenderer->setConvertToUnicode(false);
|
||||
$csvRenderer->setApiMethod(
|
||||
$this->getApiMethodNameFromUniqueId($uniqueId)
|
||||
);
|
||||
|
||||
return $csvRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uniqueId
|
||||
* @return string
|
||||
*/
|
||||
protected function getApiMethodNameFromUniqueId($uniqueId)
|
||||
{
|
||||
return str_replace("_", ".", $uniqueId);
|
||||
}
|
||||
}
|
||||
164
www/analytics/core/ReportRenderer/Html.php
Normal file
164
www/analytics/core/ReportRenderer/Html.php
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\ReportRenderer;
|
||||
|
||||
use Piwik\Plugins\API\API;
|
||||
use Piwik\ReportRenderer;
|
||||
use Piwik\SettingsPiwik;
|
||||
use Piwik\View;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Html extends ReportRenderer
|
||||
{
|
||||
const IMAGE_GRAPH_WIDTH = 700;
|
||||
const IMAGE_GRAPH_HEIGHT = 200;
|
||||
|
||||
const REPORT_TITLE_TEXT_SIZE = 11;
|
||||
const REPORT_TABLE_HEADER_TEXT_SIZE = 11;
|
||||
const REPORT_TABLE_ROW_TEXT_SIZE = 11;
|
||||
const REPORT_BACK_TO_TOP_TEXT_SIZE = 9;
|
||||
|
||||
const HTML_CONTENT_TYPE = 'text/html';
|
||||
const HTML_FILE_EXTENSION = 'html';
|
||||
|
||||
protected $renderImageInline = false;
|
||||
|
||||
private $rendering = "";
|
||||
|
||||
public function setLocale($locale)
|
||||
{
|
||||
//Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently only used for HTML reports.
|
||||
* When sent by mail, images are attached to the mail: renderImageInline = false
|
||||
* When downloaded, images are included base64 encoded in the report body: renderImageInline = true
|
||||
*
|
||||
* @param boolean $renderImageInline
|
||||
*/
|
||||
public function setRenderImageInline($renderImageInline)
|
||||
{
|
||||
$this->renderImageInline = $renderImageInline;
|
||||
}
|
||||
|
||||
public function sendToDisk($filename)
|
||||
{
|
||||
$this->epilogue();
|
||||
|
||||
return ReportRenderer::writeFile($filename, self::HTML_FILE_EXTENSION, $this->rendering);
|
||||
}
|
||||
|
||||
public function sendToBrowserDownload($filename)
|
||||
{
|
||||
$this->epilogue();
|
||||
|
||||
ReportRenderer::sendToBrowser($filename, self::HTML_FILE_EXTENSION, self::HTML_CONTENT_TYPE, $this->rendering);
|
||||
}
|
||||
|
||||
public function sendToBrowserInline($filename)
|
||||
{
|
||||
$this->epilogue();
|
||||
|
||||
ReportRenderer::inlineToBrowser(self::HTML_CONTENT_TYPE, $this->rendering);
|
||||
}
|
||||
|
||||
public function getRenderedReport()
|
||||
{
|
||||
$this->epilogue();
|
||||
|
||||
return $this->rendering;
|
||||
}
|
||||
|
||||
private function epilogue()
|
||||
{
|
||||
$view = new View('@CoreHome/ReportRenderer/_htmlReportFooter');
|
||||
$this->rendering .= $view->render();
|
||||
}
|
||||
|
||||
public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment)
|
||||
{
|
||||
$frontPageView = new View('@CoreHome/ReportRenderer/_htmlReportHeader');
|
||||
$this->assignCommonParameters($frontPageView);
|
||||
|
||||
$frontPageView->assign("reportTitle", $reportTitle);
|
||||
$frontPageView->assign("prettyDate", $prettyDate);
|
||||
$frontPageView->assign("description", $description);
|
||||
$frontPageView->assign("reportMetadata", $reportMetadata);
|
||||
|
||||
// segment
|
||||
$displaySegment = ($segment != null);
|
||||
$frontPageView->assign("displaySegment", $displaySegment);
|
||||
if ($displaySegment) {
|
||||
$frontPageView->assign("segmentName", $segment['name']);
|
||||
}
|
||||
|
||||
$this->rendering .= $frontPageView->render();
|
||||
}
|
||||
|
||||
private function assignCommonParameters(View $view)
|
||||
{
|
||||
$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("reportTableHeaderTextSize", self::REPORT_TABLE_HEADER_TEXT_SIZE);
|
||||
$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);
|
||||
|
||||
$reportMetadata = $processedReport['metadata'];
|
||||
$reportData = $processedReport['reportData'];
|
||||
$columns = $processedReport['columns'];
|
||||
list($reportData, $columns) = self::processTableFormat($reportMetadata, $reportData, $columns);
|
||||
|
||||
$reportView->assign("reportName", $reportMetadata['name']);
|
||||
$reportView->assign("reportId", $reportMetadata['uniqueId']);
|
||||
$reportView->assign("reportColumns", $columns);
|
||||
$reportView->assign("reportRows", $reportData->getRows());
|
||||
$reportView->assign("reportRowsMetadata", $processedReport['reportMetadata']->getRows());
|
||||
$reportView->assign("displayTable", $processedReport['displayTable']);
|
||||
|
||||
$displayGraph = $processedReport['displayGraph'];
|
||||
$evolutionGraph = $processedReport['evolutionGraph'];
|
||||
$reportView->assign("displayGraph", $displayGraph);
|
||||
|
||||
if ($displayGraph) {
|
||||
$reportView->assign("graphWidth", self::IMAGE_GRAPH_WIDTH);
|
||||
$reportView->assign("graphHeight", self::IMAGE_GRAPH_HEIGHT);
|
||||
$reportView->assign("renderImageInline", $this->renderImageInline);
|
||||
|
||||
if ($this->renderImageInline) {
|
||||
$staticGraph = parent::getStaticGraph(
|
||||
$reportMetadata,
|
||||
self::IMAGE_GRAPH_WIDTH,
|
||||
self::IMAGE_GRAPH_HEIGHT,
|
||||
$evolutionGraph,
|
||||
$processedReport['segment']
|
||||
);
|
||||
$reportView->assign("generatedImageGraph", base64_encode($staticGraph));
|
||||
unset($generatedImageGraph);
|
||||
}
|
||||
}
|
||||
|
||||
$this->rendering .= $reportView->render();
|
||||
}
|
||||
}
|
||||
526
www/analytics/core/ReportRenderer/Pdf.php
Normal file
526
www/analytics/core/ReportRenderer/Pdf.php
Normal file
|
|
@ -0,0 +1,526 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\ReportRenderer;
|
||||
|
||||
use Piwik\Common;
|
||||
use Piwik\Filesystem;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugins\API\API;
|
||||
use Piwik\ReportRenderer;
|
||||
use Piwik\TCPDF;
|
||||
|
||||
/**
|
||||
* @see libs/tcpdf
|
||||
*/
|
||||
require_once PIWIK_INCLUDE_PATH . '/plugins/ScheduledReports/config/tcpdf_config.php';
|
||||
require_once PIWIK_INCLUDE_PATH . '/libs/tcpdf/config/lang/eng.php';
|
||||
require_once PIWIK_INCLUDE_PATH . '/core/TCPDF.php';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Pdf extends ReportRenderer
|
||||
{
|
||||
const IMAGE_GRAPH_WIDTH_LANDSCAPE = 1050;
|
||||
const IMAGE_GRAPH_WIDTH_PORTRAIT = 760;
|
||||
const IMAGE_GRAPH_HEIGHT = 220;
|
||||
|
||||
const LANDSCAPE = 'L';
|
||||
const PORTRAIT = 'P';
|
||||
|
||||
const MAX_ROW_COUNT = 28;
|
||||
const TABLE_HEADER_ROW_COUNT = 6;
|
||||
const NO_DATA_ROW_COUNT = 6;
|
||||
const MAX_GRAPH_REPORTS = 3;
|
||||
const MAX_2COL_TABLE_REPORTS = 2;
|
||||
|
||||
const PDF_CONTENT_TYPE = 'pdf';
|
||||
|
||||
private $reportFontStyle = '';
|
||||
private $reportSimpleFontSize = 9;
|
||||
private $reportHeaderFontSize = 16;
|
||||
private $cellHeight = 6;
|
||||
private $bottomMargin = 17;
|
||||
private $reportWidthPortrait = 195;
|
||||
private $reportWidthLandscape = 270;
|
||||
private $minWidthLabelCell = 100;
|
||||
private $maxColumnCountPortraitOrientation = 6;
|
||||
private $logoWidth = 16;
|
||||
private $logoHeight = 16;
|
||||
private $totalWidth;
|
||||
private $cellWidth;
|
||||
private $labelCellWidth;
|
||||
private $truncateAfter = 55;
|
||||
private $leftSpacesBeforeLogo = 7;
|
||||
private $logoImagePosition = array(10, 40);
|
||||
private $headerTextColor;
|
||||
private $reportTextColor;
|
||||
private $tableHeaderBackgroundColor;
|
||||
private $tableHeaderTextColor;
|
||||
private $tableCellBorderColor;
|
||||
private $tableBackgroundColor;
|
||||
private $rowTopBottomBorder = array(231, 231, 231);
|
||||
private $report;
|
||||
private $reportMetadata;
|
||||
private $displayGraph;
|
||||
private $evolutionGraph;
|
||||
private $displayTable;
|
||||
private $segment;
|
||||
private $reportColumns;
|
||||
private $reportRowsMetadata;
|
||||
private $currentPage = 0;
|
||||
private $reportFont = ReportRenderer::DEFAULT_REPORT_FONT;
|
||||
private $TCPDF;
|
||||
private $orientation = self::PORTRAIT;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->TCPDF = new TCPDF();
|
||||
$this->headerTextColor = preg_split("/,/", ReportRenderer::REPORT_TITLE_TEXT_COLOR);
|
||||
$this->reportTextColor = preg_split("/,/", ReportRenderer::REPORT_TEXT_COLOR);
|
||||
$this->tableHeaderBackgroundColor = preg_split("/,/", ReportRenderer::TABLE_HEADER_BG_COLOR);
|
||||
$this->tableHeaderTextColor = preg_split("/,/", ReportRenderer::TABLE_HEADER_TEXT_COLOR);
|
||||
$this->tableCellBorderColor = preg_split("/,/", ReportRenderer::TABLE_CELL_BORDER_COLOR);
|
||||
$this->tableBackgroundColor = preg_split("/,/", ReportRenderer::TABLE_BG_COLOR);
|
||||
}
|
||||
|
||||
public function setLocale($locale)
|
||||
{
|
||||
switch ($locale) {
|
||||
case 'zh-tw':
|
||||
$reportFont = 'msungstdlight';
|
||||
break;
|
||||
|
||||
case 'ja':
|
||||
$reportFont = 'kozgopromedium';
|
||||
break;
|
||||
|
||||
case 'zh-cn':
|
||||
$reportFont = 'stsongstdlight';
|
||||
break;
|
||||
|
||||
case 'ko':
|
||||
$reportFont = 'hysmyeongjostdmedium';
|
||||
break;
|
||||
|
||||
case 'ar':
|
||||
$reportFont = 'almohanad';
|
||||
break;
|
||||
|
||||
case 'en':
|
||||
default:
|
||||
$reportFont = ReportRenderer::DEFAULT_REPORT_FONT;
|
||||
break;
|
||||
}
|
||||
$this->reportFont = $reportFont;
|
||||
}
|
||||
|
||||
public function sendToDisk($filename)
|
||||
{
|
||||
$filename = ReportRenderer::appendExtension($filename, self::PDF_CONTENT_TYPE);
|
||||
$outputFilename = ReportRenderer::getOutputPath($filename);
|
||||
|
||||
$this->TCPDF->Output($outputFilename, 'F');
|
||||
|
||||
return $outputFilename;
|
||||
}
|
||||
|
||||
public function sendToBrowserDownload($filename)
|
||||
{
|
||||
$filename = ReportRenderer::appendExtension($filename, self::PDF_CONTENT_TYPE);
|
||||
$this->TCPDF->Output($filename, 'D');
|
||||
}
|
||||
|
||||
public function sendToBrowserInline($filename)
|
||||
{
|
||||
$filename = ReportRenderer::appendExtension($filename, self::PDF_CONTENT_TYPE);
|
||||
$this->TCPDF->Output($filename, 'I');
|
||||
}
|
||||
|
||||
public function getRenderedReport()
|
||||
{
|
||||
return $this->TCPDF->Output(null, 'S');
|
||||
}
|
||||
|
||||
public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment)
|
||||
{
|
||||
$reportTitle = $this->formatText($reportTitle);
|
||||
$dateRange = $this->formatText(Piwik::translate('General_DateRange') . " " . $prettyDate);
|
||||
|
||||
// footer
|
||||
$this->TCPDF->SetFooterFont(array($this->reportFont, $this->reportFontStyle, $this->reportSimpleFontSize));
|
||||
$this->TCPDF->SetFooterContent($reportTitle . " | " . $dateRange . " | ");
|
||||
|
||||
// add first page
|
||||
$this->TCPDF->setPrintHeader(false);
|
||||
$this->TCPDF->AddPage(self::PORTRAIT);
|
||||
$this->TCPDF->AddFont($this->reportFont, '', '', false);
|
||||
$this->TCPDF->SetFont($this->reportFont, $this->reportFontStyle, $this->reportSimpleFontSize);
|
||||
$this->TCPDF->Bookmark(Piwik::translate('ScheduledReports_FrontPage'));
|
||||
|
||||
// logo
|
||||
$this->TCPDF->Image(API::getInstance()->getLogoUrl(true), $this->logoImagePosition[0], $this->logoImagePosition[1], 180 / $factor = 2, 0, $type = '', $link = '', $align = '', $resize = false, $dpi = 300);
|
||||
$this->TCPDF->Ln(8);
|
||||
|
||||
// report title
|
||||
$this->TCPDF->SetFont($this->reportFont, '', $this->reportHeaderFontSize + 5);
|
||||
$this->TCPDF->SetTextColor($this->headerTextColor[0], $this->headerTextColor[1], $this->headerTextColor[2]);
|
||||
$this->TCPDF->Cell(40, 210, $reportTitle);
|
||||
$this->TCPDF->Ln(8 * 4);
|
||||
|
||||
// date and period
|
||||
$this->TCPDF->SetFont($this->reportFont, '', $this->reportHeaderFontSize);
|
||||
$this->TCPDF->SetTextColor($this->reportTextColor[0], $this->reportTextColor[1], $this->reportTextColor[2]);
|
||||
$this->TCPDF->Cell(40, 210, $dateRange);
|
||||
$this->TCPDF->Ln(8 * 20);
|
||||
|
||||
// description
|
||||
$this->TCPDF->Write(1, $this->formatText($description));
|
||||
|
||||
// segment
|
||||
if ($segment != null) {
|
||||
|
||||
$this->TCPDF->Ln();
|
||||
$this->TCPDF->Ln();
|
||||
$this->TCPDF->SetFont($this->reportFont, '', $this->reportHeaderFontSize - 2);
|
||||
$this->TCPDF->SetTextColor($this->headerTextColor[0], $this->headerTextColor[1], $this->headerTextColor[2]);
|
||||
$this->TCPDF->Write(1, $this->formatText(Piwik::translate('ScheduledReports_CustomVisitorSegment') . ' ' . $segment['name']));
|
||||
}
|
||||
|
||||
$this->TCPDF->Ln(8);
|
||||
$this->TCPDF->SetFont($this->reportFont, '', $this->reportHeaderFontSize);
|
||||
$this->TCPDF->Ln();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a header of page.
|
||||
*/
|
||||
private function paintReportHeader()
|
||||
{
|
||||
$isAggregateReport = !empty($this->reportMetadata['dimension']);
|
||||
|
||||
// Graph-only report
|
||||
static $graphOnlyReportCount = 0;
|
||||
$graphOnlyReport = $isAggregateReport && $this->displayGraph && !$this->displayTable;
|
||||
|
||||
// Table-only report
|
||||
$tableOnlyReport = $isAggregateReport
|
||||
&& !$this->displayGraph
|
||||
&& $this->displayTable;
|
||||
|
||||
$columnCount = count($this->reportColumns);
|
||||
|
||||
// Table-only 2-column report
|
||||
static $tableOnly2ColumnReportCount = 0;
|
||||
$tableOnly2ColumnReport = $tableOnlyReport
|
||||
&& $columnCount == 2;
|
||||
|
||||
// Table-only report with more than 2 columns
|
||||
static $tableOnlyManyColumnReportRowCount = 0;
|
||||
$tableOnlyManyColumnReport = $tableOnlyReport
|
||||
&& $columnCount > 3;
|
||||
|
||||
$reportHasData = $this->reportHasData();
|
||||
|
||||
$rowCount = $reportHasData ? $this->report->getRowsCount() + self::TABLE_HEADER_ROW_COUNT : self::NO_DATA_ROW_COUNT;
|
||||
|
||||
// Only a page break before if the current report has some data
|
||||
if ($reportHasData &&
|
||||
// and
|
||||
(
|
||||
// it is the first report
|
||||
$this->currentPage == 0
|
||||
// or, it is a graph-only report and it is the first of a series of self::MAX_GRAPH_REPORTS
|
||||
|| ($graphOnlyReport && $graphOnlyReportCount == 0)
|
||||
// or, it is a table-only 2-column report and it is the first of a series of self::MAX_2COL_TABLE_REPORTS
|
||||
|| ($tableOnly2ColumnReport && $tableOnly2ColumnReportCount == 0)
|
||||
// or it is a table-only report with more than 2 columns and it is the first of its series or there isn't enough space left on the page
|
||||
|| ($tableOnlyManyColumnReport && ($tableOnlyManyColumnReportRowCount == 0 || $tableOnlyManyColumnReportRowCount + $rowCount >= self::MAX_ROW_COUNT))
|
||||
// or it is a report with both a table and a graph
|
||||
|| !$graphOnlyReport && !$tableOnlyReport
|
||||
)
|
||||
) {
|
||||
$this->currentPage++;
|
||||
$this->TCPDF->AddPage();
|
||||
|
||||
// Table-only reports with more than 2 columns are always landscape
|
||||
if ($tableOnlyManyColumnReport) {
|
||||
$tableOnlyManyColumnReportRowCount = 0;
|
||||
$this->orientation = self::LANDSCAPE;
|
||||
} else {
|
||||
// Graph-only reports are always portrait
|
||||
$this->orientation = $graphOnlyReport ? self::PORTRAIT : ($columnCount > $this->maxColumnCountPortraitOrientation ? self::LANDSCAPE : self::PORTRAIT);
|
||||
}
|
||||
|
||||
$this->TCPDF->setPageOrientation($this->orientation, '', $this->bottomMargin);
|
||||
}
|
||||
|
||||
$graphOnlyReportCount = ($graphOnlyReport && $reportHasData) ? ($graphOnlyReportCount + 1) % self::MAX_GRAPH_REPORTS : 0;
|
||||
$tableOnly2ColumnReportCount = ($tableOnly2ColumnReport && $reportHasData) ? ($tableOnly2ColumnReportCount + 1) % self::MAX_2COL_TABLE_REPORTS : 0;
|
||||
$tableOnlyManyColumnReportRowCount = $tableOnlyManyColumnReport ? ($tableOnlyManyColumnReportRowCount + $rowCount) : 0;
|
||||
|
||||
$title = $this->formatText($this->reportMetadata['name']);
|
||||
$this->TCPDF->SetFont($this->reportFont, $this->reportFontStyle, $this->reportHeaderFontSize);
|
||||
$this->TCPDF->SetTextColor($this->headerTextColor[0], $this->headerTextColor[1], $this->headerTextColor[2]);
|
||||
$this->TCPDF->Bookmark($title);
|
||||
$this->TCPDF->Cell(40, 15, $title);
|
||||
$this->TCPDF->Ln();
|
||||
$this->TCPDF->SetFont($this->reportFont, '', $this->reportSimpleFontSize);
|
||||
$this->TCPDF->SetTextColor($this->reportTextColor[0], $this->reportTextColor[1], $this->reportTextColor[2]);
|
||||
}
|
||||
|
||||
private function reportHasData()
|
||||
{
|
||||
return $this->report->getRowsCount() > 0;
|
||||
}
|
||||
|
||||
private function setBorderColor()
|
||||
{
|
||||
$this->TCPDF->SetDrawColor($this->tableCellBorderColor[0], $this->tableCellBorderColor[1], $this->tableCellBorderColor[2]);
|
||||
}
|
||||
|
||||
public function renderReport($processedReport)
|
||||
{
|
||||
$this->reportMetadata = $processedReport['metadata'];
|
||||
$this->reportRowsMetadata = $processedReport['reportMetadata'];
|
||||
$this->displayGraph = $processedReport['displayGraph'];
|
||||
$this->evolutionGraph = $processedReport['evolutionGraph'];
|
||||
$this->displayTable = $processedReport['displayTable'];
|
||||
$this->segment = $processedReport['segment'];
|
||||
list($this->report, $this->reportColumns) = self::processTableFormat($this->reportMetadata, $processedReport['reportData'], $processedReport['columns']);
|
||||
|
||||
$this->paintReportHeader();
|
||||
|
||||
if (!$this->reportHasData()) {
|
||||
$this->paintMessage(Piwik::translate('CoreHome_ThereIsNoDataForThisReport'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->displayGraph) {
|
||||
$this->paintGraph();
|
||||
}
|
||||
|
||||
if ($this->displayGraph && $this->displayTable) {
|
||||
$this->TCPDF->Ln(5);
|
||||
}
|
||||
|
||||
if ($this->displayTable) {
|
||||
$this->paintReportTableHeader();
|
||||
$this->paintReportTable();
|
||||
}
|
||||
}
|
||||
|
||||
private function formatText($text)
|
||||
{
|
||||
return Common::unsanitizeInputValue($text);
|
||||
}
|
||||
|
||||
private function paintReportTable()
|
||||
{
|
||||
//Color and font restoration
|
||||
$this->TCPDF->SetFillColor($this->tableBackgroundColor[0], $this->tableBackgroundColor[1], $this->tableBackgroundColor[2]);
|
||||
$this->TCPDF->SetTextColor($this->reportTextColor[0], $this->reportTextColor[1], $this->reportTextColor[2]);
|
||||
$this->TCPDF->SetFont('');
|
||||
|
||||
$fill = false;
|
||||
$url = false;
|
||||
$leftSpacesBeforeLogo = str_repeat(' ', $this->leftSpacesBeforeLogo);
|
||||
|
||||
$logoWidth = $this->logoWidth;
|
||||
$logoHeight = $this->logoHeight;
|
||||
|
||||
$rowsMetadata = $this->reportRowsMetadata->getRows();
|
||||
|
||||
// Draw a body of report table
|
||||
foreach ($this->report->getRows() as $rowId => $row) {
|
||||
$rowMetrics = $row->getColumns();
|
||||
$rowMetadata = isset($rowsMetadata[$rowId]) ? $rowsMetadata[$rowId]->getColumns() : array();
|
||||
if (isset($rowMetadata['url'])) {
|
||||
$url = $rowMetadata['url'];
|
||||
}
|
||||
foreach ($this->reportColumns as $columnId => $columnName) {
|
||||
// Label column
|
||||
if ($columnId == 'label') {
|
||||
$isLogoDisplayable = isset($rowMetadata['logo']);
|
||||
$text = '';
|
||||
$posX = $this->TCPDF->GetX();
|
||||
$posY = $this->TCPDF->GetY();
|
||||
if (isset($rowMetrics[$columnId])) {
|
||||
$text = substr($rowMetrics[$columnId], 0, $this->truncateAfter);
|
||||
if ($isLogoDisplayable) {
|
||||
$text = $leftSpacesBeforeLogo . $text;
|
||||
}
|
||||
}
|
||||
$text = $this->formatText($text);
|
||||
|
||||
$this->TCPDF->Cell($this->labelCellWidth, $this->cellHeight, $text, 'LR', 0, 'L', $fill, $url);
|
||||
|
||||
if ($isLogoDisplayable) {
|
||||
if (isset($rowMetadata['logoWidth'])) {
|
||||
$logoWidth = $rowMetadata['logoWidth'];
|
||||
}
|
||||
if (isset($rowMetadata['logoHeight'])) {
|
||||
$logoHeight = $rowMetadata['logoHeight'];
|
||||
}
|
||||
$restoreY = $this->TCPDF->getY();
|
||||
$restoreX = $this->TCPDF->getX();
|
||||
$this->TCPDF->SetY($posY);
|
||||
$this->TCPDF->SetX($posX);
|
||||
$topMargin = 1.3;
|
||||
// Country flags are not very high, force a bigger top margin
|
||||
if ($logoHeight < 16) {
|
||||
$topMargin = 2;
|
||||
}
|
||||
$path = Filesystem::getPathToPiwikRoot() . "/" . $rowMetadata['logo'];
|
||||
if (file_exists($path)) {
|
||||
$this->TCPDF->Image($path, $posX + ($leftMargin = 2), $posY + $topMargin, $logoWidth / 4);
|
||||
}
|
||||
$this->TCPDF->SetXY($restoreX, $restoreY);
|
||||
}
|
||||
} // metrics column
|
||||
else {
|
||||
// No value means 0
|
||||
if (empty($rowMetrics[$columnId])) {
|
||||
$rowMetrics[$columnId] = 0;
|
||||
}
|
||||
$this->TCPDF->Cell($this->cellWidth, $this->cellHeight, $rowMetrics[$columnId], 'LR', 0, 'L', $fill);
|
||||
}
|
||||
}
|
||||
|
||||
$this->TCPDF->Ln();
|
||||
|
||||
// Top/Bottom grey border for all cells
|
||||
$this->TCPDF->SetDrawColor($this->rowTopBottomBorder[0], $this->rowTopBottomBorder[1], $this->rowTopBottomBorder[2]);
|
||||
$this->TCPDF->Cell($this->totalWidth, 0, '', 'T');
|
||||
$this->setBorderColor();
|
||||
$this->TCPDF->Ln(0.2);
|
||||
|
||||
$fill = !$fill;
|
||||
}
|
||||
}
|
||||
|
||||
private function paintGraph()
|
||||
{
|
||||
$imageGraph = parent::getStaticGraph(
|
||||
$this->reportMetadata,
|
||||
$this->orientation == self::PORTRAIT ? self::IMAGE_GRAPH_WIDTH_PORTRAIT : self::IMAGE_GRAPH_WIDTH_LANDSCAPE,
|
||||
self::IMAGE_GRAPH_HEIGHT,
|
||||
$this->evolutionGraph,
|
||||
$this->segment
|
||||
);
|
||||
|
||||
$this->TCPDF->Image(
|
||||
'@' . $imageGraph,
|
||||
$x = '',
|
||||
$y = '',
|
||||
$w = 0,
|
||||
$h = 0,
|
||||
$type = '',
|
||||
$link = '',
|
||||
$align = 'N',
|
||||
$resize = false,
|
||||
$dpi = 72,
|
||||
$palign = '',
|
||||
$ismask = false,
|
||||
$imgmask = false,
|
||||
$order = 0,
|
||||
$fitbox = false,
|
||||
$hidden = false,
|
||||
$fitonpage = true,
|
||||
$alt = false,
|
||||
$altimgs = array()
|
||||
);
|
||||
|
||||
unset($imageGraph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the table header (first row)
|
||||
*/
|
||||
private function paintReportTableHeader()
|
||||
{
|
||||
$initPosX = 10;
|
||||
|
||||
// Get the longest column name
|
||||
$longestColumnName = '';
|
||||
foreach ($this->reportColumns as $columnName) {
|
||||
if (strlen($columnName) > strlen($longestColumnName)) {
|
||||
$longestColumnName = $columnName;
|
||||
}
|
||||
}
|
||||
|
||||
$columnsCount = count($this->reportColumns);
|
||||
// Computes available column width
|
||||
if ($this->orientation == self::PORTRAIT
|
||||
&& $columnsCount <= 3
|
||||
) {
|
||||
$totalWidth = $this->reportWidthPortrait * 2 / 3;
|
||||
} else if ($this->orientation == self::LANDSCAPE) {
|
||||
$totalWidth = $this->reportWidthLandscape;
|
||||
} else {
|
||||
$totalWidth = $this->reportWidthPortrait;
|
||||
}
|
||||
$this->totalWidth = $totalWidth;
|
||||
$this->labelCellWidth = max(round(($this->totalWidth / $columnsCount)), $this->minWidthLabelCell);
|
||||
$this->cellWidth = round(($this->totalWidth - $this->labelCellWidth) / ($columnsCount - 1));
|
||||
$this->totalWidth = $this->labelCellWidth + ($columnsCount - 1) * $this->cellWidth;
|
||||
|
||||
$this->TCPDF->SetFillColor($this->tableHeaderBackgroundColor[0], $this->tableHeaderBackgroundColor[1], $this->tableHeaderBackgroundColor[2]);
|
||||
$this->TCPDF->SetTextColor($this->tableHeaderTextColor[0], $this->tableHeaderTextColor[1], $this->tableHeaderTextColor[2]);
|
||||
$this->TCPDF->SetLineWidth(.3);
|
||||
$this->setBorderColor();
|
||||
$this->TCPDF->SetFont($this->reportFont, $this->reportFontStyle);
|
||||
$this->TCPDF->SetFillColor(255);
|
||||
$this->TCPDF->SetTextColor($this->tableHeaderBackgroundColor[0], $this->tableHeaderBackgroundColor[1], $this->tableHeaderBackgroundColor[2]);
|
||||
$this->TCPDF->SetDrawColor(255);
|
||||
|
||||
$posY = $this->TCPDF->GetY();
|
||||
$this->TCPDF->MultiCell($this->cellWidth, $this->cellHeight, $longestColumnName, 1, 'C', true);
|
||||
$maxCellHeight = $this->TCPDF->GetY() - $posY;
|
||||
|
||||
$this->TCPDF->SetFillColor($this->tableHeaderBackgroundColor[0], $this->tableHeaderBackgroundColor[1], $this->tableHeaderBackgroundColor[2]);
|
||||
$this->TCPDF->SetTextColor($this->tableHeaderTextColor[0], $this->tableHeaderTextColor[1], $this->tableHeaderTextColor[2]);
|
||||
$this->TCPDF->SetDrawColor($this->tableCellBorderColor[0], $this->tableCellBorderColor[1], $this->tableCellBorderColor[2]);
|
||||
|
||||
$this->TCPDF->SetXY($initPosX, $posY);
|
||||
|
||||
$countColumns = 0;
|
||||
$posX = $initPosX;
|
||||
foreach ($this->reportColumns as $columnName) {
|
||||
$columnName = $this->formatText($columnName);
|
||||
//Label column
|
||||
if ($countColumns == 0) {
|
||||
$this->TCPDF->MultiCell($this->labelCellWidth, $maxCellHeight, $columnName, 1, 'C', true);
|
||||
$this->TCPDF->SetXY($posX + $this->labelCellWidth, $posY);
|
||||
} else {
|
||||
$this->TCPDF->MultiCell($this->cellWidth, $maxCellHeight, $columnName, 1, 'C', true);
|
||||
$this->TCPDF->SetXY($posX + $this->cellWidth, $posY);
|
||||
}
|
||||
$countColumns++;
|
||||
$posX = $this->TCPDF->GetX();
|
||||
}
|
||||
$this->TCPDF->Ln();
|
||||
$this->TCPDF->SetXY($initPosX, $posY + $maxCellHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message
|
||||
*
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
private function paintMessage($message)
|
||||
{
|
||||
$this->TCPDF->SetFont($this->reportFont, $this->reportFontStyle, $this->reportSimpleFontSize);
|
||||
$this->TCPDF->SetTextColor($this->reportTextColor[0], $this->reportTextColor[1], $this->reportTextColor[2]);
|
||||
$message = $this->formatText($message);
|
||||
$this->TCPDF->Write("1em", $message);
|
||||
$this->TCPDF->Ln();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue