diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index dc3f6fe..12c00a9 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -26,9 +26,11 @@ class DefaultController extends AbstractController { $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $last4Notes = $emi->getRepository(Note::class)->getLast4Notes($user); + $openNotes = $emi->getRepository(Note::class)->reverseNoteSort($user); return $this->render('default/home.html.twig', [ 'last4Notes' => $last4Notes, + 'reverseNoteSort' => $openNotes, 'isAdmin' => $this->isGranted('ROLE_ADMIN'), ]); } diff --git a/src/Repository/NoteRepository.php b/src/Repository/NoteRepository.php index 184e94d..66948fd 100644 --- a/src/Repository/NoteRepository.php +++ b/src/Repository/NoteRepository.php @@ -17,6 +17,22 @@ class NoteRepository extends ServiceEntityRepository parent::__construct($registry, Note::class); } + public function reverseNoteSort(?User $user): array + { + if (!$user) { + return []; + } + + $ret = $this->createQueryBuilder('n') + ->where('n.user = :user') + ->setParameter('user', $user->getId()->toBinary()) + ->orderBy('n.date', 'DESC') + ->getQuery() + ->getResult(); + + return $ret; + } + public function getLast4Notes(?User $user): array { if (!$user) { @@ -36,13 +52,13 @@ class NoteRepository extends ServiceEntityRepository public function findNote(string $query, string $userId): array { $ret = $this->createQueryBuilder('n') - ->orderBy('n.date', 'DESC') ->where('n.title LIKE :query') ->orWhere('n.passage LIKE :query') ->orWhere('n.text LIKE :query') ->andWhere('n.user = :user') ->setParameter('query', "%{$query}%") ->setParameter('user', $userId) + ->orderBy('n.date', 'DESC') ->setMaxResults(3) ->getQuery() ->getResult(); diff --git a/templates/base.html.twig b/templates/base.html.twig index d7646b0..8d33a01 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -10,13 +10,10 @@