aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Controller/WallabagRestController.php28
-rw-r--r--src/Wallabag/CoreBundle/Entity/Tag.php4
-rw-r--r--src/Wallabag/CoreBundle/Repository/TagRepository.php113
3 files changed, 6 insertions, 139 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
index cb68784d..2384325f 100644
--- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
@@ -232,38 +232,14 @@ class WallabagRestController extends Controller
232 * Retrieve all tags 232 * Retrieve all tags
233 * 233 *
234 * @ApiDoc( 234 * @ApiDoc(
235 * {"name"="user", "dataType"="integer", "requirement"="\w+", "description"="The user ID"}
235 * ) 236 * )
236 */ 237 */
237 public function getTagsAction() 238 public function getTagsUserAction()
238 { 239 {
239 } 240 }
240 241
241 /** 242 /**
242 * Retrieve a single tag
243 *
244 * @ApiDoc(
245 * requirements={
246 * {"name"="label", "dataType"="string", "requirement"="\w+", "description"="Label of the tag"}
247 * }
248 * )
249 */
250 public function getTagAction($label)
251 {
252 $tag = $this
253 ->getDoctrine()
254 ->getRepository('WallabagCoreBundle:Tag')
255 ->findOneByLabel($label);
256
257 if (is_null($tag)) {
258 throw $this->createNotFoundException();
259 }
260
261 $json = $this->get('serializer')->serialize($tag, 'json');
262
263 return new Response($json, 200, array('application/json'));
264 }
265
266 /**
267 * Permanently remove one tag from **every** entry 243 * Permanently remove one tag from **every** entry
268 * 244 *
269 * @ApiDoc( 245 * @ApiDoc(
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php
index 963f32b1..0d7f8c2b 100644
--- a/src/Wallabag/CoreBundle/Entity/Tag.php
+++ b/src/Wallabag/CoreBundle/Entity/Tag.php
@@ -3,12 +3,14 @@
3namespace Wallabag\CoreBundle\Entity; 3namespace Wallabag\CoreBundle\Entity;
4 4
5use Doctrine\ORM\Mapping as ORM; 5use Doctrine\ORM\Mapping as ORM;
6use JMS\Serializer\Annotation\XmlRoot;
6 7
7/** 8/**
8 * Tag 9 * Tag
9 * 10 *
11 * @XmlRoot("tag")
10 * @ORM\Table(name="tag") 12 * @ORM\Table(name="tag")
11 * @ORM\Entity 13 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
12 */ 14 */
13class Tag 15class Tag
14{ 16{
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php
index 005142fc..903a99cd 100644
--- a/src/Wallabag/CoreBundle/Repository/TagRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php
@@ -3,119 +3,8 @@
3namespace Wallabag\CoreBundle\Repository; 3namespace Wallabag\CoreBundle\Repository;
4 4
5use Doctrine\ORM\EntityRepository; 5use Doctrine\ORM\EntityRepository;
6use Doctrine\ORM\Tools\Pagination\Paginator;
7 6
8class EntryRepository extends EntityRepository 7class TagRepository extends EntityRepository
9{ 8{
10 /**
11 * Retrieves unread entries for a user
12 *
13 * @param int $userId
14 * @param int $firstResult
15 * @param int $maxResults
16 *
17 * @return Paginator
18 */
19 public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
20 {
21 $qb = $this->createQueryBuilder('e')
22 ->setFirstResult($firstResult)
23 ->setMaxResults($maxResults)
24 ->leftJoin('e.user', 'u')
25 ->where('e.isArchived = false')
26 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
27 ->orderBy('e.createdAt', 'desc')
28 ->getQuery();
29 9
30 $paginator = new Paginator($qb);
31
32 return $paginator;
33 }
34
35 /**
36 * Retrieves read entries for a user
37 *
38 * @param int $userId
39 * @param int $firstResult
40 * @param int $maxResults
41 *
42 * @return Paginator
43 */
44 public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
45 {
46 $qb = $this->createQueryBuilder('e')
47 ->select('e')
48 ->setFirstResult($firstResult)
49 ->setMaxResults($maxResults)
50 ->leftJoin('e.user', 'u')
51 ->where('e.isArchived = true')
52 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
53 ->orderBy('e.createdAt', 'desc')
54 ->getQuery();
55
56 $paginator = new Paginator($qb);
57
58 return $paginator;
59 }
60
61 /**
62 * Retrieves starred entries for a user
63 *
64 * @param int $userId
65 * @param int $firstResult
66 * @param int $maxResults
67 *
68 * @return Paginator
69 */
70 public function findStarredByUser($userId, $firstResult, $maxResults = 12)
71 {
72 $qb = $this->createQueryBuilder('e')
73 ->select('e')
74 ->setFirstResult($firstResult)
75 ->setMaxResults($maxResults)
76 ->leftJoin('e.user', 'u')
77 ->where('e.isStarred = true')
78 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
79 ->orderBy('e.createdAt', 'desc')
80 ->getQuery();
81
82 $paginator = new Paginator($qb);
83
84 return $paginator;
85 }
86
87 /**
88 * Find Entries
89 *
90 * @param int $userId
91 * @param bool $isArchived
92 * @param bool $isStarred
93 * @param string $sort
94 * @param string $order
95 *
96 * @return array
97 */
98 public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC')
99 {
100 $qb = $this->createQueryBuilder('e')
101 ->where('e.user =:userId')->setParameter('userId', $userId);
102
103 if (null !== $isArchived) {
104 $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);
105 }
106
107 if (null !== $isStarred) {
108 $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
109 }
110
111 if ('created' === $sort) {
112 $qb->orderBy('e.createdAt', $order);
113 } elseif ('updated' === $sort) {
114 $qb->orderBy('e.updatedAt', $order);
115 }
116
117 return $qb
118 ->getQuery()
119 ->getResult();
120 }
121} 10}