CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Replacing Country column in standard reports with custom field (Answered)
Pages: [1]

Author Topic: Replacing Country column in standard reports with custom field (Answered)  (Read 1449 times)

Denver Dave

  • Ask me questions
  • ****
  • Posts: 471
  • Karma: 9
Replacing Country column in standard reports with custom field (Answered)
March 26, 2009, 08:33:38 pm
The standard reports from a "Find Contacts" and also the standard Print report lists the Country as one of the column headings.  In our case, everyone is in one country to the information is not useful.  What would be involved in modifying the standard listing and print report to instead display one or two custom fields instead.  Fields like political house district.

Thanks.
« Last Edit: April 17, 2009, 09:19:03 pm by Denver Dave »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Replacing Country column in standard reports with custom field
March 27, 2009, 07:19:06 am

1. deleting country from the template is quite easy. Read the docs at:

http://wiki.civicrm.org/confluence/display/CRMDOC/Customize+Built-in,+Profile,+Contribution+and+Event+Registration+Screens

2. Have you tried using a profile to display the search results. Create a Contact Profile with the custom fields you want displayed. and then use that profile in the search view to display the results. Check:

http://drupal.demo.civicrm.org/civicrm/contact/search/advanced?reset=1

look at the select box in the upper right corner

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Denver Dave

  • Ask me questions
  • ****
  • Posts: 471
  • Karma: 9
Re: Replacing Country column in standard reports with custom field
April 09, 2009, 06:52:17 pm
The actual template that produces the print report is located at:
templates/CRM/Contact/Form/Tast/Print.tpl

where it is straight forward to eliminate columns, hrename headings and re-arrange columns.

However, there seems to be a result set $rows that is available to the template with the standard fields.  Where is $rows calculated and can it be modified to include custom fields?

Instead of Country, we would really like to have the custom fields for house district, senate district and congressional district displayed.  I would think this would be useful for many advocacy organizations like www.HealthCareForAllColorado.org

Thank you.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Replacing Country column in standard reports with custom field
April 10, 2009, 07:56:11 am

It will require some amount of code changes to the core query code to add custom fields. CRM/Contact/BAO/Query.php, add the custom fields that you need to: defaultReturnProperties

you can also use a "a search view" profile to display only the fields that you are intersted in. So create a profile with name, address, house district, senate district and congressional district and then select that profile in advanced search (upper right hand corner)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Denver Dave

  • Ask me questions
  • ****
  • Posts: 471
  • Karma: 9
Re: Replacing Country column in standard reports with custom field
April 11, 2009, 05:31:14 pm
A little more on what's where

= = = = = = = == = = = = == =
The Find Contacts output
drupal/sites/all/modules/civicrm/CRM/Contact/Selector.php 
set's column headers

drupal/sites/all/modused/civicrm/templates/CRM/Contact/Form/Selector.tpl
sets detail line values (v 1.9 about line 76)
also script for hacked easy edit navigation

Thnk the script for the detail is:
civicrm/CRM/Contact/BAO/Query.php
But I'm not sure

= = = = = = = = = = = = =

The actual output from the print button
drupal/sites/all/modules/civicrm/templates/CRM/Contact/Form/Task/Print.tpl
Print header (v. 1.9 about line 22)
Print detail (v. 1.9 about line 43)

Quite the dungeons and dragons to get this far and am able to manually code a fixed text string in the column header and detail lines for both reports.

= = = = = = = = = = =

Anyone else interested in modifying the standard output.  We never use Country and would very much like to have a custom field available to all users the county field place.  Our case political districts.

= = = = = == = = = = = =

