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 @@ {% block title %}Welcome!{% endblock %} - {% block stylesheets %} - {% endblock %} + {% block stylesheets %}{% endblock %} {% block body %}{% endblock %} - {% block javascripts %} - {% block importmap %}{{ importmap('app') }}{% endblock %} - {% endblock %} + {% block javascripts %}{% endblock %} diff --git a/templates/default/home.html.twig b/templates/default/home.html.twig index 0f9fb75..8b08023 100644 --- a/templates/default/home.html.twig +++ b/templates/default/home.html.twig @@ -10,7 +10,6 @@ {% endblock %} {% block javascripts %} - @@ -24,19 +23,19 @@ {% block body %}
-
+
-

Reference

+

Reference

 
-
+
@@ -48,9 +47,9 @@ - {% for n in app.user.notes|reverse %} - {{ n.toTableRow()|raw }}
- {% endfor %} + {% for n in reverseNoteSort %} + {{ n.toTableRow()|raw }} + {% endfor %}
@@ -59,7 +58,7 @@

Notes

- +
  -   - + +   +
@@ -117,9 +121,12 @@ -
-
+ + + + +
diff --git a/templates/default/sidebar.html.twig b/templates/default/sidebar.html.twig index a65a173..55f4c00 100644 --- a/templates/default/sidebar.html.twig +++ b/templates/default/sidebar.html.twig @@ -12,7 +12,6 @@