diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 36a899b..f8b0f62 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -6,6 +6,7 @@ use App\Entity\Wish; use App\Entity\User; use App\Form\WishFormType; +use App\Repository\OfferingRepository; use App\Repository\WishRepository; use Doctrine\ORM\EntityManagerInterface; @@ -25,10 +26,13 @@ class UserController extends AbstractController } #[Route('/user', name: 'user_page')] - public function user(): Response + public function user(OfferingRepository $offeringRepository): Response { + $user = $this->getUser(); + return $this->render('user/index.html.twig', [ - 'user' => $this->getUser(), + 'user' => $user, + 'offers' => $offeringRepository->findByUser($user), ]); } @@ -71,7 +75,7 @@ class UserController extends AbstractController public function deleteWish(Wish $wish): Response { $user = $this->getUser(); - + $user->removeWish($wish); $this->entityManager->persist($wish); $this->entityManager->flush(); diff --git a/src/Repository/OfferingRepository.php b/src/Repository/OfferingRepository.php index bcf3f45..13c715b 100644 --- a/src/Repository/OfferingRepository.php +++ b/src/Repository/OfferingRepository.php @@ -22,19 +22,16 @@ class OfferingRepository extends ServiceEntityRepository // /** // * @return Offering[] Returns an array of Offering objects // */ - /* - public function findByExampleField($value) + public function findByUser($user) { return $this->createQueryBuilder('o') - ->andWhere('o.exampleField = :val') - ->setParameter('val', $value) + ->andWhere('o.byUser = :val') + ->setParameter('val', $user) ->orderBy('o.id', 'ASC') - ->setMaxResults(10) ->getQuery() ->getResult() ; } - */ /* public function findOneBySomeField($value): ?Offering diff --git a/templates/user/index.html.twig b/templates/user/index.html.twig index 12b1292..48d692f 100644 --- a/templates/user/index.html.twig +++ b/templates/user/index.html.twig @@ -42,4 +42,30 @@

Delete Account

+ +
+

Offers

+ {% if offers|length > 0 %} +
+ {% for offer in offers %} + +
+ {% if offer.photoFilename %} + + {% endif %} +
+
{{ offer.title }}
+

{{ offer.description }}

+
+ +
+
+ {% endfor %} +
+ {% else %} + + {% endif %} {% endblock %}