You are here

function finder_user_finder_find in Finder 6

Same name and namespace in other branches
  1. 7 modules/finder_user/finder_user.module \finder_user_finder_find()

Implementation of hook_finder_find().

See also

hook_finder_find()

File

modules/finder_user/finder_user.module, line 132
The finder user module.

Code

function finder_user_finder_find($finder, $finder_element_id, $keywords, $mode, $match, $pager) {
  foreach ($keywords as $feid => $keyword_array) {
    $element =& finder_element($finder, $feid);
    $roles[$feid] =& $element->settings['choices']['user_roles'];
    $active[$feid] =& $element->settings['choices']['active'];

    // restrict by roles
    unset($roles[$feid]['']);
    if (!empty($roles[$feid])) {
      $query['joins'] = array(
        'INNER JOIN {users_roles} users_roles ON users_roles.uid = users.uid',
      );
      if ($feid == $finder_element_id) {
        $query['wheres'][] = "users_roles.rid IN (" . db_placeholders(array_keys($roles[$feid])) . ")";
      }
      else {
        $query['wheres']['restrictions'][$feid][] = "users_roles.rid IN (" . db_placeholders(array_keys($roles[$feid])) . ")";
      }
      $query['arguments'] = isset($query['arguments']) ? array_merge($query['arguments'], array_keys($roles[$feid])) : array_keys($roles[$feid]);
    }
  }

  // restrict to active users if required
  if (in_array(1, $active)) {
    $query['wheres'][] = 'users.status = 1';
  }
  $join_ons = array(
    'role' => array(
      'users_roles' => 'users_roles.uid = users.uid',
      'role' => 'role.rid = users_roles.rid',
    ),
  );
  $base_table = 'users';
  $base_field = 'uid';
  $query = finder_find_query($query, $finder, $finder_element_id, $keywords, $mode, $match, $pager, $join_ons, $base_table, $base_field);
  return finder_query($query);
}