Skip to content
Snippets Groups Projects
Commit d1cbeb8f authored by YvanSv's avatar YvanSv
Browse files

ajout d'un bouton like aux annonces sur l'accueil

parent 9a308fb1
Branches
No related tags found
Loading
...@@ -316,7 +316,7 @@ button { ...@@ -316,7 +316,7 @@ button {
} }
.btn-like { .btn-like {
background-color: #ffffff; background-color: transparent;
border: 0px #ccc; border: 0px #ccc;
padding: 5px 10px; padding: 5px 10px;
cursor: pointer; cursor: pointer;
......
...@@ -7,15 +7,27 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; ...@@ -7,15 +7,27 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Notification;
use App\Entity\Prestations;
use DateTime;
class HomePageController extends AbstractController class HomePageController extends AbstractController
{ {
private $doctrine;
public function __construct(ManagerRegistry $doctrine) {
$this->doctrine = $doctrine;
}
#[Route('', name: 'app_home_page')] #[Route('', name: 'app_home_page')]
public function index(Request $request, PrestationsRepository $prestationsRepository): Response public function index(Request $request, PrestationsRepository $prestationsRepository): Response
{ {
$prestations = $prestationsRepository->findFilteredPrestations(); $prestations = $prestationsRepository->findFilteredPrestations();
$user = $this->getUser();
return $this->render('home_page/index.html.twig', [ return $this->render('home_page/index.html.twig', [
'prestations' => $prestations 'prestations' => $prestations,
'user' => $user
]); ]);
} }
...@@ -30,9 +42,39 @@ class HomePageController extends AbstractController ...@@ -30,9 +42,39 @@ class HomePageController extends AbstractController
if ($prixMax == '') $prixMax = null; if ($prixMax == '') $prixMax = null;
$prestations = $prestationsRepository->findFilteredPrestations($keyword, $prixMin, $prixMax, $typePrestation); $prestations = $prestationsRepository->findFilteredPrestations($keyword, $prixMin, $prixMax, $typePrestation);
$user = $this->getUser();
return $this->render('home_page/index.html.twig', [ return $this->render('home_page/index.html.twig', [
'prestations' => $prestations 'prestations' => $prestations,
'user' => $user
]); ]);
} }
#[Route('/aimer/{id}', name: 'app_like_home_page')]
public function aimerPrestation($id,PrestationsRepository $prestationsRepository): Response
{
$user = $this->getUser();
$entityManager = $this->doctrine->getManager();
$prestation = $entityManager->getRepository(Prestations::class)->find($id);
if ($user != null) {
$notification = new Notification();
$notification->setDescription($user->getLogin(). " a aimé votre annonce " . $prestation->getTitre());
$notification->setType("Annonce aimée");
$notification->setDate(new DateTime());
$notification->setUserId($prestation->getProprietaire());
$this->doctrine->getManager()->persist($notification);
$prestation->setIdClient(null);
} else return $this->redirectToRoute('app_login');
if ($user->getPrestationsAimees()->contains($prestation)) {
$user->removePrestationsAimee($prestation);
$prestation->removeUtilisateursAimant($user);
} else {
$user->addPrestationsAimee($prestation);
$prestation->addUtilisateursAimant($user);
}
$entityManager->flush();
return $this->redirectToRoute('app_home_page');
}
} }
\ No newline at end of file
...@@ -47,6 +47,17 @@ ...@@ -47,6 +47,17 @@
{% if is_granted('ROLE_ADMIN') %} {% if is_granted('ROLE_ADMIN') %}
<p class="tag_litige" id="tag">{{prestation.litiges|length}}</p> <p class="tag_litige" id="tag">{{prestation.litiges|length}}</p>
{% endif %} {% endif %}
{% if user and not is_granted ("ROLE_ADMIN") %}
{% if user.id != prestation.proprietaire.id %}
<a href="{{ path('app_like_home_page', {'id': prestation.id}) }}"><button class="btn-like">
{% if user.aimePrestation(prestation) %}
<span class="aime">&#10084;</span>
{% else %}
<span class="non_aime">&#10084;</span>
{% endif %}
</button></a>
{% endif %}
{% endif %}
{% if prestation.getType() == 'Pret' %} {% if prestation.getType() == 'Pret' %}
<p class="tag_pret" id="tag">Prêt</p> <p class="tag_pret" id="tag">Prêt</p>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment