aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Controller/WallabagRestController.php5
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntriesRepository.php10
2 files changed, 10 insertions, 5 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
index fae633fa..f14f821b 100644
--- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
@@ -80,17 +80,14 @@ class WallabagRestController extends Controller
80 */ 80 */
81 public function postEntriesAction(Request $request) 81 public function postEntriesAction(Request $request)
82 { 82 {
83 //TODO la récup ne marche pas
84 //TODO gérer si on passe le titre
85 //TODO gérer si on passe les tags 83 //TODO gérer si on passe les tags
86 //TODO ne pas avoir du code comme ça qui doit se trouver dans le Repository
87 $url = $request->request->get('url'); 84 $url = $request->request->get('url');
88 85
89 $content = Extractor::extract($url); 86 $content = Extractor::extract($url);
90 $entry = new Entries(); 87 $entry = new Entries();
91 $entry->setUserId(1); 88 $entry->setUserId(1);
92 $entry->setUrl($url); 89 $entry->setUrl($url);
93 $entry->setTitle($content->getTitle()); 90 $entry->setTitle($request->request->get('title') ?: $content->getTitle());
94 $entry->setContent($content->getBody()); 91 $entry->setContent($content->getBody());
95 $em = $this->getDoctrine()->getManager(); 92 $em = $this->getDoctrine()->getManager();
96 $em->persist($entry); 93 $em->persist($entry);
diff --git a/src/Wallabag/CoreBundle/Repository/EntriesRepository.php b/src/Wallabag/CoreBundle/Repository/EntriesRepository.php
index dd92d520..ae854e5a 100644
--- a/src/Wallabag/CoreBundle/Repository/EntriesRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntriesRepository.php
@@ -26,6 +26,7 @@ class EntriesRepository extends EntityRepository
26 ->where('e.isRead = 0') 26 ->where('e.isRead = 0')
27 ->andWhere('e.userId =:userId')->setParameter('userId', $userId) 27 ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
28 ->andWhere('e.isDeleted=0') 28 ->andWhere('e.isDeleted=0')
29 ->orderBy('e.createdAt', 'desc')
29 ->getQuery(); 30 ->getQuery();
30 31
31 $paginator = new Paginator($qb); 32 $paginator = new Paginator($qb);
@@ -50,6 +51,7 @@ class EntriesRepository extends EntityRepository
50 ->where('e.isRead = 1') 51 ->where('e.isRead = 1')
51 ->andWhere('e.userId =:userId')->setParameter('userId', $userId) 52 ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
52 ->andWhere('e.isDeleted=0') 53 ->andWhere('e.isDeleted=0')
54 ->orderBy('e.createdAt', 'desc')
53 ->getQuery(); 55 ->getQuery();
54 56
55 $paginator = new Paginator($qb); 57 $paginator = new Paginator($qb);
@@ -74,6 +76,7 @@ class EntriesRepository extends EntityRepository
74 ->where('e.isFav = 1') 76 ->where('e.isFav = 1')
75 ->andWhere('e.userId =:userId')->setParameter('userId', $userId) 77 ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
76 ->andWhere('e.isDeleted=0') 78 ->andWhere('e.isDeleted=0')
79 ->orderBy('e.createdAt', 'desc')
77 ->getQuery(); 80 ->getQuery();
78 81
79 $paginator = new Paginator($qb); 82 $paginator = new Paginator($qb);
@@ -83,7 +86,6 @@ class EntriesRepository extends EntityRepository
83 86
84 public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order) 87 public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order)
85 { 88 {
86 //TODO tous les paramètres ne sont pas utilisés, à corriger
87 $qb = $this->createQueryBuilder('e') 89 $qb = $this->createQueryBuilder('e')
88 ->select('e') 90 ->select('e')
89 ->where('e.userId =:userId')->setParameter('userId', $userId); 91 ->where('e.userId =:userId')->setParameter('userId', $userId);
@@ -100,6 +102,12 @@ class EntriesRepository extends EntityRepository
100 $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted); 102 $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted);
101 } 103 }
102 104
105 if ('created' === $sort) {
106 $qb->orderBy('e.createdAt', $order);
107 } elseif ('updated' === $sort) {
108 $qb->orderBy('e.updatedAt', $order);
109 }
110
103 return $qb 111 return $qb
104 ->getQuery() 112 ->getQuery()
105 ->getResult(Query::HYDRATE_ARRAY); 113 ->getResult(Query::HYDRATE_ARRAY);