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) »
  • Views 3 and Groups from CiviCRM
Pages: [1] 2

Author Topic: Views 3 and Groups from CiviCRM  (Read 6518 times)

NASACT

  • I post frequently
  • ***
  • Posts: 289
  • Karma: 9
    • National Association of State Auditors, Comptrollers and Treasurers
  • CiviCRM version: 4.2.2
  • CMS version: Drupal 7
  • MySQL version: 5.1.58 (ubuntu)
  • PHP version: 5.3.5
Views 3 and Groups from CiviCRM
July 27, 2012, 08:19:18 am
I am trying to get Views to filter based on Groups but I have tried using the "Name" and the "ID" values but I get SQLSTATE[42S22]: Column not found: 1054 Unknown column 'civicrm_contact.group' in 'where clause' no matter what value I put there.  ANy thoughts?  Thanks!
-AJ
My GChat - azon21@gmail.com -  This is where you can find me most days!

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Views 3 and Groups from CiviCRM
July 30, 2012, 01:47:24 am
A contact can be member of many groups, so there is no field civicrm_contact.group? You would have to look in the table civicrm_group_contact to see all groups for a contact.
I would recommend using the Webform - CiviCRM integration?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

NASACT

  • I post frequently
  • ***
  • Posts: 289
  • Karma: 9
    • National Association of State Auditors, Comptrollers and Treasurers
  • CiviCRM version: 4.2.2
  • CMS version: Drupal 7
  • MySQL version: 5.1.58 (ubuntu)
  • PHP version: 5.3.5
Re: Views 3 and Groups from CiviCRM
July 30, 2012, 07:14:07 am
Thanks, I will look into webform but I don't think that is going to help with filtering a Views criteria based on a specific group. Moreover I was looking on how to reference a group value in this instance as it forms the OpenLayers Data Layer for mapping members. Since I couldn't find a way to filter primary members only(mostly Orgs) I wanted to place those in a SmartGroup and then filter based on that group. Maybe I can't do either with the current state of Views integration?
-AJ
My GChat - azon21@gmail.com -  This is where you can find me most days!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Views 3 and Groups from CiviCRM
July 30, 2012, 11:38:32 am
I don't think views integration works with smart groups currently.
Try asking your question on the new CiviCRM help site.

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 3 and Groups from CiviCRM
July 30, 2012, 01:15:09 pm
Hold that thought - i think we just cracked this - can't see it in jira though - possible I am getting confused but will report back
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

torrance123

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 3
  • CiviCRM version: 4.0
  • CMS version: Drupal 7
  • MySQL version: 5.0.91
  • PHP version: 5.3.3
Re: Views 3 and Groups from CiviCRM
July 30, 2012, 07:43:51 pm
I created a small module that provided views access to smartgroup contacts. It's not strongly tested so I'd welcome more eyes. Ideally, this is something that should be merged into core's Drupal module if it works fine (and this would remove the need for the use of hook_views_data_alter(), as these changes could be made directly).

The special thing with the civicrm_group_contact_cache table that this views code uses is that it needs to be rebuilt from time to time on a per smartgroup basis. I've included some logic that checks the cache status if a particular view is using a simple 'group id equals xxx' filter. A little more logic could handle other operators such as greater than, between, etc.

Without a filter on the group id, I don't think this would be a very useful bit of code as we'd either have a stale cache or we'd have to check the status and possibly rebuild the cache for every smartgroup, which could be prohibitively expensive.

See attached module (removed the '.txt' suffix — I had to add this to upload the file).

Code: [Select]
function civicrm_views_smartgroups_views_handlers() {
  return array(
    'handlers' => array(
      'civicrm_handler_filter_group' => array(
        'parent' => 'views_handler_filter_numeric',
      ),
    ),
  );
}

function civicrm_views_smartgroups_views_data() {
  $data = array();
  $data['civicrm_group_contact_cache']['table']['group'] = t('CiviCRM Smartgroup');
  $data['civicrm_group_contact_cache']['table']['join']['civicrm_contact'] = array(
    'left_field' => 'id',
    'field' => 'contact_id',
  );

  return $data;
}

function civicrm_views_smartgroups_views_data_alter(&$data) {
  $data['civicrm_group']['id']['filter']['handler'] = 'civicrm_handler_filter_group';

  $data['civicrm_group']['table']['join']['civicrm_contact'] = array(
    'left_table' => 'civicrm_group_contact_cache',
    'left_field' => 'group_id',
    'field' => 'id',
  );
}

Code: [Select]
class civicrm_handler_filter_group extends views_handler_filter_numeric {
  function pre_query() {
    civicrm_initialize();
    require $GLOBALS['civicrm_root'] . '/CRM/Contact/BAO/GroupContactCache.php';
   
    if ($this->operator == '=') {
      CRM_Contact_BAO_GroupContactCache::check($this->value['value']);
    }
  }
}
« Last Edit: July 30, 2012, 07:48:46 pm by torrance123 »

