function countries_admin_overview in Countries 8
Same name and namespace in other branches
- 7.2 countries.admin.inc \countries_admin_overview()
- 7 countries.admin.inc \countries_admin_overview()
Menu callback; Displays a list of all countries.
1 string reference to 'countries_admin_overview'
- countries_menu in ./
countries.module - Implements hook_menu().
File
- ./
countries.admin.inc, line 11 - Admin page callbacks for the Countries module.
Code
function countries_admin_overview() {
global $language;
$header = array();
$header[] = array(
'data' => t('Name'),
'field' => 'c.name',
'sort' => 'asc',
);
$header[] = array(
'data' => t('ISO alpha-2 code'),
'field' => 'c.iso2',
);
$columns = variable_get('countries_admin_overview_columns', array(
'iso3' => t('ISO alpha-3 code'),
'numcode' => t('ISO numeric-3 code'),
'continent' => t('Continent'),
'official_name' => t('Official name'),
));
foreach ($columns as $key => $title) {
$header[] = array(
'data' => $title,
'field' => 'c.' . $key,
);
}
$header[] = array(
'data' => t('Status'),
'field' => 'c.enabled',
);
$header[] = array(
'data' => t('Operations'),
);
$query = db_select('countries_country', 'c')
->extend('PagerDefault')
->extend('TableSort');
$result = $query
->fields('c')
->orderByHeader($header)
->limit(50)
->execute();
$destination = drupal_get_destination();
// Show db and translated strings if supported.
$i18n = language_default('language') != $language->language && module_exists('countries_i18n');
$rows = array();
// Note that additional id's are added for testing.
foreach ($result as $country) {
$row = array();
$base_url = 'admin/config/regional/countries/' . $country->iso2;
$name = country_property($country, 'name', array(
'sanitize' => 0,
));
$row[] = l($name, $base_url, array(
'query' => $destination,
)) . ($i18n ? '<br/><small>(' . check_plain($country->name) . ')</small>' : '');
$row[] = array(
'data' => country_property($country, 'iso2'),
'id' => $country->iso2 . '-iso2',
);
foreach ($columns as $key => $title) {
switch ($key) {
case 'official_name':
$value = country_property($country, $key, array(
'default' => '',
));
$row[] = array(
'data' => $value . ($i18n && !empty($country->{$key}) ? '<br/><small>(' . check_plain($country->{$key}) . ')</small>' : ''),
'id' => $country->iso2 . '-' . $key,
);
break;
default:
$row[] = array(
'data' => country_property($country, $key, array(
'default' => '',
)),
'id' => $country->iso2 . '-' . $key,
);
}
}
$row[] = array(
'data' => country_property($country, 'enabled'),
'id' => $country->iso2 . '-enabled',
);
$operations = l(t('edit'), $base_url, array(
'query' => $destination,
));
if (module_exists('countries_regions')) {
$count = countries_regions_count($country);
$operations .= ' ' . l(t('!count regions', array(
'!count' => $count,
)), $base_url . '/regions', array(
'query' => $destination,
));
}
if (!country_is_locked($country)) {
$operations .= ' ' . l(t('delete'), $base_url . '/delete', array(
'query' => $destination,
));
}
$row[] = $operations;
$rows[] = $row;
}
if (empty($rows)) {
$rows[] = array(
array(
'data' => t('No countries are available.'),
'colspan' => count($header),
),
);
}
$build['countries_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
$build['countries_pager'] = array(
'#theme' => 'pager',
);
return $build;
}