Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace AppBundle\Entity;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Validator\Constraints as Assert;
- /**
- * @ORM\Entity(repositoryClass="AppBundle\Repository\PostRepository")
- * @ORM\Table(name="symfony_demo_post")
- *
- * Defines the properties of the Post entity to represent the blog posts.
- *
- * See https://symfony.com/doc/current/book/doctrine.html#creating-an-entity-class
- *
- * Tip: if you have an existing database, you can generate these entity class automatically.
- * See https://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
- *
- * @author Ryan Weaver <weaverryan@gmail.com>
- * @author Javier Eguiluz <javier.eguiluz@gmail.com>
- * @author Yonel Ceruto <yonelceruto@gmail.com>
- */
- class Post
- {
- /**
- * Use constants to define configuration options that rarely change instead
- * of specifying them in app/config/config.yml.
- *
- * See https://symfony.com/doc/current/best_practices/configuration.html#constants-vs-configuration-options
- */
- const NUM_ITEMS = 10;
- /**
- * @var int
- *
- * @ORM\Id
- * @ORM\GeneratedValue
- * @ORM\Column(type="integer")
- */
- private $id;
- /**
- * @var string
- *
- * @ORM\Column(type="string")
- * @Assert\NotBlank
- */
- private $title;
- /**
- * @var string
- *
- * @ORM\Column(type="string")
- */
- private $slug;
- /**
- * @var string
- *
- * @ORM\Column(type="string")
- * @Assert\NotBlank(message="post.blank_summary")
- */
- private $summary;
- /**
- * @var string
- *
- * @ORM\Column(type="text")
- * @Assert\NotBlank(message="post.blank_content")
- * @Assert\Length(min=10, minMessage="post.too_short_content")
- */
- private $content;
- /**
- * @var \DateTime
- *
- * @ORM\Column(type="datetime")
- * @Assert\DateTime
- */
- private $publishedAt;
- /**
- * @var User
- *
- * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
- * @ORM\JoinColumn(nullable=false)
- */
- private $author;
- /**
- * @var Comment[]|ArrayCollection
- *
- * @ORM\OneToMany(
- * targetEntity="Comment",
- * mappedBy="post",
- * orphanRemoval=true
- * )
- * @ORM\OrderBy({"publishedAt": "DESC"})
- */
- private $comments;
- /**
- * @var Tag[]|ArrayCollection
- *
- * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Tag", cascade={"persist"})
- * @ORM\JoinTable(name="symfony_demo_post_tag")
- * @ORM\OrderBy({"name": "ASC"})
- * @Assert\Count(max="4", maxMessage="post.too_many_tags")
- */
- private $tags;
- /**
- * @ORM\ManyToOne(targetEntity="Category", inversedBy="posts")
- * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
- */
- private $category;
- public function __construct()
- {
- $this->publishedAt = new \DateTime();
- $this->comments = new ArrayCollection();
- $this->tags = new ArrayCollection();
- }
- public function getId()
- {
- return $this->id;
- }
- public function getTitle()
- {
- return $this->title;
- }
- /**
- * @param string $title
- */
- public function setTitle($title)
- {
- $this->title = $title;
- }
- public function getSlug()
- {
- return $this->slug;
- }
- /**
- * @param string $slug
- */
- public function setSlug($slug)
- {
- $this->slug = $slug;
- }
- public function getContent()
- {
- return $this->content;
- }
- /**
- * @param string $content
- */
- public function setContent($content)
- {
- $this->content = $content;
- }
- public function getPublishedAt()
- {
- return $this->publishedAt;
- }
- public function setPublishedAt(\DateTime $publishedAt)
- {
- $this->publishedAt = $publishedAt;
- }
- /**
- * @return User
- */
- public function getAuthor()
- {
- return $this->author;
- }
- /**
- * @param User $author
- */
- public function setAuthor(User $author)
- {
- $this->author = $author;
- }
- public function getComments()
- {
- return $this->comments;
- }
- public function addComment(Comment $comment)
- {
- $comment->setPost($this);
- if (!$this->comments->contains($comment)) {
- $this->comments->add($comment);
- }
- }
- public function removeComment(Comment $comment)
- {
- $comment->setPost(null);
- $this->comments->removeElement($comment);
- }
- public function getSummary()
- {
- return $this->summary;
- }
- /**
- * @param string $summary
- */
- public function setSummary($summary)
- {
- $this->summary = $summary;
- }
- public function addTag(Tag $tag)
- {
- if (!$this->tags->contains($tag)) {
- $this->tags->add($tag);
- }
- }
- public function removeTag(Tag $tag)
- {
- $this->tags->removeElement($tag);
- }
- public function getTags()
- {
- return $this->tags;
- }
- /**
- * @return Category
- */
- public function getCategory()
- {
- return $this->category;
- }
- /**
- * @param Category $category
- */
- public function setCategory(Category $category)
- {
- $this->category = $category;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement