diff --git a/CRM/Report/Form/Contact/CurrentEmployer.php b/CRM/Report/Form/Contact/CurrentEmployer.php index 050745a50e9a..ab75475c3db6 100644 --- a/CRM/Report/Form/Contact/CurrentEmployer.php +++ b/CRM/Report/Form/Contact/CurrentEmployer.php @@ -252,17 +252,11 @@ public function from() { LEFT JOIN civicrm_relationship {$this->_aliases['civicrm_relationship']} ON ( {$this->_aliases['civicrm_relationship']}.contact_id_a={$this->_aliases['civicrm_contact']}.id AND {$this->_aliases['civicrm_relationship']}.contact_id_b={$this->_aliases['civicrm_contact']}.employer_id - AND {$this->_aliases['civicrm_relationship']}.relationship_type_id={$relType}) - 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 ) - - 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) - 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) "; + AND {$this->_aliases['civicrm_relationship']}.relationship_type_id={$relType}) "; + + $this->joinAddressFromContact(); + $this->joinPhoneFromContact(); + $this->joinEmailFromContact(); } public function where() { diff --git a/CRM/Report/Form/Contribute/Bookkeeping.php b/CRM/Report/Form/Contribute/Bookkeeping.php index 05da2d5908e8..0280a6ee0c9e 100644 --- a/CRM/Report/Form/Contribute/Bookkeeping.php +++ b/CRM/Report/Form/Contribute/Bookkeeping.php @@ -31,9 +31,6 @@ * @copyright CiviCRM LLC (c) 2004-2018 */ class CRM_Report_Form_Contribute_Bookkeeping extends CRM_Report_Form { - protected $_addressField = FALSE; - - protected $_emailField = FALSE; protected $_summary = NULL; diff --git a/CRM/Report/Form/Event/ParticipantListCount.php b/CRM/Report/Form/Event/ParticipantListCount.php index 07fcb817f066..bc15afc4996c 100644 --- a/CRM/Report/Form/Event/ParticipantListCount.php +++ b/CRM/Report/Form/Event/ParticipantListCount.php @@ -462,17 +462,12 @@ public function from() { {$this->_aclFrom} LEFT JOIN civicrm_contact {$this->_aliases['civicrm_employer']} ON ({$this->_aliases['civicrm_employer']}.id = {$this->_aliases['civicrm_contact']}.employer_id ) - 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 - 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 LEFT JOIN civicrm_line_item {$this->_aliases['civicrm_line_item']} ON {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant' AND {$this->_aliases['civicrm_participant']}.id ={$this->_aliases['civicrm_line_item']}.entity_id"; + + $this->joinAddressFromContact(); + $this->joinPhoneFromContact(); + $this->joinEmailFromContact(); } public function storeWhereHavingClauseArray() { diff --git a/CRM/Report/Form/Event/ParticipantListing.php b/CRM/Report/Form/Event/ParticipantListing.php index 11e07bdf50ca..a5269d8807a6 100644 --- a/CRM/Report/Form/Event/ParticipantListing.php +++ b/CRM/Report/Form/Event/ParticipantListing.php @@ -513,16 +513,12 @@ public function from() { LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) {$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 - 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(); + if ($this->_contribField) { $this->_from .= " LEFT JOIN civicrm_participant_payment pp diff --git a/CRM/Report/Form/Membership/Summary.php b/CRM/Report/Form/Membership/Summary.php index 5e8df23c906b..ba497f4ff7f9 100644 --- a/CRM/Report/Form/Membership/Summary.php +++ b/CRM/Report/Form/Membership/Summary.php @@ -148,6 +148,7 @@ public function preProcess() { * Generate select clause. */ public function select() { + // @todo remove this in favour of just using parent. $select = array(); $this->_columnHeaders = array(); foreach ($this->_columns as $tableName => $table) { @@ -156,14 +157,6 @@ public function select() { 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'] = $field['type']; $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; @@ -189,15 +182,8 @@ public function from() { LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']} ON {$this->_aliases['civicrm_membership']}.contact_id = {$this->_aliases['civicrm_contribution']}.contact_id "; - // Include address table 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 table 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(); } /**