You are here

function uc_wishlist_save_wishlist in UC Wish List 7

Save wishlist for the current authenticated or anonymous user.

2 calls to uc_wishlist_save_wishlist()
uc_wishlist_add_item in ./uc_wishlist.module
Adds an item to a user's wish list.
uc_wishlist_settings_form_submit in ./uc_wishlist.pages.inc
Submission handler for wish list settings form.

File

./uc_wishlist.module, line 699
Allows users to create public shopping/wish lists.

Code

function uc_wishlist_save_wishlist($wishlist = NULL) {
  if (is_object($wishlist) && $wishlist->wid) {
    $return = drupal_write_record('uc_wishlists', $wishlist, 'wid');
    return $return;
  }
  else {
    global $user;

    // Abort if user is not logged in and anonymous wish lists are not allowed.
    if (!$user->uid && !user_access('create wish lists')) {
      drupal_set_message(t('You must be logged in to create a wish list. Please <a href="!login_url">login</a> or <a href="!register_url">register</a>.', array(
        '!login_url' => url('user', array(
          'query' => drupal_get_destination(),
        )),
        '!register_url' => url('user/register', array(
          'query' => drupal_get_destination(),
        )),
      )), 'error');
      return FALSE;
    }
    $title = variable_get('uc_wishlist_default_title', "%user's wish list");
    if (strpos($title, '%user') !== FALSE) {
      $uname = !empty($user->name) ? $user->name : variable_get('anonymous', t('Anonymous'));
      $title = str_replace('%user', $uname, $title);
    }
    $wishlist = new stdClass();
    $wishlist->uid = uc_wishlist_get_uid();
    $wishlist->title = $title;
    $wishlist->expiration = REQUEST_TIME + variable_get('uc_wishlist_default_length', 2592000);
    $wishlist->private = variable_get('uc_wishlist_default_private', FALSE) ? variable_get('uc_wishlist_default_private', FALSE) : 0;
    $wishlist->description = '';
    $return = drupal_write_record('uc_wishlists', $wishlist);
  }
  return $return;
}