diff options
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/EntryRestController.php')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/EntryRestController.php | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index af5f7603..7590efbb 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -438,4 +438,107 @@ 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 delete tags from them. | ||
444 | * | ||
445 | * @ApiDoc( | ||
446 | * parameters={ | ||
447 | * {"name"="list", "dataType"="string", "required"=true, "format"="A JSON array of urls [{'url': 'http://...','tags': 'tag1, tag2'}, {'url': 'http://...','tags': 'tag1, tag2'}]", "description"="Urls (as an array) to handle."} | ||
448 | * } | ||
449 | * ) | ||
450 | * | ||
451 | * @return JsonResponse | ||
452 | */ | ||
453 | public function deleteEntriesTagsListAction(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 | foreach ($list as $key => $element) { | ||
463 | $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId( | ||
464 | $element->url, | ||
465 | $this->getUser()->getId() | ||
466 | ); | ||
467 | |||
468 | $results[$key]['url'] = $element->url; | ||
469 | $results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false; | ||
470 | |||
471 | $tags = $element->tags; | ||
472 | |||
473 | if (false !== $entry && !(empty($tags))) { | ||
474 | $tags = explode(',', $tags); | ||
475 | foreach ($tags as $label) { | ||
476 | $label = trim($label); | ||
477 | |||
478 | $tag = $this->getDoctrine() | ||
479 | ->getRepository('WallabagCoreBundle:Tag') | ||
480 | ->findOneByLabel($label); | ||
481 | |||
482 | if (false !== $tag) { | ||
483 | $entry->removeTag($tag); | ||
484 | } | ||
485 | } | ||
486 | |||
487 | $em = $this->getDoctrine()->getManager(); | ||
488 | $em->persist($entry); | ||
489 | $em->flush(); | ||
490 | } | ||
491 | } | ||
492 | } | ||
493 | |||
494 | $json = $this->get('serializer')->serialize($results, 'json'); | ||
495 | |||
496 | return (new JsonResponse())->setJson($json); | ||
497 | } | ||
498 | |||
499 | /** | ||
500 | * Handles an entries list and add tags to them. | ||
501 | * | ||
502 | * @ApiDoc( | ||
503 | * parameters={ | ||
504 | * {"name"="list", "dataType"="string", "required"=true, "format"="A JSON array of urls [{'url': 'http://...','tags': 'tag1, tag2'}, {'url': 'http://...','tags': 'tag1, tag2'}]", "description"="Urls (as an array) to handle."} | ||
505 | * } | ||
506 | * ) | ||
507 | * | ||
508 | * @return JsonResponse | ||
509 | */ | ||
510 | public function postEntriesTagsListAction(Request $request) | ||
511 | { | ||
512 | $this->validateAuthentication(); | ||
513 | |||
514 | $list = json_decode($request->query->get('list', [])); | ||
515 | $results = []; | ||
516 | |||
517 | // handle multiple urls | ||
518 | if (!empty($list)) { | ||
519 | foreach ($list as $key => $element) { | ||
520 | $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId( | ||
521 | $element->url, | ||
522 | $this->getUser()->getId() | ||
523 | ); | ||
524 | |||
525 | $results[$key]['url'] = $element->url; | ||
526 | $results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false; | ||
527 | |||
528 | $tags = $element->tags; | ||
529 | |||
530 | if (false !== $entry && !(empty($tags))) { | ||
531 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); | ||
532 | |||
533 | $em = $this->getDoctrine()->getManager(); | ||
534 | $em->persist($entry); | ||
535 | $em->flush(); | ||
536 | } | ||
537 | } | ||
538 | } | ||
539 | |||
540 | $json = $this->get('serializer')->serialize($results, 'json'); | ||
541 | |||
542 | return (new JsonResponse())->setJson($json); | ||
543 | } | ||
441 | } | 544 | } |