Symfony Serializer annotations removed. Lifecycle 'preUpdate' callbacks added in User and Post entities.

This commit is contained in:
Alexey Skobkin 2016-03-23 22:36:44 +03:00
parent f043649ad0
commit 1aacdead06
4 changed files with 48 additions and 44 deletions

View file

@ -4,7 +4,6 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* Comment * Comment
@ -19,8 +18,6 @@ class Comment
/** /**
* @var integer * @var integer
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
*/ */
@ -29,8 +26,6 @@ class Comment
/** /**
* @var string * @var string
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="text", type="text") * @ORM\Column(name="text", type="text")
*/ */
private $text; private $text;
@ -38,8 +33,6 @@ class Comment
/** /**
* @var \DateTime * @var \DateTime
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="created_at", type="datetime") * @ORM\Column(name="created_at", type="datetime")
*/ */
private $createdAt; private $createdAt;
@ -47,8 +40,6 @@ class Comment
/** /**
* @var boolean * @var boolean
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="is_rec", type="boolean") * @ORM\Column(name="is_rec", type="boolean")
*/ */
private $rec; private $rec;
@ -56,8 +47,6 @@ class Comment
/** /**
* @var bool * @var bool
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="is_deleted", type="boolean") * @ORM\Column(name="is_deleted", type="boolean")
*/ */
private $deleted = false; private $deleted = false;
@ -74,8 +63,6 @@ class Comment
/** /**
* @var User * @var User
* *
* @Serializer\Groups("post_show")
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author_id") * @ORM\JoinColumn(name="author_id")
*/ */
@ -84,8 +71,6 @@ class Comment
/** /**
* @var Comment|null * @var Comment|null
* *
* @Serializer\Groups("post_show")
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment")
* @ORM\JoinColumn(name="to_comment_id", nullable=true) * @ORM\JoinColumn(name="to_comment_id", nullable=true)
*/ */

View file

@ -5,7 +5,6 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* Post * Post
@ -15,6 +14,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
* @ORM\Index(name="idx_post_private", columns={"private"}), * @ORM\Index(name="idx_post_private", columns={"private"}),
* }) * })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository") * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository")
* @ORM\HasLifecycleCallbacks
*/ */
class Post class Post
{ {
@ -24,8 +24,6 @@ class Post
/** /**
* @var int * @var int
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="id", type="string", length=16) * @ORM\Column(name="id", type="string", length=16)
* @ORM\Id * @ORM\Id
*/ */
@ -34,8 +32,6 @@ class Post
/** /**
* @var string * @var string
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="text", type="text") * @ORM\Column(name="text", type="text")
*/ */
private $text; private $text;
@ -43,16 +39,19 @@ class Post
/** /**
* @var \DateTime * @var \DateTime
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="created_at", type="datetime") * @ORM\Column(name="created_at", type="datetime")
*/ */
private $createdAt; private $createdAt;
/** /**
* @var string * @var \DateTime
* *
* @Serializer\Groups({"posts_list", "post_show"}) * @ORM\Column(name="updated_at", type="datetime")
*/
private $updatedAt;
/**
* @var string
* *
* @ORM\Column(name="type", type="string", length=6) * @ORM\Column(name="type", type="string", length=6)
*/ */
@ -75,8 +74,6 @@ class Post
/** /**
* @var User * @var User
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author") * @ORM\JoinColumn(name="author")
*/ */
@ -85,8 +82,6 @@ class Post
/** /**
* @var Tag[]|ArrayCollection * @var Tag[]|ArrayCollection
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EXTRA_LAZY") * @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="posts.posts_tags", * @ORM\JoinTable(name="posts.posts_tags",
* joinColumns={@ORM\JoinColumn(name="post_id")}, * joinColumns={@ORM\JoinColumn(name="post_id")},
@ -98,8 +93,6 @@ class Post
/** /**
* @var Comment[]|ArrayCollection * @var Comment[]|ArrayCollection
* *
* @Serializer\Groups({"post_show"})
*
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post") * @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post")
*/ */
private $comments; private $comments;
@ -108,25 +101,23 @@ class Post
/** /**
* Post constructor. * Post constructor.
* @param string $id * @param string $id
* @param string $type
* @param bool $private
* @param string $text
* @param \DateTime $createdAt
* @param User|null $author
*/ */
public function __construct($id, $type, $private, $text, \DateTime $createdAt, User $author = null) public function __construct($id)
{ {
$this->id = $id; $this->id = $id;
$this->type = $type;
$this->private = $private;
$this->createdAt = $createdAt;
$this->text = $text;
$this->author = $author;
$this->tags = new ArrayCollection(); $this->tags = new ArrayCollection();
$this->comments = new ArrayCollection(); $this->comments = new ArrayCollection();
} }
/**
* @ORM\PreUpdate
*/
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
/** /**
* Get id * Get id
* *
@ -183,6 +174,14 @@ class Post
return $this->createdAt; return $this->createdAt;
} }
/**
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/** /**
* Set type * Set type
* *

View file

@ -3,7 +3,6 @@
namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* Tag * Tag
@ -27,8 +26,6 @@ class Tag
/** /**
* @var string * @var string
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="text", type="text", unique=true) * @ORM\Column(name="text", type="text", unique=true)
*/ */
private $text; private $text;

View file

@ -43,6 +43,13 @@ class User
*/ */
private $createdAt; private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime")
*/
private $updatedAt;
/** /**
* @var ArrayCollection * @var ArrayCollection
* *
@ -98,6 +105,14 @@ class User
} }
} }
/**
* @ORM\PreUpdate
*/
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
/** /**
* Get id * Get id
* *
@ -316,4 +331,12 @@ class User
$this->createdAt = $createdAt; $this->createdAt = $createdAt;
return $this; return $this;
} }
/**
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
} }