-
-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7961e4a
commit 583ed0d
Showing
17 changed files
with
285 additions
and
492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?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\Discussion\Filter; | ||
|
||
use Flarum\Filter\FilterInterface; | ||
use Flarum\Filter\WrappedFilter; | ||
use Flarum\Search\AbstractRegexGambit; | ||
use Flarum\Search\AbstractSearch; | ||
use Illuminate\Database\Query\Builder; | ||
|
||
class CreatedFilterGambit extends AbstractRegexGambit implements FilterInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $pattern = 'created:(\d{4}\-\d\d\-\d\d)(\.\.(\d{4}\-\d\d\-\d\d))?'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function conditions(AbstractSearch $search, array $matches, $negate) | ||
{ | ||
$this->constrain($search->getQuery(), $matches[1], $matches[3], $negate); | ||
} | ||
|
||
public function getFilterKey(): string | ||
{ | ||
return 'created'; | ||
} | ||
|
||
public function filter(WrappedFilter $wrappedFilter, string $filterValue, bool $negate) | ||
{ | ||
preg_match('/^'.$this->pattern.'$/i', 'created:'.$filterValue, $matches); | ||
|
||
$this->constrain($wrappedFilter->getQuery(), $matches[1], $matches[3], $negate); | ||
} | ||
|
||
public function constrain(Builder $query, $firstDate, $secondDate, $negate) | ||
{ | ||
// If we've just been provided with a single YYYY-MM-DD date, then find | ||
// discussions that were started on that exact date. But if we've been | ||
// provided with a YYYY-MM-DD..YYYY-MM-DD range, then find discussions | ||
// that were started during that period. | ||
if (empty($secondDate)) { | ||
$query->whereDate('created_at', $negate ? '!=' : '=', $firstDate); | ||
} else { | ||
$query->whereBetween('created_at', [$firstDate, $secondDate], 'and', $negate); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.