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;
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $id;
* @var string
*
* @ORM\Column(name="title", type="text", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $title;
*
* @Assert\NotBlank()
* @ORM\Column(name="url", type="text", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $url;
* @var bool
*
* @ORM\Column(name="is_archived", type="boolean")
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $isArchived = false;
* @var bool
*
* @ORM\Column(name="is_starred", type="boolean")
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $isStarred = false;
* @var string
*
* @ORM\Column(name="content", type="text", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $content;
* @var date
*
* @ORM\Column(name="created_at", type="datetime")
+ *
+ * @Groups({"export_all"})
*/
private $createdAt;
* @var date
*
* @ORM\Column(name="updated_at", type="datetime")
+ *
+ * @Groups({"export_all"})
*/
private $updatedAt;
* @var string
*
* @ORM\Column(name="comments", type="text", nullable=true)
+ *
+ * @Groups({"export_all"})
*/
private $comments;
* @var string
*
* @ORM\Column(name="mimetype", type="text", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $mimetype;
* @var string
*
* @ORM\Column(name="language", type="text", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $language;
* @var int
*
* @ORM\Column(name="reading_time", type="integer", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $readingTime;
* @var string
*
* @ORM\Column(name="domain_name", type="text", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $domainName;
* @var string
*
* @ORM\Column(name="preview_picture", type="text", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
*/
private $previewPicture;
* @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;
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
{
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')));
}
/**