Skip to content

Commit

Permalink
CRM-21677 - Report improvements
Browse files Browse the repository at this point in the history
CRM-21677 - fix DB error and more clean up

CRM-21677 - generalised function

minor fix

CRM-21677 - keep the naming consistent

style fix
  • Loading branch information
yashodha authored and eileenmcnaughton committed Mar 31, 2018
1 parent 370c6b2 commit 18f511e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 53 deletions.
9 changes: 9 additions & 0 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4305,8 +4305,12 @@ public function fiscalYearOffset($fieldName) {

/**
* Add Address into From Table if required.
*
* @deprecated use joinAddressFromContact
* (left here in case extensions use it).
*/
public function addAddressFromClause() {
Civi::log()->warning('Deprecated function addAddressFromClause. Use joinAddressFromContact.', array('civi.tag' => 'deprecated'));
// include address field if address column is to be included
if ((isset($this->_addressField) &&
$this->_addressField
Expand All @@ -4323,8 +4327,13 @@ public function addAddressFromClause() {

/**
* Add Phone into From Table if required.
*
* @deprecated use joinPhoneFromContact
* (left here in case extensions use it).
*/
public function addPhoneFromClause() {

Civi::log()->warning('Deprecated function addPhoneFromClause. Use joinPhoneFromContact.', array('civi.tag' => 'deprecated'));
// include address field if address column is to be included
if ($this->isTableSelected('civicrm_phone')) {
$this->_from .= "
Expand Down
17 changes: 4 additions & 13 deletions CRM/Report/Form/Contribute/Lybunt.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,10 @@ public function from() {
AND {$this->_aliases['civicrm_contribution']}.is_test = 0
INNER JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
ON restricted_contacts.cid = {$this->_aliases['civicrm_contact']}.id";
if ($this->isTableSelected('civicrm_email')) {
$this->_from .= "
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id
AND {$this->_aliases['civicrm_email']}.is_primary = 1";
}
if ($this->isTableSelected('civicrm_phone')) {
$this->_from .= "
LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id
AND {$this->_aliases['civicrm_phone']}.is_primary = 1";
}
$this->addAddressFromClause();

$this->joinAddressFromContact();
$this->joinPhoneFromContact();
$this->joinEmailFromContact();
}
else {
$this->setFromBase('civicrm_contact');
Expand Down
7 changes: 1 addition & 6 deletions CRM/Report/Form/Contribute/RecurSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,12 @@ public function setDefaultValues($freeze = TRUE) {
}

public function select() {
// @todo remove & only adjust parent with selectWhere fn (if needed)
$select = array();
$this->_columnHeaders = array();
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('group_bys', $table)) {
foreach ($table['group_bys'] as $fieldName => $field) {
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
}
if (!empty($this->_params['group_bys'][$fieldName])) {
switch (CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])) {
case 'YEARWEEK':
Expand Down Expand Up @@ -150,9 +148,6 @@ public function select() {

if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
}
if (!empty($field['required']) ||
!empty($this->_params['fields'][$fieldName])
) {
Expand Down
18 changes: 4 additions & 14 deletions CRM/Report/Form/Contribute/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @copyright CiviCRM LLC (c) 2004-2018
*/
class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
protected $_addressField = FALSE;

protected $_charts = array(
'' => 'Tabular',
Expand Down Expand Up @@ -344,9 +343,6 @@ public function select() {
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('group_bys', $table)) {
foreach ($table['group_bys'] as $fieldName => $field) {
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
}
if (!empty($this->_params['group_bys'][$fieldName])) {
switch (CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])) {
case 'YEARWEEK':
Expand Down Expand Up @@ -411,9 +407,6 @@ public function select() {

if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
}
if (!empty($field['required']) ||
!empty($this->_params['fields'][$fieldName])
) {
Expand Down Expand Up @@ -515,15 +508,12 @@ public function from($entity = NULL) {
{$softCreditJoin}
LEFT JOIN civicrm_financial_type {$this->_aliases['civicrm_financial_type']}
ON {$this->_aliases['civicrm_contribution']}.financial_type_id ={$this->_aliases['civicrm_financial_type']}.id
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
{$this->_aliases['civicrm_email']}.is_primary = 1)
";

LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
{$this->_aliases['civicrm_phone']}.is_primary = 1)";
$this->joinAddressFromContact();
$this->joinPhoneFromContact();
$this->joinEmailFromContact();

$this->addAddressFromClause();
//for contribution batches
if ($this->isTableSelected('civicrm_batch')) {
$this->_from .= "
Expand Down
17 changes: 4 additions & 13 deletions CRM/Report/Form/Contribute/Sybunt.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,22 +352,13 @@ public function from() {
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id
{$this->_aclFrom}";

if ($this->isTableSelected('civicrm_email')) {
$this->_from .= "
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id
AND {$this->_aliases['civicrm_email']}.is_primary = 1";
}
if ($this->isTableSelected('civicrm_phone')) {
$this->_from .= "
LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
{$this->_aliases['civicrm_phone']}.is_primary = 1";
}
$this->joinPhoneFromContact();
$this->joinEmailFromContact();

// for credit card type
$this->addFinancialTrxnFromClause();

$this->addAddressFromClause();
$this->joinAddressFromContact();
}

public function where() {
Expand Down
11 changes: 4 additions & 7 deletions CRM/Report/Form/Contribute/TopDonor.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,14 @@ public function from() {
FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id AND {$this->_aliases['civicrm_contribution']}.is_test = 0
LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id
AND {$this->_aliases['civicrm_email']}.is_primary = 1
LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
{$this->_aliases['civicrm_phone']}.is_primary = 1";
";

// for credit card type
$this->addFinancialTrxnFromClause();

$this->addAddressFromClause();
$this->joinAddressFromContact();
$this->joinPhoneFromContact();
$this->joinEmailFromContact();
}

public function where() {
Expand Down

0 comments on commit 18f511e

Please sign in to comment.