diff --git a/assets/styles/app.css b/assets/styles/app.css index 192bf3b864dc9374d81f36294850aec6abeb54c2..e40715f45bdfd7e4657597a83f8f0600ccbf7626 100644 --- a/assets/styles/app.css +++ b/assets/styles/app.css @@ -316,7 +316,7 @@ button { } .btn-like { - background-color: #ffffff; + background-color: transparent; border: 0px #ccc; padding: 5px 10px; cursor: pointer; diff --git a/config/routes.yaml b/config/routes.yaml index eaea01c73b4b1e33a76f49d05303d699270480fa..4ebe8e065a5748ae2e6154c426e22ae0e97a0936 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -22,4 +22,8 @@ filtmes_annonces_filtres: filtmes_annonces_repondues_filtres: path: /mes_annonces_repondues/filtres/ - controller: App\Controller\ModifUserController::mesAnnoncesReponduesFiltres \ No newline at end of file + controller: App\Controller\ModifUserController::mesAnnoncesReponduesFiltres + +filtmes_annonces_likees_filtres: + path: /mes_annonces_likees/filtres/ + controller: App\Controller\ModifUserController::mesAnnoncesLikeesFiltres \ No newline at end of file diff --git a/src/Controller/HomePageController.php b/src/Controller/HomePageController.php index b6f21d77547dadae1ce43154d41766ce1da3f6ba..d1e957b53f897461e88ab38c4022af39e59e95b5 100644 --- a/src/Controller/HomePageController.php +++ b/src/Controller/HomePageController.php @@ -7,15 +7,27 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Doctrine\Persistence\ManagerRegistry; +use App\Entity\Notification; +use App\Entity\Prestations; +use DateTime; class HomePageController extends AbstractController { + private $doctrine; + + public function __construct(ManagerRegistry $doctrine) { + $this->doctrine = $doctrine; + } + #[Route('', name: 'app_home_page')] public function index(Request $request, PrestationsRepository $prestationsRepository): Response { $prestations = $prestationsRepository->findFilteredPrestations(); + $user = $this->getUser(); return $this->render('home_page/index.html.twig', [ - 'prestations' => $prestations + 'prestations' => $prestations, + 'user' => $user ]); } @@ -30,9 +42,39 @@ class HomePageController extends AbstractController if ($prixMax == '') $prixMax = null; $prestations = $prestationsRepository->findFilteredPrestations($keyword, $prixMin, $prixMax, $typePrestation); + $user = $this->getUser(); 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 diff --git a/src/Controller/ModifUserController.php b/src/Controller/ModifUserController.php index 388ad12bf7ab8b176af878c23d046b998a970f27..ac3119bea3954c7fde43f3abe4c8a806ea41b262 100644 --- a/src/Controller/ModifUserController.php +++ b/src/Controller/ModifUserController.php @@ -101,7 +101,7 @@ class ModifUserController extends AbstractController } #[Route('/mettreCompteSommeil/{errorType}', name: 'app_compte_sommeil')] - public function mettreCompteSommeil(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, $errorType): Response + public function mettreCompteSommeil(Request $request, EntityManagerInterface $entityManager, $errorType): Response { $user = $this->getUser(); $form = $this->createForm(CompteSommeilFormType::class, $user); @@ -159,7 +159,7 @@ class ModifUserController extends AbstractController } #[Route('/mes_annonces', name: 'app_mes_annonces')] - public function mesAnnonces(Request $request, EntityManagerInterface $entityManager, PrestationsRepository $prestationsRepository): Response + public function mesAnnonces(EntityManagerInterface $entityManager, PrestationsRepository $prestationsRepository): Response { $user = $this->getUser(); @@ -175,11 +175,33 @@ class ModifUserController extends AbstractController 'prets' => $prets, 'services' => $services, 'prestations' => $prestations, + 'publiee' => true, + 'reservee' => false, + 'likee' => false, + ]); + } + + #[Route('/mes_likes', name: 'app_mes_likes')] + public function mesLikes(EntityManagerInterface $entityManager): Response + { + $prestations = $this->getUser()->getPrestationsAimees(); + $entrees = $entityManager->getRepository(Prestations::class)->findAll(); + $prets = $entityManager->getRepository(Pret::class)->findAll(); + $services = $entityManager->getRepository(Services::class)->findAll(); + + return $this->render('security/mes_annonces_likes.html.twig', [ + 'entrees' => $entrees, + 'prets' => $prets, + 'services' => $services, + 'prestations' => $prestations, + 'publiee' => false, + 'reservee' => false, + 'likee' => true, ]); } #[Route('/mes_annonces_repondues', name: 'app_mes_annonces_repondues')] - public function mesAnnoncesRepondues(Request $request, EntityManagerInterface $entityManager, PrestationsRepository $prestationsRepository): Response + public function mesAnnoncesRepondues(EntityManagerInterface $entityManager, PrestationsRepository $prestationsRepository): Response { $user = $this->getUser(); @@ -195,6 +217,9 @@ class ModifUserController extends AbstractController 'prets' => $prets, 'services' => $services, 'prestations' => $prestations, + 'publiee' => false, + 'reservee' => true, + 'likee' => false, ]); } @@ -231,6 +256,9 @@ class ModifUserController extends AbstractController 'prets' => $prets, 'services' => $services, 'prestations' => $res, + 'publiee' => true, + 'reservee' => false, + 'likee' => false, ]); } @@ -262,11 +290,51 @@ class ModifUserController extends AbstractController $services = $entityManager->getRepository(Services::class)->findAll(); return $this->render('security/mes_annonces_repondues.html.twig', [ + 'entrees' => $entrees, + 'prets' => $prets, + 'services' => $services, + 'prestations' => $res, + 'publiee' => false, + 'reservee' => true, + 'likee' => false, + ]); + } + + #[Route('', name: 'mes_annonces_likees_filtres')] + public function mesAnnoncesLikeesFiltres(Request $request, EntityManagerInterface $entityManager, PrestationsRepository $prestationsRepository): Response + { + $user = $this->getUser(); + $keyword = $request->query->get('keyword'); + $prixMin = $request->query->get('prixMin'); + $prixMax = $request->query->get('prixMax'); + $typePrestation = $request->query->get('type_prestation'); + if ($prixMin == '') $prixMin = null; + if ($prixMax == '') $prixMax = null; + + $res = []; + $prestations = $user->getPrestationsAimees(); + $prestations2 = $prestationsRepository->findFilteredPrestations($keyword, $prixMin, $prixMax, $typePrestation); + + foreach ($prestations as $pres) { + foreach ($prestations2 as $pres2) { + if ($pres === $pres2) + array_push($res,$pres); + } + } + + $entrees = $entityManager->getRepository(Prestations::class)->findAll(); + $prets = $entityManager->getRepository(Pret::class)->findAll(); + $services = $entityManager->getRepository(Services::class)->findAll(); + + return $this->render('security/mes_annonces.html.twig', [ 'controller_name' => 'ModifUserController', 'entrees' => $entrees, 'prets' => $prets, 'services' => $services, 'prestations' => $res, + 'publiee' => false, + 'reservee' => false, + 'likee' => true, ]); } diff --git a/templates/home_page/index.html.twig b/templates/home_page/index.html.twig index b93ba36ecdd3567dda7f2edbd9b04bf90c152b70..ac3c1e970d6c20f1187d8d52af13e71791620933 100644 --- a/templates/home_page/index.html.twig +++ b/templates/home_page/index.html.twig @@ -47,6 +47,17 @@ {% if is_granted('ROLE_ADMIN') %} <p class="tag_litige" id="tag">{{prestation.litiges|length}}</p> {% 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">❤</span> + {% else %} + <span class="non_aime">❤</span> + {% endif %} + </button></a> + {% endif %} + {% endif %} {% if prestation.getType() == 'Pret' %} <p class="tag_pret" id="tag">Prêt</p> diff --git a/templates/security/entete_mes_annonces.html.twig b/templates/security/entete_mes_annonces.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..d9003d9aa8a22af5448b66576e57ceef93f0e5d8 --- /dev/null +++ b/templates/security/entete_mes_annonces.html.twig @@ -0,0 +1,59 @@ +{% block body %} +<div class="container-recherche"> + <form id="filterForm" method="post"> + <input class="txt_form" type="text" name="keyword" value="{{ app.request.query.get('keyword') }}" placeholder="Mot-clé"> + <input class="txt_form prix" type="number" name="prixMin" value="{{ app.request.query.get('prixMin') }}" placeholder="€ minimum"> + <input class="txt_form prix" type="number" name="prixMax" value="{{ app.request.query.get('prixMax') }}" placeholder="€ maximum"> + <select class="txt_form" name="type_prestation"> + <option value="">Tous les types de prestation</option> + <option value="pret" {% if app.request.query.get('type_prestation') == 'pret' %} selected {% endif %}>Prêts</option> + <option value="service" {% if app.request.query.get('type_prestation') == 'service' %} selected {% endif %}>Services</option> + </select> + <button type="submit" class="btn_recherche">Filtrer</button> + </form> + + <script> + document.getElementById("filterForm").addEventListener("submit", function(event) { + event.preventDefault(); + + var keyword = document.getElementsByName("keyword")[0].value; + var prixMin = document.getElementsByName("prixMin")[0].value; + var prixMax = document.getElementsByName("prixMax")[0].value; + var typePrestation = document.getElementsByName("type_prestation")[0].value; + + {% if publiee %} + var url = "../../mes_annonces/filtres/?keyword=" + encodeURIComponent(keyword) + "&prixMin=" + encodeURIComponent(prixMin) + "&prixMax=" + encodeURIComponent(prixMax) + "&type_prestation=" + encodeURIComponent(typePrestation); + {% else %} + {% if reservee %} + var url = "../../mes_annonces_repondues/filtres/?keyword=" + encodeURIComponent(keyword) + "&prixMin=" + encodeURIComponent(prixMin) + "&prixMax=" + encodeURIComponent(prixMax) + "&type_prestation=" + encodeURIComponent(typePrestation); + {% else %} + var url = "../../mes_annonces_likees/filtres/?keyword=" + encodeURIComponent(keyword) + "&prixMin=" + encodeURIComponent(prixMin) + "&prixMax=" + encodeURIComponent(prixMax) + "&type_prestation=" + encodeURIComponent(typePrestation); + {% endif %} + {% endif %} + + window.location.href = url; + }); + </script> +</div> + +<div class="container-mes-annonces"> + {% if publiee %} + <a id="btnPostees" class="btn-navigation active" href="{{ path('app_mes_annonces') }}">Annonces postées</a> + {% else %} + <a id="btnPostees" class="btn-navigation" href="{{ path('app_mes_annonces') }}">Annonces postées</a> + {% endif %} + + {% if reservee %} + <a id="btnRepondues" class="btn-navigation active" href="{{ path('app_mes_annonces_repondues') }}">Annonces répondues</a> + {% else %} + <a id="btnRepondues" class="btn-navigation" href="{{ path('app_mes_annonces_repondues') }}">Annonces répondues</a> + {% endif %} + + {% if likee %} + <a id="btnRepondues" class="btn-navigation active" href="{{ path('app_mes_likes') }}">Annonces likées</a> + {% else %} + <a id="btnRepondues" class="btn-navigation" href="{{ path('app_mes_likes') }}">Annonces likées</a> + {% endif %} +</div> + +{% endblock %} \ No newline at end of file diff --git a/templates/security/mes_annonces.html.twig b/templates/security/mes_annonces.html.twig index 5fcd4108f2663746ade2211e147bc9e3ec276ed5..35d1f2adfcdae052149acdb1da2a01b5b4965455 100644 --- a/templates/security/mes_annonces.html.twig +++ b/templates/security/mes_annonces.html.twig @@ -3,39 +3,8 @@ {% block title %}Mes annonces{% endblock %} {% block body %} -<div class="container-recherche"> - <form id="filterForm" method="post"> - <input class="txt_form" type="text" name="keyword" value="{{ app.request.query.get('keyword') }}" placeholder="Mot-clé"> - <input class="txt_form prix" type="number" name="prixMin" value="{{ app.request.query.get('prixMin') }}" placeholder="€ minimum"> - <input class="txt_form prix" type="number" name="prixMax" value="{{ app.request.query.get('prixMax') }}" placeholder="€ maximum"> - <select class="txt_form" name="type_prestation"> - <option value="">Tous les types de prestation</option> - <option value="pret" {% if app.request.query.get('type_prestation') == 'pret' %} selected {% endif %}>Prêts</option> - <option value="service" {% if app.request.query.get('type_prestation') == 'service' %} selected {% endif %}>Services</option> - </select> - <button type="submit" class="btn_recherche">Filtrer</button> - </form> - <script> - document.getElementById("filterForm").addEventListener("submit", function(event) { - event.preventDefault(); - - var keyword = document.getElementsByName("keyword")[0].value; - var prixMin = document.getElementsByName("prixMin")[0].value; - var prixMax = document.getElementsByName("prixMax")[0].value; - var typePrestation = document.getElementsByName("type_prestation")[0].value; - - var url = "../../mes_annonces/filtres/?keyword=" + encodeURIComponent(keyword) + "&prixMin=" + encodeURIComponent(prixMin) + "&prixMax=" + encodeURIComponent(prixMax) + "&type_prestation=" + encodeURIComponent(typePrestation); - - window.location.href = url; - }); - </script> -</div> - -<div class="container-mes-annonces"> - <a id="btnPostees" class="btn-navigation active" href="{{ path('app_mes_annonces') }}">Annonces postées</a> - <a id="btnRepondues" class="btn-navigation" href="{{ path('app_mes_annonces_repondues') }}">Annonces répondues</a> -</div> +{% include 'security/entete_mes_annonces.html.twig' %} <div class="prestations"> {% for prestation in prestations %} diff --git a/templates/security/mes_annonces_likes.html.twig b/templates/security/mes_annonces_likes.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..91b13cb6ce8c78f41119d57dd78b9004644d93f9 --- /dev/null +++ b/templates/security/mes_annonces_likes.html.twig @@ -0,0 +1,40 @@ +{% extends 'base.html.twig' %} + +{% block title %}Mes annonces{% endblock %} + +{% block body %} + +{% include 'security/entete_mes_annonces.html.twig' %} +<div class="prestations"> + {% for prestation in prestations %} + <div class="prestation"> + {% if prestation.getType() == 'Pret' %} + <p class="tag_pret" id="tag">Prêt</p> + <p>{{ prestation.titre }}</p> + <p>{{ prestation.CoutPrestation }} florains</p> + <a href="{{ path('annonce_detail', {'id': prestation.id}) }}"><button class="tag_pret">Voir le détail >></button></a> + {% elseif prestation.getType() == 'Service' %} + <p class="tag_service" id="tag">Service</p> + <p>{{ prestation.titre }}</p> + <p>{{ prestation.CoutPrestation }} florains</p> + <a href="{{ path('annonce_detail', {'id': prestation.id}) }}"><button class="tag_service">Voir le détail >></button></a> + {% endif %} + </div> + {% endfor %} +</div> + +<script> + const btnPostees = document.getElementById('btnPostees'); + const btnRepondues = document.getElementById('btnRepondues'); + + btnPostees.addEventListener('click', () => { + btnPostees.classList.add('active'); + btnRepondues.classList.remove('active'); + }); + + btnRepondues.addEventListener('click', () => { + btnRepondues.classList.add('active'); + btnPostees.classList.remove('active'); + }); +</script> +{% endblock %} \ No newline at end of file diff --git a/templates/security/mes_annonces_repondues.html.twig b/templates/security/mes_annonces_repondues.html.twig index 031c8c3f21573418a916ee807013bb72d2175182..35d1f2adfcdae052149acdb1da2a01b5b4965455 100644 --- a/templates/security/mes_annonces_repondues.html.twig +++ b/templates/security/mes_annonces_repondues.html.twig @@ -3,39 +3,8 @@ {% block title %}Mes annonces{% endblock %} {% block body %} -<div class="container-recherche"> - <form id="filterForm" method="post"> - <input class="txt_form" type="text" name="keyword" value="{{ app.request.query.get('keyword') }}" placeholder="Mot-clé"> - <input class="txt_form prix" type="number" name="prixMin" value="{{ app.request.query.get('prixMin') }}" placeholder="€ minimum"> - <input class="txt_form prix" type="number" name="prixMax" value="{{ app.request.query.get('prixMax') }}" placeholder="€ maximum"> - <select class="txt_form" name="type_prestation"> - <option value="">Tous les types de prestation</option> - <option value="pret" {% if app.request.query.get('type_prestation') == 'pret' %} selected {% endif %}>Prêts</option> - <option value="service" {% if app.request.query.get('type_prestation') == 'service' %} selected {% endif %}>Services</option> - </select> - <button type="submit" class="btn_recherche">Filtrer</button> - </form> - <script> - document.getElementById("filterForm").addEventListener("submit", function(event) { - event.preventDefault(); - - var keyword = document.getElementsByName("keyword")[0].value; - var prixMin = document.getElementsByName("prixMin")[0].value; - var prixMax = document.getElementsByName("prixMax")[0].value; - var typePrestation = document.getElementsByName("type_prestation")[0].value; - - var url = "../../mes_annonces_repondues/filtres/?keyword=" + encodeURIComponent(keyword) + "&prixMin=" + encodeURIComponent(prixMin) + "&prixMax=" + encodeURIComponent(prixMax) + "&type_prestation=" + encodeURIComponent(typePrestation); - - window.location.href = url; - }); - </script> -</div> - -<div class="container-mes-annonces"> - <a id="btnPostees" class="btn-navigation" href="{{ path('app_mes_annonces') }}">Annonces postées</a> - <a id="btnRepondues" class="btn-navigation active" href="{{ path('app_mes_annonces_repondues') }}">Annonces répondues</a> -</div> +{% include 'security/entete_mes_annonces.html.twig' %} <div class="prestations"> {% for prestation in prestations %} diff --git a/templates/security/modifUser.html.twig b/templates/security/modifUser.html.twig index d485e88d69369d05c1fd13ad0ca31d376f7dd34f..988c60379a98a9f2d8ebe5bc4daed49e63510d66 100644 --- a/templates/security/modifUser.html.twig +++ b/templates/security/modifUser.html.twig @@ -16,8 +16,8 @@ <div class="container-connexion3"> <div class="container-connexion"> <div class="container-connexion2"> - <button class="btn-connexion2" onclick="window.location.href='{{ path("app_user_coord") }}'">Mon profil</button> - <button class="btn-connexion2" onclick="window.location.href='{{ path("app_mes_annonces") }}'">Consulter mes transactions</button> + <button class="btn-connexion2" onclick="window.location.href='{{ path("app_user_coord") }}'">Consulter mon profil</button> + <button class="btn-connexion2" onclick="window.location.href='{{ path("app_mes_annonces") }}'">Consulter mes annonces</button> <button class="btn-connexion2" onclick="window.location.href='{{ path("app_modif_user_coord") }}'">Modifier mes coordonnées</button> <button class="btn-connexion2" onclick="window.location.href='{{ path("app_modif_user_abonnement") }}'">Modifier mon abonnement</button> <button class="btn-connexion2" onclick="window.location.href='{{ path("app_modif_user_mdp") }}'">Modifier mon mot de passe</button>