]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
First draft for EntrySortType
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index 5157653c6480f05cbb106e34547eb5c350e678cd..85e711160c5a000de76969ce5e0633826c0cd43c 100644 (file)
@@ -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;
 
@@ -535,11 +536,11 @@ class EntryController extends Controller
         // 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
         $sortBy = null;
-        if (\in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
-            $sortBy = $request->get('sort', null);
+        if (\in_array($request->get('entry_sort')['sortType'], ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
+            $sortBy = $request->get('entry_sort')['sortType'];
         }
 
-        $direction = 'DESC' === $request->get('direction') ? 'DESC' : 'ASC';
+        $direction = isset($request->get('entry_sort')['sortOrder']) ? 'DESC' : 'ASC';
 
         switch ($type) {
             case 'search':
@@ -565,6 +566,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
@@ -574,6 +576,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);
@@ -592,6 +599,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,