Skip to content

Commit

Permalink
Enotice fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 19, 2021
1 parent 74d69e4 commit 96b1435
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 48 deletions.
24 changes: 21 additions & 3 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
* Class CRM_Report_Form
*/
class CRM_Report_Form extends CRM_Core_Form {
/**
* Variables smarty expects to have set.
*
* We ensure these are assigned (value = NULL) when Smarty is instantiated in
* order to avoid e-notices / having to use empty or isset in the template layer.
*
* @var string[]
*/
public $expectedSmartyVariables = ['pager', 'skip', 'sections', 'grandStat'];

/**
* Deprecated constant, Reports should be updated to use the getRowCount function.
*/
Expand Down Expand Up @@ -2471,11 +2481,11 @@ public function formatDisplay(&$rows, $pager = TRUE) {
if ($pager) {
$this->setPager();
}

$chartEnabled = !empty($this->_params['charts']) && !empty($rows);
$this->assign('chartEnabled', $chartEnabled);
// allow building charts if any
if (!empty($this->_params['charts']) && !empty($rows)) {
if ($chartEnabled) {
$this->buildChart($rows);
$this->assign('chartEnabled', TRUE);
$this->_chartId = "{$this->_params['charts']}_" .
($this->_id ? $this->_id : substr(get_class($this), 16)) . '_' .
CRM_Core_Config::singleton()->userSystem->getSessionId();
Expand Down Expand Up @@ -3378,6 +3388,10 @@ public function groupByStat(&$statistics) {
'value' => implode(' & ', $combinations),
];
}
else {
// prevents an e-notice in statistics.tpl.
$statistics['groups'] = [];
}
}

/**
Expand Down Expand Up @@ -3485,6 +3499,10 @@ public function filterStat(&$statistics) {
}
}
}
else {
// Prevents an e-notice in statistics.tpl.
$statistics['filters'] = [];
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Report/Utils/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public static function processReport($params) {
$_REQUEST['reset'] = CRM_Utils_Array::value('reset', $params, 1);

$optionVal = self::getValueFromUrl($instanceId);
$messages = ["Report Mail Triggered..."];
$messages = ['Report Mail Triggered...'];

$templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', $optionVal, 'value');
$obj = new CRM_Report_Page_Instance();
Expand Down
8 changes: 4 additions & 4 deletions templates/CRM/Report/Form.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{elseif $section eq 2}
<div class="crm-block crm-content-block crm-report-layoutTable-form-block">
{*include the table layout*}
{if empty($chartEnabled) || empty($chartSupported)}
{if !$chartEnabled || empty($chartSupported)}
{include file="CRM/Report/Form/Layout/Table.tpl"}
{/if}
</div>
Expand All @@ -32,19 +32,19 @@
{include file="CRM/Report/Form/Actions.tpl"}

{*Statistics at the Top of the page*}
{include file="CRM/Report/Form/Statistics.tpl" top=true}
{include file="CRM/Report/Form/Statistics.tpl" top=true bottom=false}

{*include the graph*}
{include file="CRM/Report/Form/Layout/Graph.tpl"}

{*include the table layout*}

{if empty($chartEnabled) || empty($chartSupported)}
{if !$chartEnabled || empty($chartSupported)}
{include file="CRM/Report/Form/Layout/Table.tpl"}
{/if}
<br />
{*Statistics at the bottom of the page*}
{include file="CRM/Report/Form/Statistics.tpl" bottom=true}
{include file="CRM/Report/Form/Statistics.tpl" top="false" bottom=true}

{include file="CRM/Report/Form/ErrorMessage.tpl"}
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/CRM/Report/Form/Contact/Detail.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="crm-block crm-content-block crm-report-form-block">
{include file="CRM/Report/Form/Actions.tpl"}
{if !$section }
{include file="CRM/Report/Form/Statistics.tpl" top=true}
{include file="CRM/Report/Form/Statistics.tpl" top=true bottom=false}
{/if}
{if $rows}
<div class="report-pager">
Expand Down Expand Up @@ -180,7 +180,7 @@

{if !$section }
{*Statistics at the bottom of the page*}
{include file="CRM/Report/Form/Statistics.tpl" bottom=true}
{include file="CRM/Report/Form/Statistics.tpl" top="false" bottom=true}
{/if}
{/if}
{include file="CRM/Report/Form/ErrorMessage.tpl"}
Expand Down
8 changes: 4 additions & 4 deletions templates/CRM/Report/Form/Contribute/DeferredRevenue.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
{include file="CRM/Report/Form/Actions.tpl"}

{*Statistics at the Top of the page*}
{include file="CRM/Report/Form/Statistics.tpl" top=true}
{include file="CRM/Report/Form/Statistics.tpl" top=true bottom=false}

<table class="report-layout display">
{foreach from=$rows item=row}
<thead><th colspan=16><font color="black" size="3">{$row.label}</font></th></thead>

<thead class="sticky">
<tr>
{foreach from=$columnHeaders item=label key=header}
Expand All @@ -43,7 +43,7 @@

<br />
{*Statistics at the bottom of the page*}
{include file="CRM/Report/Form/Statistics.tpl" bottom=true}
{include file="CRM/Report/Form/Statistics.tpl" top="false" bottom=true}

{include file="CRM/Report/Form/ErrorMessage.tpl"}
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/CRM/Report/Form/Event/Income.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{include file="CRM/Report/Form/Actions.tpl"}
{*Statistics at the Top of the page*}
{if !$section }
{include file="CRM/Report/Form/Statistics.tpl" top=true}
{include file="CRM/Report/Form/Statistics.tpl" top=true bottom=false}
{/if}

{if $events}
Expand Down Expand Up @@ -70,7 +70,7 @@
</div>
{if !$section }
{*Statistics at the bottom of the page*}
{include file="CRM/Report/Form/Statistics.tpl" bottom=true}
{include file="CRM/Report/Form/Statistics.tpl" top="false" bottom=true}
{/if}
{/if}
{include file="CRM/Report/Form/ErrorMessage.tpl"}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Report/Form/Layout/Graph.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*}
{assign var=uploadURL value=$config->imageUploadURL|replace:'/persist/contribute/':'/persist/'}
{* Display weekly,Quarterly,monthly and yearly contributions using pChart (Bar and Pie) *}
{if !empty($chartEnabled) and !empty($chartSupported)}
{if $chartEnabled and !empty($chartSupported)}
<div class='crm-chart'>
{if $outputMode eq 'print' OR $outputMode eq 'pdf'}
<img src="{$uploadURL|cat:$chartId}.png" />
Expand Down
12 changes: 6 additions & 6 deletions templates/CRM/Report/Form/Layout/Table.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{if empty($rows)}
{if !$rows}
<p>{ts}None found.{/ts}</p>
{else}
{if !empty($pager) and $pager->_response and $pager->_response.numPages > 1}
{if $pager and $pager->_response and $pager->_response.numPages > 1}
<div class="report-pager">
{include file="CRM/common/pager.tpl" location="top"}
</div>
Expand All @@ -24,7 +24,7 @@
{else}
{assign var=class value="class='reports-header'"}
{/if}
{if empty($skip)}
{if !$skip}
{if !empty($header.colspan)}
<th colspan={$header.colspan}>{$header.title|escape}</th>
{assign var=skip value=true}
Expand All @@ -41,7 +41,7 @@
{/foreach}
{/capture}

{if empty($sections)} {* section headers and sticky headers aren't playing nice yet *}
{if !$sections} {* section headers and sticky headers aren't playing nice yet *}
<thead class="sticky">
<tr>
{$tableHeader}
Expand Down Expand Up @@ -136,7 +136,7 @@
</tr>
{/foreach}

{if !empty($grandStat)}
{if $grandStat}
{* foreach from=$grandStat item=row*}
<tr class="total-row">
{foreach from=$columnHeaders item=header key=field}
Expand All @@ -156,7 +156,7 @@
{* /foreach*}
{/if}
</table>
{if !empty($pager) and $pager->_response and $pager->_response.numPages > 1}
{if $pager and $pager->_response and $pager->_response.numPages > 1}
<div class="report-pager">
{include file="CRM/common/pager.tpl" location="bottom"}
</div>
Expand Down
32 changes: 14 additions & 18 deletions templates/CRM/Report/Form/Statistics.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,30 @@
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{if !empty($top)}
{if $top}
{if !empty($printOnly)}
<h1>{$reportTitle}</h1>
<div id="report-date">{if !empty($reportDate)}{$reportDate}{/if}</div>
{/if}
{if !empty($statistics)}
<table class="report-layout statistics-table">
{if !empty($statistics.groups)}
{foreach from=$statistics.groups item=row}
<tr>
<th class="statistics" scope="row">{$row.title}</th>
<td>{$row.value|escape}</td>
</tr>
{/foreach}
{/if}
{if !empty($statistics.filters)}
{foreach from=$statistics.filters item=row}
<tr>
<th class="statistics" scope="row">{$row.title}</th>
<td>{$row.value|escape}</td>
</tr>
{/foreach}
{/if}
{foreach from=$statistics.groups item=row}
<tr>
<th class="statistics" scope="row">{$row.title}</th>
<td>{$row.value|escape}</td>
</tr>
{/foreach}
{foreach from=$statistics.filters item=row}
<tr>
<th class="statistics" scope="row">{$row.title}</th>
<td>{$row.value|escape}</td>
</tr>
{/foreach}
</table>
{/if}
{/if}

{if !empty($bottom) and !empty($rows) and !empty($statistics)}
{if $bottom and !empty($rows) and !empty($statistics)}
<table class="report-layout">
{if !empty($statistics.counts)}
{foreach from=$statistics.counts item=row}
Expand Down
13 changes: 6 additions & 7 deletions tests/phpunit/CRM/Report/Utils/ReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testMakeCsv() {
* tests for that - we're more interested in does it echo it in print
* format.
*/
public function testOutputPrint() {
public function testOutputPrint(): void {
// Create many contacts, in particular so that the report would be more
// than a one-pager.
for ($i = 0; $i < 110; $i++) {
Expand Down Expand Up @@ -114,8 +114,7 @@ public function testOutputPrint() {
]);
}
catch (CRM_Core_Exception_PrematureExitException $e) {
$contents = ob_get_contents();
ob_end_clean();
$contents = ob_get_clean();
}
$this->assertStringContainsString('<title>CiviCRM Report</title>', $contents);
$this->assertStringContainsString('test report', $contents);
Expand All @@ -133,7 +132,8 @@ public function testOutputPrint() {
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testOutputPdf() {
public function testOutputPdf(): void {
$contents = '';
// Create many contacts, in particular so that the report would be more
// than a one-pager.
for ($i = 0; $i < 110; $i++) {
Expand Down Expand Up @@ -171,8 +171,7 @@ public function testOutputPdf() {
]);
}
catch (CRM_Core_Exception_PrematureExitException $e) {
$contents = ob_get_contents();
ob_end_clean();
$contents = ob_get_clean();
}
$this->assertStringStartsWith('%PDF', $contents);
$this->assertStringContainsString("id_value={$last_contact['id']}", $contents);
Expand All @@ -181,7 +180,7 @@ public function testOutputPdf() {
/**
* Test when you choose Csv from the actions dropdown.
*/
public function testOutputCsv() {
public function testOutputCsv(): void {
// Create many contacts, in particular so that the report would be more
// than a one-pager.
for ($i = 0; $i < 110; $i++) {
Expand Down

0 comments on commit 96b1435

Please sign in to comment.