function uc_wishlist_display in UC Wish List 7
Same name and namespace in other branches
- 6 uc_wishlist.pages.inc \uc_wishlist_display()
Display a wish list for viewing or altering.
Parameters
numeric $wid: The ID of the wish list to display.
Return value
html HTML output for the wish list display and form.
1 string reference to 'uc_wishlist_display'
- uc_wishlist_menu in ./
uc_wishlist.module - Implements 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 = FALSE;
if (empty($wid)) {
// Default to the current user's wish list if no wishlist ID is specified.
$wid = uc_wishlist_get_wid();
$own = TRUE;
}
elseif (is_object($wid)) {
// $wid is actually a user account.
$wid = uc_wishlist_get_wid($wid->uid);
}
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');
}
}
// Display only if it's my own or it's not private.
if (!$wishlist->private || $own) {
drupal_set_title($wishlist->title);
// Add the settings form if the user is viewing his own wish list.
if ($own) {
if (!$user->uid) {
drupal_set_message(filter_xss(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;
}
// Add the wishlist description.
if ($wishlist->description) {
$output .= '<p>' . filter_xss($wishlist->description) . '</p>';
}
// Add expiration information to the display.
if ($wishlist->expiration < REQUEST_TIME) {
$output .= '<p>' . t('This wish list may no longer be 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>';
}
$form = drupal_get_form('uc_wishlist_view_form', $items, $wid, $own);
$output .= drupal_render($form);
}
else {
drupal_goto('wishlist/search');
}
return $output;
}