mirror of
https://github.com/flarum/core.git
synced 2025-10-26 21:21:28 +01:00
Implement user searching & minor search refactor
This commit is contained in:
@@ -5,7 +5,7 @@ use Flarum\Core\Models\User;
|
||||
interface DiscussionRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get a new query builder for ths discussions table.
|
||||
* Get a new query builder for the discussions table.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ use Flarum\Core\Models\User;
|
||||
class EloquentDiscussionRepository implements DiscussionRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get a new query builder for ths discussions table.
|
||||
* Get a new query builder for the discussions table.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,16 @@ use Flarum\Core\Models\User;
|
||||
|
||||
class EloquentUserRepository implements UserRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get a new query builder for the users table.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return User::query();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a user by ID, optionally making sure it is visible to a certain
|
||||
* user, or throw an exception.
|
||||
@@ -49,6 +59,24 @@ class EloquentUserRepository implements UserRepositoryInterface
|
||||
return $this->scopeVisibleForUser($query, $user)->pluck('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Find users by matching a string of words against their username,
|
||||
* optionally making sure they are visible to a certain user.
|
||||
*
|
||||
* @param string $string
|
||||
* @param \Flarum\Core\Models\User|null $user
|
||||
* @return array
|
||||
*/
|
||||
public function getIdsForUsername($string, User $user = null)
|
||||
{
|
||||
$query = User::select('id')
|
||||
->where('username', 'like', '%'.$string.'%')
|
||||
->orderByRaw('username = ? desc', [$string])
|
||||
->orderByRaw('username like ? desc', [$string.'%']);
|
||||
|
||||
return $this->scopeVisibleForUser($query, $user)->lists('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include records that are visible to a user.
|
||||
*
|
||||
|
||||
@@ -4,6 +4,13 @@ use Flarum\Core\Models\User;
|
||||
|
||||
interface UserRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get a new query builder for the users table.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function query();
|
||||
|
||||
/**
|
||||
* Find a user by ID, optionally making sure it is visible to a certain
|
||||
* user, or throw an exception.
|
||||
@@ -32,4 +39,14 @@ interface UserRepositoryInterface
|
||||
* @return integer|null
|
||||
*/
|
||||
public function getIdForUsername($username, User $user = null);
|
||||
|
||||
/**
|
||||
* Find users by matching a string of words against their username,
|
||||
* optionally making sure they are visible to a certain user.
|
||||
*
|
||||
* @param string $string
|
||||
* @param \Flarum\Core\Models\User|null $user
|
||||
* @return array
|
||||
*/
|
||||
public function getIdsForUsername($string, User $user = null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user