diff --git a/config/routes.yaml b/config/routes.yaml index aa67fd3..15131fa 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -23,6 +23,12 @@ user_register: method: GET inviteCode: \w{32} +user_account_invites: + path: /account/invites + controller: App\Controller\AccountController::invites + requirements: + method: GET + user_login: path: /login controller: App\Controller\SecurityController::login diff --git a/src/Controller/AccountController.php b/src/Controller/AccountController.php new file mode 100644 index 0000000..3ed5c55 --- /dev/null +++ b/src/Controller/AccountController.php @@ -0,0 +1,23 @@ +getUser()) { + throw $this->createAccessDeniedException('User not found exception'); + } + + return $this->render('Account/invites.html.twig', [ + 'invites' => $inviteRepo->findInvitesByUser($user), + ]); + } +} \ No newline at end of file diff --git a/src/Repository/InviteRepository.php b/src/Repository/InviteRepository.php index 58bf7b0..b39e8ae 100644 --- a/src/Repository/InviteRepository.php +++ b/src/Repository/InviteRepository.php @@ -2,7 +2,7 @@ namespace App\Repository; -use App\Entity\Invite; +use App\Entity\{Invite, User}; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Symfony\Bridge\Doctrine\RegistryInterface; @@ -17,4 +17,16 @@ class InviteRepository extends ServiceEntityRepository { $this->getEntityManager()->persist($invite); } + + /** @return Invite[] */ + public function findInvitesByUser(User $user): iterable + { + $qb = $this->createQueryBuilder('i'); + $qb + ->select(['i', 'uu']) + ->leftJoin('i.usedBy', 'uu') + ; + + return $qb->getQuery()->getResult(); + } } \ No newline at end of file diff --git a/templates/Account/invites.html.twig b/templates/Account/invites.html.twig new file mode 100644 index 0000000..c878313 --- /dev/null +++ b/templates/Account/invites.html.twig @@ -0,0 +1,30 @@ +{% extends 'base.html.twig' %} + +{% block content %} +

Your invites

+ + + + + + + + + + {# @var invite \App\Entity\Invite #} + {% for invite in invites %} + + + + + {% endfor %} + +
#
{{ loop.index }} + {% if invite.usedBy %} + Used by {{ invite.usedBy.username }}. + {% else %} + {% set invite_url = url('user_register', { inviteCode: invite.code }) %} + + {% endif %} +
+{% endblock %} diff --git a/templates/base.html.twig b/templates/base.html.twig index 9601fd5..23d2bab 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -13,6 +13,8 @@ {% block css %} + + {% endblock %} @@ -20,7 +22,7 @@