You are here

function avatar_selection_get_random_image in Avatar Selection 7

Same name and namespace in other branches
  1. 5.2 avatar_selection.module \avatar_selection_get_random_image()
  2. 5 avatar_selection.module \avatar_selection_get_random_image()
  3. 6 avatar_selection.module \avatar_selection_get_random_image()

Select a random avatar picture for a certain user.

Parameters

$user: User object.

Return value

Return the file object of the image to be used as an avatar.

1 call to avatar_selection_get_random_image()
avatar_selection_validate_user_avatar in ./avatar_selection.module
Validate and upload the user's picture.

File

./avatar_selection.module, line 461
The Avatar Selection module allows the user to pick an avatar image from a list already loaded by an administrative user, and to the administrator to disable uploading other avatar files by the user.

Code

function avatar_selection_get_random_image($user) {
  $avatars = _avatar_selection_image_list($user);
  if ($avatars['total'] > 0) {
    $fid = array_rand($avatars['avatars'], 1);
    if ($fid) {
      $avatar = file_load($fid);
      return $avatar;
    }
  }
  return FALSE;
}