function uc_wishlist_display in UC Wish List 6
Same name and namespace in other branches
- 7 uc_wishlist.pages.inc \uc_wishlist_display()
Display a wish list for viewing or altering.
Parameters
$wid: The ID of the wish list to display.
Return value
HTML output for the wish list display and form.
1 string reference to 'uc_wishlist_display'
- uc_wishlist_menu in ./
uc_wishlist.module - Implementation of hook_menu().
File
- ./
uc_wishlist.pages.inc, line 17 - Page callback and functions for wish lists.
Code
function uc_wishlist_display($wid = NULL, $mode = 'wid') {
global $user;
$output = '';
// $own defines whether the wish list is owned by the current user or not.
// This affects how many parts of the page are rendered.
$own = FALSE;
if ($mode == 'user') {
// $wid is actually a user account
$wid = uc_wishlist_get_wid($wid->uid);
}
else {
if (empty($wid)) {
// Default to the current user's wish list if no wishlist ID is specified.
$wid = uc_wishlist_get_wid();
$own = TRUE;
}
}
if (!$own && $wid == uc_wishlist_get_wid()) {
$own = TRUE;
}
// Attempt to load the wish list.
$wishlist = uc_wishlist_load($wid);
// Handle a non-existent wish list.
if (!$wishlist) {
// If the requested list was for the current user...
if ($own) {
// Display a message letting them know their list is empty.
drupal_set_title(t('Wish list'));
drupal_set_message(t("You have not added any products to your wish list. You can add any product from the store to your wish list by clicking the 'Add to wish list' button on the product's page."));
return t('There are no products on this wish list.');
}
else {
// Otherwise send them to the search form.
drupal_set_message(t('The wish list you requested could not be found. Perhaps you can try looking for it through the wish list search form below.'));
drupal_goto('wishlist/search');
}
}
drupal_set_title(check_plain($wishlist->title));
// Add the settings form if the user is viewing his own wish list.
if ($own) {
if (!$user->uid) {
drupal_set_message(t('You must <a href="!login_url">login</a> or <a href="!register_url">register</a> to save your wish list.', array(
'!login_url' => url('user/login'),
'!register_url' => url('user/register'),
)));
}
$collapsed = TRUE;
if (empty($wishlist->address->firstname) || empty($wishlist->address->lastname) || empty($wishlist->address->addr1) || empty($wishlist->address->city) || empty($wishlist->address->postcode)) {
$collapsed = FALSE;
}
$output .= drupal_get_form('uc_wishlist_settings_form', $wishlist, $collapsed);
}
// Add expiration information to the display.
if ($wishlist->expiration < time()) {
$output .= '<p>' . t('This wish list may be no longer valid. It was for an event on @date.', array(
'@date' => format_date($wishlist->expiration),
)) . '</p>';
}
elseif ($wishlist->expiration > 0) {
$output .= '<p>' . t('This wish list is valid until @date.', array(
'@date' => format_date($wishlist->expiration),
)) . '</p>';
}
$items = uc_wishlist_get_contents($wid);
if (empty($items)) {
return '<p>' . t('There are no products on this wish list.') . '</p>';
}
$output .= drupal_get_form('uc_wishlist_view_form', $items, $wid, $own);
return $output;
}