mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-23 17:41:01 +00:00
Merge pull request #2157 from wallabag/lower-upper-readingtime
Handle only upper or only lower reading filter
This commit is contained in:
commit
fb5c17a9ab
2 changed files with 52 additions and 7 deletions
|
@ -36,16 +36,25 @@ class EntryFilterType extends AbstractType
|
|||
$builder
|
||||
->add('readingTime', NumberRangeFilterType::class, [
|
||||
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
|
||||
$value = $values['value'];
|
||||
$lower = $values['value']['left_number'][0];
|
||||
$upper = $values['value']['right_number'][0];
|
||||
|
||||
if (null === $value['left_number'][0] || null === $value['right_number'][0]) {
|
||||
$min = (int) ($lower * $this->user->getConfig()->getReadingSpeed());
|
||||
$max = (int) ($upper * $this->user->getConfig()->getReadingSpeed());
|
||||
|
||||
if (null === $lower && null === $upper) {
|
||||
// no value? no filter
|
||||
return;
|
||||
}
|
||||
|
||||
$min = (int) ($value['left_number'][0] * $this->user->getConfig()->getReadingSpeed());
|
||||
$max = (int) ($value['right_number'][0] * $this->user->getConfig()->getReadingSpeed());
|
||||
|
||||
} elseif (null === $lower && null !== $upper) {
|
||||
// only lower value is defined: query all entries with reading LOWER THAN this value
|
||||
$expression = $filterQuery->getExpr()->lte($field, $max);
|
||||
} elseif (null !== $lower && null === $upper) {
|
||||
// only upper value is defined: query all entries with reading GREATER THAN this value
|
||||
$expression = $filterQuery->getExpr()->gte($field, $min);
|
||||
} else {
|
||||
// both value are defined, perform a between
|
||||
$expression = $filterQuery->getExpr()->between($field, $min, $max);
|
||||
}
|
||||
|
||||
return $filterQuery->createCondition($expression);
|
||||
},
|
||||
|
|
|
@ -499,6 +499,42 @@ class EntryControllerTest extends WallabagCoreTestCase
|
|||
$this->assertCount(1, $crawler->filter('div[class=entry]'));
|
||||
}
|
||||
|
||||
public function testFilterOnReadingTimeOnlyUpper()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/unread/list');
|
||||
|
||||
$form = $crawler->filter('button[id=submit-filter]')->form();
|
||||
|
||||
$data = [
|
||||
'entry_filter[readingTime][right_number]' => 22,
|
||||
];
|
||||
|
||||
$crawler = $client->submit($form, $data);
|
||||
|
||||
$this->assertCount(2, $crawler->filter('div[class=entry]'));
|
||||
}
|
||||
|
||||
public function testFilterOnReadingTimeOnlyLower()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/unread/list');
|
||||
|
||||
$form = $crawler->filter('button[id=submit-filter]')->form();
|
||||
|
||||
$data = [
|
||||
'entry_filter[readingTime][left_number]' => 22,
|
||||
];
|
||||
|
||||
$crawler = $client->submit($form, $data);
|
||||
|
||||
$this->assertCount(4, $crawler->filter('div[class=entry]'));
|
||||
}
|
||||
|
||||
public function testFilterOnUnreadStatus()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
|
|
Loading…
Reference in a new issue