...
 
Commits (10)
......@@ -47,7 +47,9 @@ class CRM_Reportplus_Form extends CRM_Report_Form {
*/
protected $_extraActions = [];
// [ML] Required for civiexportexcel
/**
* [ML] Required for civiexportexcel
*/
public $supportsExportExcel = TRUE;
public function __construct() {
......@@ -278,6 +280,33 @@ class CRM_Reportplus_Form extends CRM_Report_Form {
}
}
public function addAddressTable() {
$tables = $this->selectedTables();
if (isset($tables) && !$this->isTableSelected('civicrm_address')) {
foreach ($tables as $table) {
if (substr($table, 0, 14) === "civicrm_value_") {
$result = civicrm_api3('CustomGroup', 'get', [
'sequential' => 1,
'return' => ["extends"],
'table_name' => $table,
]);
if ($result['values'][0]['extends'] == 'Address') {
$this->_selectedTables[] = 'civicrm_address';
break;
}
}
}
}
}
/**
* Join address table from custom address table
*/
public function joinAddressFromContact($prefix = '', $extra = []) {
$this->addAddressTable();
parent::joinAddressFromContact($prefix, $extra);
}
public function preProcessCommon() {
parent::preProcessCommon();
......@@ -351,7 +380,6 @@ class CRM_Reportplus_Form extends CRM_Report_Form {
// override this method for building Chart JS.
}
public function setDefaultValues($freeze = TRUE) {
parent::setDefaultValues($freeze);
......@@ -446,7 +474,7 @@ class CRM_Reportplus_Form extends CRM_Report_Form {
public function getBasicContactFields() {
$result = parent::getBasicContactFields() + [
'contact_source' => [
'title' => ts('Source of Contact Data') ,
'title' => ts('Source of Contact Data'),
],
'is_deceased' => [
'title' => ts('Contact is Deceased'),
......
......@@ -169,7 +169,7 @@ class CRM_Reportplus_Form_Activity_Matrix extends CRM_Reportplus_Form_Matrix {
if ($fieldType) {
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
$this->_selectedTables[] = 'civicrm_address';
}
if ($field['type'] & CRM_Utils_Type::T_DATE) {
......
<?php
class CRM_Reportplus_Form_Case_Matrix extends CRM_Reportplus_Form_Contact_Matrix {
/**
* Class constructor.
*/
......
......@@ -83,6 +83,11 @@ class CRM_Reportplus_Form_Contact_Birthday extends CRM_Reportplus_Form {
'type' => CRM_Utils_Type::T_DATE,
'default' => 'this.day',
],
'age' => [
'title' => ts('Age'),
'type' => CRM_Utils_Type::T_INT,
'dbAlias' => "DATE_FORMAT(FROM_DAYS((TO_DAYS(NOW())+1)-TO_DAYS(contact_civireport.birth_date)), '%Y')+0",
],
'is_deceased' => [
'title' => ts('Is Deceased'),
'default' => 0,
......@@ -105,7 +110,7 @@ class CRM_Reportplus_Form_Contact_Birthday extends CRM_Reportplus_Form {
'default_weight' => '0',
'default_order' => 'ASC',
],
'birth_date_year' => [
'birth_date_year' => [
'title' => E::ts('Birth Date (Year)'),
'default_weight' => '1',
'dbAlias' => 'YEAR(contact_civireport.birth_date)',
......@@ -394,7 +399,6 @@ class CRM_Reportplus_Form_Contact_Birthday extends CRM_Reportplus_Form {
$entryFound = TRUE;
}
// display birthday in the configured custom format
if (array_key_exists('civicrm_contact_birth_date', $row)) {
$birthDate = $row['civicrm_contact_birth_date'];
......
......@@ -5,9 +5,8 @@ class CRM_Reportplus_Form_Contact_Matrix extends CRM_Reportplus_Form_Matrix {
* Class constructor.
*/
public function __construct() {
$this->_customGroupExtends = ['Contact', 'Individual', 'Organization'];
$this->_customGroupExtends = ['Contact', 'Individual', 'Organization', 'Address'];
$this->_customGroupGroupBy = TRUE;
$this->_addressField = TRUE;
$this->_columns = [
'civicrm_statistics' => [
......
......@@ -200,11 +200,8 @@ class CRM_Reportplus_Form_Contact_Summary extends CRM_Reportplus_Form {
}
public function from() {
$this->_from = "
FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
{$this->_aliases['civicrm_address']}.is_primary = 1 ) ";
$this->_from = "FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}";
$this->joinAddressFromContact();
if ($this->isTableSelected('civicrm_email')) {
$this->_from .= "
......
......@@ -6,9 +6,8 @@ class CRM_Reportplus_Form_Contribute_Matrix extends CRM_Reportplus_Form_Matrix {
* Class constructor.
*/
public function __construct() {
$this->_customGroupExtends = ['Contribution', 'Contact', 'Individual'];
$this->_customGroupExtends = ['Contribution', 'Contact', 'Individual', 'Address'];
$this->_customGroupGroupBy = TRUE;
$this->_addressField = FALSE;
$this->_columns = [
'civicrm_statistics' => [
......
......@@ -13,6 +13,7 @@ class CRM_Reportplus_Form_Matrix extends CRM_Reportplus_Form {
protected $_rowHeaders = [];
protected $_showTotals = FALSE;
protected $_addressField = FALSE;
/**
* Class constructor.
......@@ -30,7 +31,6 @@ class CRM_Reportplus_Form_Matrix extends CRM_Reportplus_Form {
'col' => E::ts("columns"),
'row' => E::ts("rows"),
];
$this->_addressField = FALSE;
// If we have a campaign, build out the relevant elements
if ($campaignEnabled && !empty($this->_activeCampaigns)) {
......@@ -111,9 +111,6 @@ class CRM_Reportplus_Form_Matrix extends CRM_Reportplus_Form {
if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
}
if ($tableName == 'civicrm_statistics') {
switch ($fieldName) {
......@@ -166,7 +163,7 @@ class CRM_Reportplus_Form_Matrix extends CRM_Reportplus_Form {
if ($fieldType) {
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
$this->_selectedTables[] = 'civicrm_address';
}
if ($field['type'] & CRM_Utils_Type::T_DATE) {
......@@ -215,13 +212,7 @@ class CRM_Reportplus_Form_Matrix extends CRM_Reportplus_Form {
FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
";
if ($this->_addressField) {
$this->_from .= "
LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
ON {$this->_aliases['civicrm_contact']}.id =
{$this->_aliases['civicrm_address']}.contact_id AND
{$this->_aliases['civicrm_address']}.is_primary = 1\n";
}
$this->joinAddressFromContact();
}
public function orderBy() {
......@@ -783,6 +774,36 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a
return FALSE;
}
/**
* Join address table from custom address table
*/
public function joinAddressFromContact($prefix = '', $extra = []) {
$this->addAddressTable();
// Join row from custom address table
if (substr($this->_params['group_bys_row'], 0, 7) === "custom_") {
// Extract custom field id
$customID = substr($this->_params['group_bys_row'], strrpos($this->_params['group_bys_row'], "_") + 1);
// Get extension of custom table
$result = civicrm_api3('CustomField', 'get', ['sequential' => 1, 'return' => ["custom_group_id.extends"], 'id' => $customID]);
if ($result['values'][0]['custom_group_id.extends'] == 'Address') {
$this->_selectedTables[] = 'civicrm_address';
}
}
// Join col from custom address table
if (substr($this->_params['group_bys_column'], 0, 7) === "custom_") {
// Extract custom field id
$customID = substr($this->_params['group_bys_column'], strrpos($this->_params['group_bys_column'], "_") + 1);
// Get extension of custom table
$result = civicrm_api3('CustomField', 'get', ['sequential' => 1, 'return' => ["custom_group_id.extends"], 'id' => $customID]);
if ($result['values'][0]['custom_group_id.extends'] == 'Address') {
$this->_selectedTables[] = 'civicrm_address';
}
}
parent::joinAddressFromContact($prefix, $extra);
}
private function _columnHeadersSort($a, $b) {
return ($this->_colOptionsWeight[$a['value']] > $this->_colOptionsWeight[$b['value']]) ? +1 : -1;
}
......@@ -880,7 +901,7 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a
break;
case 'campaign_id':
$campaigns = array_merge($this->_activeCampaigns, $this->_disabledCampaigns);
$campaigns = $this->_activeCampaigns + $this->_disabledCampaigns;
$this->_setColumnLabel($headers, $campaigns);
break;
......@@ -904,6 +925,14 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a
$this->_setColumnLabel($headers, $optionLabels);
}
}
// Empty
elseif (empty($field['type'])) {
if ($field['dataType'] == 'Country') {
$countries = CRM_Core_PseudoConstant::country(FALSE, FALSE);
$this->_setColumnLabel($headers, $countries);
}
}
break;
}
}
......
......@@ -6,9 +6,8 @@ class CRM_Reportplus_Form_Member_Matrix extends CRM_Reportplus_Form_Matrix {
* Class constructor.
*/
public function __construct() {
$this->_customGroupExtends = ['Membership', 'Contact', 'Individual', 'Household', 'Organization'];
$this->_customGroupExtends = ['Membership', 'Contact', 'Individual', 'Household', 'Organization', 'Address'];
$this->_customGroupGroupBy = TRUE;
$this->_addressField = FALSE;
$this->_columns = [
'civicrm_statistics' => [
......
......@@ -11,7 +11,7 @@ class CRM_Reportplus_Form_Member_Summary extends CRM_Reportplus_Form {
];
protected $_add2groupSupported = FALSE;
protected $_customGroupExtends = ['Membership', 'Contact', 'Individual', 'Household', 'Organization'];
protected $_customGroupExtends = ['Membership', 'Contact', 'Individual', 'Household', 'Organization', 'Address'];
protected $_customGroupGroupBy = TRUE;
public $_drilldownReport = ['member/detail' => 'Link to Detail Report'];
......
......@@ -21,10 +21,17 @@ The extension is licensed under [AGPL-3.0](LICENSE.txt).
## Requirements
* PHP v5.6+ / PHP v7.0+
* **CiviCRM 4.6.x**: Use branch **1.x** / PHP v5.6+ (not maintained anymore)
* **CiviCRM 5.21.x**: Use releases on branch **2.x** / PHP v7.2
### Disclaimer
**ReportPlus** extends from the CiviCRM core Report framework, which means that any change on this framework and its related classes (specially `CRM/Report/*.php` files) from the new
CiviCRM monthly releases, a revision on **ReportPlus** compatibility must be performed. And this involves a big continous effort we cannot commit monthly basis.
**ReportPlus** releases will guarantee compatibility with the [CiviCRM ESR](https://civicrm.org/esr) bi-annual releases. Please follow the *Requirements* section to know which version to install
on each [CiviCRM ESR](https://civicrm.org/esr) version
* CiviCRM 4.6+ - Use branch **1.x** (not maintained anymore)
* CiviCRM 4.7+ - Use branch **2.x**
## Usage
......
......@@ -12,11 +12,11 @@
<url desc="Main Extension Page">https://lab.civicrm.org/extensions/reportplus</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-01-07</releaseDate>
<version>2.3.8</version>
<releaseDate>2020-06-26</releaseDate>
<version>2.3.9</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.16</ver>
<ver>5.21</ver>
</compatibility>
<civix>
<namespace>CRM/Reportplus</namespace>
......