diff --git a/migrations/Version20240623151419.php b/migrations/Version20240623151419.php new file mode 100644 index 0000000..40fa402 --- /dev/null +++ b/migrations/Version20240623151419.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE teamer ADD viewed TINYINT(1) NOT NULL'); + } + + public function postUp(Schema $schema): void + { + $this->connection->executeQuery('UPDATE teamer SET viewed = 1'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE teamer DROP viewed'); + } +} diff --git a/src/Controller/Administrative/Teamer/IndexController.php b/src/Controller/Administrative/Teamer/IndexController.php index 6002dd3..3f679cf 100644 --- a/src/Controller/Administrative/Teamer/IndexController.php +++ b/src/Controller/Administrative/Teamer/IndexController.php @@ -25,20 +25,17 @@ class IndexController extends AbstractController public function index(Request $request): Response { $filterDto = $this->filterHandler->getFilterSettings(); + $requestedSorting = $request->query->get('sort'); $query = $this ->teamerRepository - ->getListQuery($filterDto) + ->getListQuery($filterDto, $requestedSorting) ; $pagination = $this->paginator->paginate( $query, $request->query->getInt('page', 1), - 10, - [ - 'defaultSortFieldName' => 'teamer.lastName', - 'defaultSortDirection' => 'asc', - ] + 10 ); return $this->render('administrative/teamer/index.html.twig', [ diff --git a/src/Controller/Administrative/Teamer/ProfileController.php b/src/Controller/Administrative/Teamer/ProfileController.php index ee9305e..edddabb 100644 --- a/src/Controller/Administrative/Teamer/ProfileController.php +++ b/src/Controller/Administrative/Teamer/ProfileController.php @@ -4,6 +4,7 @@ namespace App\Controller\Administrative\Teamer; use App\Controller\Traits\ReturnUrlTrait; use App\Entity\Teamer; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -14,10 +15,19 @@ class ProfileController extends AbstractController { use ReturnUrlTrait; + public function __construct(private readonly EntityManagerInterface $entityManager) + { + } + #[Route('/administrative/teamer/profile/{uuid}', name: 'app_administrative_teamer_profile')] #[IsGranted('ROLE_ADMINISTRATIVE')] public function index(Teamer $teamer, Request $request): Response { + if (false === $teamer->isViewed()) { + $teamer->setViewed(true); + $this->entityManager->flush(); + } + $returnUrl = $this->getReturnUrl($request, 'app_administrative_teamer_index'); return $this->render('administrative/teamer/profile.html.twig', [ diff --git a/src/Entity/Teamer.php b/src/Entity/Teamer.php index bae6c86..65569a3 100644 --- a/src/Entity/Teamer.php +++ b/src/Entity/Teamer.php @@ -131,6 +131,9 @@ class Teamer implements TimestampableEntityInterface #[ORM\Column(nullable: true)] private ?array $crmSelections = null; + #[ORM\Column] + private bool $viewed = false; + public function __construct() { $this->uuid = Uuid::v4(); @@ -767,4 +770,16 @@ class Teamer implements TimestampableEntityInterface return $this; } + + public function isViewed(): bool + { + return $this->viewed; + } + + public function setViewed(bool $viewed): static + { + $this->viewed = $viewed; + + return $this; + } } diff --git a/src/Repository/TeamerRepository.php b/src/Repository/TeamerRepository.php index 4fc121a..0288c05 100644 --- a/src/Repository/TeamerRepository.php +++ b/src/Repository/TeamerRepository.php @@ -27,7 +27,7 @@ class TeamerRepository extends ServiceEntityRepository parent::__construct($registry, Teamer::class); } - public function getListQuery(TeamerFilterDto $filterDto): Query + public function getListQuery(TeamerFilterDto $filterDto, ?string $requestedSorting = null): Query { $qb = $this->createQueryBuilder('teamer'); @@ -40,6 +40,13 @@ class TeamerRepository extends ServiceEntityRepository ->leftJoin('teamer.user', 'user') ; + if (null === $requestedSorting) { + $qb + ->orderBy('teamer.viewed', 'asc') + ->addOrderBy('teamer.lastName', 'asc') + ; + } + if (null !== $filterDto->getName()) { $qb ->andWhere($qb->expr()->orX(