diff --git a/src/Twig/FieldGuesser.php b/src/Twig/FieldGuesser.php new file mode 100644 index 00000000..833b5960 --- /dev/null +++ b/src/Twig/FieldGuesser.php @@ -0,0 +1,71 @@ +book->setSerie($this->guessSerie()); + $this->book->setSerieIndex((float) $this->guessIndex()); + $this->book->setMainAuthor($this->guessAuthor()); + $entityManager->flush(); + $this->dispatchBrowserEvent('manager:flush'); + + $this->flashMessage = 'Saved'; + } + + public function guessSerie(): string + { + $author = $this->book->getMainAuthor(); + $parts = explode(' - ', $author); + if (3 === count($parts)) { + return $parts[1]; + } + + return ''; + } + + public function guessIndex(): string + { + $author = $this->book->getMainAuthor(); + $parts = explode(' - ', $author); + if (3 === count($parts)) { + return $parts[2]; + } + + return ''; + } + + public function guessAuthor(): string + { + $author = $this->book->getMainAuthor(); + $parts = explode(' - ', $author); + if (3 === count($parts)) { + return $parts[0]; + } + + return ''; + } +} diff --git a/templates/book/_list.html.twig b/templates/book/_list.html.twig index 644540fd..18e8f91c 100644 --- a/templates/book/_list.html.twig +++ b/templates/book/_list.html.twig @@ -45,7 +45,8 @@