diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2020-04-12 18:42:31 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2020-04-28 10:13:58 +0200 |
commit | 19c407f2967786bb106ebae636055b30af900e7b (patch) | |
tree | 8d908313c4183f74f6108a28a32efda103fa3070 /src/Wallabag/CoreBundle/Controller | |
parent | 4bc6ef346ab28025d613d308da84812325f4c7ce (diff) | |
download | wallabag-19c407f2967786bb106ebae636055b30af900e7b.tar.gz wallabag-19c407f2967786bb106ebae636055b30af900e7b.tar.zst wallabag-19c407f2967786bb106ebae636055b30af900e7b.zip |
First draft for EntrySortType
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 5157653c..85e71116 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -15,6 +15,7 @@ use Wallabag\CoreBundle\Event\EntryDeletedEvent; | |||
15 | use Wallabag\CoreBundle\Event\EntrySavedEvent; | 15 | use Wallabag\CoreBundle\Event\EntrySavedEvent; |
16 | use Wallabag\CoreBundle\Form\Type\EditEntryType; | 16 | use Wallabag\CoreBundle\Form\Type\EditEntryType; |
17 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; | 17 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; |
18 | use Wallabag\CoreBundle\Form\Type\EntrySortType; | ||
18 | use Wallabag\CoreBundle\Form\Type\NewEntryType; | 19 | use Wallabag\CoreBundle\Form\Type\NewEntryType; |
19 | use Wallabag\CoreBundle\Form\Type\SearchEntryType; | 20 | use Wallabag\CoreBundle\Form\Type\SearchEntryType; |
20 | 21 | ||
@@ -535,11 +536,11 @@ class EntryController extends Controller | |||
535 | // defined as null by default because each repository method have the right field as default value too | 536 | // defined as null by default because each repository method have the right field as default value too |
536 | // like `getBuilderForStarredByUser` will have `starredAt` sort by default | 537 | // like `getBuilderForStarredByUser` will have `starredAt` sort by default |
537 | $sortBy = null; | 538 | $sortBy = null; |
538 | if (\in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { | 539 | if (\in_array($request->get('entry_sort')['sortType'], ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { |
539 | $sortBy = $request->get('sort', null); | 540 | $sortBy = $request->get('entry_sort')['sortType']; |
540 | } | 541 | } |
541 | 542 | ||
542 | $direction = 'DESC' === $request->get('direction') ? 'DESC' : 'ASC'; | 543 | $direction = isset($request->get('entry_sort')['sortOrder']) ? 'DESC' : 'ASC'; |
543 | 544 | ||
544 | switch ($type) { | 545 | switch ($type) { |
545 | case 'search': | 546 | case 'search': |
@@ -565,6 +566,7 @@ class EntryController extends Controller | |||
565 | } | 566 | } |
566 | 567 | ||
567 | $form = $this->createForm(EntryFilterType::class); | 568 | $form = $this->createForm(EntryFilterType::class); |
569 | $sortForm = $this->createForm(EntrySortType::class); | ||
568 | 570 | ||
569 | if ($request->query->has($form->getName())) { | 571 | if ($request->query->has($form->getName())) { |
570 | // manually bind values from the request | 572 | // manually bind values from the request |
@@ -574,6 +576,11 @@ class EntryController extends Controller | |||
574 | $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb); | 576 | $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb); |
575 | } | 577 | } |
576 | 578 | ||
579 | if ($request->query->has($sortForm->getName())) { | ||
580 | // manually bind values from the request | ||
581 | $sortForm->submit($request->query->get($sortForm->getName())); | ||
582 | } | ||
583 | |||
577 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); | 584 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); |
578 | 585 | ||
579 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter); | 586 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter); |
@@ -592,6 +599,7 @@ class EntryController extends Controller | |||
592 | return $this->render( | 599 | return $this->render( |
593 | 'WallabagCoreBundle:Entry:entries.html.twig', [ | 600 | 'WallabagCoreBundle:Entry:entries.html.twig', [ |
594 | 'form' => $form->createView(), | 601 | 'form' => $form->createView(), |
602 | 'sortForm' => $sortForm->createView(), | ||
595 | 'entries' => $entries, | 603 | 'entries' => $entries, |
596 | 'currentPage' => $page, | 604 | 'currentPage' => $page, |
597 | 'searchTerm' => $searchTerm, | 605 | 'searchTerm' => $searchTerm, |