Skip to content

Commit

Permalink
insensitive case on authors
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMendolia committed Sep 23, 2023
1 parent 9b76dca commit f0290d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ public function setPublishDate(?\DateTimeInterface $publishDate): static
*/
public function getAuthors(): array
{
return $this->authors;
return array_map(static function($item){
return ucwords(strtolower($item), " \t\r\n\f\v-.");
},$this->authors);
}

/**
Expand All @@ -300,7 +302,7 @@ public function setAuthors(array $authors): static
public function addAuthor(string $author): static
{
if (!in_array($author, $this->authors, true) && '' !== $author) {
$this->authors[] = $author;
$this->authors[] = ucwords(strtolower($author), " \t\r\n\f\v-.");
}
$this->authors = array_values($this->authors);

Expand All @@ -314,6 +316,7 @@ public function removeAuthor(string $author): static
unset($this->authors[$key]);
}
}

$this->authors = array_values($this->authors);

return $this;
Expand Down
8 changes: 4 additions & 4 deletions src/Form/BookFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$orModule = $qb->expr()->orX();

foreach ($authors as $key => $author) {
$orModule->add('JSON_CONTAINS(book.authors, :author'.$key.')=1');
$qb->setParameter('author'.$key, json_encode([$author]));
$orModule->add('JSON_CONTAINS(lower(book.authors), :author'.$key.')=1');
$qb->setParameter('author'.$key, json_encode([strtolower($author)]));
}
$qb->andWhere($orModule);
},
Expand All @@ -96,8 +96,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$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]));
$orModule->add('JSON_CONTAINS(lower(book.authors), :authorNot'.$key.')=0');
$qb->setParameter('authorNot'.$key, json_encode([strtolower($author)]));
}
$qb->andWhere($orModule);
},
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/BookRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ private function convertResults(mixed $intermediateResults): array
foreach ($result['item'] as $item) {
if (!array_key_exists($item, $results)) {
$results[$item] = [
'item' => $item,
'item' => ucwords(strtolower($item), " \t\r\n\f\v-."),
'bookCount' => 0,
'booksFinished' => 0,
];
}
$results[$item] = [
'item' => $item,
'item' => ucwords(strtolower($item), " \t\r\n\f\v-."),
'bookCount' => $result['bookCount'] + $results[$item]['bookCount'],
'booksFinished' => $result['booksFinished'] + $results[$item]['booksFinished'],
];
Expand Down

0 comments on commit f0290d9

Please sign in to comment.