Skip to content

Commit

Permalink
ref #71, #3934 - segment selection for scheduled html, pdf & sms reports
Browse files Browse the repository at this point in the history
  • Loading branch information
julienmoumne committed May 19, 2013
1 parent 1ec8657 commit 8a8ce3e
Show file tree
Hide file tree
Showing 17 changed files with 282 additions and 52 deletions.
18 changes: 10 additions & 8 deletions core/ReportRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ abstract public function getRenderedReport();
* @param string $reportTitle
* @param string $prettyDate formatted date
* @param string $description
* @param array $reportMetadata metadata for all reports
* @param array $reportMetadata metadata for all reports
* @param array $segment segment applied to all reports
*/
abstract public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata);
abstract public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment);

/**
* Render the provided report.
Expand Down Expand Up @@ -215,7 +216,7 @@ protected static function processTableFormat($reportMetadata, $report, $reportCo
);
}

public static function getStaticGraph($reportMetadata, $width, $height, $evolution)
public static function getStaticGraph($reportMetadata, $width, $height, $evolution, $segment)
{

$imageGraphUrl = $reportMetadata['imageGraphUrl'];
Expand All @@ -226,11 +227,12 @@ public static function getStaticGraph($reportMetadata, $width, $height, $evoluti

$request = new Piwik_API_Request(
$imageGraphUrl .
'&outputType=' . Piwik_ImageGraph_API::GRAPH_OUTPUT_PHP .
'&format=original&serialize=0' .
'&filter_truncate=' .
'&width=' . $width .
'&height=' . $height
'&outputType=' . Piwik_ImageGraph_API::GRAPH_OUTPUT_PHP .
'&format=original&serialize=0' .
'&filter_truncate=' .
'&width=' . $width .
'&height=' . $height .
($segment != null ? '&segment=' . $segment['definition'] : '')
);

try {
Expand Down
17 changes: 15 additions & 2 deletions core/ReportRenderer/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function epilogue()
$this->rendering .= $smarty->fetch(self::prefixTemplatePath("html_report_footer.tpl"));
}

public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata)
public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment)
{
$smarty = new Piwik_Smarty();
$this->assignCommonParameters($smarty);
Expand All @@ -93,6 +93,13 @@ public function renderFrontPage($reportTitle, $prettyDate, $description, $report
$smarty->assign("description", $description);
$smarty->assign("reportMetadata", $reportMetadata);

// segment
$displaySegment = ($segment != null);
$smarty->assign("displaySegment", $displaySegment);
if ($displaySegment) {
$smarty->assign("segmentName", $segment['name']);
}

$this->rendering .= $smarty->fetch(self::prefixTemplatePath("html_report_header.tpl"));
}

Expand Down Expand Up @@ -139,7 +146,13 @@ public function renderReport($processedReport)
$smarty->assign("renderImageInline", $this->renderImageInline);

if ($this->renderImageInline) {
$staticGraph = parent::getStaticGraph($reportMetadata, self::IMAGE_GRAPH_WIDTH, self::IMAGE_GRAPH_HEIGHT, $evolutionGraph);
$staticGraph = parent::getStaticGraph(
$reportMetadata,
self::IMAGE_GRAPH_WIDTH,
self::IMAGE_GRAPH_HEIGHT,
$evolutionGraph,
$processedReport['segment']
);
$smarty->assign("generatedImageGraph", base64_encode($staticGraph));
unset($generatedImageGraph);
}
Expand Down
29 changes: 24 additions & 5 deletions core/ReportRenderer/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Piwik_ReportRenderer_Pdf extends Piwik_ReportRenderer
private $displayGraph;
private $evolutionGraph;
private $displayTable;
private $segment;
private $reportColumns;
private $reportRowsMetadata;
private $currentPage = 0;
Expand Down Expand Up @@ -142,35 +143,51 @@ public function getRenderedReport()
return $this->TCPDF->Output(null, 'S');
}

public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata)
public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment)
{
$reportTitle = $this->formatText($reportTitle);
$dateRange = $this->formatText(Piwik_Translate('General_DateRange') . " " . $prettyDate);

//Setup Footer font and data
// footer
$this->TCPDF->SetFooterFont(array($this->reportFont, $this->reportFontStyle, $this->reportSimpleFontSize));
$this->TCPDF->SetFooterContent($reportTitle . " | " . $dateRange . " | ");

// add first page
$this->TCPDF->setPrintHeader(false);
// $this->SetMargins($left = , $top, $right=-1, $keepmargins=true)
$this->TCPDF->AddPage(self::PORTRAIT);
$this->TCPDF->AddFont($this->reportFont, '', '', false);
$this->TCPDF->SetFont($this->reportFont, $this->reportFontStyle, $this->reportSimpleFontSize);
//Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false) {
$this->TCPDF->Bookmark(Piwik_Translate('PDFReports_FrontPage'));

// logo
$this->TCPDF->Image(Piwik_API_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('PDFReports_CustomVisitorSegment') . ' ' . $segment['name']));
}

$this->TCPDF->Ln(8);
$this->TCPDF->SetFont($this->reportFont, '', $this->reportHeaderFontSize);
$this->TCPDF->Ln();
Expand Down Expand Up @@ -270,6 +287,7 @@ public function renderReport($processedReport)
$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();
Expand Down Expand Up @@ -388,7 +406,8 @@ private function paintGraph()
$this->reportMetadata,
$this->orientation == self::PORTRAIT ? self::IMAGE_GRAPH_WIDTH_PORTRAIT : self::IMAGE_GRAPH_WIDTH_LANDSCAPE,
self::IMAGE_GRAPH_HEIGHT,
$this->evolutionGraph
$this->evolutionGraph,
$this->segment
);

$this->TCPDF->Image(
Expand Down
30 changes: 30 additions & 0 deletions core/Updates/1.12-b16.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package Updates
*/

