You are here

function finder_user_finder_find in Finder 7

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

Implements hook_finder_find().

See also

hook_finder_find()

File

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

Code

function finder_user_finder_find($finder, $finder_element_id, $keywords, $mode, $match, $pager) {
  $prequery = array();
  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])) {
      $prequery['joins']['innerJoin'][] = array(
        'users_roles',
        'users_roles',
        'users_roles.uid = users.uid',
      );
      if ($feid == $finder_element_id) {
        $prequery['conditions'][] = (object) array(
          'field' => 'users_roles.rid',
          'value' => array_keys($roles[$feid]),
          'match' => 'IN',
        );
      }
      else {
        $prequery['conditions']['restrictions'][$feid][] = (object) array(
          'field' => 'users_roles.rid',
          'value' => array_keys($roles[$feid]),
          'match' => 'IN',
        );
      }
    }
  }

  // restrict to active users if required
  if (in_array(1, $active)) {
    $prequery['conditions'][] = array(
      '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';
  return finder_find_query($prequery, $finder, $finder_element_id, $keywords, $mode, $match, $pager, $join_ons, $base_table, $base_field);
}