diff --git a/src/Controller/AnnonceDetailController.php b/src/Controller/AnnonceDetailController.php index 6f7dbd89b27ed89302f14b539704980759e370ff..edd3f1ea22c5dc641e2d70f7f71c6081f1544964 100644 --- a/src/Controller/AnnonceDetailController.php +++ b/src/Controller/AnnonceDetailController.php @@ -66,21 +66,15 @@ class AnnonceDetailController extends AbstractController } if ($prestation->getIdClient() != null) { - $notification = new Notification(); - $notification->setDescription("L'utilisateur " . $this->getUser()->getLogin() . " a supprimé l'annonce " . $prestation->getTitre() . " que vous aviez réservé."); - $notification->setType("Suppression annonce réservée"); - $notification->setDate(new DateTime()); - $notification->setUserId($entityManager->getRepository(Personne::class)->find($prestation->getIdClient())); - $this->doctrine->getManager()->persist($notification); + $this->makeNotif("L'utilisateur " . $this->getUser()->getLogin() . " a supprimé l'annonce " . $prestation->getTitre() . " que vous aviez réservé.", + "Suppression annonce réservée", + $entityManager->getRepository(Personne::class)->find($prestation->getIdClient())); } foreach ($prestation->getUtilisateursAimant() as $u) { - $notification = new Notification(); - $notification->setDescription("L'utilisateur " . $this->getUser()->getLogin() . " a supprimé l'annonce " . $prestation->getTitre() . " que vous aviez aimé."); - $notification->setType("Suppression annonce aimée"); - $notification->setDate(new DateTime()); - $notification->setUserId($u); - $this->doctrine->getManager()->persist($notification); + $this->makeNotif("L'utilisateur " . $this->getUser()->getLogin() . " a supprimé l'annonce " . $prestation->getTitre() . " que vous aviez aimé.", + "Suppression annonce aimée", + $u); } $entityManager->remove($prestation); @@ -111,12 +105,9 @@ class AnnonceDetailController extends AbstractController $prestation->setFournisseurValide(false); $prestation->setClientValide(false); - $notification = new Notification(); - $notification->setDescription("Annulation de la réservation de l'annonce " . $prestation->getTitre() . " par " . $this->getUser()->getLogin()); - $notification->setType("Annulation réservation annonce"); - $notification->setDate(new DateTime()); - $notification->setUserId($prestation->getProprietaire()); - $this->doctrine->getManager()->persist($notification); + $this->makeNotif("Annulation de la réservation de l'annonce " . $prestation->getTitre() . " par " . $this->getUser()->getLogin(), + "Annulation réservation annonce", + $prestation->getProprietaire()); $prestation->setIdClient(null); $litiges = $prestation->getLitiges(); @@ -132,12 +123,9 @@ class AnnonceDetailController extends AbstractController //On prélève le compte du client sans verser le propriétaire $data['user']->setNbFlorains($data['user']->getNbFlorains() - $data['annonce']->getCoutPrestation()); - $notification = new Notification(); - $notification->setDescription("Réservation de l'annonce " . $data['annonce']->getTitre() . " par " . $this->getUser()->getLogin()); - $notification->setType("Réservation annonce"); - $notification->setDate(new DateTime()); - $notification->setUserId($data['annonce']->getProprietaire()); - $this->doctrine->getManager()->persist($notification); + $this->makeNotif("Réservation de l'annonce " . $data['annonce']->getTitre() . " par " . $this->getUser()->getLogin(), + "Réservation annonce", + $data['annonce']->getProprietaire()); } } @@ -153,12 +141,9 @@ class AnnonceDetailController extends AbstractController $prestation = $data['annonce']; 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); + $this->makeNotif($user->getLogin(). " a aimé votre annonce " . $prestation->getTitre(), + "Annonce aimée", + $prestation->getProprietaire()); $prestation->setIdClient(null); } else return $this->redirectToRoute('app_login'); @@ -180,8 +165,14 @@ class AnnonceDetailController extends AbstractController $prestation = $data['annonce']; if($user->getId() == $prestation->getFournisseur()->getId()) { + $this->makeNotif("Le fournisseur de la prestation " . $prestation->getTitre() . " a validé votre réservation.", + "Réservation validée", + $data['entityManager']->getRepository(Personne::class)->find($prestation->getIdClient())); $prestation->setFournisseurValide(true); }else if ($user->getId() == $prestation->getIdClient()->getId()){ + $this->makeNotif("Le client de la prestation " . $prestation->getTitre() . " a validé sa réservation.", + "Réservation validée", + $data['entityManager']->getRepository(Personne::class)->find($prestation->getFournisseur())); $prestation->setClientValide(true); } @@ -190,6 +181,14 @@ class AnnonceDetailController extends AbstractController if(count($prestation->getLitiges()) == 0 && $prestation->isFournisseurValide() && $prestation->isClientValide()){ //La prestation est validé, donc on verse le montant de florain au fournisseur + // Notif pour le propriétaire + $this->makeNotif("La prestation " . $prestation->getTitre() . " a été validé des deux côtés. Elle est terminée.", + "Prestation conclue", + $data['entityManager']->getRepository(Personne::class)->find($prestation->getFournisseur())); + // Notif pour le client + $this->makeNotif("La prestation " . $prestation->getTitre() . " a été validé des deux côtés. Elle est terminée.", + "Prestation conclue", + $data['entityManager']->getRepository(Personne::class)->find($prestation->getIdClient())); $prestation->getFournisseur()->setNbFlorains($prestation->getFournisseur()->getNbFlorains() + $prestation->getCoutPrestation()); $prestation->setTermine(true); @@ -200,4 +199,14 @@ class AnnonceDetailController extends AbstractController return $this->redirectToRoute('annonce_detail', ['id' => $id]); } + + public function makeNotif($desc,$type,$userID) { + $notification = new Notification(); + $notification->setDescription($desc); + $notification->setType($type); + $notification->setDate(new DateTime()); + $notification->setUserId($userID); + $this->doctrine->getManager()->persist($notification); + $this->doctrine->getManager()->flush(); + } } diff --git a/templates/annonce_detail/annonce.html.twig b/templates/annonce_detail/annonce.html.twig index c0cdff427d36ba46d9fd8e14266f952ca1b1e4b6..b31b9eae758d8368f1459d571a3d182f8dae6f78 100644 --- a/templates/annonce_detail/annonce.html.twig +++ b/templates/annonce_detail/annonce.html.twig @@ -75,7 +75,7 @@ {% endif %} {% endif %} {% else %} - {% if user.nb_florains >= annonce.cout_prestation %} + {% if user.NbFlorains() >= annonce.CoutPrestation %} <a href="{{ path('app_reserver_prestation', {'id': annonce.id, 'interet': true}) }}"><button class="btn-connexion" id="btnRepondre">Répondre à l'annonce</button></a> {% else %} <a href=""><button class="btn-connexion" id="btnRepondre">Trop pauvre pour payer</button></a>