diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-02-19 14:22:20 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-02-19 14:22:20 +0100 |
commit | c2656f96d4776c86b13d8a4c93a78ee7c4d3824c (patch) | |
tree | e7aaddb8e35197420db96bb067fe410e40c0025c /src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |
parent | fa64d861105bd0713acd7ac5d116353273524b4f (diff) | |
download | wallabag-c2656f96d4776c86b13d8a4c93a78ee7c4d3824c.tar.gz wallabag-c2656f96d4776c86b13d8a4c93a78ee7c4d3824c.tar.zst wallabag-c2656f96d4776c86b13d8a4c93a78ee7c4d3824c.zip |
Move assignTagsToEntry in ContentProxy helper
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 84bc14a9..03990088 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -15,31 +15,6 @@ use Wallabag\CoreBundle\Entity\Tag; | |||
15 | 15 | ||
16 | class WallabagRestController extends FOSRestController | 16 | class WallabagRestController extends FOSRestController |
17 | { | 17 | { |
18 | /** | ||
19 | * @param Entry $entry | ||
20 | * @param string $tags | ||
21 | */ | ||
22 | private function assignTagsToEntry(Entry $entry, $tags) | ||
23 | { | ||
24 | foreach (explode(',', $tags) as $label) { | ||
25 | $label = trim($label); | ||
26 | $tagEntity = $this | ||
27 | ->getDoctrine() | ||
28 | ->getRepository('WallabagCoreBundle:Tag') | ||
29 | ->findOneByLabel($label); | ||
30 | |||
31 | if (is_null($tagEntity)) { | ||
32 | $tagEntity = new Tag(); | ||
33 | $tagEntity->setLabel($label); | ||
34 | } | ||
35 | |||
36 | // only add the tag on the entry if the relation doesn't exist | ||
37 | if (!$entry->getTags()->contains($tagEntity)) { | ||
38 | $entry->addTag($tagEntity); | ||
39 | } | ||
40 | } | ||
41 | } | ||
42 | |||
43 | private function validateAuthentication() | 18 | private function validateAuthentication() |
44 | { | 19 | { |
45 | if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { | 20 | if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { |
@@ -140,7 +115,7 @@ class WallabagRestController extends FOSRestController | |||
140 | 115 | ||
141 | $tags = $request->request->get('tags', ''); | 116 | $tags = $request->request->get('tags', ''); |
142 | if (!empty($tags)) { | 117 | if (!empty($tags)) { |
143 | $this->assignTagsToEntry($entry, $tags); | 118 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); |
144 | } | 119 | } |
145 | 120 | ||
146 | $em = $this->getDoctrine()->getManager(); | 121 | $em = $this->getDoctrine()->getManager(); |
@@ -192,7 +167,7 @@ class WallabagRestController extends FOSRestController | |||
192 | 167 | ||
193 | $tags = $request->request->get('tags', ''); | 168 | $tags = $request->request->get('tags', ''); |
194 | if (!empty($tags)) { | 169 | if (!empty($tags)) { |
195 | $this->assignTagsToEntry($entry, $tags); | 170 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); |
196 | } | 171 | } |
197 | 172 | ||
198 | $em = $this->getDoctrine()->getManager(); | 173 | $em = $this->getDoctrine()->getManager(); |
@@ -270,7 +245,7 @@ class WallabagRestController extends FOSRestController | |||
270 | 245 | ||
271 | $tags = $request->request->get('tags', ''); | 246 | $tags = $request->request->get('tags', ''); |
272 | if (!empty($tags)) { | 247 | if (!empty($tags)) { |
273 | $this->assignTagsToEntry($entry, $tags); | 248 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); |
274 | } | 249 | } |
275 | 250 | ||
276 | $em = $this->getDoctrine()->getManager(); | 251 | $em = $this->getDoctrine()->getManager(); |