aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle/Controller/EntryRestController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/EntryRestController.php')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index af5f7603..fc46e782 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -438,4 +438,72 @@ class EntryRestController extends WallabagRestController
438 438
439 return (new JsonResponse())->setJson($json); 439 return (new JsonResponse())->setJson($json);
440 } 440 }
441
442 /**
443 * Handles an entries list and add / delete to them some tags.
444 *
445 * @ApiDoc(
446 * parameters={
447 * {"name"="list", "dataType"="string", "required"=true, "format"="A JSON array of urls [{'url': 'http://...','tags': 'tag1, tag2','action': 'delete'}, {'url': 'http://...','tags': 'tag1, tag2','action': 'add'}]", "description"="Urls (as an array) to handle."}
448 * }
449 * )
450 *
451 * @return JsonResponse
452 */
453 public function postEntriesTagsListAction(Request $request)
454 {
455 $this->validateAuthentication();
456
457 $list = json_decode($request->query->get('list', []));
458 $results = [];
459
460 // handle multiple urls
461 if (!empty($list)) {
462 $results = [];
463 foreach ($list as $key => $element) {
464 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
465 $element->url,
466 $this->getUser()->getId()
467 );
468
469 $results[$key]['url'] = $element->url;
470 $results[$key]['action'] = $element->action;
471 $results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false;
472
473 $tags = $element->tags;
474
475 if (false !== $entry && !(empty($tags))) {
476 switch ($element->action) {
477 case 'delete':
478 $tags = explode(',', $tags);
479 foreach ($tags as $label) {
480 $label = trim($label);
481
482 $tag = $this->getDoctrine()
483 ->getRepository('WallabagCoreBundle:Tag')
484 ->findOneByLabel($label);
485
486 if (false !== $tag) {
487 $entry->removeTag($tag);
488 }
489 }
490
491 break;
492 case 'add':
493 $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags);
494
495 break;
496 }
497
498 $em = $this->getDoctrine()->getManager();
499 $em->persist($entry);
500 $em->flush();
501 }
502 }
503 }
504
505 $json = $this->get('serializer')->serialize($results, 'json');
506
507 return (new JsonResponse())->setJson($json);
508 }
441} 509}