/www/drupal/sites/all/modules/civicrm/CRM/Contact/BAO/Query.php 
About line 2372 v 1.9

    static function &defaultReturnProperties( $mode = 1 ) {
        if ( ! isset( self::$_defaultReturnProperties ) ) {
            self::$_defaultReturnProperties = array( );
        }

        if ( ! isset( self::$_defaultReturnProperties[$mode] ) ) {
            require_once 'CRM/Core/Component.php';
            self::$_defaultReturnProperties[$mode] = CRM_Core_Component::defaultReturnProperties( $mode );

            if ( empty( self::$_defaultReturnProperties[$mode] ) ) {
                self::$_defaultReturnProperties[$mode] = array(
                                                               'home_URL'               => 1,

= = = = = = =
Objective to have values as part of the $rows array used by the template, but not sure where this is populated.

Denver Dave

  • Ask me questions
  • ****
  • Posts: 471
  • Karma: 9
Re: Replacing Country column in standard reports with custom field
April 15, 2009, 10:07:14 pm
OK - found where $row is assigned.  In v 1.9 - Selector.php about line 594 for the find listing and is also used for the print button listing.

                $row['contact_type'] = $contact_type;
                $row['contact_id'  ] = $result->contact_id;
                $row['sort_name'   ] = $result->sort_name;

// davehack
            //$row['district'] = 'cccccc<br>99-88-7';
            $row['district'] = $result->district;
// end davehack   

Of course, since each contact will have different values, will have to now track back the $result - so ...

In Query.php about line 455 I've tried to create a value

// davehack
                            if ($name == 'district') {
                                $this->_select [$name] = "'test5' as `$name`";
                                $this->_element['district'] = 1;
                            }
// enddavehack

I was hoping the above would create a field named district with a value of 'test5', don't seem to be there yet.  And later figure out how to pull in custom field {contact.custom_28}

Tips?
« Last Edit: April 16, 2009, 06:54:52 pm by Denver Dave »

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Replacing Country column in standard reports with custom field
April 16, 2009, 07:00:28 pm
I have just lifted this from somewhere  - not tested but this might be a pointer

 $customfields = CRM_Core_BAO_CustomValueTable::getEntityValues($contactID );
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Replacing Country column in standard reports with custom field
April 16, 2009, 07:02:18 pm
nb - this will return an array of all custom fields for that id - might need to filter it & comma separate it if multiple value fields are likely to be there
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Denver Dave

  • Ask me questions
  • ****
  • Posts: 471
  • Karma: 9
Re: Replacing Country column in standard reports with custom field
April 17, 2009, 09:18:46 pm
Thanks Eileen - got us looking in a more productive area and thank you to Colin O'Connor for knowing how to apply the ideas.  Here is the solution that works for us under v 1.9

Hope this helps someone else - seems like for those with important custom fields, it might be very useful:

IN
/www/drupal/sites/all/modules/civicrm/CRM/Contact/Selector.php
 
// davehack
// custom_10, custom_11, custom_17 - districts
// custom_28 - CO County Name
 
    static $_properties = array('contact_id', 'contact_type', 'contact_sub_type',
                                'sort_name', 'street_address',
                                'city', 'state_province', 'postal_code', 'country',
                                'geo_code_1', 'geo_code_2',
                                'email', 'on_hold', 'phone', 'status', custom_10, custom_11, custom_17, custom_28 );
 
ALSO IN SAME SCRIPT
// *** davehack ***
    $row['custom_10'] = CRM_Core_BAO_CustomField::getDisplayValue($row['custom_10'], 2, $this->_query->_options);
    $row['custom_11'] = CRM_Core_BAO_CustomField::getDisplayValue($row['custom_11'], 2, $this->_query->_options);
    $row['custom_17'] = CRM_Core_BAO_CustomField::getDisplayValue($row['custom_17'], 2, $this->_query->_options);
    $row['custom_28'] = CRM_Core_BAO_CustomField::getDisplayValue($row['custom_28'], 2, $this->_query->_options);
// *** end davehack ***
 
ALSO IN SAME SCRIP
    private static function &_getColumnHeaders()
    {
  //davehack - change country column heading to political districts
                                          array(
                                                'name'      => ts('County<br>HD-SD-C'),
                                                'sort'      => 'county',
                                              'direction' => CRM_Utils_Sort::DONTCARE,
                                                ),
 
IN
/www/drupal/sites/all/modules/civicrm/CRM/Contact/BAO/Query.php
 
// *** davehack ***
// add custom fields to the array below
'custom_10'              => 1,
'custom_11'              => 1,
'custom_17'              => 1,   
'custom_28'              => 1,
 
IN
/www/drupal/sites/all/modules/civicrm/templates/CRM/Contact/Form/Selector.tpl
<td>{$row.custom_28}<br>{$row.custom_10}-{$row.custom_11}-{$row.custom_17}</td>
 
IN
/www/drupal/sites/all/modules/civicrm/templates/CRM/Contact/Form/Task/Print.tpl
<th>{ts}County<br>HD-SD-C{/ts}</th>
 
And also in same script
<td>{$row.custom_28}<br>{$row.custom_10}-{$row.custom_11}-{$row.custom_17}</td>


« Last Edit: April 17, 2009, 09:20:20 pm by Denver Dave »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Replacing Country column in standard reports with custom field (Answered)

This forum was archived on 2017-11-26.