You are here

function uc_wishlist_user_display in UC Wish List 7

Display a wishlist in user account page.

We will display wish list address settings and wishlist expiry settings.

2 string references to 'uc_wishlist_user_display'
uc_wishlist_menu in ./uc_wishlist.module
Implements hook_menu().
uc_wishlist_theme in ./uc_wishlist.module
Implements hook_theme().

File

./uc_wishlist.pages.inc, line 99
Page callback and functions for wish lists.

Code

function uc_wishlist_user_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);
  }
  elseif (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($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;
    if (variable_get('uc_wishlist_save_address', TRUE) && (empty($wishlist->address->firstname) || empty($wishlist->address->lastname) || empty($wishlist->address->addr1) || empty($wishlist->address->city) || empty($wishlist->address->postcode))) {
      $collapsed = FALSE;
    }
    $settings_form = drupal_get_form('uc_wishlist_settings_form', $wishlist, $collapsed);
  }

  // Display only if it's my own or it's not private.
  if (!$wishlist->private || $own) {
    $expired = $wishlist->expiration < REQUEST_TIME;
    $expiration_date = format_date($wishlist->expiration, 'uc_store');

    // Add expiration information to the display.
    if ($expired) {
      $message = t('This wish list may no longer be valid. It was for an event on @date.', array(
        '@date' => $expiration_date,
      ));
    }
    elseif ($wishlist->expiration > 0) {
      $message = t('This wish list is valid until @date.', array(
        '@date' => $expiration_date,
      ));
    }
    $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 = theme('uc_wishlist_user_display', array(
      'settings_form' => $settings_form,
      'expired' => $expired,
      'expiration_date' => $expiration_date,
      'message' => $message,
      'wishlist' => $form,
      'email_link' => url('user/' . $user->uid . '/wishlist-email'),
    ));
  }
  return $output;
}