function location_views_handler_arg_city in Location 5
Same name and namespace in other branches
- 5.3 contrib/location_views/location_views.module \location_views_handler_arg_city()
1 call to location_views_handler_arg_city()
- location_views_handler_arg_user_city in contrib/
location_views/ location_views.module - City argument handler.
1 string reference to 'location_views_handler_arg_city'
- location_views_arguments in contrib/
location_views/ location_views.module
File
- contrib/
location_views/ location_views.module, line 711 - Views-enables the location module.
Code
function location_views_handler_arg_city($op, &$query, $argtype, $arg = '', $table = 'location') {
switch ($op) {
case 'summary':
// if a length option has been provided, display only the $len left letters of the name
$len = intval($arg);
$query
->ensure_table($table, true);
if ($len <= 0) {
$fieldinfo['field'] = "IF ({$table}.city='' OR {$table}.city IS NULL, '" . LOCATION_VIEWS_UNKNOWN . "', {$table}.city)";
}
else {
$fieldinfo['field'] = "IF ({$table}.city='' OR {$table}.city IS NULL, '" . LOCATION_VIEWS_UNKNOWN . "', LEFT({$table}.city, {$len}))";
}
$fieldinfo['fieldname'] = 'city';
return $fieldinfo;
break;
case 'sort':
$query
->add_orderby($table, 'city', 'ASC');
break;
case 'filter':
$query
->ensure_table($table);
$query
->add_field('city', $table);
// adjust the search based on whether you are looking for the full city name or the first $len letters
$len = intval($argtype['options']);
if ($len <= 0) {
$query
->add_where("{$table}.city = '%s'", strcasecmp($arg, LOCATION_VIEWS_UNKNOWN) ? $arg : '');
}
else {
$query
->add_where("LEFT({$table}.city, {$len}) = '%s'", strcasecmp($arg, LOCATION_VIEWS_UNKNOWN) ? $arg : '');
}
break;
case 'link':
// if using first letter directory, use strtoupper on the link
if ($len) {
return l($query->city == LOCATION_VIEWS_UNKNOWN ? LOCATION_VIEWS_UNKNOWN : strtoupper($query->city), "{$arg}/{$query->city}");
}
else {
return l($query->city == LOCATION_VIEWS_UNKNOWN ? LOCATION_VIEWS_UNKNOWN : $query->city, "{$arg}/{$query->city}");
}
case 'title':
return $query;
}
}