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 Drupal Modules (Moderator: Donald Lobo) »
  • Drupal Views integration
Pages: [1]

Author Topic: Drupal Views integration  (Read 9288 times)

Alan.Guggenheim

  • Guest
Drupal Views integration
March 03, 2010, 10:48:09 am
I found the following in the documenation:
Some tips and tricks for integrating Views2 and CiviCRM

•If your CiviCRM install uses a different database to your Drupal install, ensure that your Drupal DB user has SELECT rights to your CiviCRM DB. Some hosting platforms might make this difficult. For more information about setting up Drupal multi-database access: http://drupal.org/node/18429
•You will need to set database prefixes in your Drupal settings.php file so that Views2 can access your CiviCRM DB. The prefixes can be seen on a url like: http://drupal.demo.civicrm.org/civicrm/admin/setting/uf?reset=1. You will need to have Views2 enabled to see those settings. Important: You will have to update your settings.php with new prefixes every time you add new Custom Field Group.  Also, after making changes in civicrm you should clear Drupal's view cache at:  Administer › Site building › Views › Tools and press "Clear Views cache".
•If you have CiviCRM and Drupal installed on the same database, and drupal tables are prefixed, you might receive an error in your views saying table does not exist, if this happens, you need to alter your drupal sites/default/settings.php file.  find the part that says $db_prefix = 'drupal_'; and change it to this: $db_prefix = array ('default'=>'drupal_','civicrm_event'=>'','civicrm_activity'=>'','civicrm_contact'=>'','civicrm_address'=>'','civicrm_contribution'=>'');  NOTE: your prefix may be something other then drupal_, just replace drupal_ with whatever prefix you have configured.
•If the above steps dont work for you or your drupal/civicrm db's have a different user name/password, try this recipe from andrew: CiviCRM Views 2 integration with a remote CiviCRM database

The problem is that it does not say what to do:
Can we have a simple procedure and an example of settings.php that works?

When I try to see the civicrm/admin/setting/uf&reset=1 link, it shows me Drupal version 6.15 and Drupal users table name : users, but I thought it should show me the civicrm tables linked to the custom fields and custom groups?

mhm

  • I post occasionally
  • **
  • Posts: 82
  • Karma: 2
Re: Drupal Views integration
March 08, 2010, 06:43:53 pm
Yes, it should be showing you something like this:
Code: [Select]
Views integration settings
To enable CiviCRM Views integration, add the following to the site settings.php file:

