1
0
mirror of https://github.com/flarum/core.git synced 2025-08-13 20:04:24 +02:00

Update for search filter split

This commit is contained in:
Alexander Skvortsov
2021-03-13 15:35:53 -05:00
parent cea10c8e9b
commit 668de47095
3 changed files with 50 additions and 37 deletions

View File

@@ -1,29 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Lock\Gambit;
use Flarum\Search\AbstractRegexGambit;
use Flarum\Search\AbstractSearch;
class LockedGambit extends AbstractRegexGambit
{
/**
* {@inheritdoc}
*/
protected $pattern = 'is:locked';
/**
* {@inheritdoc}
*/
protected function conditions(AbstractSearch $search, array $matches, $negate)
{
$search->getQuery()->where('is_locked', ! $negate);
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Lock\Query;
use Flarum\Filter\FilterInterface;
use Flarum\Filter\FilterState;
use Flarum\Search\AbstractRegexGambit;
use Flarum\Search\SearchState;
use Illuminate\Database\Query\Builder;
class LockedFilterGambit extends AbstractRegexGambit implements FilterInterface
{
protected function getGambitPattern() {
return 'is:locked';
}
protected function conditions(SearchState $searchState, array $matches, $negate)
{
$this->constrain($searchState->getQuery(), $negate);
}
public function getFilterKey(): string {
return 'locked';
}
public function filter(FilterState $filterState, string $filterValue, bool $negate)
{
$this->constrain($filterState->getQuery(), $negate);
}
protected function constrain(Builder $query, bool $negate)
{
$query->where('is_locked', ! $negate);
}
}