function _avatar_selection_image_list in Avatar Selection 6
Same name and namespace in other branches
- 5.2 avatar_selection.module \_avatar_selection_image_list()
- 5 avatar_selection.module \_avatar_selection_image_list()
- 7 avatar_selection.module \_avatar_selection_image_list()
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 calls to _avatar_selection_image_list()
- avatar_selection_edit_form in ./
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 ./
avatar_selection.module - Implementation of hook_form_alter().
- avatar_selection_form_user_register_alter in ./
avatar_selection.module - Implementation of hook_form_alter().
- avatar_selection_get_random_image in ./
avatar_selection.module - Select a random avatar picture for a certain user.
File
- ./
avatar_selection.module, line 390 - 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_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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
if (module_exists('imagecache')) {
$imagecache_preset = variable_get('avatar_selection_imagecache_preset', 0);
}
while ($avatar = db_fetch_object($result)) {
$avs_image = $avatar->avatar;
$name = $avatar->name;
if (module_exists('imagecache') && $imagecache_preset) {
$avatars[$avs_image] = theme('imagecache', $imagecache_preset, $dir . '/' . $avs_image, $name, $name);
}
else {
$avatars[$avs_image] = theme('image', $url . '/' . $avs_image, $name, $name, NULL, FALSE);
}
}
$selects['avatars'] = $avatars;
$selects['total'] = $total;
return $selects;
}