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) »
  • Customizing Advanced Search to find Contacts where Memebership status is NOT = X
Pages: [1] 2

Author Topic: Customizing Advanced Search to find Contacts where Memebership status is NOT = X  (Read 3621 times)

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Customizing Advanced Search to find Contacts where Memebership status is NOT = X
April 09, 2008, 07:58:13 pm
Hi, running 2.0.1 (soon to upgrade) with Drupal.

I have a question about using Advanced Search for memberships.  Here is the situation, we have about half a dozen different memberships that we use.

We'd like to use Advanced Search to search for instance, for any Contacts that have any "Status: Current" memberships and simultaneously DO NOT have any "Status: Grace" memberships and vice versa.   Or another situation might be search for any Contacts with any "Status: Grace" memberships that do not have any "Status: Expired" memberships.

I cannot find a way to search where something "IS NOT" (like in MySQL) using the Advanced Search.  I have read the docs and although it has ways to customize the Search template, not the way the Search itself behaves.  How can I ad "NOT"/negative criteria into the search functionality?

THANKS!
Try CiviTeacher: the online video tutorial CiviCRM learning library.

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: Customizing Advanced Search to find Contacts where Memebership status is NOT = X
April 09, 2008, 08:21:06 pm

check: http://wiki.civicrm.org/confluence/display/CRMDOC/Custom+Search+Components

you need to be familiar with php and mysql to take advantage of this option

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

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Customizing Advanced Search to find Contacts where Memebership status is NOT
April 14, 2008, 07:23:51 am
Hey,

Yes, I see I can create some powerful and customized searches using this method.  I looked at the link you posted, I tried the demo and walked through and did the demo.   Ok, so it works.  Unfortunately, to customize my own search that integrate the CiviMember data will take more time than I or my client has.  Is there a faster way to just enhance the Advanced Search?

Really, all I need to do is just create a way to search for Contacts who have a "Current" membership and DO NOT have a "Grace" membership.

There has got to be a faster way?  Ideas?

Try CiviTeacher: the online video tutorial CiviCRM learning library.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Customizing Advanced Search to find Contacts where Memebership status is NOT
April 14, 2008, 10:56:28 am
Do your contacts generally have multiple membership records? I'm trying to understand the reasons for needing to do the queries you've described. Generally CiviMember updates status on a single membership record for a given contact as time progresses....

New -> Current -> Grace -> Expired

... and I'm pretty sure that searching (Find Members) on Status = Grace for a particular membership type does NOT return records with status = Current.

« Last Edit: April 14, 2008, 11:27:20 am by Dave Greenberg »
Protect your investment in CiviCRM by  becoming a Member!

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Customizing Advanced Search to find Contacts where Memebership status is NOT
April 14, 2008, 05:11:16 pm
Yes we have multiple memberships per contact.  Because of the way the data was before the import into CiviCRM (crappy) we could only think to import in this way.   I tried doing an "update" when duplicate records were found, but this was ineffective, and the client wanted a record of each payment and each expired membership date anyway.   So now we may have one member with four memberships at the same time.  Two memberships may be Current, one may be Grace and one may be Expired.

We want to solicit people to renew their Grace memberships, but only if they have no Current memberships.   Searching for Contacts with membership = "Grace" could return members who have Grace and Current memberships, which is not what we want.

So this is why I want to basically find people who have Grace and/or Expired memberships, but no current memberships.  I have made a homegrown query which returns these results, but have yet to find an elegant way (aka. less than 8 hours work) to make a custom query.  I'm sorry, maybe I'm dumb, but custom queries and making them within the CiviCRM framework take a long time.

So does this help explain why I need the query that I need?
Stuart

Try CiviTeacher: the online video tutorial CiviCRM learning library.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Customizing Advanced Search to find Contacts where Memebership status is NOT
April 14, 2008, 05:54:06 pm
Yes - explained :-)
Unfortunately there's no "quick fix" for this that we can think of. The only other approach I can think of (which is probably no better than the query approach u already have) is to export the results of two searches (one on Current status and one on Grace) and use Excel to find the non-dupes in the Grace set.
Protect your investment in CiviCRM by  becoming a Member!

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: Customizing Advanced Search to find Contacts where Memebership status is NOT = X
April 14, 2008, 06:13:45 pm

If you are good at sql and php, doing a custom search component should take much less than 8 hours. We typically do at least one of these during our training and spend 2-4 hours on it as a group.  There are quite a few sample custom search components in the release

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

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Customizing Advanced Search to find Contacts where Memebership status is NOT
April 15, 2008, 10:30:29 am
It is possible my PHP and MySQL skills are not up to par or I overestimate the tasks required.  I will attempt the custom query page and tell you how it turns out.  Failing that I will manually generate reports and exclude the undesired records from our solicitation. 

Thank you both for your continued attention.  I want you to know the project is going well and already the staff of our NGO are enjoying the flexibility of CiviCRM for record keeping and so on.   It's just this challenge of memberships that is troublesome.
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Customizing Advanced Search to find Contacts where Memebership status is NOT
April 15, 2008, 12:07:23 pm
Cool - let us know if you get stuck somewhere....

Also, once the immediate implementation tasks have died down - it would be excellent karma if you or someone from your NGO posts a brief write-up for the project showcase (organization description, what you used prior to CiviCRM, how you are currently using the software...). :-)

http://forum.civicrm.org/index.php/board,4.0.html
Protect your investment in CiviCRM by  becoming a Member!

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Customizing Advanced Search to find Contacts where Memebership status is NOT
April 28, 2008, 12:42:34 pm
Yes once our new site is published I will definitely post something in your forums.

And also I am stuck!   :)  Can you help please?

I followed the instructions at http://wiki.civicrm.org/confluence/display/CRMDOC/Custom+Search+Components

Let me give you as much info as I can and maybe you can help me figure out why this is happening...I believe it is not even getting as far as the query, the page won't load at all.

Error when I load the page /civicrm/contact/search/custom?csid=7&reset=1
Code: [Select]
backTrace

/var/www/html/rn/sites/all/modules/civicrm/CRM/Core/Error.php, backtrace, 258
/var/www/html/rn/sites/all/modules/civicrm/CRM/Contact/Form/Search/Custom.php, fatal, 54
/var/www/html/rn/sites/all/modules/civicrm/CRM/Core/Form.php, preProcess, 300
/var/www/html/rn/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Display.php, buildForm, 98
/var/www/html/rn/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php, perform, 195
/var/www/html/rn/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php, handle, 95
/var/www/html/rn/sites/all/modules/civicrm/CRM/Core/Controller.php, handle, 223
/var/www/html/rn/sites/all/modules/civicrm/CRM/Core/Invoke.php, run, 540
/var/www/html/rn/sites/all/modules/civicrm/CRM/Core/Invoke.php, search, 435
/var/www/html/rn/sites/all/modules/civicrm/CRM/Core/Invoke.php, contact, 98
/var/www/html/rn/sites/all/modules/civicrm/drupal/civicrm.module, invoke, 321
, civicrm_invoke,
/var/www/html/rn/includes/menu.inc, call_user_func_array, 418
/var/www/html/rn/index.php, menu_execute_active_handler, 15

unrecoverable error
    Sorry. A non-recoverable error has occurred.

    Could not get details for custom search

    Return to home page.




line 38 from my MembershipStatus.php file: 
Code: [Select]
class CRM_Contact_Form_Search_Custom_Membership

Excerpt from the database where I inserted the class and file as value 7 in the `civicrm_option_value` table
Code: [Select]
| id  | option_group_id | label                                     | value | name
| 203 |              24 | CRM_Contact_Form_Search_Custom_Membership | 7     | CRM/Contact/Form/Search/Custom/MembershipStatus.php

There ya go, make any sense to you?  I'm lost...

Also, although I don't believe the query is the problem (as the page won't even load in the first place) here is the query I wish to run.  It's an interesting query because I don't need to accept user input at all.  The query is designed simply to find contacts who have a grace membership or a membership that has expired within 2 years while simultaneously NOT having a current membership.

When the contacts are returned, I would like to ultimately be able to print out a mailing list of these members that fit the above criteria.  This query serves my purposes:

Code: [Select]
SELECT count(*) as n, mem.contact_id as contact_id, mem.id as membership_id, con.display_name as name, stat.name as status

FROM
civicrm_membership mem
LEFT JOIN civicrm_contact con ON (mem.contact_id = con.id)
LEFT JOIN civicrm_membership_status stat ON (mem.status_id = stat.id)

WHERE contact_id NOT IN (SELECT mem.contact_id FROM civicrm_membership mem WHERE mem.status_id = 2)
AND mem.status_id IN (3,4) AND mem.end_date > DATE_SUB(NOW(), INTERVAL 2 YEAR)

GROUP BY contact_id HAVING n > 0

ORDER BY
name, status

Try CiviTeacher: the online video tutorial CiviCRM learning library.

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: Customizing Advanced Search to find Contacts where Memebership status is NOT = X
April 28, 2008, 01:27:44 pm

can you attach your custom search file. we'll modify it and upload it back :)

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

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Customizing Advanced Search to find Contacts where Memebership status is NOT
April 28, 2008, 04:46:03 pm
Sure here you go... I was a little unsure of how to handle the "HAVING" clause.  Maybe that is the problem.  Or maybe something else.  Thank you!

Try CiviTeacher: the online video tutorial CiviCRM learning library.

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: Customizing Advanced Search to find Contacts where Memebership status is NOT = X
April 28, 2008, 07:35:27 pm

there is an error in your php file. can you ensure that your file is valid. you can check by doing:

$ php ~/WebDownload/MembershipStatus.txt
PHP Parse error:  syntax error, unexpected ';' in /Users/lobo/WebDownload/MembershipStatus.txt on line 72

u need to ensure that there is no php parse error. once done, can u re-upload the file

unfortunately we cannot do that when we load the file (i spent a few mins trying to see if we could)

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

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Customizing Advanced Search to find Contacts where Memebership status is NOT
April 29, 2008, 07:45:49 am
Ok was a missing ) here is the reuploaded file.

$ php MembershipStatus.txt   >  no warnings, errors

Thanks.
Try CiviTeacher: the online video tutorial CiviCRM learning library.

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Customizing Advanced Search to find Contacts where Memebership status is NOT
April 29, 2008, 12:26:20 pm
Here is a version with relative include paths.  It does pop an error when I run PHP, but since your server is different maybe you need it this way.   Just another option.

Try CiviTeacher: the online video tutorial CiviCRM learning library.

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Customizing Advanced Search to find Contacts where Memebership status is NOT = X

This forum was archived on 2017-11-26.