]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
use the groups annotation instead of setIgnoredAttributes
authorThomas Citharel <tcit@tcit.fr>
Mon, 19 Oct 2015 18:31:30 +0000 (20:31 +0200)
committerNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>
Mon, 9 Nov 2015 15:32:48 +0000 (16:32 +0100)
src/Wallabag/CoreBundle/Entity/Entry.php
src/Wallabag/CoreBundle/Helper/EntriesExport.php

index 9e5446a64835db4e3f8fb920636cd0405e697d62..a2bb507eacf4f500233a45f092fd6e1a2b759e19 100644 (file)
@@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
 use Hateoas\Configuration\Annotation as Hateoas;
+use Symfony\Component\Serializer\Annotation\Groups;
 use JMS\Serializer\Annotation\XmlRoot;
 use Wallabag\UserBundle\Entity\User;
 
@@ -27,6 +28,8 @@ class Entry
      * @ORM\Column(name="id", type="integer")
      * @ORM\Id
      * @ORM\GeneratedValue(strategy="AUTO")
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $id;
 
@@ -34,6 +37,8 @@ class Entry
      * @var string
      *
      * @ORM\Column(name="title", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $title;
 
@@ -42,6 +47,8 @@ class Entry
      *
      * @Assert\NotBlank()
      * @ORM\Column(name="url", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $url;
 
@@ -49,6 +56,8 @@ class Entry
      * @var bool
      *
      * @ORM\Column(name="is_archived", type="boolean")
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $isArchived = false;
 
@@ -56,6 +65,8 @@ class Entry
      * @var bool
      *
      * @ORM\Column(name="is_starred", type="boolean")
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $isStarred = false;
 
@@ -63,6 +74,8 @@ class Entry
      * @var string
      *
      * @ORM\Column(name="content", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $content;
 
@@ -70,6 +83,8 @@ class Entry
      * @var date
      *
      * @ORM\Column(name="created_at", type="datetime")
+     *
+     * @Groups({"export_all"})
      */
     private $createdAt;
 
@@ -77,6 +92,8 @@ class Entry
      * @var date
      *
      * @ORM\Column(name="updated_at", type="datetime")
+     *
+     * @Groups({"export_all"})
      */
     private $updatedAt;
 
@@ -84,6 +101,8 @@ class Entry
      * @var string
      *
      * @ORM\Column(name="comments", type="text", nullable=true)
+     *
+     * @Groups({"export_all"})
      */
     private $comments;
 
@@ -91,6 +110,8 @@ class Entry
      * @var string
      *
      * @ORM\Column(name="mimetype", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $mimetype;
 
@@ -98,6 +119,8 @@ class Entry
      * @var string
      *
      * @ORM\Column(name="language", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $language;
 
@@ -105,6 +128,8 @@ class Entry
      * @var int
      *
      * @ORM\Column(name="reading_time", type="integer", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $readingTime;
 
@@ -112,6 +137,8 @@ class Entry
      * @var string
      *
      * @ORM\Column(name="domain_name", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $domainName;
 
@@ -119,6 +146,8 @@ class Entry
      * @var string
      *
      * @ORM\Column(name="preview_picture", type="text", nullable=true)
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $previewPicture;
 
@@ -126,17 +155,23 @@ class Entry
      * @var bool
      *
      * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
+     *
+     * @Groups({"export_all"})
      */
     private $isPublic;
 
     /**
      * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries")
+     *
+     * @Groups({"export_all"})
      */
     private $user;
 
     /**
      * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
      * @ORM\JoinTable
+     *
+     * @Groups({"entries_for_user", "export_all"})
      */
     private $tags;
 
index e073606cf9dfe155df5f9d176f4f3f243efc6896..f073ed7f46447b655d8459fd0fe1c81e6d1198f9 100644 (file)
@@ -8,7 +8,10 @@ use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Serializer\Serializer;
 use Symfony\Component\Serializer\Encoder\XmlEncoder;
 use Symfony\Component\Serializer\Encoder\JsonEncoder;
-use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
+use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
+use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
+use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
+use Doctrine\Common\Annotations\AnnotationReader;
 
 class EntriesExport
 {
@@ -363,11 +366,11 @@ class EntriesExport
     private function prepareSerializingContent($format)
     {
         $encoders = array(new XmlEncoder(), new JsonEncoder());
-        $normalizers = array(new ObjectNormalizer());
-        $normalizers[0]->setIgnoredAttributes(array('user', 'createdAt', 'updatedAt'));
+        $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
+        $normalizers = array(new PropertyNormalizer($classMetadataFactory));
         $serializer = new Serializer($normalizers, $encoders);
 
-        return $serializer->serialize($this->entries, $format);
+        return $serializer->serialize($this->entries, $format, array('groups' => array('entries_for_user')));
     }
 
     /**