- trop de trucs d'un coup... je vais faire attention ensuite ^^'
This commit is contained in:
27
src/Twig/Components/AddMangaModalComponent.php
Normal file
27
src/Twig/Components/AddMangaModalComponent.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use App\Entity\Manga;
|
||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveProp;
|
||||
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
||||
|
||||
#[AsLiveComponent]
|
||||
class AddMangaModalComponent
|
||||
{
|
||||
use DefaultActionTrait;
|
||||
|
||||
#[LiveProp(writable: true)]
|
||||
public ?Manga $manga;
|
||||
|
||||
public function open(Manga $manga): void
|
||||
{
|
||||
$this->manga = $manga;
|
||||
}
|
||||
|
||||
public function close(): void
|
||||
{
|
||||
$this->manga = null;
|
||||
}
|
||||
}
|
||||
11
src/Twig/Components/BootstrapModal.php
Normal file
11
src/Twig/Components/BootstrapModal.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||
|
||||
#[AsTwigComponent]
|
||||
class BootstrapModal
|
||||
{
|
||||
public ?string $id = null;
|
||||
}
|
||||
33
src/Twig/Components/DownloadChapter.php
Normal file
33
src/Twig/Components/DownloadChapter.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use App\Repository\ChapterRepository;
|
||||
use App\Repository\MangaRepository;
|
||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
||||
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
||||
|
||||
#[AsLiveComponent]
|
||||
final class DownloadChapter
|
||||
{
|
||||
use DefaultActionTrait;
|
||||
|
||||
public ?string $mangaSlug = '';
|
||||
public float $chapter;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function downloadChapter(MangaRepository $mangaRepository, ChapterRepository $chapterRepository): int
|
||||
{
|
||||
// $mangaSlug = $this->mangaSlug;
|
||||
// $chapter = $this->chapter;
|
||||
// $manga = $mangaRepository->findOneBy(['slug' => $mangaSlug]);
|
||||
// $chapter = $chapterRepository->findOneBy(['manga' => $manga, 'number' => $chapter]);
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
38
src/Twig/Components/MangaSearch.php
Normal file
38
src/Twig/Components/MangaSearch.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use App\Service\MangadexProvider;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Exception;
|
||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveProp;
|
||||
use Symfony\UX\LiveComponent\ComponentToolsTrait;
|
||||
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
||||
use Symfony\UX\LiveComponent\ValidatableComponentTrait;
|
||||
|
||||
#[AsLiveComponent]
|
||||
class MangaSearch
|
||||
{
|
||||
use DefaultActionTrait;
|
||||
|
||||
#[LiveProp(writable: true)]
|
||||
public ?string $query = null;
|
||||
|
||||
public function __construct(private readonly MangadexProvider $mangadexProvider)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getMangas(): Collection|null
|
||||
{
|
||||
if ($this->query === null || $this->query === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->mangadexProvider->search($this->query);
|
||||
}
|
||||
}
|
||||
79
src/Twig/Components/NewMangaForm.php
Normal file
79
src/Twig/Components/NewMangaForm.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use App\Entity\Manga;
|
||||
use App\Service\MangadexProvider;
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveAction;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveProp;
|
||||
use Symfony\UX\LiveComponent\ComponentToolsTrait;
|
||||
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
||||
|
||||
#[AsLiveComponent]
|
||||
class NewMangaForm
|
||||
{
|
||||
use ComponentToolsTrait;
|
||||
use DefaultActionTrait;
|
||||
|
||||
public ?Manga $manga = null;
|
||||
#[LiveProp(writable: true)]
|
||||
public array $mangaData = [];
|
||||
|
||||
#[LiveProp(writable: true)]
|
||||
public ?int $index = 0;
|
||||
|
||||
public function mount(Manga $manga): void
|
||||
{
|
||||
$this->manga = $manga;
|
||||
$this->mangaData = [
|
||||
'title' => $manga->getTitle(),
|
||||
'slug' => $manga->getSlug(),
|
||||
'description' => $manga->getDescription(),
|
||||
'imageUrl' => $manga->getImageUrl(),
|
||||
'status' => $manga->getStatus(),
|
||||
'genres' => $manga->getGenres(),
|
||||
'author' => $manga->getAuthor(),
|
||||
'publicationYear' => $manga->getPublicationYear(),
|
||||
'rating' => $manga->getRating(),
|
||||
'externalId' => $manga->getExternalId(),
|
||||
];
|
||||
}
|
||||
|
||||
#[LiveAction]
|
||||
public function saveManga(EntityManagerInterface $entityManager, MangadexProvider $mangadexProvider): Response
|
||||
{
|
||||
$manga = new Manga();
|
||||
$manga->setTitle($this->mangaData['title'])
|
||||
->setSlug($this->mangaData['slug'])
|
||||
->setDescription($this->mangaData['description'])
|
||||
->setImageUrl($this->mangaData['imageUrl'])
|
||||
->setStatus($this->mangaData['status'])
|
||||
->setGenres($this->mangaData['genres'])
|
||||
->setAuthor($this->mangaData['author'])
|
||||
->setPublicationYear($this->mangaData['publicationYear'])
|
||||
->setRating($this->mangaData['rating'])
|
||||
->setExternalId($this->mangaData['externalId']);
|
||||
|
||||
$mangadexProvider->getFeed($manga);
|
||||
try {
|
||||
foreach ($manga->getChapters() as $chapter) {
|
||||
$entityManager->persist($chapter);
|
||||
}
|
||||
|
||||
$entityManager->persist($manga);
|
||||
$entityManager->flush();
|
||||
} catch (\Exception $e) {
|
||||
if ($e instanceof UniqueConstraintViolationException) {
|
||||
return new RedirectResponse('/manga/' . $manga->getSlug());
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return new RedirectResponse('/manga/' . $manga->getSlug());
|
||||
}
|
||||
}
|
||||
28
src/Twig/Components/Search.php
Normal file
28
src/Twig/Components/Search.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use App\Repository\MangaRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
||||
use Symfony\UX\LiveComponent\Attribute\LiveProp;
|
||||
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
||||
|
||||
#[AsLiveComponent]
|
||||
final class Search
|
||||
{
|
||||
use DefaultActionTrait;
|
||||
|
||||
#[LiveProp (writable: true)]
|
||||
public ?string $query = null;
|
||||
|
||||
public function __construct(private readonly MangaRepository $mangaRepository)
|
||||
{
|
||||
}
|
||||
|
||||
public function getMangas(): array
|
||||
{
|
||||
return $this->query ? $this->mangaRepository->findByTitle($this->query) : [];
|
||||
}
|
||||
}
|
||||
12
src/Twig/Components/ToolBarButton.php
Normal file
12
src/Twig/Components/ToolBarButton.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Components;
|
||||
|
||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
|
||||
use Symfony\UX\LiveComponent\DefaultActionTrait;
|
||||
|
||||
#[AsLiveComponent]
|
||||
final class ToolBarButton
|
||||
{
|
||||
use DefaultActionTrait;
|
||||
}
|
||||
24
src/Twig/Extension/TruncateExtension.php
Normal file
24
src/Twig/Extension/TruncateExtension.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Extension;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class TruncateExtension extends AbstractExtension
|
||||
{
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
new TwigFilter('truncate', [$this, 'truncate']),
|
||||
];
|
||||
}
|
||||
|
||||
public function truncate(?string $value, int $limit): string
|
||||
{
|
||||
if ($value === null) {
|
||||
return '';
|
||||
}
|
||||
return strlen($value) > $limit ? substr($value, 0, $limit) . '...' : $value;
|
||||
}
|
||||
}
|
||||
18
src/Twig/Runtime/TruncateExtensionRuntime.php
Normal file
18
src/Twig/Runtime/TruncateExtensionRuntime.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Twig\Runtime;
|
||||
|
||||
use Twig\Extension\RuntimeExtensionInterface;
|
||||
|
||||
class TruncateExtensionRuntime implements RuntimeExtensionInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// Inject dependencies if needed
|
||||
}
|
||||
|
||||
public function doSomething($value)
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user