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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom Search for multiple contat IDs (e.g. useful for bounces and re-email)
Pages: [1]

Author Topic: Custom Search for multiple contat IDs (e.g. useful for bounces and re-email)  (Read 1328 times)

obiuquido144

  • I post occasionally
  • **
  • Posts: 34
  • Karma: 4
Custom Search for multiple contat IDs (e.g. useful for bounces and re-email)
October 21, 2009, 06:23:26 am
Hi, we're having bounce issues with CiviMail (attachment-size related), but are already on full production. We would like to keep all mailing in CiviCRM, so I was looking for a way to create a new mailing just out of the list of Bounces in the mail report.

This currently isn't supported natively and there is no option to do an advanced search e.g. by comma-separated contact IDs, which I find could be a useful multi-purpose tool for various non-standard tasks.

So I created a custom search that accepts a list of contact ids as input and returns the contact ID, name, email and email id, and the SQL is written so that the Direct Mail and Mass Mailing work seamlesly with this select.

Would you be interested in adding a similar custom search to default CiviCRM? (It is my first attempt with custom searches so I don't know if actions other than Email would work etc. [This version below also returns all addresses assigned to the contact, but only the bulk-one is actually used.])

Perhaps the functionality could later be directly integrated into the Bounces screen ("Create a new mailing using bounced addresses").

One more quick question: in 3.0, how can I add my new custom search to the 4 rollout Custom search "shortcuts" in the top menu? Just a quick note where in the db I should look would help me a lot!

Thanks, Boris

Code: [Select]
<?php

//Custom Search Path: CRM_Contact_Form_Search_Custom_aaaIDsearch
//Search Title: aaaIDsearch
//Weight: 1

/*
SELECT
civicrm_email.contact_id as contact_id,
civicrm_email.email    as email,
civicrm_email.id as eid,
contact_a.sort_name as sort_name
FROM       civicrm_email civicrm_email, civicrm_contact contact_a
WHERE civicrm_email.contact_id IN (3,4) AND civicrm_email.contact_id = contact_a.id 
*/


require_once 'CRM/Contact/Form/Search/Custom/Base.php';

class 
CRM_Contact_Form_Search_Custom_aaaIDsearch
   
extends    CRM_Contact_Form_Search_Custom_Base
   
implements CRM_Contact_Form_Search_Interface {

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

        
$this->_columns = array( ts('Contact Id')   => 'contact_id'  ,
                                 
ts('Name')         => 'sort_name' ,
                                 
ts('Email')        => 'email' ,
                                 
ts('Email Id')     => 'eid' 
                                  
);
    }

    function 
buildForm( &$form ) {

        
$form->add( 'text',
                    
'ids',
                    
ts( 'Contact ID\'s' ),
                    
true );

        
/**
         * You can define a custom title for the search form
         */
         
$this->setTitle('aaaIDsearch');
         
         
/**
         * if you are using the standard template, this array tells the template what elements
         * are part of the search criteria
         */
        
$form->assign( 'elements', array( 'ids' ) );
    }

    function 
summary( ) {
    }

    function 
all( $offset = 0, $rowcount = 0, $sort = null,
                  
$includeContactIDs = false ) {

//SELECT
        
$selectClause = "

civicrm_email.contact_id as contact_id,
civicrm_email.email    as email,
civicrm_email.id as eid,
contact_a.sort_name as sort_name

"
;

        return 
$this->sql( $selectClause,
                           
$offset, $rowcount, $sort,
                           
$includeContactIDs, null );

    }
    
    function 
from( ) {
        return 
"
FROM      civicrm_email civicrm_email, civicrm_contact contact_a
"
;
    }

    function 
where( $includeContactIDs = false ) {
        
$params = array( );
        
$name   = CRM_Utils_Array::value( 'ids',
                                          
$this->_formValues );

//WHERE
        
$where  = "
civicrm_email.contact_id IN ("
.$name.") AND civicrm_email.contact_id = contact_a.id 
     
     "
;
        
$count  = 1;
        
$clause = array( );

        
//if ( ! empty( $clause ) ) {            $where .= ' OR ' . implode( ' OR ', $clause );        }

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

    function 
templateFile( ) {
        return 
'CRM/Contact/Form/Search/Custom/Sample.tpl';
    }
   
    function 
setTitle( $title ) {
        if ( 
$title ) {
            
CRM_Utils_System::setTitle( $title );
        } else {
            
CRM_Utils_System::setTitle(ts('Search'));
        }
    }
}

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: Custom Search for multiple contat IDs (e.g. useful for bounces and re-email)
October 23, 2009, 01:53:49 pm

Hey Boris:

1. Can you package your custom search. preferably comment the code a fair amount, add the licensing / copyright stuff: http://civicrm.org/licensing

2. to update navigation, check:

http://drupal.demo.civicrm.org/civicrm/admin/menu&reset=1

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

obiuquido144

  • I post occasionally
  • **
  • Posts: 34
  • Karma: 4
Re: Custom Search for multiple contat IDs (e.g. useful for bounces and re-email)
November 16, 2009, 01:17:15 pm
My final workaround for resending to bounced addresses is in this thread:
http://forum.civicrm.org/index.php/topic,10346.0.html

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom Search for multiple contat IDs (e.g. useful for bounces and re-email)

This forum was archived on 2017-11-26.