function theme_avatar_selection_pager in Avatar Selection 7
Same name and namespace in other branches
- 5.2 avatar_selection.module \theme_avatar_selection_pager()
- 6 avatar_selection.module \theme_avatar_selection_pager()
Output themed pager navigation.
Parameters
$total: Total number of elements to navigate through.
$limit: Maximum number of elements to show on one page.
Return value
HTML formatted pager navigation.
3 theme calls to theme_avatar_selection_pager()
- avatar_selection_edit_form in ./
avatar_selection.admin.inc - Create the form structure for listing the avatars and managing them in the 'Manage Avatars' tab under the Avatar Selection administration page.
- avatar_selection_form_user_profile_form_alter in ./
avatar_selection.module - Implements hook_form_alter().
- avatar_selection_form_user_register_form_alter in ./
avatar_selection.module - Implements hook_form_alter().
File
- ./
avatar_selection.module, line 687 - The Avatar Selection module allows the user to pick an avatar image from a list already loaded by an administrative user, and to the administrator to disable uploading other avatar files by the user.
Code
function theme_avatar_selection_pager($variables) {
$total = $variables['total'];
$limit = $variables['limit'];
$path = $_GET['q'];
$total_pages = ceil($total / $limit);
$current_page = isset($_GET['page']) ? $_GET['page'] : 0;
// Calculate various markers within this pager piece:
// Middle is used to 'center' pages around the current page.
$middle_page = 5;
$first_page = $current_page - $middle_page + 1;
$last_page = $current_page + $middle_page + 1;
$output = '<div class="avatar-selection-pager-nav">';
if ($current_page > 0) {
$output .= theme('avatar_selection_pager_link', array(
'text' => t('« first'),
'url' => $path,
'page' => 0,
));
$output .= theme('avatar_selection_pager_link', array(
'text' => t('‹ previous'),
'url' => $path,
'page' => $current_page - 1,
));
}
$i = $first_page;
// Adjust 'center' if at end of query.
if ($last_page > $total_pages) {
$i = $i + ($total_pages - $last_page);
$last_page = $total_pages;
}
// Adjust 'center' if at start of query.
if ($i <= 0) {
$last_page = $last_page + (1 - $i);
$i = 1;
}
// When there is more than one page, create the pager list.
if ($total_pages > 1) {
for (; $i <= $last_page && $i <= $total_pages; $i++) {
if ($i < $current_page + 1) {
$output .= theme('avatar_selection_pager_link', array(
'text' => $i,
'url' => $path,
'page' => $i - 1,
));
}
if ($i == $current_page + 1) {
$output .= '<strong class="pager-current">' . $i . '</strong>';
}
if ($i > $current_page + 1) {
$output .= theme('avatar_selection_pager_link', array(
'text' => $i,
'url' => $path,
'page' => $i - 1,
));
}
}
}
if ($current_page + 1 < $total_pages) {
$output .= theme('avatar_selection_pager_link', array(
'text' => t('next ›'),
'url' => $path,
'page' => $current_page + 1,
));
$output .= theme('avatar_selection_pager_link', array(
'text' => t('last »'),
'url' => $path,
'page' => $total_pages - 1,
));
}
$output .= '</div>';
return $output;
}