X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FEntryController.php;h=56759adba0625ad5b71b74680bde2dbb1ad980d6;hb=074110ca2dd3ba0d58f2fa93076933d06b46df77;hp=cef299900d0636970c4e8e3c3a6477893446b3ec;hpb=8d2527ec528d1631be21967137f63d2fc0cf218f;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index cef29990..56759adb 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -15,6 +15,7 @@ use Wallabag\CoreBundle\Event\EntryDeletedEvent; use Wallabag\CoreBundle\Event\EntrySavedEvent; use Wallabag\CoreBundle\Form\Type\EditEntryType; use Wallabag\CoreBundle\Form\Type\EntryFilterType; +use Wallabag\CoreBundle\Form\Type\EntrySortType; use Wallabag\CoreBundle\Form\Type\NewEntryType; use Wallabag\CoreBundle\Form\Type\SearchEntryType; @@ -531,9 +532,18 @@ class EntryController extends Controller $repository = $this->get('wallabag_core.entry_repository'); $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); + $direction = 'asc'; + $sortBy = null; - $sortBy = $request->get('sort', 'id'); - $direction = $request->get('direction', 'DESC'); + if (null !== ($request->query->get('entry_sort'))) { + $direction = (null !== $request->query->get('entry_sort')['sortOrder'] ? $request->query->get('entry_sort')['sortOrder'] : 'asc'); + + // defined as null by default because each repository method have the right field as default value too + // like `getBuilderForStarredByUser` will have `starredAt` sort by default + if (\in_array($request->get('entry_sort')['sortType'], ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { + $sortBy = $request->get('entry_sort')['sortType']; + } + } switch ($type) { case 'search': @@ -559,6 +569,7 @@ class EntryController extends Controller } $form = $this->createForm(EntryFilterType::class); + $sortForm = $this->createForm(EntrySortType::class); if ($request->query->has($form->getName())) { // manually bind values from the request @@ -568,6 +579,11 @@ class EntryController extends Controller $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb); } + if ($request->query->has($sortForm->getName())) { + // manually bind values from the request + $sortForm->submit($request->query->get($sortForm->getName())); + } + $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter); @@ -586,6 +602,7 @@ class EntryController extends Controller return $this->render( 'WallabagCoreBundle:Entry:entries.html.twig', [ 'form' => $form->createView(), + 'sortForm' => $sortForm->createView(), 'entries' => $entries, 'currentPage' => $page, 'searchTerm' => $searchTerm,