diff --git a/docker-compose.yml b/docker-compose.yml index 357df7f6..bd7887e2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,7 +43,6 @@ services: - mariadb:/var/lib/mysql networks: - default - - pontsun volumes: mariadb: diff --git a/src/Controller/AutocompleteGroupController.php b/src/Controller/AutocompleteGroupController.php index 1cc6fe3c..9af12dd7 100644 --- a/src/Controller/AutocompleteGroupController.php +++ b/src/Controller/AutocompleteGroupController.php @@ -42,6 +42,9 @@ 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]; } diff --git a/src/Form/BookFilterType.php b/src/Form/BookFilterType.php index 23be5e00..7cd02467 100644 --- a/src/Form/BookFilterType.php +++ b/src/Form/BookFilterType.php @@ -30,6 +30,29 @@ public function buildForm(FormBuilderInterface $builder, array $options): void }, ]); + $builder->add('serieIndexGTE', Type\SearchType::class, [ + 'required' => false, + 'mapped'=>false, + 'target_callback' => function (QueryBuilder $qb, ?string $searchValue): void { + if ($searchValue !== null) { + $qb->andWhere('book.serieIndex >= :indexGTE'); + $qb->setParameter('indexGTE', $searchValue); + } + }, + ]); + + $builder->add('serieIndexLTE', Type\SearchType::class, [ + 'required' => false, + 'mapped'=>false, + + 'target_callback' => function (QueryBuilder $qb, ?string $searchValue): void { + if ($searchValue !== null) { + $qb->andWhere('book.serieIndex <= :indexLTE'); + $qb->setParameter('indexLTE', $searchValue); + } + }, + ]); + $builder->add('authors', Type\TextType::class, [ 'autocomplete' => true, 'tom_select_options' => [ @@ -54,6 +77,31 @@ public function buildForm(FormBuilderInterface $builder, array $options): void }, ]); + $builder->add('authorsNot', Type\TextType::class, [ + 'autocomplete' => true, + 'tom_select_options' => [ + 'create' => false, + ], + 'mapped' => false, + 'label' => 'Author not in', + 'required' => false, + 'autocomplete_url' => $this->router->generate('app_autocomplete_group', ['type' => 'authors', 'create' => false]), + 'target_callback' => function (QueryBuilder $qb, ?string $searchValue): void { + if ($searchValue === null || $searchValue === '') { + return; + } + $authors = explode(',', $searchValue); + + $orModule = $qb->expr()->orX(); + + foreach ($authors as $key => $author) { + $orModule->add('JSON_CONTAINS(book.authors, :authorNot'.$key.')=0'); + $qb->setParameter('authorNot'.$key, json_encode([$author])); + } + $qb->andWhere($orModule); + }, + ]); + $builder->add('tags', Type\TextType::class, [ 'autocomplete' => true, 'tom_select_options' => [ @@ -71,8 +119,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $orModule = $qb->expr()->orX(); foreach ($tags as $key => $tag) { - $orModule->add('JSON_CONTAINS(book.tags, :tag'.$key.')=1'); - $qb->setParameter('tag'.$key, json_encode([$tag])); + if ($tag === 'no_tags') { + $orModule->add('book.tags = \'[]\''); + } else { + $orModule->add('JSON_CONTAINS(book.tags, :tag'.$key.')=1'); + $qb->setParameter('tag'.$key, json_encode([$tag])); + } } $qb->andWhere($orModule); }, @@ -95,8 +147,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $orModule = $qb->expr()->orX(); foreach ($series as $key => $serie) { - $orModule->add('book.serie=:serie'.$key); - $qb->setParameter('serie'.$key, $serie); + if ($serie === 'no_serie') { + $orModule->add('book.serie = \'[]\''); + } else { + $orModule->add('book.serie=:serie'.$key); + $qb->setParameter('serie'.$key, $serie); + } } $qb->andWhere($orModule); }, @@ -119,8 +175,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $orModule = $qb->expr()->orX(); foreach ($publishers as $key => $publisher) { - $orModule->add('book.publisher=:publisher'.$key); - $qb->setParameter('publisher'.$key, $publisher); + if ($publisher === 'no_publisher') { + $orModule->add('book.publisher = \'[]\''); + } else { + $orModule->add('book.publisher=:publisher'.$key); + $qb->setParameter('publisher'.$key, $publisher); + } } $qb->andWhere($orModule); }, @@ -189,10 +249,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->add('orderBy', Type\ChoiceType::class, [ 'choices' => [ 'title' => 'title', + 'created' => 'created', + 'updated' => 'updated', 'id' => 'id', 'serieIndex' => 'serieIndex', ], - 'data' => 'title', + 'data' => 'created', 'mapped' => false, 'target_callback' => function (QueryBuilder $qb, ?string $orderByValue): void { $params = $qb->getParameters()->toArray(); @@ -203,7 +265,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $orderByValue = 'serieIndex'; } if ($orderByValue === null) { - $orderByValue = 'title'; + $orderByValue = 'created'; } $qb->orderBy('book.'.$orderByValue, 'ASC'); $qb->addOrderBy('book.serieIndex', 'ASC'); diff --git a/src/Service/FilteredBookUrlGenerator.php b/src/Service/FilteredBookUrlGenerator.php index f2856989..e69dab00 100644 --- a/src/Service/FilteredBookUrlGenerator.php +++ b/src/Service/FilteredBookUrlGenerator.php @@ -9,6 +9,9 @@ class FilteredBookUrlGenerator public const FIELDS_DEFAULT_VALUE = [ 'title' => '', 'authors' => [], + 'authorsNot' => [], + 'serieIndexLTE' => '', + 'serieIndexGTE' => '', 'tags' => [], 'serie' => '', 'publisher' => '', @@ -52,7 +55,7 @@ public function getParametersArrayForCurrent(bool $onlyModified = false): array foreach (self::FIELDS_DEFAULT_VALUE as $key => $value) { if (array_key_exists($key, $queryParams)) { $value = $queryParams[$key]; - if (($key === 'authors' || $key === 'tags') && is_string($value)) { + if (($key === 'authors' || $key === 'authorsNot' || $key === 'tags') && is_string($value)) { $value = array_filter(explode(',', $value)); } } diff --git a/templates/book/_list.html.twig b/templates/book/_list.html.twig index 5c0e97df..543ffa91 100644 --- a/templates/book/_list.html.twig +++ b/templates/book/_list.html.twig @@ -44,9 +44,11 @@ {{ component('InlineEditBook', {'book':book, 'field':'authors'}) }}