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

dev/core#2684 Fix filters tpl in civi reports to permit more than one table in a grouping #20820

Merged
merged 1 commit into from
Jul 16, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jul 9, 2021

Overview

This fixes the handling of 'grouping' in civireport table definition to do what it was seemingly intended to do - but didn't

Before

If you attempt to assign more than one table to the same 'Grouping' in the report you wind up with duplicate accordians rather than one accordian with one header & both tables in it . You can also wind up with broken html in some cases

repeat

After

In this example the Contact, phone and email tables are all grouped as 'contact'. Note the PR doesn't make this change to any core reports - but this PR in extended reports uses it eileenmcnaughton/nz.co.fuzion.extendedreport#490

better -

Technical Details

In 'classic' CiviCRM fashion we were assigning an array of 'filterGroupings' and separately an array or filters and trying to cross reference them in the tpl layer to figure out when to open and close the accordians. This switched to only using the 'filterGroupings' array and adding the values from the 'filters' array into that array at the php layer - leaving a single iteration at the tpl layer

Comments

To test this make the below changes - note I'm not including this change or any change that actually changes output in this patch (and I don't necessarily see us changing any core reports) - but by applying the patch it can be seen the filters can be directed to go in an accordion

image

--- a/CRM/Report/Form/Contribute/Detail.php
+++ b/CRM/Report/Form/Contribute/Detail.php
@@ -77,6 +77,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
         'fields_required' => ['id'],
         'filters_defaults' => ['is_deleted' => 0],
         'no_field_disambiguation' => TRUE,
+        'grouping' => 'contact-fields',
+        'group_title' => ts('Contact fields'),
       ]),
       [
:
         'filters_defaults' => ['is_deleted' => 0],
         'no_field_disambiguation' => TRUE,
+        'grouping' => 'contact-fields',
+        'group_title' => ts('Contact fields'),
       ]),
       [
         'civicrm_email' => [
:
         'filters_defaults' => ['is_deleted' => 0],
         'no_field_disambiguation' => TRUE,
+        'grouping' => 'contact-fields',
+        'group_title' => ts('Contact fields'),
       ]),
       [
         'civicrm_email' => [
@@ -253,7 +255,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
:
         'filters_defaults' => ['is_deleted' => 0],
         'no_field_disambiguation' => TRUE,
+        'grouping' => 'contact-fields',
+        'group_title' => ts('Contact fields'),
       ]),
       [
         'civicrm_email' => [
@@ -253,7 +255,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
               'title' => ts('Contribution'),
:
         'filters_defaults' => ['is_deleted' => 0],
         'no_field_disambiguation' => TRUE,
+        'grouping' => 'contact-fields',
+        'group_title' => ts('Contact fields'),
       ]),
       [
         'civicrm_email' => [
@@ -253,7 +255,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
               'title' => ts('Contribution'),
             ],
:
         'filters_defaults' => ['is_deleted' => 0],
         'no_field_disambiguation' => TRUE,
+        'grouping' => 'contact-fields',
+        'group_title' => ts('Contact fields'),
       ]),
       [
         'civicrm_email' => [
@@ -253,7 +255,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
               'title' => ts('Contribution'),
             ],
           ],
:
         'filters_defaults' => ['is_deleted' => 0],
         'no_field_disambiguation' => TRUE,
+        'grouping' => 'contact-fields',
+        'group_title' => ts('Contact fields'),
       ]),
       [
         'civicrm_email' => [
@@ -253,7 +255,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
               'title' => ts('Contribution'),
             ],
           ],
-          'grouping' => 'contri-fields',
:
         'filters_defaults' => ['is_deleted' => 0],
         'no_field_disambiguation' => TRUE,
+        'grouping' => 'contact-fields',
+        'group_title' => ts('Contact fields'),
       ]),
       [
         'civicrm_email' => [
@@ -253,7 +255,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
               'title' => ts('Contribution'),
             ],
           ],
-          'grouping' => 'contri-fields',
+          'grouping' => 'contribution-fields',
+          'group_title' => ts('Contribution fields')
         ],
         'civicrm_contribution_soft' => [
           'dao' => 'CRM_Contribute_DAO_ContributionSoft',
@@ -276,9 +279,11 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
               'title' => ts('Soft Credit'),
             ],
           ],
+          'grouping' => 'contribution-fields',
         ],
         'civicrm_financial_trxn' => [
           'dao' => 'CRM_Financial_DAO_FinancialTrxn',
+          'grouping' => 'contribution-fields',
           'fields' => [
             'card_type_id' => [
               'title' => ts('Credit Card Type'),
@@ -296,7 +301,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
         ],
         'civicrm_batch' => [
           'dao' => 'CRM_Batch_DAO_EntityBatch',
-          'grouping' => 'contri-fields',
+          'grouping' => 'contribution-fields',
           'fields' => [
             'batch_id' => [
               'name' => 'batch_id',
@@ -316,6 +321,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
         'civicrm_contribution_ordinality' => [
           'dao' => 'CRM_Contribute_DAO_Contribution',
           'alias' => 'cordinality',
+          'grouping' => 'contribution-fields',
           'filters' => [
             'ordinality' => [
               'title' => ts('Contribution Ordinality'),
@@ -330,6 +336,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
         ],
         'civicrm_note' => [
           'dao' => 'CRM_Core_DAO_Note',
+          'grouping' => 'contribution-fields',
           'fields' => [
             'contribution_note' => [
               'name' => 'note',
@@ -347,6 +354,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
         ],
         'civicrm_pledge_payment' => [
           'dao' => 'CRM_Pledge_DAO_PledgePayment',
+          'grouping' => 'contribution-fields',
           'fields' => [
             'pledge_id' => [
               'title' => ts('Pledge ID'),
@@ -360,7 +368,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
           ],
         ],
       ],
-      $this->getColumns('Address')
+      $this->getColumns('Address', ['grouping' => 'contact-fields'])
     );
     // The tests test for this variation of the sort_name field. Don't argue with the tests :-).
     $this->_columns['civicrm_contact']['fields']['sort_name']['title'] = ts('Donor Name');

@civibot
Copy link

civibot bot commented Jul 9, 2021

(Standard links)

@civibot civibot bot added the master label Jul 9, 2021
eileenmcnaughton added a commit to eileenmcnaughton/nz.co.fuzion.extendedreport that referenced this pull request Jul 9, 2021
@eileenmcnaughton
Copy link
Contributor Author

test this please

@demeritcowboy
Copy link
Contributor

So far so good, just noticing it does seem to rearrange the filters on the contribution detail report, almost into virtual accordions. Not necessarily bad just checking it's all still working.

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy yeah - that's why I haven't added it to any core reports - it just is a way to see what it does

@demeritcowboy
Copy link
Contributor

I mean even without the additional patch for seeing the accordions, a stock install with this PR applied has different order/grouping of filters on that report.

@eileenmcnaughton
Copy link
Contributor Author

Hmm - the ordering should be according to the grouping key - else that key shouldn't be set. But we shouldn't be showing changes in the use or otherwise of accordions in core

{assign var="counter" value=1}
{foreach from=$filters item=table key=tableName}
Copy link
Contributor

@demeritcowboy demeritcowboy Jul 14, 2021

Choose a reason for hiding this comment

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

Minor thing: Because there's no more tableName, down on line 37/31 it doesn't like it. Also 42/36.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks - updated

@demeritcowboy
Copy link
Contributor

demeritcowboy commented Jul 14, 2021

I think it's ok function-wise it's just what it's doing is putting anything with a different 'grouping' key into its own <table>. It's easier to see if you also give the group a group_title. It happens in participant listing and others too. So there's a visual change but I'm personally ok with it.

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy yeah I believe that was the original intent of the 'grouping' parameter - it was just poorly implemented

@demeritcowboy
Copy link
Contributor

If you want to address the missing tableName above I'm ok to merge this.

@eileenmcnaughton
Copy link
Contributor Author

I think I fixed it

@demeritcowboy
Copy link
Contributor

jenkins retest this please

(api.v4.Action.CreateWithOptionGroupTest.testWithCustomDataForMultipleContacts)

@demeritcowboy
Copy link
Contributor

jenkins retest this please

This is a new one:

CRM_Core_DAOTest::testSqlModePresent
Failed asserting that an array contains 'ONLY_FULL_GROUP_BY'.

/home/jenkins/bknix-dfl/build/core-20820-5chgm/web/sites/all/modules/civicrm/tests/phpunit/CRM/Core/DAOTest.php:385

@eileenmcnaughton
Copy link
Contributor Author

Yeah - it's popping up a bit now thought!

@eileenmcnaughton
Copy link
Contributor Author

test this please

@eileenmcnaughton
Copy link
Contributor Author

Fail still seems unrelated but let's see what happens

api\v4\Action\CreateWithOptionGroupTest::testWithCustomDataForMultipleContacts
PEAR_Exception: DB Error: already exists

@eileenmcnaughton
Copy link
Contributor Author

Back to just the unrelated sqlmode failure

@eileenmcnaughton eileenmcnaughton merged commit b00ecc5 into civicrm:master Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants