30 lines
906 B
PHP
30 lines
906 B
PHP
|
<?php
|
||
|
|
||
|
class user_selector extends user_selector_base
|
||
|
{
|
||
|
|
||
|
public function find_users($search)
|
||
|
{
|
||
|
global $DB;
|
||
|
|
||
|
// Define the fields you want to select.
|
||
|
$fields = 'id, firstname, lastname, email';
|
||
|
|
||
|
// Create an SQL query to find users based on the search criteria.
|
||
|
$sql = "SELECT $fields
|
||
|
FROM {user}
|
||
|
WHERE CONCAT(firstname, ' ', lastname) LIKE ? OR email LIKE ?";
|
||
|
|
||
|
// Execute the SQL query and retrieve the users.
|
||
|
$users = $DB->get_records_sql($sql, array('%' . $search . '%', '%' . $search . '%'));
|
||
|
|
||
|
// Format the users into a format expected by the user selector.
|
||
|
$options = [];
|
||
|
foreach ($users as $user) {
|
||
|
$options[$user->id] = $user->firstname . ' ' . $user->lastname . ' (' . $user->email . ')';
|
||
|
}
|
||
|
|
||
|
return array(get_string('users') => $options);
|
||
|
}
|
||
|
}
|