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) »
  • Extending Participant Search
Pages: [1]

Author Topic: Extending Participant Search  (Read 874 times)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Extending Participant Search
January 22, 2012, 11:09:16 am
On a Drupal 6 CiviCRM 3.4.5 site I am trying extend the Participant Search page civicrm/event/search?reset=1 We want to allow the user to filter the results by Group. I added a dropdown for Group and can access it via $_POST (this may have been the easy way out of that part, heh heh) but now on the back end I am not able to properly adjust the search.

In CRM/Event/Form/Search.php at line 447 I added this:

Code: [Select]
        $query   =& $selector->getQuery( );

        /* Start code added by Hershel Robinson */
        if(0 != $_POST['group_id']) {
       //   $query->_whereClause .= ' AND civicrm_group_contact.group_id = ' .  $_POST['group_id'];
         $results=civicrm_api("Contact","get", array (
                                                 'version' =>'3',
                                                 'group' =>$_POST['group_id'],
                                                 'rowCount' =>'200000', 'return.contact_id' =>'1'
                                               )
                             );
         if (0 != $results['count']) {
          $in_clause  = 'contact_a.id IN ( ' .  join(',',array_keys($results['values'])) . ')';
          $query->_where[] = $in_clause;
          $query->_whereClause = "( {$query->_whereClause} AND $in_clause )";
         }
       //  $query->_tables['civicrm_group_contact'] = 1;
        }
        /* END Start code added by Hershel Robinson */

The search results are actually filtered by Group, but the header part of the results page like "211 Results" doesn't reflect this filtering--it shows the full values without the Group filter.

You can see in the code how I tried to do this the correct way, but it failed, so I commented that out and I used a kludge.

Can anyhow assist in getting this done properly, including the header (and pager) parts?

Thanks.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

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: Extending Participant Search
January 22, 2012, 11:28:40 am

1. Did u add the same group drop down as advanced search via the buildForm hook? If so, it should have picked up the values and included it in the search automatically (since they all go thru the same code path). I would try it this way to begin with

2. if the above does not work, i would move the call:

Code: [Select]
  $controller = new CRM_Core_Selector_Controller($selector , ...

below your code section. The constructor gets the total count and alphabetic pager and hence its important to modify the query before the controller is created

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

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Extending Participant Search
January 24, 2012, 07:35:41 am
Your 1. worked great.

In CRM/Event/Form/Search/Common.tpl we added

Code: [Select]
<tr><td><label>Group</label>
  {crmAPI var="GroupS" entity="Group" action="get" version="3" }
  <select name="group">
    <option value="">- Any -</option>
    {foreach from=$GroupS.values item=Group}
      <option value="{$Group.id}">{$Group.name}</option>
    {/foreach}
  </select>
</td></tr>

to get the group drop down, and in a custom hook_buildForm we added

Code: [Select]
if ('CRM_Event_Form_Search' == $formName) {
  $groupResult = civicrm_api('Group', 'get', array('version' =>'3'));
  $groups = array();
  foreach ($groupResult['values'] as $group) {
    $group[$group['id']] = $group['name'];
  }
  $form->addElement('select', 'group', 'Group', $groups);
}

We didn't have to customize Search.php at all.

Thank you.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Extending Participant Search

This forum was archived on 2017-11-26.