All pastes #367540 Raw Edit

Anonymous

public php v1 · immutable
#367540 ·published 2007-02-22 12:39 UTC
rendered paste body
/** * Gets the image and name of the awards for a user, or group of users * * @parameter	$user_id	mixed	An array or int of user id(s). * @return					mixed	The data for the user(s) */function get_awards_data($user_id, $exclude_id = false){	global $db;		$user_was_int	= ( !is_array($user_id) ) ? true : false;	$user_id		= ( is_array($user_id) ) ? $user_id : array($user_id);	$exclude_id		= ( is_array($exclude_id) ) ? $exclude_id : array($exclude_id);		array_walk($user_id, 'intval');	array_walk($exclude_id, 'intval');	$where_sql = 'au.user_id IN (' . implode(',', $user_id) . ')';	if ( sizeof($exclude_id) > 0 )	{		$where_sql .= ' AND a.award_id NOT IN (' . implode(',', $exclude_id) . ')';	}		$sql = $db->sql_build_query('SELECT', array(		'SELECT'	=> 'au.user_id, a.award_id, a.award_image, a.award_name',		'FROM'		=> array(AWARDS_USERS_TABLE => 'au'),		'LEFT_JOIN'	=> array(			array(				'FROM'	=> array(AWARDS_TABLE => 'a'),				'ON'	=> 'au.award_id = a.award_id',			)		),		'WHERE'		=> $where_sql,		'ORDER_BY'	=> 'a.award_name')	);	$result = $db->sql_query($sql);	$resultset = array();	while ( $row = $db->sql_fetchrow($result) )	{		$resultset[ $row['user_id'] ][] = $row;	}	$db->sql_freeresult($result);	if ( sizeof ( array_diff ( $user_id, array_keys($resultset) ) ) < 1 )	{		return (!$user_was_int) ? $resultset : $resultset[$user_id];	}	$where_sql = 'm.user_id IN (' . implode(',', $user_id) . ')';	if ( sizeof($exclude_id) > 0 )	{		$where_sql .= ' AND a.award_id NOT IN (' . implode(',', $exclude_id) . ')';	}	$sql = $db->sql_build_query('SELECT', array(		'SELECT'	=> 'm.user_id, a.award_id, a.award_image, a.award_name',		'FROM'		=> array(AWARDS_MODS_TABLE => 'm'),		'LEFT_JOIN'	=> array(			array(				'FROM'	=> array(AWARDS_CATS_TABLE => 'c'),				'ON'	=> 'm.cat_id = c.cat_id',			),			array(				'FROM'	=> array(AWARDS_TABLE => 'a'),				'ON'	=> 'c.cat_id = a.cat_id',			)		),		'WHERE'		=> $where_sql,		'ORDER_BY'	=> 'a.award_name')	);	$result = $db->sql_query($sql);	while ( $row = $db->sql_fetchrow($result) )	{		$resultset[ $row['user_id'] ][] = $row;	}	$db->sql_freeresult($result);	return (!$user_was_int) ? $resultset : $resultset[$user_id];}