Skip to content
Snippets Groups Projects
Commit a0846c7a authored by SAVERGNE Yvan's avatar SAVERGNE Yvan
Browse files

Merge branch 'master' into 'main'

Master

See merge request !61
parents 82bee9b1 6140ed65
Branches
No related tags found
1 merge request!61Master
...@@ -314,3 +314,19 @@ button { ...@@ -314,3 +314,19 @@ button {
background-color: green; background-color: green;
color: white; color: white;
} }
.btn-like {
background-color: #ffffff;
border: 0px #ccc;
padding: 5px 10px;
cursor: pointer;
font-size: 30px;
}
.aime {
color: red;
}
.non_aime {
color: lightgray;
}
\ No newline at end of file
...@@ -18,8 +18,7 @@ class AnnonceDetailController extends AbstractController ...@@ -18,8 +18,7 @@ class AnnonceDetailController extends AbstractController
{ {
private $doctrine; private $doctrine;
public function __construct(ManagerRegistry $doctrine) public function __construct(ManagerRegistry $doctrine) {
{
$this->doctrine = $doctrine; $this->doctrine = $doctrine;
} }
...@@ -27,17 +26,15 @@ class AnnonceDetailController extends AbstractController ...@@ -27,17 +26,15 @@ class AnnonceDetailController extends AbstractController
{ {
$entityManager = $this->doctrine->getManager(); $entityManager = $this->doctrine->getManager();
$annonce = $entityManager->getRepository(Prestations::class)->find($id); $annonce = $entityManager->getRepository(Prestations::class)->find($id);
$nbAimees = $annonce->getUtilisateursAimant()->count();
$prets = $entityManager->getRepository(Pret::class)->findAll(); $prets = $entityManager->getRepository(Pret::class)->findAll();
$services = $entityManager->getRepository(Services::class)->findAll(); $services = $entityManager->getRepository(Services::class)->findAll();
$user = $this->getUser(); $user = $this->getUser();
if (!$annonce) {
throw $this->createNotFoundException('Annonce non trouvée');
}
return [ return [
'entityManager' => $entityManager, 'entityManager' => $entityManager,
'annonce' => $annonce, 'annonce' => $annonce,
'nbAimees' => $nbAimees,
'prets' => $prets, 'prets' => $prets,
'services' => $services, 'services' => $services,
'user' => $user, 'user' => $user,
...@@ -50,15 +47,12 @@ class AnnonceDetailController extends AbstractController ...@@ -50,15 +47,12 @@ class AnnonceDetailController extends AbstractController
public function detail($id) public function detail($id)
{ {
$data = $this->getCommonData($id); $data = $this->getCommonData($id);
return $this->render('annonce_detail/annonce.html.twig', $data); $prest = $data['annonce'];
if ($prest) {
$prest->setNbVues($prest->getNbVues() + 1);
$data['entityManager']->flush();
} }
return $this->render('annonce_detail/annonce.html.twig', $data);
#[Route('/annonce/detail', name: 'app_annonce_detail')]
public function index(): Response
{
return $this->render('annonce_detail/annonce.html.twig', [
'controller_name' => 'AnnonceDetailController',
]);
} }
#[Route('/deleteTransaction/{prestationId}', name: 'app_delete_transaction')] #[Route('/deleteTransaction/{prestationId}', name: 'app_delete_transaction')]
...@@ -100,6 +94,12 @@ class AnnonceDetailController extends AbstractController ...@@ -100,6 +94,12 @@ class AnnonceDetailController extends AbstractController
$entityManager = $this->doctrine->getManager(); $entityManager = $this->doctrine->getManager();
$prestation = $data['annonce']; $prestation = $data['annonce'];
$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);
$prestation->setIdClient(null); $prestation->setIdClient(null);
$litiges = $prestation->getLitiges(); $litiges = $prestation->getLitiges();
...@@ -123,4 +123,32 @@ class AnnonceDetailController extends AbstractController ...@@ -123,4 +123,32 @@ class AnnonceDetailController extends AbstractController
$data['entityManager']->flush(); $data['entityManager']->flush();
return $this->redirectToRoute('annonce_detail', ['id' => $id]); return $this->redirectToRoute('annonce_detail', ['id' => $id]);
} }
#[Route('/aimerPrestation/{id}', name: 'app_aimer_prestation')]
public function aimerPrestation($id): Response
{
$data = $this->getCommonData($id);
$user = $data['user'];
$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);
$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);
}
$data['entityManager']->flush();
return $this->redirectToRoute('annonce_detail', ['id' => $id]);
}
} }
...@@ -50,9 +50,16 @@ class Prestations ...@@ -50,9 +50,16 @@ class Prestations
#[ORM\OneToMany(mappedBy: 'id_prestation', targetEntity: Litige::class, orphanRemoval: true)] #[ORM\OneToMany(mappedBy: 'id_prestation', targetEntity: Litige::class, orphanRemoval: true)]
private Collection $litiges; private Collection $litiges;
#[ORM\Column]
private ?int $nbVues = null;
#[ORM\ManyToMany(targetEntity: Utilisateur::class, mappedBy: 'prestations_aimees')]
private Collection $utilisateurs_aimant;
public function __construct() public function __construct()
{ {
$this->litiges = new ArrayCollection(); $this->litiges = new ArrayCollection();
$this->utilisateurs_aimant = new ArrayCollection();
} }
public function getId(): ?int public function getId(): ?int
...@@ -208,4 +215,39 @@ class Prestations ...@@ -208,4 +215,39 @@ class Prestations
return $this; return $this;
} }
public function getNbVues(): ?int
{
return $this->nbVues;
}
public function setNbVues(int $nbVues): static
{
$this->nbVues = $nbVues;
return $this;
}
/**
* @return Collection<int, Utilisateur>
*/
public function getUtilisateursAimant(): Collection
{
return $this->utilisateurs_aimant;
}
public function addUtilisateursAimant(Utilisateur $utilisateursAimant): static
{
if (!$this->utilisateurs_aimant->contains($utilisateursAimant))
$this->utilisateurs_aimant->add($utilisateursAimant);
return $this;
}
public function removeUtilisateursAimant(Utilisateur $utilisateursAimant): static
{
$this->utilisateurs_aimant->removeElement($utilisateursAimant);
return $this;
}
} }
...@@ -72,6 +72,9 @@ class Utilisateur extends Personne ...@@ -72,6 +72,9 @@ class Utilisateur extends Personne
#[ORM\Column] #[ORM\Column]
private ?bool $sommeil = null; private ?bool $sommeil = null;
#[ORM\ManyToMany(targetEntity: Prestations::class, inversedBy: 'utilisateurs_aimant')]
private Collection $prestations_aimees;
public function __construct() public function __construct()
{ {
$this->inscriptions = new ArrayCollection(); $this->inscriptions = new ArrayCollection();
...@@ -80,6 +83,7 @@ class Utilisateur extends Personne ...@@ -80,6 +83,7 @@ class Utilisateur extends Personne
$this->prestations_client = new ArrayCollection(); $this->prestations_client = new ArrayCollection();
$this->prestations_proprietaire = new ArrayCollection(); $this->prestations_proprietaire = new ArrayCollection();
$this->litiges = new ArrayCollection(); $this->litiges = new ArrayCollection();
$this->prestations_aimees = new ArrayCollection();
} }
public function getNbFlorains(): ?int public function getNbFlorains(): ?int
...@@ -466,4 +470,34 @@ class Utilisateur extends Personne ...@@ -466,4 +470,34 @@ class Utilisateur extends Personne
return $this; return $this;
} }
/**
* @return Collection<int, Prestations>
*/
public function getPrestationsAimees(): Collection
{
return $this->prestations_aimees;
}
public function addPrestationsAimee(Prestations $prestationsAimee): static
{
if (!$this->prestations_aimees->contains($prestationsAimee)) {
$this->prestations_aimees->add($prestationsAimee);
}
return $this;
}
public function removePrestationsAimee(Prestations $prestationsAimee): static
{
$this->prestations_aimees->removeElement($prestationsAimee);
return $this;
}
public function aimePrestation(Prestations $prestation): bool
{
if (!$this->prestations_aimees) return false;
return $this->prestations_aimees->contains($prestation);
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; } .example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; } .example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style> </style>
{% if annonce %}
<div class="annonce"> <div class="annonce">
<div class="annonce_img"> <div class="annonce_img">
<h1>{{ annonce.Titre }}</h1> <h1>{{ annonce.Titre }}</h1>
...@@ -47,6 +48,21 @@ ...@@ -47,6 +48,21 @@
</div> </div>
<div class="annonce_desc"> <div class="annonce_desc">
{% if user %}
{% if user.id != annonce.proprietaire.id %}
<a href="{{ path('app_aimer_prestation', {'id': annonce.id}) }}"><button class="btn-like">
{% if user.aimePrestation(annonce) %}
<span class="aime">&#10084;</span>
{% else %}
<span class="non_aime">&#10084;</span>
{% endif %}
</button></a>
{% endif %}
{% else %}
<a href="{{ path('app_aimer_prestation', {'id': annonce.id}) }}"><button class="btn-like">
<span class="non_aime">&#10084;</span>
</button></a>
{% endif %}
<h3>Description</h3> <h3>Description</h3>
{% for pret in prets %} {% for pret in prets %}
{% if pret.id == annonce.id %} {% if pret.id == annonce.id %}
...@@ -66,6 +82,9 @@ ...@@ -66,6 +82,9 @@
<hr> <hr>
<h3>Date de validité</h3> <h3>Date de validité</h3>
{{ annonce.DateDebut | date('d-m-Y')}} {{ annonce.DateDebut | date('d-m-Y')}}
<hr>
<h3>Statistiques</h3>
<p>{{ annonce.nbVues }}👁 | {{ nbAimees }} <u>J'aime</u></p>
{% if is_granted('ROLE_ADMIN') and annonce.litiges|length > 0 %} {% if is_granted('ROLE_ADMIN') and annonce.litiges|length > 0 %}
<hr> <hr>
...@@ -78,4 +97,11 @@ ...@@ -78,4 +97,11 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% else %}
<div class="annonce">
<div class="annonce_img">
<h1>Annonce inexistante ou supprimée</h1>
</div>
</div>
{% endif %}
{% endblock %} {% endblock %}
...@@ -10,18 +10,18 @@ ...@@ -10,18 +10,18 @@
<h1>Notifications</h1> <h1>Notifications</h1>
<table class="table_notif"> <table class="table_notif">
{% if notifs %}
<tr> <tr>
<td>Date</td> <td><b>Date</b></td>
<td>Type</td> <td><b>Type</b></td>
<td>Description</td> <td><b>Description</b></td>
</tr> </tr>
{% if notifs %} {% for notif in notifs|reverse %}
{% for notif in notifs %}
<tr> <tr>
<td>{{ notif.date|date('d/m/y') }}</td> <td>{{ notif.date|date('d/m/y') }}</td>
<td>{{ notif.type }}</td> <td>{{ notif.type }}</td>
<td>{{ notif.description }}</td> <td>{{ notif.description }}</td>
</tr>> </tr>
{% endfor %} {% endfor %}
{% else %} {% else %}
<p>Aucune notification trouvée.</p> <p>Aucune notification trouvée.</p>
... ...
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<li><strong>Code postal:</strong> {{ user.codepostal }}</li> <li><strong>Code postal:</strong> {{ user.codepostal }}</li>
<li><strong>Ville:</strong> {{ user.ville }}</li> <li><strong>Ville:</strong> {{ user.ville }}</li>
<li><strong>Téléphone:</strong> {{ user.telephone }}</li> <li><strong>Téléphone:</strong> {{ user.telephone }}</li>
<li><strong>Status abonnement:</strong> {% if user.statusabonnement == 0 %} Abonnement standard {% else %} Abonnement premium {% endif %}</li> <li><strong>Statut abonnement:</strong> {% if user.statusabonnement == 0 %} Abonnement standard {% else %} Abonnement premium {% endif %}</li>
</ul> </ul>
</div> </div>
<button class="btn-connexion2" onclick="window.location.href='{{ path("app_modif_user") }}'">Retour</button> <button class="btn-connexion2" onclick="window.location.href='{{ path("app_modif_user") }}'">Retour</button>
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment