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