Skip to content

Commit

Permalink
Allow chart dropdown labels to be translatable.
Browse files Browse the repository at this point in the history
Prior to this change, the strings 'Tabular', 'Bar Chart' and 'Pie Chart' were hardcoded.
  • Loading branch information
braders committed Dec 31, 2021
1 parent fdc7a55 commit 28a4c4f
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 43 deletions.
31 changes: 30 additions & 1 deletion CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,12 @@ class CRM_Report_Form extends CRM_Core_Form {
*/
public $optimisedForOnlyFullGroupBy = TRUE;

/**
* Determines which chart types are supported for this report
* @var string[]
*/
protected $_charts = [];

/**
* Get the number of rows to show
* @return int
Expand Down Expand Up @@ -1574,12 +1580,35 @@ public function addOptions() {
*/
public function addChartOptions() {
if (!empty($this->_charts)) {
$this->addElement('select', "charts", ts('Chart'), $this->_charts);
$this->addElement('select', "charts", ts('Chart'), $this->getChartLabels($this->_charts));
$this->assign('charts', $this->_charts);
$this->addElement('xbutton', $this->_chartButtonName, ts('View'), ['type' => 'submit']);
}
}

/**
* Map supported chart types to translated labels for use in the chart type select field
*
* @return array
*/
private function getChartLabels() {
$charts = [];
$charts[''] = 'Tabular';

foreach ($this->_charts as $chart) {
if ($chart === 'barChart') {
$charts[$chart] = ts('Bar Chart');
}
elseif ($chart === 'pieChart') {
$charts[$chart] = ts('Pie Chart');
}
else {
$charts[$chart] = $chart;
}
};
return $charts;
}

/**
* Add group by options to the report.
*/
Expand Down
8 changes: 5 additions & 3 deletions CRM/Report/Form/Contribute/Lybunt.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/
class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form {

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

/**
Expand Down
9 changes: 6 additions & 3 deletions CRM/Report/Form/Contribute/SoftCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ class CRM_Report_Form_Contribute_SoftCredit extends CRM_Report_Form {
protected $_emailFieldCredit = FALSE;
protected $_phoneField = FALSE;
protected $_phoneFieldCredit = FALSE;

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

protected $_customGroupExtends = [
Expand Down
9 changes: 6 additions & 3 deletions CRM/Report/Form/Contribute/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
*/
class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

protected $_customGroupExtends = ['Contribution', 'Contact', 'Individual'];
protected $_customGroupGroupBy = TRUE;

Expand Down
8 changes: 5 additions & 3 deletions CRM/Report/Form/Contribute/Sybunt.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/
class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form {

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

protected $_customGroupExtends = [
Expand Down
8 changes: 5 additions & 3 deletions CRM/Report/Form/Contribute/TopDonor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ class CRM_Report_Form_Contribute_TopDonor extends CRM_Report_Form {

public $_drilldownReport = ['contribute/detail' => 'Link to Detail Report'];

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

/**
Expand Down
8 changes: 5 additions & 3 deletions CRM/Report/Form/Event/IncomeCountSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class CRM_Report_Form_Event_IncomeCountSummary extends CRM_Report_Form {

protected $_summary = NULL;

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

protected $_add2groupSupported = FALSE;
Expand Down
8 changes: 5 additions & 3 deletions CRM/Report/Form/Event/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class CRM_Report_Form_Event_Summary extends CRM_Report_Form {

protected $_summary = NULL;

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

protected $_add2groupSupported = FALSE;
Expand Down
8 changes: 5 additions & 3 deletions CRM/Report/Form/Mailing/Bounce.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class CRM_Report_Form_Mailing_Bounce extends CRM_Report_Form {
'Organization',
];

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

/**
Expand Down
8 changes: 5 additions & 3 deletions CRM/Report/Form/Mailing/Clicks.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class CRM_Report_Form_Mailing_Clicks extends CRM_Report_Form {
'Organization',
];

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

/**
Expand Down
8 changes: 5 additions & 3 deletions CRM/Report/Form/Mailing/Opened.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class CRM_Report_Form_Mailing_Opened extends CRM_Report_Form {
'Organization',
];

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

/**
Expand Down
6 changes: 4 additions & 2 deletions CRM/Report/Form/Mailing/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ class CRM_Report_Form_Mailing_Summary extends CRM_Report_Form {

public $_drilldownReport = ['mailing/detail' => 'Link to Detail Report'];

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barchart' => 'Bar Chart',
'barchart',
];

/**
Expand Down
1 change: 0 additions & 1 deletion CRM/Report/Form/Member/Lapse.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
class CRM_Report_Form_Member_Lapse extends CRM_Report_Form {

protected $_summary = NULL;
protected $_charts = ['' => 'Tabular'];
protected $_customGroupExtends = [
'Membership',
];
Expand Down
9 changes: 6 additions & 3 deletions CRM/Report/Form/Member/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {

protected $_summary = NULL;
protected $_interval = NULL;

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];
protected $_add2groupSupported = FALSE;

Expand Down
8 changes: 5 additions & 3 deletions CRM/Report/Form/Membership/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class CRM_Report_Form_Membership_Summary extends CRM_Report_Form {

protected $_summary = NULL;

/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

/**
Expand Down
9 changes: 6 additions & 3 deletions CRM/Report/Form/Pledge/Pbnp.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form {
/**
* @var string[]
*/
protected $_charts = [
'' => 'Tabular',
'barChart' => 'Bar Chart',
'pieChart' => 'Pie Chart',
'barChart',
'pieChart',
];

public $_drilldownReport = ['pledge/summary' => 'Link to Detail Report'];

protected $_customGroupExtends = [
Expand Down

0 comments on commit 28a4c4f

Please sign in to comment.