$db_prefix = array(
  'civicrm_acl'                              => 'civcrm.',
  'civicrm_acl_cache'                        => 'civcrm.',
  'civicrm_acl_contact_cache'                => 'civcrm.',
  'civicrm_acl_entity_role'                  => 'civcrm.',
  'civicrm_activity'                         => 'civcrm.',
  'civicrm_activity_assignment'              => 'civcrm.',
  'civicrm_activity_target'                  => 'civcrm.',
  'civicrm_address'                          => 'civcrm.',
  'civicrm_cache'                            => 'civcrm.',
  'civicrm_case'                             => 'civcrm.',
  'civicrm_case_activity'                    => 'civcrm.',
  'civicrm_case_contact'                     => 'civcrm.',
  'civicrm_component'                        => 'civcrm.',
  'civicrm_contact'                          => 'civcrm.',
  'civicrm_contact_type'                     => 'civcrm.',
  'civicrm_contribution'                     => 'civcrm.',
  'civicrm_contribution_page'                => 'civcrm.',
  'civicrm_contribution_product'             => 'civcrm.',
  'civicrm_contribution_recur'               => 'civcrm.',
  'civicrm_contribution_soft'                => 'civcrm.',
  'civicrm_contribution_type'                => 'civcrm.',
  'civicrm_contribution_widget'              => 'civcrm.',
  'civicrm_country'                          => 'civcrm.',
  'civicrm_county'                           => 'civcrm.',
  'civicrm_currency'                         => 'civcrm.',
  'civicrm_custom_field'                     => 'civcrm.',
  'civicrm_custom_group'                     => 'civcrm.',
  'civicrm_dashboard'                        => 'civcrm.',
  'civicrm_dashboard_contact'                => 'civcrm.',
  'civicrm_dedupe_rule'                      => 'civcrm.',
  'civicrm_dedupe_rule_group'                => 'civcrm.',
  'civicrm_discount'                         => 'civcrm.',
  'civicrm_domain'                           => 'civcrm.',
  'civicrm_email'                            => 'civcrm.',
  'civicrm_entity_file'                      => 'civcrm.',
  'civicrm_entity_tag'                       => 'civcrm.',
  'civicrm_event'                            => 'civcrm.',
  'civicrm_file'                             => 'civcrm.',
  'civicrm_financial_trxn'                   => 'civcrm.',
  'civicrm_grant'                            => 'civcrm.',
  'civicrm_group'                            => 'civcrm.',
  'civicrm_group_contact'                    => 'civcrm.',
  'civicrm_group_contact_cache'              => 'civcrm.',
  'civicrm_group_nesting'                    => 'civcrm.',
  'civicrm_group_organization'               => 'civcrm.',
  'civicrm_im'                               => 'civcrm.',
  'civicrm_import_job_c2f1dcd8ff0a7d94af7b89f6fef53a4d' => 'civcrm.',
  'civicrm_line_item'                        => 'civcrm.',
  'civicrm_loc_block'                        => 'civcrm.',
  'civicrm_location_type'                    => 'civcrm.',
  'civicrm_log'                              => 'civcrm.',
  'civicrm_mail_settings'                    => 'civcrm.',
  'civicrm_mailing'                          => 'civcrm.',
  'civicrm_mailing_bounce_pattern'           => 'civcrm.',
  'civicrm_mailing_bounce_type'              => 'civcrm.',
  'civicrm_mailing_component'                => 'civcrm.',
  'civicrm_mailing_event_bounce'             => 'civcrm.',
  'civicrm_mailing_event_confirm'            => 'civcrm.',
  'civicrm_mailing_event_delivered'          => 'civcrm.',
  'civicrm_mailing_event_forward'            => 'civcrm.',
  'civicrm_mailing_event_opened'             => 'civcrm.',
  'civicrm_mailing_event_queue'              => 'civcrm.',
  'civicrm_mailing_event_reply'              => 'civcrm.',
  'civicrm_mailing_event_subscribe'          => 'civcrm.',
  'civicrm_mailing_event_trackable_url_open' => 'civcrm.',
  'civicrm_mailing_event_unsubscribe'        => 'civcrm.',
  'civicrm_mailing_group'                    => 'civcrm.',
  'civicrm_mailing_job'                      => 'civcrm.',
  'civicrm_mailing_spool'                    => 'civcrm.',
  'civicrm_mailing_trackable_url'            => 'civcrm.',
  'civicrm_mapping'                          => 'civcrm.',
  'civicrm_mapping_field'                    => 'civcrm.',
  'civicrm_membership'                       => 'civcrm.',
  'civicrm_membership_block'                 => 'civcrm.',
  'civicrm_membership_log'                   => 'civcrm.',
  'civicrm_membership_payment'               => 'civcrm.',
  'civicrm_membership_status'                => 'civcrm.',
  'civicrm_membership_type'                  => 'civcrm.',
  'civicrm_menu'                             => 'civcrm.',
  'civicrm_msg_template'                     => 'civcrm.',
  'civicrm_navigation'                       => 'civcrm.',
  'civicrm_note'                             => 'civcrm.',
  'civicrm_openid'                           => 'civcrm.',
  'civicrm_openid_associations'              => 'civcrm.',
  'civicrm_openid_nonces'                    => 'civcrm.',
  'civicrm_option_group'                     => 'civcrm.',
  'civicrm_option_value'                     => 'civcrm.',
  'civicrm_participant'                      => 'civcrm.',
  'civicrm_participant_payment'              => 'civcrm.',
  'civicrm_participant_status_type'          => 'civcrm.',
  'civicrm_payment_processor'                => 'civcrm.',
  'civicrm_payment_processor_type'           => 'civcrm.',
  'civicrm_pcp'                              => 'civcrm.',
  'civicrm_pcp_block'                        => 'civcrm.',
  'civicrm_phone'                            => 'civcrm.',
  'civicrm_pledge'                           => 'civcrm.',
  'civicrm_pledge_block'                     => 'civcrm.',
  'civicrm_pledge_payment'                   => 'civcrm.',
  'civicrm_preferences'                      => 'civcrm.',
  'civicrm_preferences_date'                 => 'civcrm.',
  'civicrm_premiums'                         => 'civcrm.',
  'civicrm_premiums_product'                 => 'civcrm.',
  'civicrm_price_field'                      => 'civcrm.',
  'civicrm_price_set'                        => 'civcrm.',
  'civicrm_price_set_entity'                 => 'civcrm.',
  'civicrm_product'                          => 'civcrm.',
  'civicrm_project'                          => 'civcrm.',
  'civicrm_relationship'                     => 'civcrm.',
  'civicrm_relationship_type'                => 'civcrm.',
  'civicrm_report_instance'                  => 'civcrm.',
  'civicrm_saved_search'                     => 'civcrm.',
  'civicrm_state_province'                   => 'civcrm.',
  'civicrm_subscription_history'             => 'civcrm.',
  'civicrm_tag'                              => 'civcrm.',
  'civicrm_task'                             => 'civcrm.',
  'civicrm_task_status'                      => 'civcrm.',
  'civicrm_tell_friend'                      => 'civcrm.',
  'civicrm_timezone'                         => 'civcrm.',
  'civicrm_uf_field'                         => 'civcrm.',
  'civicrm_uf_group'                         => 'civcrm.',
  'civicrm_uf_join'                          => 'civcrm.',
  'civicrm_uf_match'                         => 'civcrm.',
  'civicrm_value_member_data_1'              => 'civcrm.',
  'civicrm_worldregion'                      => 'civcrm.',
);

