From 46a54f5debe317ccb3a473ec4b54d3755fe6606c Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 24 Nov 2016 11:44:21 +0100 Subject: WIP Signed-off-by: Thomas Citharel --- .../ApiBundle/Controller/EntryRestController.php | 46 +++++++++++++++++---- .../CoreBundle/Controller/EntryController.php | 48 ++++++++++++++++++++++ src/Wallabag/CoreBundle/Entity/Entry.php | 33 +++++++++++++++ 3 files changed, 120 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 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"}, * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"}, * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"}, + * {"name"="progress", "dataType"="integer", "required"=false, "format"="A percentage between 0 and 100", "description"="changed progress."}, * } * ) * @@ -641,6 +642,7 @@ class EntryRestController extends WallabagRestController $picture = $request->request->get('preview_picture'); $publishedAt = $request->request->get('published_at'); $authors = $request->request->get('authors', ''); + $progress = $request->request->get('progress'); try { $this->get('wallabag_core.content_proxy')->updateEntry( @@ -667,26 +669,33 @@ class EntryRestController extends WallabagRestController ]); } - if (!is_null($isArchived)) { - $entry->setArchived((bool) $isArchived); + if (null !== $isArchived) { + $entry->setArchived((bool)$isArchived); } - if (!is_null($isStarred)) { - $entry->setStarred((bool) $isStarred); + if (null !== $isStarred) { + $entry->setStarred((bool)$isStarred); } if (!empty($tags)) { $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); } - if (!is_null($isPublic)) { - if (true === (bool) $isPublic && null === $entry->getUid()) { + if (null !== $isPublic) { + if (true === (bool)$isPublic && null === $entry->getUid()) { $entry->generateUid(); - } elseif (false === (bool) $isPublic) { + } elseif (false === (bool)$isPublic) { $entry->cleanUid(); } } + if (null !== $progress) { + $progress = (int) $progress; + if ($progress >= 0 && $progress <= 100) { + $entry->setProgress($progress); + } + } + $em = $this->getDoctrine()->getManager(); $em->persist($entry); $em->flush(); @@ -694,4 +703,27 @@ class EntryRestController extends WallabagRestController // entry saved, dispatch event about it! $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); } + + /** + * Get the progress of an entry. + * + * @ApiDoc( + * requirements={ + * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} + * } + * ) + * + * @param Entry $entry + * + * @return JsonResponse + */ + public function getEntriesProgressAction(Entry $entry) + { + $this->validateAuthentication(); + $this->validateUserAccess($entry->getUser()->getId()); + + $json = $this->get('serializer')->serialize($entry->getProgress(), 'json'); + + return (new JsonResponse())->setJson($json); + } } diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index fafa49f1..ba3db806 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -6,7 +6,9 @@ use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Exception\OutOfRangeCurrentPageException; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Form\Type\EntryFilterType; @@ -604,4 +606,50 @@ class EntryController extends Controller { return $this->showEntries('untagged', $request, $page); } + + /** + * Get the progress of an entry. + * + * @param Entry $entry + * + * @Route("/progress/{entry}", name="get_progress") + * + * @return JsonResponse + */ + public function getEntriesProgressAction(Entry $entry) + { + $this->checkUserAction($entry); + + $json = $this->get('serializer')->serialize($entry->getProgress(), 'json'); + + return (new JsonResponse())->setJson($json); + } + + /** + * Set the progress of an entry. + * + * @param Entry $entry + * @param int $progress + * + * @Route("/set-progress/{entry}", name="set_progress") + * + * @return JsonResponse + */ + public function setEntriesProgressAction(Entry $entry, $progress) + { + $this->checkUserAction($entry); + $response = new JsonResponse(); + + if (is_null($progress)) { + $response->setStatusCode(Response::HTTP_BAD_REQUEST); + } else { + $progress = (int) $progress; + if ($progress >= 0 && $progress <= 100) { + $entry->setProgress($progress); + $response->setStatusCode(Response::HTTP_OK); + } + } + + return $response; + } } diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index a0503c39..639af6aa 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -210,6 +210,15 @@ class Entry */ private $headers; + /** + * @var int + * + * @ORM\Column(name="progress", type="integer", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) + */ + private $progress = 0; + /** * @Exclude * @@ -759,6 +768,20 @@ class Entry return $this; } + /** + * Set progress. + * + * @param int $progress + * + * @return Entry + */ + public function setProgress($progress) + { + $this->progress = $progress; + + return $this; + } + /** * @return array */ @@ -778,4 +801,14 @@ class Entry return $this; } + + /** + * Get progress. + * + * @return int + */ + public function getProgress() + { + return $this->progress; + } } -- cgit v1.2.3