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 Drupal Modules (Moderator: Donald Lobo) »
  • limiting countries in exposed filters
Pages: [1]

Author Topic: limiting countries in exposed filters  (Read 1339 times)

jyee

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
limiting countries in exposed filters
September 23, 2010, 01:08:32 pm
This is a followup/related post to my last one about limiting the state/province based on the country selected in an exposed filter (http://forum.civicrm.org/index.php/topic,15828.0.html).

Often you'll want to include every country (via civi's administer >> configure >> global settings >> localization), because you want those countries available for new users, etc.  But when using a drupal view with an exposed country filter, you only want to show the countries that have been used.  Why show "Tuvalu" in the exposed filter, only to have a user select it and have no results?  This code fixes that:

/civicrm/drupal/modules/views/civicrm/civicrm_handler_filter_country.inc:
Code: [Select]
        /* code to limit the options of countries to only
         * display countries that have been used by contacts
         */
   
        // get the distinct list of countries used
        $result = db_query('SELECT DISTINCT country_id FROM {civicrm_address}');
        $countries = array();
        while ($row = db_fetch_array($result)) $countries[$row['country_id']] = $row['country_id'];
        // filter down to an intersect of the full list and the used list
        $this->value_options = array_intersect_key($this->value_options, $countries);

insert the code at line 59, after the if block, but before the end of the get_value_options() function.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: limiting countries in exposed filters
September 23, 2010, 09:38:11 pm
Hi,

Why do you intersect?

Isn't the list of used country always a subset of the list of all the available countries?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: limiting countries in exposed filters
September 24, 2010, 02:41:48 pm
x - if you expose a filter in Views you will end up with a list of all states - I think this approach is meant to limit the list to only those states for countries that have been selected in civicrm - his other fix on other thread is exactly what i need for a client where I have been through selecting just those countries in Views to show if they have actually been used for any contacts

great help for me, thanks j.
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • limiting countries in exposed filters

This forum was archived on 2017-11-26.