mirror of
https://github.com/symfony/demo.git
synced 2026-03-24 00:02:32 +01:00
148 lines
2.9 KiB
PHP
148 lines
2.9 KiB
PHP
<?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\ORM\Mapping as ORM;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
/**
|
|
* @ORM\Entity
|
|
* @ORM\Table(name="symfony_demo_comment")
|
|
*
|
|
* Defines the properties of the Comment entity to represent the blog comments.
|
|
* 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>
|
|
*/
|
|
class Comment
|
|
{
|
|
/**
|
|
* @var int
|
|
*
|
|
* @ORM\Id
|
|
* @ORM\GeneratedValue
|
|
* @ORM\Column(type="integer")
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @var Post
|
|
*
|
|
* @ORM\ManyToOne(targetEntity="Post", inversedBy="comments")
|
|
* @ORM\JoinColumn(nullable=false)
|
|
*/
|
|
private $post;
|
|
|
|
/**
|
|
* @var string
|
|
*
|
|
* @ORM\Column(type="text")
|
|
* @Assert\NotBlank(message="comment.blank")
|
|
* @Assert\Length(
|
|
* min=5,
|
|
* minMessage="comment.too_short",
|
|
* max=10000,
|
|
* maxMessage="comment.too_long"
|
|
* )
|
|
*/
|
|
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;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->publishedAt = new \DateTime();
|
|
}
|
|
|
|
/**
|
|
* @Assert\IsTrue(message="comment.is_spam")
|
|
*/
|
|
public function isLegitComment()
|
|
{
|
|
$containsInvalidCharacters = false !== strpos($this->content, '@');
|
|
|
|
return !$containsInvalidCharacters;
|
|
}
|
|
|
|
public function getId()
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
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 getPost()
|
|
{
|
|
return $this->post;
|
|
}
|
|
|
|
public function setPost(Post $post)
|
|
{
|
|
$this->post = $post;
|
|
}
|
|
}
|