Skip to content
Snippets Groups Projects
Commit 9de710bd authored by user's avatar user
Browse files

git pull

parent f2d84c49
No related branches found
No related tags found
No related merge requests found
...@@ -9,4 +9,4 @@ vendor/ ...@@ -9,4 +9,4 @@ vendor/
.idea/ .idea/
docker/server docker/server
migrations/ migrations/
public/uploads public/uploads
\ No newline at end of file
...@@ -8,7 +8,9 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; ...@@ -8,7 +8,9 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use App\Entity\User;
use App\Entity\Item; use App\Entity\Item;
use App\Entity\Wishlist; use App\Entity\Wishlist;
use Twig\TokenParser\UseTokenParser; use Twig\TokenParser\UseTokenParser;
...@@ -55,31 +57,36 @@ final class AdminController extends AbstractController ...@@ -55,31 +57,36 @@ final class AdminController extends AbstractController
]); ]);
} }
#[Route('/admin/user/{id}/lock', name: 'admin_user_lock', methods: ['POST'])] #[Route('/admin/user/{id}/lock', name: 'admin_user_lock', methods: ['POST'])]
public function lockUser(User $user, EntityManagerInterface $entityManager): Response public function lockUser(User $user, EntityManagerInterface $entityManager): RedirectResponse
{ {
$user->setIsLocked(true); $user->setIsLocked(true);
$entityManager->flush(); $entityManager->flush();
return $this->redirectToRoute('admin_users'); $this->addFlash('success', "User has been locked.");
return $this->redirectToRoute('admin_dashboard');
} }
#[Route('/admin/user/{id}/unlock', name: 'admin_user_unlock', methods: ['POST'])] #[Route('/admin/user/{id}/unlock', name: 'admin_user_unlock', methods: ['POST'])]
public function unlockUser(User $user, EntityManagerInterface $entityManager): Response public function unlockUser(User $user, EntityManagerInterface $entityManager): RedirectResponse
{ {
$user->setIsLocked(false); $user->setIsLocked(false);
$entityManager->flush(); $entityManager->flush();
return $this->redirectToRoute('admin_users'); $this->addFlash('success', "User has been unlocked.");
return $this->redirectToRoute('admin_dashboard');
} }
#[Route('/admin/user/{id}/delete', name: 'admin_user_delete', methods: ['POST'])] #[Route('/admin/user/{id}/delete', name: 'admin_user_delete', methods: ['POST'])]
public function deleteUser(User $user, EntityManagerInterface $entityManager): Response public function deleteUser(User $user, EntityManagerInterface $entityManager): RedirectResponse
{ {
$entityManager->remove($user); $entityManager->remove(object: $user);
$entityManager->flush(); $entityManager->flush();
return $this->redirectToRoute('admin_users'); $this->addFlash('success', "User has been deleted.");
return $this->redirectToRoute('admin_dashboard');
} }
} }
...@@ -23,8 +23,8 @@ class PurchaseProofController extends AbstractController ...@@ -23,8 +23,8 @@ class PurchaseProofController extends AbstractController
} }
$purchaseProof = new PurchaseProof(); $purchaseProof = new PurchaseProof();
$purchaseProof->setItem($item); $purchaseProof->setItem(item: $item);
$form = $this->createForm(PurchaseProofType::class, $purchaseProof); $form = $this->createForm(PurchaseProofType::class, $purchaseProof);
$form->handleRequest($request); $form->handleRequest($request);
......
...@@ -39,10 +39,10 @@ class Item ...@@ -39,10 +39,10 @@ class Item
#[ORM\Column] #[ORM\Column]
private ?float $price = null; private ?float $price = null;
#[ORM\OneToOne(mappedBy: 'item', targetEntity: PurchaseProof::class, cascade: ['persist', 'remove'])] #[ORM\OneToOne(mappedBy: 'item', targetEntity: PurchaseProof::class, cascade: ['remove'])]
private ?PurchaseProof $purchaseProof = null; private ?PurchaseProof $purchaseProof = null;
#[ORM\ManyToOne(inversedBy: 'items')] #[ORM\ManyToOne(inversedBy: 'items', cascade: ['remove'])]
#[ORM\JoinColumn(nullable: false)] #[ORM\JoinColumn(nullable: false)]
private ?Wishlist $wishlist = null; private ?Wishlist $wishlist = null;
......
...@@ -23,8 +23,8 @@ class PurchaseProof ...@@ -23,8 +23,8 @@ class PurchaseProof
#[ORM\JoinColumn(nullable: false)] #[ORM\JoinColumn(nullable: false)]
private ?Item $item = null; private ?Item $item = null;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'purchaseProofs')] #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'purchaseProofs',cascade: ['remove'])]
#[ORM\JoinColumn(nullable: false)] #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?User $buyer = null; private ?User $buyer = null;
public function getId(): ?int public function getId(): ?int
......
...@@ -29,11 +29,13 @@ class Wishlist ...@@ -29,11 +29,13 @@ class Wishlist
/** /**
* @var Collection<int, Item> * @var Collection<int, Item>
*/ */
#[ORM\OneToMany(targetEntity: Item::class, mappedBy: 'wishlist', orphanRemoval: true)] #[ORM\OneToMany(targetEntity: Item::class, mappedBy: 'wishlist', orphanRemoval: true, cascade: ['remove'])]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private Collection $items; private Collection $items;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'wishlists')] #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'wishlists', cascade: ['remove'] )]
#[ORM\JoinColumn(nullable: false)] #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?User $owner = null; private ?User $owner = null;
public function getOwner(): ?User public function getOwner(): ?User
...@@ -150,14 +152,15 @@ class Wishlist ...@@ -150,14 +152,15 @@ class Wishlist
} }
public function wishlistTotalPrice() { public function wishlistTotalPrice(): float
$itemsArray = (($this->items->toArray())) ; {
$itemsArray = $this->items->toArray(); // Pas besoin des doubles parenthèses
$total = 0 ; $total = 0;
for ($i = 0; $i < count($itemsArray); $i++) { for ($i = 0; $i < count($itemsArray); $i++) {
$total += $itemsArray[i]->getPrice() ; $total += $itemsArray[$i]->getPrice(); // Utilisation correcte des crochets
} }
return $total ; return $total;
} }
} }
...@@ -58,8 +58,8 @@ class WishlistRepository extends ServiceEntityRepository ...@@ -58,8 +58,8 @@ class WishlistRepository extends ServiceEntityRepository
usort($rankings, callback: function($a, $b) {return $a['total'] - $b['total'];}); usort($rankings, callback: function($a, $b) {return $a['total'] - $b['total'];});
} else { } else {
for ($i = 0; $i < sizeof($rankings) ; $i++ ) { for ($i = 0; $i < sizeof($rankings) ; $i++ ) {
if ($rankings[i]['total'] < $total ) { if ($rankings[$i]['total'] < $total ) {
$rankings[i] = ['wishlist' => $wishlist, 'total' => $total] ; $rankings[$i] = ['wishlist' => $wishlist, 'total' => $total] ;
} }
} }
...@@ -68,7 +68,7 @@ class WishlistRepository extends ServiceEntityRepository ...@@ -68,7 +68,7 @@ class WishlistRepository extends ServiceEntityRepository
} }
$result = array() ; $result = array() ;
for ($i = 0 ; $i < sizeof($rankings) ; $i++ ) { for ($i = 0 ; $i < sizeof($rankings) ; $i++ ) {
$result[] = $rankings[i]['wishlist'] ; $result[] = $rankings[$i]['wishlist'] ;
} }
return $result; return $result;
} }
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
{% for wishlist in topWishlists %} {% for wishlist in topWishlists %}
<li class="list-group-item d-flex justify-content-between align-items-center"> <li class="list-group-item d-flex justify-content-between align-items-center">
{{ wishlist.name }} {{ wishlist.name }}
<span class="badge bg-success rounded-pill">{{ wishlist.totalValue }}</span> <span class="badge bg-success rounded-pill">{{ wishlist.wishlistTotalPrice() }}</span>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
...@@ -72,7 +72,8 @@ ...@@ -72,7 +72,8 @@
{% for user in users %} {% for user in users %}
<tr> <tr>
<td>{{ user.id }}</td> <td>{{ user.id }}</td>
<td>{{ user.username }}</td> <td>{{ user.firstName }}</td>
<td>{{ user.lastName }}</td>
<td>{{ user.email }}</td> <td>{{ user.email }}</td>
<td> <td>
{% if user.isLocked %} {% if user.isLocked %}
......
{% extends 'base.html.twig' %}
{% block title %}User Management{% endblock %}
{% block body %}
<header>
<div class="admin-icon"></div>
<h1><a href="#">User Management</a></h1>
<input type="text" placeholder="Search users…" class="search-bar">
</header>
<main>
<div class="container">
<section class="form-section">
<h1>User List</h1>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Is Locked</th>
<th>Is Admin</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ user.id }}</td>
<td>{{ user.firstName }}</td>
<td>{{ user.lastName }}</td>
<td>{{ user.email }}</td>
<td>
{% if user.isLocked %}
<span class="text-danger">Yes</span>
{% else %}
<span class="text-success">No</span>
{% endif %}
</td>
<td>
{% if user.isAdmin %}
<span class="text-primary">Yes</span>
{% else %}
<span class="text-secondary">No</span>
{% endif %}
</td>
<td>
<a href="{{ path('admin_user_lock', {'id': user.id}) }}" class="btn btn-danger btn-sm">Lock</a>
<a href="{{ path('admin_user_unlock', {'id': user.id}) }}" class="btn btn-success btn-sm">Unlock</a>
<a href="{{ path('admin_user_delete', {'id': user.id}) }}" class="btn btn-warning btn-sm">Delete</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="7">No users found</td>
</tr>
{% endfor %}
</tbody>
</table>
</section>
</div>
</main>
{% endblock %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment