XF 2.0 Search for users in database based on user criteria

nocte

Well-known member
I have a set of database entries with a user criteria field.

Now I want to fetch all users that match this criteria.

I searched in the core files, and tired a few things out. This does not work:

PHP:
$users = $this->searcher('XF:User', $message->user_criteria)->getFinder()->fetch();

It gives me just all users. SQL:
SQL:
SELECT `xf_user`.*
FROM `xf_user`

When i dump my $message->user_criteria I get this:
Code:
array:1 [
  "messages_posted" => array:2 [
    "rule" => "messages_posted"
    "data" => array:1 [
      "messages" => "1"
    ]
  ]
]
 
The searcher system to search for users uses a different criteria schema than the criteria system to match against an existing user. You'd have to convert the ruleset accordingly. Dumping the criteria from the admin controller gives the expected form:
PHP:
array(13) {
  ["username"]=>
  string(0) ""
  ["email"]=>
  string(0) ""
  ["user_group_id"]=>
  string(0) ""
  ["no_secondary_group_ids"]=>
  string(1) "0"
  ["register_date"]=>
  array(2) {
    ["start"]=>
    string(0) ""
    ["end"]=>
    string(0) ""
  }
  ["last_activity"]=>
  array(2) {
    ["start"]=>
    string(0) ""
    ["end"]=>
    string(0) ""
  }
  ["message_count"]=>
  array(2) {
    ["start"]=>
    string(1) "0"
    ["end"]=>
    string(2) "-1"
  }
  ["trophy_points"]=>
  array(2) {
    ["start"]=>
    string(1) "0"
    ["end"]=>
    string(2) "-1"
  }
  ["user_state"]=>
  array(7) {
    [0]=>
    string(5) "valid"
    [1]=>
    string(13) "email_confirm"
    [2]=>
    string(18) "email_confirm_edit"
    [3]=>
    string(12) "email_bounce"
    [4]=>
    string(9) "moderated"
    [5]=>
    string(8) "rejected"
    [6]=>
    string(8) "disabled"
  }
  ["is_banned"]=>
  array(2) {
    [0]=>
    string(1) "0"
    [1]=>
    string(1) "1"
  }
  ["Option"]=>
  array(1) {
    ["is_discouraged"]=>
    array(2) {
      [0]=>
      string(1) "0"
      [1]=>
      string(1) "1"
    }
  }
  ["is_staff"]=>
  array(2) {
    [0]=>
    string(1) "0"
    [1]=>
    string(1) "1"
  }
  ["user_field"]=>
  array(3) {
    ["skype"]=>
    string(0) ""
    ["facebook"]=>
    string(0) ""
    ["twitter"]=>
    string(0) ""
  }
}

It looks like it maps each index in the root array to a column in the entity, with subarrays to match multiple values or minimums and maximums (starts and ends).
 
Back
Top Bottom