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 @@
{{ component('InlineEditBook', {'book':book, 'field':'serie'}) }} - {{ component('InlineEditBook', {'book':book, 'field':'serieIndex'}) }} +
{{ component('InlineEditBook', {'book':book, 'field':'serieIndex'}) }}
+ {{ component('FieldGuesser',{'book':book}) }}
diff --git a/templates/components/FieldGuesser.html.twig b/templates/components/FieldGuesser.html.twig new file mode 100644 index 00000000..407f1a0a --- /dev/null +++ b/templates/components/FieldGuesser.html.twig @@ -0,0 +1,18 @@ + + {% if this.guessAuthor!='' %} +
+ +
+ {% endif %} +