NASACT

  • I post frequently
  • ***
  • Posts: 289
  • Karma: 9
    • National Association of State Auditors, Comptrollers and Treasurers
  • CiviCRM version: 4.2.2
  • CMS version: Drupal 7
  • MySQL version: 5.1.58 (ubuntu)
  • PHP version: 5.3.5
Re: Views 3 and Groups from CiviCRM
July 31, 2012, 11:21:12 am
Just so I understand the code here, we would use the explicit group id value (a #) in Views to filter not the display name for the group?

Also, I assume we are talking about integrating into the CiviCRM core for Drupal Views not Drupal Views module itself right?
-AJ
My GChat - azon21@gmail.com -  This is where you can find me most days!

torrance123

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 3
  • CiviCRM version: 4.0
  • CMS version: Drupal 7
  • MySQL version: 5.0.91
  • PHP version: 5.3.3
Re: Views 3 and Groups from CiviCRM
July 31, 2012, 02:31:31 pm
Quote
Just so I understand the code here, we would use the explicit group id value (a #) in Views to filter not the display name for the group?

That's right, it's doing only very rudimentary checks on the group id filter. If you were to filter on the display name for the group, you'd risk using an empty or stale cache for that smart group.

Quote
Also, I assume we are talking about integrating into the CiviCRM core for Drupal Views not Drupal Views module itself right?

Yes, that's right.

Lionsharz

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 0
    • www.ulearnschool.com
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7
  • PHP version: 5.3 / 5.4
Re: Views 3 and Groups from CiviCRM
August 25, 2013, 01:46:19 pm
Hi

This thread is old but I'm interested to know how this module is to be used exactly. Did you get it to work?

I have installed it on a Drupal 6 site but I see no additional info supplied by it to pull in the data from the SmartGroup.

Thanks for any advice you can give on this topic generally. If this module doesn't work, does anyone know of other work that's been done to pull in and display SmartGroup data in Drupal Views?

ta
www.ulearnschool.com

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: Views 3 and Groups from CiviCRM
August 26, 2013, 08:19:14 am

pretty sure no work has been done to add this to core.

would be good if you can investigate and submit a PR against core for this so its included in future versions

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

Lionsharz

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 0
    • www.ulearnschool.com
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7
  • PHP version: 5.3 / 5.4
Re: Views 3 and Groups from CiviCRM
August 29, 2013, 06:31:53 am
Hi Lobo,

The above code for Drupal 6 is limited in filtering abilities, but it does function.

I would like to pay for that code to be tweaked somewhat to allow and / or filtering on the group IDs and then ported to Drupal 7.

Further to that there was / is an issue with Drupal Groups being synced into Views which results in an SQL error. If that issue is still outstanding (from the chat on this forum it seems nobody is attending to Drupal integration code so I'm guessing it is still there as a bug) I will ask the developers to attend to this issue in the Drupal / Views integration code.

I have seen you mention Web Access as a go-to. Could you confirm that what I propose above is the right way to go about this? I'll contact you through web access for quotes on this work.

Thanks
www.ulearnschool.com

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: Views 3 and Groups from CiviCRM
August 29, 2013, 06:58:21 am

You should chat with the folks at WA with regard to this. I do suspect these improvements are valuable to the larger community. Thanx for doing this

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

Lionsharz

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 0
    • www.ulearnschool.com
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7
  • PHP version: 5.3 / 5.4
Re: Views 3 and Groups from CiviCRM
November 01, 2013, 07:10:13 am
Hi,

So I went ahead with the creation of a module that allows the data from a SmartGroup to pulled into Views in Drupal 7. Currently it functions but only on newly created SmartGroups, not existing ones.

One question came up with this development. Some SmartGroups seem to store the contacts in civicrm_group_contact, while other groups appear to be stored in civicrm_group_contact_cache. Those that are stored in the _cache table are flushed and removed (not avail to Drupal Views) while the others in civicrm_group_contact table are always available.

Anybody got any hints on why this is?

Also any advice on where developers can put this module for community? On drupal.org?
www.ulearnschool.com

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: Views 3 and Groups from CiviCRM
November 01, 2013, 08:20:36 am

smart groups are query based and most of the dynamic contacts are stored in the _cache table. For the view, you can load them into the cache table (which ensures they stay there for a few minutes before being refreshed). The static members of the smart group are in the _contact table

wouldn't u just extend the current views integration rather than creating a new module? if so, might want to create a github account, fork the repo and then file a PR against the civicrm drupal repo

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

Lionsharz

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 0
    • www.ulearnschool.com
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7
  • PHP version: 5.3 / 5.4
Re: Views 3 and Groups from CiviCRM
November 01, 2013, 11:10:24 am
Hi Lobo,

The issue we found with the current Views handler is that it searches the _cache table, which in many cases may be empty. In my case there are no permanent members (assigned manually) - all dynamic - so the views were always empty.

So the developers decided on creating an custom table to hold these Contacts. Views looks in there and pulls them from that position.

Is this a silly way to do things? Pointers?
www.ulearnschool.com

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

This forum was archived on 2017-11-26.