public function prepareUserConditions(array $conditions, array &$fetchOptions)
{
$db = $this->_getDb();
$sqlConditions = array();
if (!empty($conditions['username']))
{
if (is_array($conditions['username']))
{
$sqlConditions[] = 'user.username LIKE ' . XenForo_Db::quoteLike($conditions['username'][0], $conditions['username'][1], $db);
}
else
{
$sqlConditions[] = 'user.username LIKE ' . XenForo_Db::quoteLike($conditions['username'], 'lr', $db);
}
}
// this is mainly for dynamically filtering a search that already matches user names
if (!empty($conditions['username2']))
{
if (is_array($conditions['username2']))
{
$sqlConditions[] = 'user.username LIKE ' . XenForo_Db::quoteLike($conditions['username2'][0], $conditions['username2'][1], $db);
}
else
{
$sqlConditions[] = 'user.username LIKE ' . XenForo_Db::quoteLike($conditions['username2'], 'lr', $db);
}
}
if (!empty($conditions['usernames']) && is_array($conditions['usernames']))
{
$sqlConditions[] = 'user.username IN (' . $db->quote($conditions['usernames']) . ')';
}
if (!empty($conditions['email']))
{
if (is_array($conditions['email']))
{
$sqlConditions[] = 'user.email LIKE ' . XenForo_Db::quoteLike($conditions['email'][0], $conditions['email'][1], $db);
}
else
{
$sqlConditions[] = 'user.email LIKE ' . XenForo_Db::quoteLike($conditions['email'], 'lr', $db);
}
}
if (!empty($conditions['emails']) && is_array($conditions['emails']))
{
$sqlConditions[] = 'user.email IN (' . $db->quote($conditions['emails']) . ')';
}
if (!empty($conditions['user_group_id']))
{
if (is_array($conditions['user_group_id']))
{
$sqlConditions[] = 'user.user_group_id IN (' . $db->quote($conditions['user_group_id']) . ')';
}
else
{
$sqlConditions[] = 'user.user_group_id = ' . $db->quote($conditions['user_group_id']);
}
}
if (!empty($conditions['secondary_group_ids']))
{
if (is_array($conditions['secondary_group_ids']))
{
$groupConds = array();
foreach ($conditions['secondary_group_ids'] AS $groupId)
{
$groupConds[] = 'FIND_IN_SET(' . $db->quote($groupId) . ', user.secondary_group_ids)';
}
$sqlConditions[] = '(' . implode(' OR ', $groupConds) . ')';
}
else
{
$sqlConditions[] = 'FIND_IN_SET(' . $db->quote($conditions['secondary_group_ids']) . ', user.secondary_group_ids)';
}
}
if (!empty($conditions['last_activity']) && is_array($conditions['last_activity']))
{
list($operator, $cutOff) = $conditions['last_activity'];
$this->assertValidCutOffOperator($operator);
$sqlConditions[] = "user.last_activity $operator " . $db->quote($cutOff);
}
if (!empty($conditions['message_count']) && is_array($conditions['message_count']))
{
list($operator, $cutOff) = $conditions['message_count'];
$this->assertValidCutOffOperator($operator);
$sqlConditions[] = "user.message_count $operator " . $db->quote($cutOff);
}
if (!empty($conditions['user_state']) && $conditions['user_state'] !== 'any')
{
if (is_array($conditions['user_state']))
{
$sqlConditions[] = 'user.user_state IN (' . $db->quote($conditions['user_state']) . ')';
}
else
{
$sqlConditions[] = 'user.user_state = ' . $db->quote($conditions['user_state']);
}
}
if (isset($conditions['is_admin']))
{
$sqlConditions[] = 'user.is_admin = ' . ($conditions['is_admin'] ? 1 : 0);
}
if (isset($conditions['is_moderator']))
{
$sqlConditions[] = 'user.is_moderator = ' . ($conditions['is_moderator'] ? 1 : 0);
}
if (isset($conditions['is_banned']))
{
$sqlConditions[] = 'user.is_banned = ' . ($conditions['is_banned'] ? 1 : 0);
}
if (!empty($conditions['receive_admin_email']))
{
$sqlConditions[] = 'user_option.receive_admin_email = 1';
$this->addFetchOptionJoin($fetchOptions, self::FETCH_USER_OPTION);
}
return $this->getConditionsForClause($sqlConditions);
}