_avatar_selection_image_list

Versions
5
_avatar_selection_image_list($user = "", $set_type = "", $set_id = 0)
6
_avatar_selection_image_list($user = "", $set_type = "", $set_id = 0, $from = 0, $count = 0)

Get the list of avatars available to a certain user.

Parameters

$user User object (optional).

$set_type Set type, can be 'role' or 'og' (optional).

$set_id The unique identifier of the set (optional).

$from The offset.

$count Number of avatars to return.

Return value

Return an array with the list of avatars for the current user, together with the number of avatars.

▾ 4 functions call _avatar_selection_image_list()

avatar_selection_edit_form in contributions/avatar_selection/avatar_selection.admin.inc
Create the form structure for listing the avatars and managing them in the 'Manage Avatars' tab under the Avatar Selection administration page.
avatar_selection_form_user_profile_form_alter in contributions/avatar_selection/avatar_selection.module
Implementation of hook_form_alter().
avatar_selection_form_user_register_alter in contributions/avatar_selection/avatar_selection.module
Implementation of hook_form_alter().
avatar_selection_get_random_image in contributions/avatar_selection/avatar_selection.module
Select a random avatar picture for a certain user.

Code

contributions/avatar_selection/avatar_selection.module, line 390

<?php
function _avatar_selection_image_list($user = "", $set_type = "", $set_id = 0, $from = 0, $count = 0) {
  $avatars = array();
  $dir = file_create_path('avatar_selection');
  $url = file_create_url($dir);
  $total = 0;

  // If we're searching on a particular role.
  if ($set_type =='role') {
    if ($set_id) {
      $total = db_result(db_query("SELECT count(*) FROM {avatar_selection} avs, {avatar_selection_roles} avsr WHERE avs.aid = avsr.aid AND avsr.rid = %d", $set_id));
      $result = db_query_range("SELECT DISTINCT avatar, name, weight FROM {avatar_selection} avs, {avatar_selection_roles} avsr WHERE avs.aid = avsr.aid AND avsr.rid = %d ORDER BY weight, name, avatar", $set_id, $from, $count);
    }
    else {
      $total = db_result(db_query("SELECT count(*) FROM {avatar_selection} avs LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid WHERE avsr.rid IS NULL"));
      $result = db_query_range("SELECT DISTINCT avatar, name, weight FROM {avatar_selection} avs LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid WHERE avsr.rid IS NULL ORDER BY weight, name, avatar", $from, $count);
    }
  }

  // If we're searching on a particular organic group.
  elseif ($set_type =='og') {
    if ($set_id) {
      $total = db_result(db_query("SELECT count(*) FROM {avatar_selection} avs, {avatar_selection_og} og WHERE avs.aid = og.aid AND og.ogid = %d", $set_id));
      $result = db_query_range("SELECT DISTINCT avatar, name, weight FROM {avatar_selection} avs, {avatar_selection_og} og WHERE avs.aid = og.aid AND og.ogid = %d ORDER BY weight, name, avatar", $set_id, $from
, $count);
    }
    else {
      $total = db_result(db_query("SELECT count(*) FROM {avatar_selection} avs LEFT JOIN {avatar_selection_og} og ON avs.aid = og.aid WHERE og.ogid IS NULL"));
      $result = db_query_range("SELECT DISTINCT avatar, name, weight FROM {avatar_selection} avs LEFT JOIN {avatar_selection_og} og ON avs.aid = og.aid WHERE og.ogid IS NULL ORDER BY weight, name, avatar", $from, $count);
    }
  }  // Searching for available avatars for a particular user.
  elseif (!empty($user)) {
    // Set up some variables.
    $user_roles = array_keys($user->roles);
    $user_og = array();
    if (module_exists("og")) {
      if (!empty($user->og_groups) && is_array($user->og_groups)) {
        $user_og = array_keys($user->og_groups);
      }
    }

    // Distinct avatars are enabled.
    if (variable_get('avatar_selection_distinctive_avatars', FALSE)) {
      // Organic groups enabled.
      if (module_exists("og") && !empty($user_og)) {
        $total = db_result(db_query("SELECT count(distinct avs.aid) FROM {avatar_selection} avs LEFT JOIN {users} u ON u.picture = concat('%s/', avs.avatar) LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid LEFT JOIN {avatar_selection_og} avso ON avs.aid = avso.aid WHERE u.picture IS NULL AND (avsr.rid IS NULL OR avsr.rid IN (". db_placeholders($user_roles) .")) AND (avso.ogid IS NULL OR avso.ogid IN (". db_placeholders($user_og) ."))", array_merge(array($dir), $user_roles, $user_og)));
        if ($count == 0) $count = $total;
        $result = db_query_range("SELECT DISTINCT avatar, avs.name, avs.weight FROM {avatar_selection} avs LEFT JOIN {users} u ON u.picture = concat('%s/', avs.avatar) LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid LEFT JOIN {avatar_selection_og} avso ON avs.aid = avso.aid WHERE u.picture IS NULL AND (avsr.rid IS NULL OR avsr.rid IN (". db_placeholders($user_roles) .")) AND (avso.ogid IS NULL OR avso.ogid IN (". db_placeholders($user_og) .")) ORDER BY avs.weight, avs.name, avatar", array_merge(array($dir), $user_roles, $user_og), $from, $count);
      }
      else {
        $total = db_result(db_query("SELECT count(distinct avs.aid) FROM {avatar_selection} avs LEFT JOIN {users} u ON u.picture = concat('%s/', avs.avatar) LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid WHERE u.picture IS NULL AND (avsr.rid IS NULL OR avsr.rid IN (". db_placeholders($user_roles) ."))", array_merge(array($dir), $user_roles)));
        if ($count == 0) $count = $total;
        $result = db_query_range("SELECT DISTINCT avatar, avs.name, avs.weight FROM {avatar_selection} avs LEFT JOIN {users} u ON u.picture = concat('%s/', avs.avatar) LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid WHERE u.picture IS NULL AND (avsr.rid IS NULL OR avsr.rid IN (". db_placeholders($user_roles) .")) ORDER BY avs.weight, avs.name, avatar", array_merge(array($dir), $user_roles), $from, $count);
      }
    }

    // Not root user, check permissions.
    // User is logged in and is not root, or is an anonymous user.
    elseif ($user->uid > 1 || in_array(1, array_keys($user->roles))) {
      // Organic groups enabled.
      if (module_exists("og") && !empty($user_og)) {
        $total = db_result(db_query("SELECT count(distinct avs.aid) FROM {avatar_selection} avs LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid LEFT JOIN {avatar_selection_og} avso ON avs.aid = avso.aid WHERE (avsr.rid IS NULL OR avsr.rid IN (". db_placeholders($user_roles) .")) AND (avso.ogid IS NULL OR avso.ogid IN (". db_placeholders($user_og) ."))", array_merge($user_roles, $user_og)));
        if ($count == 0) $count = $total;
        $result = db_query_range("SELECT DISTINCT avatar, name, weight FROM {avatar_selection} avs LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid LEFT JOIN {avatar_selection_og} avso ON avs.aid = avso.aid WHERE (avsr.rid IS NULL OR avsr.rid IN (". db_placeholders($user_roles) .")) AND (avso.ogid IS NULL OR avso.ogid IN (". db_placeholders($user_og) .")) ORDER BY weight, name, avatar", array_merge($user_roles, $user_og), $from, $count);
      }
      else {
        $total = db_result(db_query("SELECT count(distinct avs.aid) FROM {avatar_selection} avs LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid WHERE avsr.rid IS NULL OR avsr.rid IN (". db_placeholders($user_roles) .")", $user_roles));
        if ($count == 0) $count = $total;
        $result = db_query_range("SELECT DISTINCT avatar, name, weight FROM {avatar_selection} avs LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid WHERE avsr.rid IS NULL OR avsr.rid IN (". db_placeholders($user_roles) .") ORDER BY weight, name, avatar", $user_roles, $from, $count);
      }
    }

    // Root user, so just fetch all avatars.
    else {
      $total = db_result(db_query("SELECT count(*) FROM {avatar_selection} avs"));
      if ($count == 0) $count = $total;
      $result = db_query_range("SELECT aid, avatar, name, weight FROM {avatar_selection} avs ORDER BY weight, name, avatar", $from, $count);
    }
  }

  while ($avatar = db_fetch_object($result)) {
    $avs_image = $avatar->avatar;
    $name = $avatar->name;
    $avatars[$avs_image] = theme('image', $url .'/'. $avs_image, $name, $name, NULL, FALSE);
  }
  $selects['avatars'] = $avatars;
  $selects['total'] = $total;

  return $selects;
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.