/[drupal]/contributions/modules/country_code/country_code_handler_filter_node_country.inc
ViewVC logotype

Contents of /contributions/modules/country_code/country_code_handler_filter_node_country.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (show annotations) (download) (as text)
Wed Dec 10 13:46:50 2008 UTC (11 months, 2 weeks ago) by catch
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +3 -3 lines
File MIME type: text/x-php
#328194 by recidive: use lowercase country codes.
1 <?php
2 // $Id: country_code_handler_filter_node_country.inc,v 1.10 2008/10/30 20:10:56 nedjo Exp $
3
4 /**
5 * @file
6 * Implementation of a views country filter for the country code module.
7 */
8
9 /**
10 * Filter by country.
11 */
12 class country_code_handler_filter_node_country extends views_handler_filter_in_operator {
13
14 function get_value_options() {
15 if (!isset($this->value_options)) {
16 $this->value_title = t('Country');
17 $countries = array(
18 '***COUNTRY_CODE***' => t("Current country"),
19 );
20 foreach (country_code_countries() as $code => $country) {
21 $countries[$code] = $country->name;
22 }
23 $this->value_options = $countries;
24 }
25 }
26
27 function query() {
28 // If the current country code is global, we don't restrict content.
29 if (empty($this->value) || in_array(COUNTRY_CODE_GLOBAL, $this->value)) {
30 return;
31 }
32
33 $table = $this->ensure_my_table();
34 $language_substrings = array();
35 $options = array();
36 foreach ($this->value as $value) {
37 // The search strings include a dash(-), e.g., -ca, so we begin at the 3rd
38 // character.
39 $options[] = "SUBSTRING({$this->table_alias}.{$this->real_field}, 3) = '%s'";
40 $language_substrings[] = '-' . $value;
41 }
42
43 $where = ' (' . implode(" OR ", $options) . ')';
44
45 $this->query->add_where($this->options['group'], $where, $language_substrings);
46 }
47
48 }

  ViewVC Help
Powered by ViewVC 1.1.2