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) »
  • Custom Search Next Page Fails
Pages: [1]

Author Topic: Custom Search Next Page Fails  (Read 844 times)

geraldr_sc

  • Guest
Custom Search Next Page Fails
July 19, 2010, 03:18:09 pm
I have written a custom search and the accompanying template as follows:

The buildForm function assigns elements to the template by querying the civicrm_option_value and the civicrm_option_group and using the return values to create the checkbox fields in the template. This allows the user to select checkboxes that are for custom data fields that are related to companies (organizations).  The "all" and related functions are then used to create the sql to get the contacts who are employees of the companies (The companies are Media companies and the contacts are reporters, writers, etc).

The template works fine and returns the appropriate data. I then use the results posted from the form to construct the sql to return the contacts that are employees of the companies. Follows is a sample query that was constructed by the results of a number of checkboxes that were checked. The queries differ depending on the user selections.

SELECT DISTINCT
              contact_a.id as contact_id,
              contact_a.sort_name as sort_name,
              cc1.display_name as media_organization,
              cv.geographical_tag_14 ,
              cv.media_type_15
       
            FROM
            civicrm_relationship_type c,
            civicrm_relationship c1,
            civicrm_contact contact_a,
            civicrm_contact cc1,
            civicrm_value_media_tags_7 cv
       
            WHERE
              c1.relationship_type_id = c.id AND
              contact_a.id = c1.contact_id_a AND
              cc1.id = c1.contact_id_b AND
              c.name_a_b = 'Employee of' AND
              cv.entity_id= cc1.id                   
         AND (
                                cv.geographical_tag_14 LIKE "%regional%"  OR   
                                cv.geographical_tag_14 LIKE "%richland%"  OR   
                                cv.geographical_tag_14 LIKE "%orangeburg%"  OR   
                                cv.geographical_tag_14 LIKE "%sumter%"  OR
                                cv.geographical_tag_14 LIKE "%charleston%"  OR   
                                cv.geographical_tag_14 LIKE "%greenville_spartanburg%"  OR   
                                cv.geographical_tag_14 LIKE "%florence%"  OR   
                                cv.geographical_tag_14 LIKE "%beaufort%")
            ORDER BY contact_a.sort_name asc

This query works fine and returns the correct search results. But when I click the next page in the search results tables, the count jumps to the entire set of contacts who are employees of the media companies suggesting maybe the first part of the WHERE clause is being used but the part resulting from the checkbox selections (the part starting with the cv.geographical_tag_14 in the query above) is not being used.

I did not know how to use civicrm functions to get the posted values so I used the php $_POST variable directly to create the sql to search for the contacts. Is civicrm requerying on the second page and thus losing the $_POST variable? How can I get the next page of contact results correctly? If that is not possible, is there a way to stop the limit on the first page so it does not need a second page?

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Custom Search Next Page Fails
July 20, 2010, 12:12:56 am
You can get submitted values of your custom search form in $this->_formValues , accordingly you can build your where clause in function where( ).
Please follow the doc available for custom search
http://wiki.civicrm.org/confluence/display/CRMDOC/Custom+Search+Components.

For reference you can look @ CRM/Contact/Form/Search/Custom/Sample.php

Regards,
Rajan

geraldr_sc

  • Guest
Re: Custom Search Next Page Fails
July 20, 2010, 02:42:32 am
Quote
You can get submitted values of your custom search form in $this->_formValues

I tried that and it only returned this:
Array
(
    [qfKey] => 89ed4288e64d6973d8c98364bf807a63
    [radio_ts] =>
    [customSearchID] => 16
    [customSearchClass] => CRM_Contact_Form_Search_Custom_MediaContact
)
while $_POST returned this (for the selected checkboxex):
Array
(
    [qfKey] => 89ed4288e64d6973d8c98364bf807a63
    [_qf_default] => Custom:refresh
    [custom_14] => Array
        (
            [regional] => 1
            [richland] => 1
            [orangeburg] => 1
            [sumter] => 1
            [charleston] => 1
            [greenville_spartanburg] => 1
            [florence] => 1
            [beaufort] => 1
            [any] => 1
        )

    [_qf_Custom_refresh] => Search
)
I see where Sample.php uses CRM_Utils_Request::retrieve in the constructor, but the checkboxes return an array the way it is written, and it doesn't seem to retrieve any posts. As a test I tried CRM_Utils_Request::retrieve('qfKey','String',CRM_Core_DAO::$_nullObject ) as it was used in Sample since qfKey is a non-array in the post. It returned nothing.




« Last Edit: July 21, 2010, 10:23:32 am by geraldr_sc »

geraldr_sc

  • Guest
Re: Custom Search Next Page Fails
July 21, 2010, 10:22:17 am
I don't know how elegant this is or if there is a better way, but I resolved the problem of the checkbox POSTS dissappearing between the first page of results and the second page by storing them in a session variable and using them if the posted values came up empty. I unset the session variable when the $this->_formValue was empty as it is when the form is being built before anything is posted.

If there is a better way, I would love to know. I was not able to get it to work without reading $_POST directly.
« Last Edit: July 21, 2010, 10:26:14 am by geraldr_sc »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Custom Search Next Page Fails

This forum was archived on 2017-11-26.