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 »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Views should include primary contact info only?
Pages: [1]

Author Topic: Views should include primary contact info only?  (Read 546 times)

civicrmsav

  • I post frequently
  • ***
  • Posts: 121
  • Karma: 5
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7.x
Views should include primary contact info only?
June 11, 2014, 09:23:07 pm
This is a possible feature request and a note for others who may want to go down this path.  If there's a better/easier way to do this, I'd love to know it.

Using Views to generate a list of participants, I want to show all participants along with their primary contact information (address, phone, email).  I found however, that by default views shows all the contact info - so both home and billing emails for example.   You can't just use views to filter "is_primary= false" because then if a contact doesn't happen to have any email at all their participation is completely filtered out.

Instead I modified the joins to bring in only the primary contact information in the first place.  Specifically, in civicrm.core.inc I added "'extra' => 'civicrm_phone.is_primary=1'" in each relevant place, for example ...

  //CiviCRM Phone Using Contacts as a pitstop before going on to Participants
  $data['civicrm_phone']['table']['join']['civicrm_participant'] = array(
    'left_table' => 'civicrm_contact
    'left_field' => 'id',
    'field' => 'contact_id',
    'table' => 'civicrm_phone',
    'extra' => 'civicrm_phone.is_primary=1'
  );


Unfortunately, I couldn't get this to work out of the box with views (I'm in drupal 7, views 3, civicrm 4.4.5).   This could very well be something I'm doing wrong with the syntax of the 'extra' line, but the only way I could get it to work was to add some code to  views/includes/handlers.inc.

function build_join($select_query, $table, $view_query) {
  //add this code
  if(isset($this->extra)){
        $this->extra = $this->definition['extra'];
     }

Without that, no matter how I set the extra, I couldn't get it to appear in the join.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Views should include primary contact info only?
June 11, 2014, 10:24:06 pm
sounds like you are doing this the hard way

in the Views field, there should be the options to specify if you want to select Home, or Primary, etc.
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Fabian_SYSTOPIA

  • I post occasionally
  • **
  • Posts: 74
  • Karma: 3
  • CiviCRM version: 4.3.x, 4.4.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.4.10
  • PHP version: 5.4.10
Re: Views should include primary contact info only?
June 11, 2014, 11:46:49 pm
Hi,

as Pete said, there are options to select, which Adress Type to use (see screenshot attached). You should find these options when you click on an address field in your view.

We are running Drupal 7 and CiviCRM 4.4.4 - however, it should also be availabe for other versions.

Best Regards
Fabian

civicrmsav

  • I post frequently
  • ***
  • Posts: 121
  • Karma: 5
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7.x
Re: Views should include primary contact info only?
June 12, 2014, 05:31:17 am
Doh.   I see it now, the section is collapsed by default and when added the field I passed by it without noticing it, then went about trying to solve the problem with filters etc and never went back to the field definition. 

Well, now I know more about views under the hood than I did before ;)   I guess I'd propose that either this be defaulted to primary being checked, or at least expanded by default, but obviously this problem is mostly PEBCAK. 

Thanks folks.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Views should include primary contact info only?

This forum was archived on 2017-11-26.