/**
* @package Updates
*/
class Piwik_Updates_1_12_b16 extends Piwik_Updates
{
static function getSql($schema = 'Myisam')
{
return array(
// ignore existing column name error (1060)
'ALTER TABLE ' . Piwik_Common::prefixTable('report')
. " ADD COLUMN idsegment INT(11) AFTER description" => 1060,
);
}

static function update()
{
Piwik_Updater::updateDatabase(__FILE__, self::getSql());
}
}
4 changes: 4 additions & 0 deletions lang/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,8 @@
'PDFReports_CreateAndScheduleReport' => 'Create and Schedule a report',
'PDFReports_CancelAndReturnToReports' => 'Cancel and %sreturn to the list of reports%s',
'PDFReports_DescriptionOnFirstPage' => 'The report description will be displayed on the first page of the report.',
'PDFReports_Segment_Help' => 'You can select an existing custom segment to apply to data in this email report. You may create and edit custom segments in your dashboard %s(click here to open)%s, then clicking on the "%s" box, then "%s".',
'PDFReports_Segment_Deletion_Error' => 'This segment cannot be deleted, because it is used to generate the email report(s) %s. To delete this segment, you can first edit these reports so they don\'t use this segment.',
'PDFReports_WeeklyScheduleHelp' => 'Weekly schedule: report will be sent on Monday of each week.',
'PDFReports_MonthlyScheduleHelp' => 'Monthly schedule: report will be sent the first day of each month.',
'PDFReports_ReportHour' => 'Send report at',
Expand All @@ -2022,6 +2024,8 @@
'PDFReports_EmailHello' => 'Hello,',
'PDFReports_PleaseFindAttachedFile' => 'Please find in attached file your %1$s report for %2$s.',
'PDFReports_PleaseFindBelow' => 'Please find below your %1$s report for %2$s.',
'PDFReports_SegmentAppliedToReports' => 'The segment \'%s\' is applied to the reports.',
'PDFReports_CustomVisitorSegment' => 'Custom Visitor Segment:',
'PDFReports_AreYouSureDeleteReport' => 'Are you sure you want to delete this report and its schedule?',
'PDFReports_ThereIsNoReportToManage' => 'There is no report to manage for website %s',
'PDFReports_MustBeLoggedIn' => 'You must be logged in to create and schedule custom reports.',
Expand Down
6 changes: 6 additions & 0 deletions plugins/CoreHome/templates/html_report_header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
{$description} - {'General_DateRange'|translate} {$prettyDate}
</p>

