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.php46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 768c4fdc..c276d5eb 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -344,6 +344,7 @@ class EntryRestController extends WallabagRestController
344 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"}, 344 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"},
345 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"}, 345 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"},
346 * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"}, 346 * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"},
347 * {"name"="progress", "dataType"="integer", "required"=false, "format"="A percentage between 0 and 100", "description"="changed progress."},
347 * } 348 * }
348 * ) 349 * )
349 * 350 *
@@ -641,6 +642,7 @@ class EntryRestController extends WallabagRestController
641 $picture = $request->request->get('preview_picture'); 642 $picture = $request->request->get('preview_picture');
642 $publishedAt = $request->request->get('published_at'); 643 $publishedAt = $request->request->get('published_at');
643 $authors = $request->request->get('authors', ''); 644 $authors = $request->request->get('authors', '');
645 $progress = $request->request->get('progress');
644 646
645 try { 647 try {
646 $this->get('wallabag_core.content_proxy')->updateEntry( 648 $this->get('wallabag_core.content_proxy')->updateEntry(
@@ -667,26 +669,33 @@ class EntryRestController extends WallabagRestController
667 ]); 669 ]);
668 } 670 }
669 671
670 if (!is_null($isArchived)) { 672 if (null !== $isArchived) {
671 $entry->setArchived((bool) $isArchived); 673 $entry->setArchived((bool)$isArchived);
672 } 674 }
673 675
674 if (!is_null($isStarred)) { 676 if (null !== $isStarred) {
675 $entry->setStarred((bool) $isStarred); 677 $entry->setStarred((bool)$isStarred);
676 } 678 }
677 679
678 if (!empty($tags)) { 680 if (!empty($tags)) {
679 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); 681 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
680 } 682 }
681 683
682 if (!is_null($isPublic)) { 684 if (null !== $isPublic) {
683 if (true === (bool) $isPublic && null === $entry->getUid()) { 685 if (true === (bool)$isPublic && null === $entry->getUid()) {
684 $entry->generateUid(); 686 $entry->generateUid();
685 } elseif (false === (bool) $isPublic) { 687 } elseif (false === (bool)$isPublic) {
686 $entry->cleanUid(); 688 $entry->cleanUid();
687 } 689 }
688 } 690 }
689 691
692 if (null !== $progress) {
693 $progress = (int) $progress;
694 if ($progress >= 0 && $progress <= 100) {
695 $entry->setProgress($progress);
696 }
697 }
698
690 $em = $this->getDoctrine()->getManager(); 699 $em = $this->getDoctrine()->getManager();
691 $em->persist($entry); 700 $em->persist($entry);
692 $em->flush(); 701 $em->flush();
@@ -694,4 +703,27 @@ class EntryRestController extends WallabagRestController
694 // entry saved, dispatch event about it! 703 // entry saved, dispatch event about it!
695 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); 704 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
696 } 705 }
706
707 /**
708 * Get the progress of an entry.
709 *
710 * @ApiDoc(
711 * requirements={
712 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
713 * }
714 * )
715 *
716 * @param Entry $entry
717 *
718 * @return JsonResponse
719 */
720 public function getEntriesProgressAction(Entry $entry)
721 {
722 $this->validateAuthentication();
723 $this->validateUserAccess($entry->getUser()->getId());
724
725 $json = $this->get('serializer')->serialize($entry->getProgress(), 'json');
726
727 return (new JsonResponse())->setJson($json);
728 }
697} 729}