I think I ultimately had to follow Andrew's procedure to get this all working.
It took me awhile, but I just had to dedicate some time to work through each possible procedure until it worked (I'm guessing this is why there's not one simple here's-how-to-do-it listing -- I think there are various ways based on your setup, and your host).

Alan.Guggenheim

  • Guest
Re: Drupal Views integration
March 16, 2010, 08:14:05 am
Thanks. I did update my profile, but it did not change the views fields: I still see what I was seing before: CiviCRM Address, Contacts, Email Member, Phone details, relationships, but not the custom data fields I need.
Any idea?

mhm

  • I post occasionally
  • **
  • Posts: 82
  • Karma: 2
Re: Drupal Views integration
March 16, 2010, 05:59:21 pm
What are the types of custom data fields? I have a problem with images showing up (i.e., it shows a number probably referring to the image, but won't show the image itself), but my other custom data fields are fine.

Alan.Guggenheim

  • Guest
Re: Drupal Views integration
March 20, 2010, 11:21:09 am
Interesting, they are mostly text custom fields: name, address, occupation, skills, activities,...

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Drupal Views integration
March 20, 2010, 01:29:23 pm
Hi Alan,

Are you just trying to get 'contact' custom fields to show? & the core fields show but no error?

Is the specific custom value table in your settings.php as described e.g

 
Code: [Select]
'civicrm_value_member_data_1'              => 'civicrm.',
I'm also finding that on several sites I no longer see the tables showing at that url - it doesn't stop it from working if they are in settings.php though.

nb - your profile says 3.2 for CiviCRM so you are more than up-to-date but I would note for other readers that views handling of custom fields improves substantially between 3.0 & 3.1
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

Alan.Guggenheim

  • Guest
Re: Drupal Views integration
March 21, 2010, 08:57:12 am
Eileen,
Yes, I need 'contact' and 'individual' specific fields to show (I have created groups in CiviCRM first, where people can select on their profile what activity they are interested in). I have the corresponding groups in OG (Organic Groups) in Drupal, and I need to produce views in Drupal with information from CiviCRM because the integration/sync is not working very well and is mostly one way Drupal--> CiviCRM, not the other way around. The core fields show indeed (for example, CiviCRM Contact shows birthdate, ContactID,...)
The specific tables I need are defined in my settings.php as:
'civicrm_value_skills_2'                   => 'civcrm.',
'civicrm_value_system_4'                   => 'civcrm.',
'civicrm_value_volunteer_interest_3'       => 'civcrm.',
and i got the list of tables directly from MySQL.
I do not have a civicrm_value_member_data_1 table

nb: my profile had a typo... I am actually running 3.1.3 for CiviCRM. 3.2 is for ckeditor...

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Drupal Views integration
March 21, 2010, 11:46:55 am
No, that table name was an example BUT

'civicrm_value_volunteer_interest_3'       => 'civcrm.',

Assuming your database really is spelt like that it should probably be

'civicrm_value_volunteer_interest_3'       => 'civcrm.civicrm_',

There's an e.g. from one of our files here
http://forum.civicrm.org/index.php/topic,12802.msg55359.html#msg55359



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

Alan.Guggenheim

  • Guest
Re: Drupal Views integration
March 21, 2010, 12:15:09 pm
Eileen, thanks for your help, but there is still some confusion between database name and table name.

if my MySQL database name is : home_db
I use one database for all the tables (Drupal, civicrm,...)

examples of table names are:
access
acl
blocks
civicrm_acl
civicrm_acl-cache
...
(all my civicrm table have the civicr_ prefix in their name)
...

node

node_access

...

so now what should be in the array?

'civicrm_value_volunteer_interest_3'       => 'civicrm_',
'civicrm_value_volunteer_interest_3'       => 'home_db.civicrm_',
'civicrm_value_volunteer_interest_3'       => 'home_db',

or something else? obviously php and drupal know already about the nemae of the database by the $db_Url array, so what should the "prefix" be?
Thanks

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Drupal Views integration
March 21, 2010, 01:37:22 pm
OK, so if they are all in the same database & there are no prefixes added  ... did you actually try it without putting anything in settings.php?

I just checked and I only needed to put that entry in where either the drupal tables are prefixed or in a different database. ie if the query


Have you gotten to the point of having an error or are you just trying to figure out the steps
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

Alan.Guggenheim

  • Guest
Re: Drupal Views integration
March 21, 2010, 02:04:02 pm
Yes, I did try without anything, and I just tried all the combinations I proposed. After quite a lot of testing, it looks like

1- In Views, I can create a view with types CiviCRM Contacts and there my Custom data fields are available, but none of the Drupal user fields.
2- If I create a view with type "user", I see fields from the CiviCRM types of Address, Contacts, Email, Member, phone Detail, Relationship and in each of these categories, the fields that are defined by default in CiviCRM, but none of my fields defined in Custom data in CiviCRM and used in profiles

We are getting close, but still not able to generate the views I need with data from Drupal (Username, email, OG membership) and CiviCRM (custom data fields)

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: Drupal Views integration
March 21, 2010, 07:41:29 pm

if i had to guess, its probably the integration code not exposing custom data in relationship mode or something like that.

Your best bet might be to dive into the views integration code here: /drupal/modules/views and figure out whats happening and why

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

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Drupal Views integration
September 22, 2011, 03:11:29 pm
I realize this is an old topic but I'm dredging up past issues with a Drupal/civiCRM website and I didn't want to complicate things by adding another thread about the same issue.

@Alan.Guggenheim: Did you manage to successfully expose the data you wanted to access in Views?

We had a similar need and failing any other options we modified a file in Views to achieve that.

File: views/includes/view.inc
Line: 739/740

Right after $start = views_microtime();

We change the $query and $count query replacing "{users}" with "drupal-database-name.users" by adding the following two lines of code:
Code: [Select]
$query = str_replace("{users}", "databasename_drupal.users", $query);
$count_query = str_replace("{users}", "databasename_drupal.users", $count_query);

We also have provided Drupal with information about our civiCRM database in settings.php

Code: [Select]
$db_url['default'] = 'mysql://username:password@localhost/databasename_drupal';
$db_url['civicrm'] = 'mysql://username:password@localhost/databasename_civicrm';

This does expose the fields we are looking for filtering our results for but it is difficult to maintain for updates and sometimes the view crashes and returns a results page that ignores all of the filters. I am looking for a better solution. This solution was used with civiCRM 3.1 and now we are on civiCRM 3.4.5.

Is there a recommended method to expose civiCRM Data and particularly Contact and Custom data related to the individual contacts?

Thanks,
Andrew   
« Last Edit: September 22, 2011, 03:13:59 pm by awasson »
My CiviCRM Extension Workshop: https://github.com/awasson

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Drupal Views integration
September 23, 2011, 09:40:35 am
Well, not to beat this topic to a pulp but I've identified a problem with Views 2 integration and civiCRM 3.4.5 in my Drupal site.

I removed my hack from views/includes/view.inc and added my database mappings that I identified at my-site/civicrm/admin/setting/uf?reset=1

  • Then I created a new view with the View Type set to "CiviCRM Contacts".
  • Then I simply added a single field of CiviCRM Contacts: Display Name and everything lists out just fine.
  • As soon as I add the relationship CiviCRM Contacts: Drupal ID it stops working.

Is this a bug and is there a resolution? I am running Drupal 6.22, Views 6.x-2.12, civiCRM 3.4.5

Thanks,
Andrew

EDIT: Sorry, I forgot to paste the logged error. I checked my recent log and found the following error:

Table 'my-database_civicrm.users' doesn't exist

I have two databases: my-database_civicrm and mydatabase_drupal. I think instead of trying to run the query with a join to my-database_drupal.users, it is trying to run the query against my-database_civicrm.users.

Here's the full error:
Quote
Table 'my-database_civicrm.users' doesn't exist query: SELECT civicrm_contact.id AS id, civicrm_contact.display_name AS civicrm_contact_display_name FROM `my-database_civicrm`.civicrm_contact civicrm_contact LEFT JOIN `my-database_civicrm`.civicrm_uf_match civicrm_uf_match ON civicrm_contact.id = civicrm_uf_match.contact_id LEFT JOIN users users_civicrm_uf_match ON civicrm_uf_match.uf_id = users_civicrm_uf_match.uid LIMIT 0, 10 in /home/my-database/public_html/bcpa/sites/all/modules/views/includes/view.inc on line 775.

Any ideas?
« Last Edit: September 23, 2011, 09:54:03 am by awasson »
My CiviCRM Extension Workshop: https://github.com/awasson

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Drupal Views integration
September 23, 2011, 05:06:54 pm
Do you ever get the feeling you're just talking to yourself?

Well, I found something kind of neat this morning... If I follow the instructions on the Views 2 Integration page and modify my settings.php file accordingly I can not make a "CiviCRM Contacts" view and create a relationship between the civiCRM Contact record and a Drupal User ID... It just won't work; end of sentence.

However, if I make a Drupal "User" view then I can access all of the civiCRM fields I need to without creating a relationship between Contacts & Users. I must have the changes to the settings.php file in place for this to work.

Initially I thought I would have to create a "CiviCRM Contacts" view because the fields I am returning are 99% civiCRM Contact data. The only user field I need is the user name that links to their profile page.

I hope this helps out someone who is in the same boat.

Cheers,
Andrew

« Last Edit: September 23, 2011, 05:08:46 pm by awasson »
My CiviCRM Extension Workshop: https://github.com/awasson

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Drupal Views integration

This forum was archived on 2017-11-26.