{if $displaySegment}
<p style="color: rgb({$reportTitleTextColor});">
{'PDFReports_CustomVisitorSegment'|translate:"Piwik"} {$segmentName}
</p>
{/if}

{if sizeof($reportMetadata) > 1}
<h2 style="color: rgb({$reportTitleTextColor}); font-size: {$reportTitleTextSize}pt;">
{'PDFReports_TableOfContent'|translate}
Expand Down
7 changes: 4 additions & 3 deletions plugins/ImageGraph/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public function get(
$backgroundColor = Piwik_ImageGraph_API::DEFAULT_BACKGROUND_COLOR,
$gridColor = Piwik_ImageGraph_API::DEFAULT_GRID_COLOR,
$idSubtable = false,
$legendAppendMetric = true
$legendAppendMetric = true,
$segment = false
) {
Piwik::checkUserHasViewAccess($idSite);

Expand Down Expand Up @@ -296,7 +297,7 @@ public function get(
$apiModule,
$apiAction,
$labels,
$segment = false,
$segment,
$plottedMetric,
$languageLoaded,
$idGoal,
Expand Down Expand Up @@ -352,7 +353,7 @@ public function get(
$date,
$apiModule,
$apiAction,
$segment = false,
$segment,
$apiParameters = false,
$idGoal,
$languageLoaded,
Expand Down
2 changes: 1 addition & 1 deletion plugins/MobileMessaging/ReportRenderer/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getRenderedReport()
return $this->rendering;
}

public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata)
public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment)
{
// nothing to do
}
Expand Down
10 changes: 9 additions & 1 deletion plugins/MobileMessaging/ReportRenderer/Sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getRenderedReport()
return $this->rendering;
}

public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata)
public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment)
{
// nothing to do
}
Expand Down Expand Up @@ -121,6 +121,14 @@ public function renderReport($processedReport)
$smarty->assign("siteHasECommerce", $siteHasECommerce);
$smarty->assign("displaySiteName", $processedReport['metadata']['action'] == 'getAll');

// segment
$segment = $processedReport['segment'];
$displaySegment = ($segment != null);
$smarty->assign("displaySegment", $displaySegment);
if ($displaySegment) {
$smarty->assign("segmentName", $segment['name']);
}

$this->rendering .= $smarty->fetch(PIWIK_USER_PATH . '/plugins/MobileMessaging/templates/SMSReport.tpl');
}
}
14 changes: 9 additions & 5 deletions plugins/MobileMessaging/templates/SMSReport.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{strip}
{$prettyDate}.{literal} {/literal}
{$prettyDate}
{if $displaySegment}
,{literal} {/literal}{$segmentName}
{/if}
.{literal} {/literal}

{if empty($reportRows)}
{'CoreHome_ThereIsNoDataForThisReport'|translate}
Expand All @@ -14,15 +18,15 @@
{$rowMetrics.label}:{literal} {/literal}
{/if}

{*visits*}
{*visits*}
{$rowMetrics.nb_visits} {'General_ColumnNbVisits'|translate}
{if $rowMetrics.visits_evolution != 0}
{literal} {/literal}({$rowMetrics.visits_evolution}%)
{/if}

{if $rowMetrics.nb_visits != 0}

{*actions*}
{*actions*}
,{literal} {/literal}
{$rowMetrics.nb_actions} {'General_ColumnNbActions'|translate}
{if $rowMetrics.actions_evolution != 0}
Expand All @@ -31,7 +35,7 @@

{if $isGoalPluginEnabled}

{*goal metrics*}
{*goal metrics*}
{if $rowMetrics.nb_conversions != 0}

,{literal} {/literal}
Expand All @@ -47,7 +51,7 @@
{/if}
{/if}

{*eCommerce metrics*}
{*eCommerce metrics*}
{if $siteHasECommerce[$rowMetadata.idsite]}

,{literal} {/literal}
Expand Down
Loading

0 comments on commit 8a8ce3e

Please sign in to comment.