]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
WIP
authorThomas Citharel <tcit@tcit.fr>
Thu, 24 Nov 2016 10:44:21 +0000 (11:44 +0100)
committerThomas Citharel <tcit@tcit.fr>
Fri, 23 Jun 2017 07:33:54 +0000 (09:33 +0200)
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
src/Wallabag/ApiBundle/Controller/EntryRestController.php
src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Entity/Entry.php

index 768c4fdc3423c7db828a9bca9d854bc2f884e69a..c276d5eb7957417519f6606d2d1b8e4c971d3043 100644 (file)
@@ -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);
+    }
 }
index fafa49f1b0bb69a156db8318a6ab3e9a9c2bba02..ba3db806384e967bb1003ac6dc905e90c12d0e35 100644 (file)
@@ -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;
+    }
 }
index a0503c3918170dfbb9fc8bb29a0e8a4f22f72f4c..639af6aa96f5d3ad458dbd1c146e1f08e0a180cd 100644 (file)
@@ -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;
+    }
 }