feat: persist and sort by viewed by admins status of teamers

This commit is contained in:
Björn Fromme
2024-06-23 17:28:15 +02:00
parent 8d8d6dacd3
commit b58bd9f34f
5 changed files with 72 additions and 7 deletions
+36
View File
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240623151419 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}
@@ -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', [
@@ -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', [
+15
View File
@@ -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;
}
}
+8 -1
View File
@@ -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(