From: eileen Date: Mon, 26 Mar 2018 04:37:29 +0000 (+1300) Subject: CRM-21677 reduce unnecessary joins in pledge reports X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=cd2426ba63c0a0dc8d9b1d5be1aa75e67d05a8e4;p=civicrm-core.git CRM-21677 reduce unnecessary joins in pledge reports And walklist report: Pledge/Detail pledge/pbnp pledge/summary walklist/walklist --- diff --git a/CRM/Report/Form/Pledge/Detail.php b/CRM/Report/Form/Pledge/Detail.php index 85a485caa5..7c2c1da2a5 100644 --- a/CRM/Report/Form/Pledge/Detail.php +++ b/CRM/Report/Form/Pledge/Detail.php @@ -286,16 +286,9 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form { "; } - $this->addPhoneFromClause(); - $this->addAddressFromClause(); - // include email field if email column is to be included - if ($this->_emailField) { - $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\n"; - } + $this->joinPhoneFromContact(); + $this->joinAddressFromContact(); + $this->joinEmailFromContact(); } /** diff --git a/CRM/Report/Form/Pledge/Pbnp.php b/CRM/Report/Form/Pledge/Pbnp.php index 596d91dd1b..01294d59c6 100644 --- a/CRM/Report/Form/Pledge/Pbnp.php +++ b/CRM/Report/Form/Pledge/Pbnp.php @@ -230,14 +230,6 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form { if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName]) ) { - // to include optional columns address and email, only if checked - if ($tableName == 'civicrm_address') { - $this->_addressField = TRUE; - $this->_emailField = TRUE; - } - elseif ($tableName == 'civicrm_email') { - $this->_emailField = TRUE; - } $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field); @@ -279,23 +271,9 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form { ON ({$this->_aliases['civicrm_pledge']}.id = {$this->_aliases['civicrm_pledge_payment']}.pledge_id AND {$this->_aliases['civicrm_pledge_payment']}.status_id = {$pendingStatus} ) "; - // include address field if address column is to be included - 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(); + $this->joinEmailFromContact(); - // include email field if email column is to be included - if ($this->_emailField) { - $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\n"; - } } public function groupBy() { diff --git a/CRM/Report/Form/Pledge/Summary.php b/CRM/Report/Form/Pledge/Summary.php index 39749ef804..b5905c5c8d 100644 --- a/CRM/Report/Form/Pledge/Summary.php +++ b/CRM/Report/Form/Pledge/Summary.php @@ -38,8 +38,6 @@ class CRM_Report_Form_Pledge_Summary extends CRM_Report_Form { protected $_totalPaid = FALSE; protected $_customGroupExtends = array('Pledge', 'Individual'); protected $_customGroupGroupBy = TRUE; - protected $_addressField = FALSE; - protected $_emailField = FALSE; /** * This report has not been optimised for group filtering. @@ -216,23 +214,8 @@ class CRM_Report_Form_Pledge_Summary extends CRM_Report_Form { {$this->_aliases['civicrm_pledge']}.contact_id ) {$this->_aclFrom} "; - // include address field if address column is to be included - 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"; - } - - // include email field if email column is to be included - if ($this->_emailField) { - $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\n"; - } + $this->joinAddressFromContact(); + $this->joinEmailFromContact(); if (!empty($this->_params['fields']['total_paid'])) { $this->_from .= " diff --git a/CRM/Report/Form/Walklist/Walklist.php b/CRM/Report/Form/Walklist/Walklist.php index 98e51413fe..25e92d7027 100644 --- a/CRM/Report/Form/Walklist/Walklist.php +++ b/CRM/Report/Form/Walklist/Walklist.php @@ -31,11 +31,6 @@ * @copyright CiviCRM LLC (c) 2004-2018 */ class CRM_Report_Form_Walklist_Walklist extends CRM_Report_Form { - protected $_addressField = FALSE; - - protected $_emailField = FALSE; - - protected $_phoneField = FALSE; protected $_summary = NULL; @@ -149,6 +144,7 @@ class CRM_Report_Form_Walklist_Walklist extends CRM_Report_Form { } public function select() { + // @todo remove this function & use parent. $select = array(); $this->_columnHeaders = array(); @@ -157,15 +153,6 @@ class CRM_Report_Form_Walklist_Walklist extends CRM_Report_Form { if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName]) ) { - if ($tableName == 'civicrm_address') { - $this->_addressField = TRUE; - } - elseif ($tableName == 'civicrm_email') { - $this->_emailField = TRUE; - } - elseif ($tableName == 'civicrm_phone') { - $this->_phoneField = TRUE; - } $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; @@ -183,17 +170,10 @@ class CRM_Report_Form_Walklist_Walklist extends CRM_Report_Form { $this->_from = " 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"; - } - - if ($this->_emailField) { - $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\n"; - } - if ($this->_phoneField) { - $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\n"; - } + $this->joinAddressFromContact(); + $this->joinPhoneFromContact(); + $this->joinEmailFromContact(); } public function where() {