function birthdays_view_page in Birthdays 6
Same name and namespace in other branches
- 5 birthdays.module \birthdays_view_page()
Show birthdays page @desc Callback for birthdays menu item to show a page which lists all users.
Return value
string Themed birthday listing of all users
1 string reference to 'birthdays_view_page'
- birthdays_menu in ./
birthdays.module - Implementation of hook_menu().
File
- ./
birthdays.page.inc, line 13 - All functions related to the birthdays listings page
Code
function birthdays_view_page() {
global $_birthdays_field;
// Nothing to see when the birthdays profile field hasn't been set yet.
if (!isset($_birthdays_field)) {
return NULL;
}
drupal_add_css(drupal_get_path('module', 'birthdays') . '/birthdays.css');
if (isset($_REQUEST['birthdays_filter_month'])) {
$filter_month = (int) $_REQUEST['birthdays_filter_month'];
}
if (isset($_REQUEST['birthdays_filter_year'])) {
$filter_year = (int) $_REQUEST['birthdays_filter_year'];
}
$output = '';
$filter = '';
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
// Right join = filtering out
$join = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) != BIRTHDAYS_PAGE_NOFILTER_SORT_USER || !empty($filter_month) || !empty($filter_year) ? 'RIGHT JOIN' : 'LEFT JOIN';
$sort = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) == BIRTHDAYS_PAGE_FILTER_SORT_DATE || !empty($filter_month) || !empty($filter_year) ? 'MONTH({dob}.birthday), DAYOFMONTH({dob}.birthday), YEAR({dob}.birthday), ' : '';
$filter .= !empty($filter_month) ? " AND MONTH({dob}.birthday) = " . $filter_month : '';
$filter .= !empty($filter_year) ? " AND YEAR({dob}.birthday) = " . $filter_year : '';
break;
case 'pgsql':
// Right join = filtering out
$join = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) != BIRTHDAYS_PAGE_NOFILTER_SORT_USER || !empty($filter_month) || !empty($filter_year) ? 'RIGHT JOIN' : 'LEFT JOIN';
$sort = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) == BIRTHDAYS_PAGE_FILTER_SORT_DATE || !empty($filter_month) || !empty($filter_year) ? "date_part('month', {dob}.birthday), date_part('day', {dob}.birthday), date_part('year', {dob}.birthday), " : '';
$filter .= !empty($filter_month) ? " AND date_part('month', {dob}.birthday) = " . $filter_month : '';
$filter .= !empty($filter_year) ? " AND date_part('year', {dob}.birthday) = " . $filter_year : '';
break;
}
// Select all users (but ignore blocked and never logged in ones)
$result = pager_query("SELECT {users}.uid FROM {users} " . $join . " {dob} ON {users}.uid = {dob}.uid WHERE {users}.status <> 0 AND {users}.access <> 0" . $filter . " ORDER BY " . $sort . "{users}.name", variable_get('birthdays_page_list_number', 25));
while ($uid = db_fetch_object($result)) {
// load the user objects
$account = user_load(array(
'uid' => $uid->uid,
));
if (empty($filter_year) || !$account->birthdays_user_hide_year) {
$accounts[] = $account;
}
}
// Call theme_birthdays_page
$output .= theme('birthdays_page', $accounts, $filter_month, $filter_year);
// Get the filter form
return $output;
}