class location_handler_filter_location_country in Location 6.3
Same name and namespace in other branches
- 7.5 handlers/location_handler_filter_location_country.inc \location_handler_filter_location_country
- 7.3 handlers/location_handler_filter_location_country.inc \location_handler_filter_location_country
- 7.4 handlers/location_handler_filter_location_country.inc \location_handler_filter_location_country
Filter on country.
Hierarchy
- class \location_handler_filter_location_country extends \views_handler_filter_in_operator
Expanded class hierarchy of location_handler_filter_location_country
1 string reference to 'location_handler_filter_location_country'
- location_views_data in ./
location.views.inc - Implementation of hook_views_data().
File
- handlers/
location_handler_filter_location_country.inc, line 6
View source
class location_handler_filter_location_country extends views_handler_filter_in_operator {
function option_definition() {
$options = parent::option_definition();
$options['operator'] = array(
'default' => 'in',
);
return $options;
}
function admin_summary() {
return '';
// $options = $this->operator_options('short');
// return (!empty($this->options['exposed']) ? t('exposed') : $options[$this->operator]);
}
function get_value_options() {
$this->value_options = location_get_iso3166_list();
}
/**
* Provide widgets for filtering by country.
*/
function value_form(&$form, &$form_state) {
$this
->get_value_options();
$options = $this->value_options;
$default_value = (array) $this->value;
if (!empty($form_state['exposed'])) {
$identifier = $this->options['expose']['identifier'];
if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator'])) {
// exposed and locked.
$which = in_array($this->operator, $this
->operator_values(1)) ? 'value' : 'none';
}
else {
$source = 'edit-' . form_clean_id($this->options['expose']['operator']);
}
if (!empty($this->options['expose']['reduce'])) {
$options = $this
->reduce_value_options();
if (empty($this->options['expose']['single']) && !empty($this->options['expose']['optional'])) {
$default_value = array();
}
}
if (!empty($this->options['expose']['single'])) {
if (!empty($this->options['expose']['optional']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) {
$default_value = 'All';
}
else {
if (empty($default_value)) {
$keys = array_keys($options);
$default_value = array_shift($keys);
}
else {
$copy = $default_value;
$default_value = array_shift($copy);
}
}
}
}
$form['value'] = array(
'#type' => 'select',
'#title' => t('Country'),
'#default_value' => $default_value,
'#options' => $options,
// Used by province autocompletion js.
'#attributes' => array(
'class' => 'location_auto_country',
),
'#multiple' => TRUE,
);
// Let location_autocomplete.js find the correct fields to attach.
$form['value']['#attributes']['class'] .= ' location_auto_join_' . $this->options['expose']['identifier'];
}
function reduce_value_options($input = NULL) {
if (empty($this->options)) {
$this
->get_value_options();
}
if (!empty($this->options['expose']['reduce']) && !empty($this->options['value'])) {
$reduced_options = array();
foreach ($this->options['value'] as $value) {
$reduced_options[$value] = $this->value_options[$value];
}
return $reduced_options;
}
return $this
->get_value_options();
}
function accept_exposed_input($input) {
if (empty($this->options['exposed'])) {
return TRUE;
}
if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']) && isset($input[$this->options['expose']['operator_id']])) {
$this->operator = $input[$this->options['expose']['operator_id']];
}
if (!empty($this->options['expose']['identifier'])) {
$value = $input[$this->options['expose']['identifier']];
if (empty($this->options['expose']['required'])) {
if ($value == 'All' || $value === array()) {
if (empty($this->options['value']) || !empty($this->options['value']) && empty($this->options['expose']['reduce'])) {
return FALSE;
}
else {
$value = $this->options['value'];
}
}
if (!empty($this->always_multiple) && $value === '') {
return FALSE;
}
}
if (isset($value)) {
$this->value = $value;
if (empty($this->always_multiple) && empty($this->options['expose']['multiple'])) {
$this->value = array(
$value,
);
}
}
else {
return FALSE;
}
}
return TRUE;
}
function operator_options($which = 'title') {
if (empty($this->options['expose']['multiple'])) {
return array(
'in' => t('Is'),
'not in' => t('Is not'),
);
}
else {
return array(
'in' => t('Is one of'),
'not in' => t('Is not one of'),
);
}
}
function query() {
if (empty($this->value)) {
return;
}
$this
->ensure_my_table();
$field = "{$this->table_alias}.{$this->real_field}";
// Normalize values.
$value = $this->value;
if (is_array($value)) {
$value = array_keys($value);
if (count($value) == 1) {
// If multiple is allowed but only one was chosen, use a string instead.
$value = reset($value);
}
}
if (is_array($value)) {
// Multiple values
$placeholders = db_placeholders($value, 'varchar');
$operator = $this->operator == 'in' ? 'IN' : 'NOT IN';
$this->query
->add_where($this->options['group'], "{$field} {$operator}({$placeholders})", $value);
}
else {
// Single value
$operator = $this->operator == 'in' ? '=' : '!=';
$this->query
->add_where($this->options['group'], "{$field} {$operator} '%s'", $this->value);
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
location_handler_filter_location_country:: |
function | |||
location_handler_filter_location_country:: |
function | |||
location_handler_filter_location_country:: |
function | |||
location_handler_filter_location_country:: |
function | |||
location_handler_filter_location_country:: |
function | |||
location_handler_filter_location_country:: |
function | |||
location_handler_filter_location_country:: |
function | |||
location_handler_filter_location_country:: |
function | Provide widgets for filtering by country. |