You are here

function favorites_load_favorites in Favorites 7

Same name and namespace in other branches
  1. 6 favorites.module \favorites_load_favorites()
  2. 7.2 favorites.module \favorites_load_favorites()

Load the favorites for a particular user.

Parameters

$account: The user account to load the favorites for. (Optional; defaults to the current user.)

1 call to favorites_load_favorites()
favorites_list in ./favorites.module
Generate the "My Favorites" list.

File

./favorites.module, line 300
The favorites module allows users to bookmark any path within a site.

Code

function favorites_load_favorites($account = NULL) {
  if (!isset($account)) {
    global $user;
    $account = $user;
  }
  if (_favorites_user_storage_db($account)) {

    // Load registered users' data from the DB.
    $raw_data = _favorites_load_favorites_db($account);
  }
  else {

    // Load anonymous users' data from their cookies.
    $raw_data = _favorites_load_favorites_cookie();
  }

  // Initialize result array.
  $favorites = array();

  // Process favorites.
  foreach ($raw_data as $favorite) {
    $favorite->token = favorites_token($favorite);
    $favorite->path = drupal_get_path_alias($favorite->path);
    $favorites[] = $favorite;
  }
  return $favorites;
}