- Ajout des favoris
This commit is contained in:
35
src/Controller/FavorisController.php
Normal file
35
src/Controller/FavorisController.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Repository\FavorisRepository;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use App\Service\GoogleBooksService;
|
||||||
|
|
||||||
|
class FavorisController extends AbstractController
|
||||||
|
{
|
||||||
|
private GoogleBooksService $googleBooksService;
|
||||||
|
private array $favorisResult = [];
|
||||||
|
|
||||||
|
public function __construct(GoogleBooksService $googleBooksService)
|
||||||
|
{
|
||||||
|
$this->googleBooksService = $googleBooksService;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/favoris', name: 'app_favoris')]
|
||||||
|
public function index(FavorisRepository $favorisRepository): Response
|
||||||
|
{
|
||||||
|
$favorisUser = $favorisRepository->findBy(['user' => $this->getUser()]);
|
||||||
|
foreach ($favorisUser as $favori) {
|
||||||
|
array_push($this->favorisResult, $this->googleBooksService->searchBooks($favori->getIdGoogle(), 'fr', 0));
|
||||||
|
|
||||||
|
}
|
||||||
|
return $this->render('favoris/index.html.twig', [
|
||||||
|
'controller_name' => 'FavorisController',
|
||||||
|
'datas' => $this->favorisResult,
|
||||||
|
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
19
templates/favoris/index.html.twig
Normal file
19
templates/favoris/index.html.twig
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Mes favoris{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div>
|
||||||
|
{% for data in datas %}
|
||||||
|
{% if data.items is defined %}
|
||||||
|
{% for book in data.items %}
|
||||||
|
{% if book.volumeInfo.authors is defined %}
|
||||||
|
<p>{{ book.volumeInfo.title }} - {{ book.volumeInfo.authors | join(", ") }} </p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Reference in New Issue
Block a user