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 Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* Comment
@ -19,8 +18,6 @@ class Comment
/**
* @var integer
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
*/
@ -29,8 +26,6 @@ class Comment
/**
* @var string
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="text", type="text")
*/
private $text;
@ -38,8 +33,6 @@ class Comment
/**
* @var \DateTime
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
@ -47,8 +40,6 @@ class Comment
/**
* @var boolean
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="is_rec", type="boolean")
*/
private $rec;
@ -56,8 +47,6 @@ class Comment
/**
* @var bool
*
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="is_deleted", type="boolean")
*/
private $deleted = false;
@ -74,8 +63,6 @@ class Comment
/**
* @var User
*
* @Serializer\Groups("post_show")
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author_id")
*/
@ -84,8 +71,6 @@ class Comment
/**
* @var Comment|null
*
* @Serializer\Groups("post_show")
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment")
* @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\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* Post
@ -15,6 +14,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
* @ORM\Index(name="idx_post_private", columns={"private"}),
* })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository")
* @ORM\HasLifecycleCallbacks
*/
class Post
{
@ -24,8 +24,6 @@ class Post
/**
* @var int
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="id", type="string", length=16)
* @ORM\Id
*/
@ -34,8 +32,6 @@ class Post
/**
* @var string
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="text", type="text")
*/
private $text;
@ -43,16 +39,19 @@ class Post
/**
* @var \DateTime
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="created_at", type="datetime")
*/
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)
*/
@ -75,8 +74,6 @@ class Post
/**
* @var User
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author")
*/
@ -85,8 +82,6 @@ class Post
/**
* @var Tag[]|ArrayCollection
*
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="posts.posts_tags",
* joinColumns={@ORM\JoinColumn(name="post_id")},
@ -98,8 +93,6 @@ class Post
/**
* @var Comment[]|ArrayCollection
*
* @Serializer\Groups({"post_show"})
*
* @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post")
*/
private $comments;
@ -108,25 +101,23 @@ class Post
/**
* Post constructor.
* @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->type = $type;
$this->private = $private;
$this->createdAt = $createdAt;
$this->text = $text;
$this->author = $author;
$this->tags = new ArrayCollection();
$this->comments = new ArrayCollection();
}
/**
* @ORM\PreUpdate
*/
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
/**
* Get id
*
@ -183,6 +174,14 @@ class Post
return $this->createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set type
*

View file

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

View file

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