mirror of
https://github.com/flarum/framework.git
synced 2025-02-02 16:48:31 +08:00
Clean up gambit
This commit is contained in:
parent
204f63fa29
commit
c89def0d78
|
@ -45,6 +45,7 @@ class SearchServiceProvider extends AbstractServiceProvider
|
|||
$gambits->setFulltextGambit('Flarum\Core\Search\User\Gambit\FulltextGambit');
|
||||
$gambits->add('Flarum\Core\Search\User\Gambit\EmailGambit');
|
||||
$gambits->add('Flarum\Core\Search\User\Gambit\GroupGambit');
|
||||
|
||||
$app->make('events')->fire(
|
||||
new ConfigureUserGambits($gambits)
|
||||
);
|
||||
|
|
|
@ -46,11 +46,11 @@ class GroupGambit extends AbstractRegexGambit
|
|||
throw new LogicException('This gambit can only be applied on a UserSearch');
|
||||
}
|
||||
|
||||
$groupName = trim($matches[1], '"');
|
||||
$groupName = explode(',', $groupName);
|
||||
$groupNames = $this->extractGroupNames($matches);
|
||||
|
||||
// TODO: Use a JOIN instead (and don't forget to remove the findByName() method again)
|
||||
$ids = [];
|
||||
foreach ($groupName as $name) {
|
||||
foreach ($groupNames as $name) {
|
||||
$group = $this->groups->findByName($name);
|
||||
if ($group && count($group->users)) {
|
||||
$ids = array_merge($ids, $group->users->pluck('id')->all());
|
||||
|
@ -59,4 +59,15 @@ class GroupGambit extends AbstractRegexGambit
|
|||
|
||||
$search->getQuery()->whereIn('id', $ids, 'and', $negate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the group names from the pattern match.
|
||||
*
|
||||
* @param array $matches
|
||||
* @return array
|
||||
*/
|
||||
protected function extractGroupNames(array $matches)
|
||||
{
|
||||
return explode(',', trim($matches[1], '"'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user