Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21677 - Report improvements #11550

Closed
wants to merge 8 commits into from
Closed

Conversation

yashodha
Copy link
Contributor

@yashodha yashodha commented Jan 18, 2018

Overview

Clean up reports that have unnecessary joins to phone, email and address.

Before

unnecessary joins to phone, email and address tables

After

join only when needed.


@yashodha
Copy link
Contributor Author

test this please

@@ -41,7 +41,7 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
protected $_customGroupExtends = array('Contribution', 'Contact', 'Individual');
protected $_customGroupGroupBy = TRUE;

public $_drilldownReport = array('contribute/detail' => 'Link to Detail Report');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be in a separate PR as it is a behaviour change & we need to check if it will get buy in (I tend to agree with it). The other changes in this are just technical so better to put on 2 tracks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yashodha this line is the only thing that I think is blocking merge here - because I think it;s a separate change -
although I think it would be better if we changed joinAddressFromClause to joinAddressFromContactClause - and the same on the other functions. (that would make it more in line with extendedReport and differentiate between joinAddressFromLocation from joinAddressFromContact.

@eileenmcnaughton
Copy link
Contributor

@yashodha this looks like a nice clean up! Yay + double yay.

I think we should probably sync the approach here with that in the extended report extension since we are cleaning up. I had been porting a few of the approaches I use in that extension to core over time but it takes a little co-ordination because if the signature changes in core I have to change it in extended report ( I try to just remove the function & rely on core where I can)

In extended report I use the following:

  /**
  * Add join from contact table to email.
   *
   * Prefix will be added to both tables as it's assumed you are using it to get address of a secondary contact.
   *
   * @param string $prefix
  *  @param array $extra Additional options.
  *      Not currently used in core but may be used in override extensions.
   */
  protected function joinEmailFromContact($prefix = '', , $extra = array()) {

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

The differences are the parameters that are passed in & the function name. Because I have similar functions for a lot of joins I use the pattern Join...From - since there might also be a join to email from LocationBlock.

Passing in $prefix permits 2 joins to email table (from contact a & from contact b). The $extra array is a relatively recent one & I haven't used it much but I think for a standard pattern it's better to have it - it might be used to indicate 'is_primary_only' = FALSE in the above for a report that wants all addresses returned.

{$this->_aliases['civicrm_phone']}.is_primary = 1 ";
}
$this->addPhoneFromClause();
$this->addEmailFromClause()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a ; here @yashodha

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 : fixed

@eileenmcnaughton
Copy link
Contributor

test errors are on the contact/detail report

@yashodha
Copy link
Contributor Author

@eileenmcnaughton : the functions now have parameters in the same format.

@eileenmcnaughton
Copy link
Contributor

Thanks @yashodha - are you OK changing the names too? I think it is clearer saying what table it's coming from

@yashodha
Copy link
Contributor Author

yashodha commented Feb 9, 2018

@eileenmcnaughton yes, sure!

@yashodha
Copy link
Contributor Author

test this please

1 similar comment
@yashodha
Copy link
Contributor Author

test this please

@yashodha
Copy link
Contributor Author

@eileenmcnaughton : made the changes

@yashodha
Copy link
Contributor Author

yashodha commented Mar 5, 2018

test this please

1 similar comment
@eileenmcnaughton
Copy link
Contributor

test this please

* @param array $extra Additional options.
* Not currently used in core but may be used in override extensions.
*/
public function joinCountryFromClause($prefix = '', $extra = array()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to joinCountryFromAddressClause

public function addPhoneFromClause() {
// include address field if address column is to be included
if ($this->isTableSelected('civicrm_phone')) {
public function joinPhoneFromClause($prefix = '', $extra = array()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change to joinPhoneFromContactClause

* @param array $extra Additional options.
* Not currently used in core but may be used in override extensions.
*/
public function joinEmailFromClause($prefix = '', $extra = array()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change to joinEmailFromContactClause

@eileenmcnaughton
Copy link
Contributor

@yashodha there are a few minor things here + it needs squashing. I'm going to squash & put up in an alternate PR with the tweaks. You can then check my reviewers cut is still good & merge

@eileenmcnaughton
Copy link
Contributor

I'm closing this in favour of #11814 which is a reviewer's cut of it - note that since that is very big I have started to split off chunks of a few reports so that someone can spend 15-20 minutes testing & confirm a chunk - currently #11867

@eileenmcnaughton
Copy link
Contributor

Closing this in favour of #11814 which is a reviewer's cut of this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants