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 (Moderator: Dave Greenberg) »
  • Question about Custom Searches.....
Pages: [1]

Author Topic: Question about Custom Searches.....  (Read 1937 times)

newfoundcivicrm

  • I post occasionally
  • **
  • Posts: 42
  • Karma: 0
Question about Custom Searches.....
December 03, 2010, 03:23:25 pm
First off I do NOT know if this is the right place to post this question, I kinda defaulted to it. So if it needs to be moved by all means lets move it.


I was wondering if someone could tell me based off the code below why I can not get "Contact ID" (contact_id) to appear in the results. The column name appears but the values for each row do not. Name (sort_name) works fine but contact id has been a mystery. I also can't get a text box to display so I can enter in a contact id to search by it. My goal if any one has any ideas is to be able to search by just contact_id to return a single associated contact (if it exists).


Code: [Select]
require_once 'CRM/Contact/Form/Search/Custom/Base.php';

class CRM_Contact_Form_Search_Custom_ByContactID
  extends    CRM_Contact_Form_Search_Custom_Base
   implements CRM_Contact_Form_Search_Interface
{

protected $_query;

function __construct( &$formValues )
{
parent::__construct( $formValues );

$this->_columns = array( ts('Contact ID') => 'contact_id', ts('Name'   ) => 'sort_name' );

$params =& CRM_Contact_BAO_Query::convertFormValues( $this->_formValues );
$returnProperties = array( );

foreach ( $this->_columns as $name => $field )
{
$returnProperties[$field] = 1;
}

$this->_query =& new CRM_Contact_BAO_Query( $params, $returnProperties, null, true, false, 1, false, false );
}

function buildForm( &$form )
{

$this->setTitle('Contact ID Search');

// text for sort_name
$form->add('text', 'sort_name', ts('Name'));

$form->add('text', 'contact_id', ts('Contact ID'));

$form->assign( 'elements', array( 'sort_name', 'contact_type', ) );
}

function count( )
{
return $this->_query->searchQuery( 0, 0, null, true, true );
}

function all( $offset = 0, $rowCount = 0, $sort = null, $includeContactIDs = true )
{

return $this->_query->searchQuery( $offset, $rowCount, $sort, false, $includeContactIDs, false, false, true );
}

function from( )
{
return $this->_query->_fromClause;
}

function where( $includeContactIDs = false )
{
if ( $whereClause = $this->_query->whereClause( ) )
{
return $whereClause;
}
return ' (1) ' ;
}

function templateFile( )
{
return 'CRM/Contact/Form/Search/Basic.tpl';
}

function setTitle( $title )
{
CRM_Utils_System::setTitle( $title );
}
}

Thanks in advance!

PS: The above code is based off the Basic.php example in the 3.1.3 version under the /sites/all/modules/civicrm/CRM/Contact/Form/Search/Custom directory of a 6.19 Drupal install. Also the host just moved the site to a "secure" version of php.... so nothing can run greater then 655 (or 644 I can't remember).
« Last Edit: December 03, 2010, 03:31:08 pm by newfoundcivicrm »

newfoundcivicrm

  • I post occasionally
  • **
  • Posts: 42
  • Karma: 0
Re: Question about Custom Searches.....
December 03, 2010, 03:42:09 pm
Also I saw and read http://forum.civicrm.org/index.php/topic,12901.0.html where Dave recommended "You can create a profile with Internal Contact ID as a 'public' and 'searchable' field, and use Profile search to search by Internal Contact ID (and / or other fields)." I don't want to do this I should be able to do this with some simple dedicated php. It seems like every time I enable one more thing to be searched the site gets a little bit slower and my client gets (an older crowd) a whole lot more confused.
« Last Edit: December 03, 2010, 10:22:37 pm by newfoundcivicrm »

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Question about Custom Searches.....
December 03, 2010, 05:31:11 pm
First, if you're still on 3.1 and having performance issues you should consider upgrading to the latest release (3.3) - and consider whether you have adequate server resources where you're hosting the site (memory, cpu ...).

Using contact id in custom searches is a bit tricky since it needs to be aliased (the actual column name is civicrm_contact.id and id is ambiguous in most searches). You could start with a custom search which already exposes it as a column - http://svn.civicrm.org/civicrm/branches/v3.3/CRM/Contact/Form/Search/Custom/PostalMailing.php for example.

Then you need to add code to add that search param to the where() function. This worked for me (modifying  PostalMailing.php as an example):
Code: [Select]
    function where( $includeContactIDs = false ) {
        $params = array( );

        $count   = 1;
        $clause  = array( );
        $groupID = CRM_Utils_Array::value( 'group_id',
                                           $this->_formValues );
        if ( $groupID ) {
            $params[$count] = array( $groupID, 'Integer' );
            $clause[] = "cgc.group_id = %{$count}";
            $count++;
        }

        $contactID = CRM_Utils_Array::value( 'contact_id',
                                           $this->_formValues );
        if ( $contactID != '' ) {
            $params[$count] = array( $contactID, 'Integer' );
            $clause[] = "contact_a.id =  %{$count}";
        }

        $clause[] = "cgc.status   = 'Added'";
        $clause[] = "contact_a.id = IF( EXISTS(select cr.id from civicrm_relationship cr where (cr.contact_id_a = cgc.contact_id AND (cr.relationship_type_id = 7 OR cr.relationship_type_id = 6))),
                                       (select cr.contact_id_b from civicrm_relationship cr where (cr.contact_id_a = cgc.contact_id AND (cr.relationship_type_id = 7 OR cr.relationship_type_id = 6))),
                                        cgc.contact_id )";
        $clause[] = "contact_a.contact_type IN ('Individual','Household')";

        if ( ! empty( $clause ) ) {
            $where = implode( ' AND ', $clause );
        }
        return $this->whereClause( $where, $params );
    }
Protect your investment in CiviCRM by  becoming a Member!

newfoundcivicrm

  • I post occasionally
  • **
  • Posts: 42
  • Karma: 0
Re: Question about Custom Searches.....
December 04, 2010, 01:00:20 am
Thanks for the help Dave. Ultimately with the other associative changes I made to the page PostalMailing.php code and using the code below, as inspired from your code changes, I got what I needed, a form that will allow me to search for and return a single contact from their entered internal contact id.

Code: [Select]
function where( $includeContactIDs = false )
{
        $params = array( );

        $count   = 1;

        $contactID = CRM_Utils_Array::value( 'contact_id', $this->_formValues );
        if ( $contactID != '' )
{
            $params[$count] = array( $contactID, 'Integer' );
            $where = "contact_a.id =  %{$count}";
        }

        return $this->whereClause( $where, $params );
}

Do you know anything about creating other custom forms? I need to be able to select, from a drop down list, a group and return a list of the contacts in that group, their contact id, and their membership (latest by calendar year and freshly expired or active). I then need to be able to select each contact from that list and be able to renew their said membership. I also need to show the total of the renewals at the bottom before submission. Others have told me that I need to use the API and that might be true but I have absolutely no clue where to start.

Thanks!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Question about Custom Searches.....
December 04, 2010, 04:17:07 pm
"Find Members" search functionality is the closest to what you've described "out of the box". Not clear if you're looking for a batch "renew a whole bunch of memberships at once" flow? If so, that is definitely not available currently - and you'd need to potentially deal w/ applying different payment info (credit card, check, etc.) unless these are free.

You might want to revisit whether you need exactly the flow described, since I'm pretty sure it will be non-trivial to build. I'd look at some of the Membership reports (which do allow filtering by group and membership status) as a way of driving a slightly more manual workflow - i.e. run the report w/ desired filters, print it and then use Find Members -> Renew action on the results rows ... to renew each one.
Protect your investment in CiviCRM by  becoming a Member!

newfoundcivicrm

  • I post occasionally
  • **
  • Posts: 42
  • Karma: 0
Re: Question about Custom Searches.....
December 04, 2010, 04:29:46 pm
That is exactly what I was thinking at first as far as finding the members and manually going through them. The site has a couple of memberships but there are some local governments who pay for their employees memberships (the memberships are all the same) so you might get 150 "Level 1 - $1/yr"  members. I was told I should just use an organization membership a while back in IRC but that is the opposite of what they want. It needs to be granular thus all members are currently individuals even if their membership is paid for by an organization. What they are looking for is a group renewal. Their old custom build java based system had it but that is long and gone, thank god.

Does that spur any ideas on where I should start?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Question about Custom Searches.....
December 05, 2010, 07:17:54 pm
Hmm - I think you might have to build something outside of Civi core (custom Drupal module?) - which calls a BAO method to do the renewals.
Protect your investment in CiviCRM by  becoming a Member!

newfoundcivicrm

  • I post occasionally
  • **
  • Posts: 42
  • Karma: 0
Re: Question about Custom Searches.....
December 05, 2010, 08:43:40 pm
That is what I was thinking. I have never done a custom module but I have done plenty of PHP over the last couple of years. Are there any examples you know of of modules built by people to extend civicm that I could use as a reference? I am a decent learn by example programmer when I need to be?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Question about Custom Searches.....
December 06, 2010, 01:23:02 pm
There's a bunch of modules in the distributed codebase under the drupal directory. You might also look at the Gift Aid module which is in the tools part of the svn repository:
http://svn.civicrm.org/tools/branches/v3.3/drupal/modules/civicrm_giftaid/

That module uses a custom search + custom "task" which might be a good model for you.
Protect your investment in CiviCRM by  becoming a Member!

newfoundcivicrm

  • I post occasionally
  • **
  • Posts: 42
  • Karma: 0
Re: Question about Custom Searches.....
December 06, 2010, 11:04:39 pm
Thanks Dave I will check it out.

gastrit

  • I post occasionally
  • **
  • Posts: 60
  • Karma: 2
  • CiviCRM version: 4.2.2
  • CMS version: 7.8
  • MySQL version: 5.1.41
  • PHP version: 5.3.2
Re: Question about Custom Searches.....
November 28, 2011, 06:03:56 am
Hi!

Just wanted to ask if you did any work on this? I also need a batch renew membership option. I also need a batch create contribution. Has anyone heard of anyone who has done this?

// Jonas

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Question about Custom Searches.....

This forum was archived on 2017-11-26.