Skip to content

Commit

Permalink
add filter on picture
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMendolia committed Sep 21, 2023
1 parent 43bdad5 commit 78483ab
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/Controller/AutocompleteGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function index(Request $request, BookRepository $bookRepository, string $

$exactmatch = false;
$json = ['results' => []];

if ($type !== 'authors' && $query === '' && $request->get('create', true) !== true) {
$json['results'][] = ['value' => 'no_'.$type, 'text' => '[No '.$type.' defined]'];
}
foreach ($group as $item) {
if (!str_contains(strtolower($item['item']), strtolower($query))) {
continue;
Expand All @@ -42,9 +46,7 @@ public function index(Request $request, BookRepository $bookRepository, string $
}
$json['results'][] = ['value' => $item['item'], 'text' => $item['item']];
}
if (($type !== 'authors') && $query === '' && $request->get('create', true) !== true) {
$json['results'][] = ['value' => 'no_'.$type, 'text' => '[No '.$type.' defined]'];
}

if (!$exactmatch && strlen($query) > 2 && $request->get('create', true) === true) {
$json['results'][] = ['value' => $query, 'text' => 'New: '.$query];
}
Expand Down
24 changes: 22 additions & 2 deletions src/Form/BookFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void

$builder->add('serieIndexGTE', Type\SearchType::class, [
'required' => false,
'mapped'=>false,
'mapped' => false,
'target_callback' => function (QueryBuilder $qb, ?string $searchValue): void {
if ($searchValue !== null) {
$qb->andWhere('book.serieIndex >= :indexGTE');
Expand All @@ -43,7 +43,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void

$builder->add('serieIndexLTE', Type\SearchType::class, [
'required' => false,
'mapped'=>false,
'mapped' => false,

'target_callback' => function (QueryBuilder $qb, ?string $searchValue): void {
if ($searchValue !== null) {
Expand Down Expand Up @@ -246,6 +246,26 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('picture', Type\ChoiceType::class, [
'choices' => [
'Any' => '',
'Has picture' => 'with',
'No picture' => 'without',
],
'required' => false,
'mapped' => false,
'target_callback' => function (QueryBuilder $qb, ?string $readValue): void {
switch ($readValue) {
case 'with':
$qb->andWhere('book.imageFilename is not null');
break;
case 'without':
$qb->andWhere('book.imageFilename is null');
break;
}
},
]);

$builder->add('orderBy', Type\ChoiceType::class, [
'choices' => [
'title' => 'title',
Expand Down
1 change: 1 addition & 0 deletions src/Service/FilteredBookUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FilteredBookUrlGenerator
'serie' => '',
'publisher' => '',
'read' => '',
'picture' => '',
'favorite' => '',
'verified' => '',
'orderBy' => 'title',
Expand Down
7 changes: 5 additions & 2 deletions templates/default/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="col-md-2">
{{ form_row(form.authorsNot) }}
</div>
<div class="col-md-3">
<div class="col-md-2">
{{ form_row(form.tags) }}
</div>
<div class="col-md-2">
{{ form_row(form.picture) }}
</div>
<div class="col-md-2">
{{ form_row(form.favorite) }}
</div>
Expand Down

0 comments on commit 78483ab

Please sign in to comment.