2012-07-03 12:56:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace KekRozsak\FrontBundle\Entity;
|
|
|
|
|
2012-07-31 08:14:26 +00:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2012-07-03 12:56:28 +00:00
|
|
|
|
2012-07-09 11:37:01 +00:00
|
|
|
use KekRozsak\FrontBundle\Entity\ForumTopic;
|
|
|
|
|
2012-07-03 12:56:28 +00:00
|
|
|
/**
|
2012-07-13 10:07:21 +00:00
|
|
|
* @ORM\Entity
|
2012-07-31 08:14:26 +00:00
|
|
|
* @ORM\HasLifecycleCallbacks
|
2012-07-13 10:07:21 +00:00
|
|
|
* @ORM\Table(name="forum_posts")
|
2012-07-03 12:56:28 +00:00
|
|
|
*/
|
|
|
|
class ForumPost
|
|
|
|
{
|
2012-07-13 10:07:21 +00:00
|
|
|
/**
|
|
|
|
* @var integer $id
|
|
|
|
* @ORM\Id
|
|
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
|
|
* @ORM\Column(type="integer")
|
|
|
|
*/
|
2012-07-17 16:47:20 +00:00
|
|
|
protected $id;
|
2012-07-13 10:07:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get id
|
|
|
|
*
|
2012-07-15 12:56:31 +00:00
|
|
|
* @return integer
|
2012-07-13 10:07:21 +00:00
|
|
|
*/
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-15 12:56:31 +00:00
|
|
|
* @ORM\ManyToOne(targetEntity="\KekRozsak\SecurityBundle\Entity\User")
|
|
|
|
* @ORM\JoinColumn(name="created_by_id")
|
2012-07-13 10:07:21 +00:00
|
|
|
*/
|
2012-07-17 16:47:20 +00:00
|
|
|
protected $createdBy;
|
2012-07-13 10:07:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set createdBy
|
|
|
|
*
|
2012-07-15 12:56:31 +00:00
|
|
|
* @param \KekRozsak\SecurityBundle\Entity\User $createdBy
|
2012-07-13 10:07:21 +00:00
|
|
|
* @return ForumPost
|
|
|
|
*/
|
2012-07-15 12:56:31 +00:00
|
|
|
public function setCreatedBy(\KekRozsak\SecurityBundle\Entity\User $createdBy)
|
2012-07-13 10:07:21 +00:00
|
|
|
{
|
|
|
|
$this->createdBy = $createdBy;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get createdBy
|
|
|
|
*
|
2012-07-15 12:56:31 +00:00
|
|
|
* @return \KekRozsak\SecurityBundle\Entity\User
|
2012-07-13 10:07:21 +00:00
|
|
|
*/
|
|
|
|
public function getCreatedBy()
|
|
|
|
{
|
|
|
|
return $this->createdBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-15 12:56:31 +00:00
|
|
|
* @var DateTime $createdAt
|
|
|
|
* @ORM\Column(type="datetime", name="created_at")
|
2012-07-13 10:07:21 +00:00
|
|
|
*/
|
2012-07-17 16:47:20 +00:00
|
|
|
protected $createdAt;
|
2012-07-13 10:07:21 +00:00
|
|
|
|
|
|
|
/**
|
2012-07-15 12:56:31 +00:00
|
|
|
* Set createdAt
|
2012-07-13 10:07:21 +00:00
|
|
|
*
|
2012-07-15 12:56:31 +00:00
|
|
|
* @param DateTime $createdAt
|
2012-07-13 10:07:21 +00:00
|
|
|
* @return ForumPost
|
|
|
|
*/
|
2012-07-15 12:56:31 +00:00
|
|
|
public function setCreatedAt(\DateTime $createdAt)
|
2012-07-13 10:07:21 +00:00
|
|
|
{
|
2012-07-15 12:56:31 +00:00
|
|
|
$this->createdAt = $createdAt;
|
2012-07-13 10:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-15 12:56:31 +00:00
|
|
|
* Get createdAt
|
2012-07-13 10:07:21 +00:00
|
|
|
*
|
2012-07-15 12:56:31 +00:00
|
|
|
* @return DateTime
|
2012-07-13 10:07:21 +00:00
|
|
|
*/
|
2012-07-15 12:56:31 +00:00
|
|
|
public function getCreatedAt()
|
2012-07-13 10:07:21 +00:00
|
|
|
{
|
2012-07-15 12:56:31 +00:00
|
|
|
return $this->createdAt;
|
2012-07-13 10:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-15 12:56:31 +00:00
|
|
|
* @var string $text
|
|
|
|
* @ORM\Column(type="text", nullable=false)
|
2012-07-13 10:07:21 +00:00
|
|
|
*/
|
2012-07-17 16:47:20 +00:00
|
|
|
protected $text;
|
2012-07-13 10:07:21 +00:00
|
|
|
|
|
|
|
/**
|
2012-07-15 12:56:31 +00:00
|
|
|
* Set text
|
2012-07-13 10:07:21 +00:00
|
|
|
*
|
2012-07-15 12:56:31 +00:00
|
|
|
* @param string $text
|
2012-07-13 10:07:21 +00:00
|
|
|
* @return ForumPost
|
|
|
|
*/
|
2012-07-15 12:56:31 +00:00
|
|
|
public function setText($text)
|
2012-07-13 10:07:21 +00:00
|
|
|
{
|
2012-07-15 12:56:31 +00:00
|
|
|
$this->text = $text;
|
2012-07-13 10:07:21 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-15 12:56:31 +00:00
|
|
|
* Get text
|
2012-07-13 10:07:21 +00:00
|
|
|
*
|
2012-07-15 12:56:31 +00:00
|
|
|
* @return string
|
2012-07-13 10:07:21 +00:00
|
|
|
*/
|
2012-07-15 12:56:31 +00:00
|
|
|
public function getText()
|
2012-07-13 10:07:21 +00:00
|
|
|
{
|
2012-07-15 12:56:31 +00:00
|
|
|
return $this->text;
|
2012-07-13 10:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ForumTopic $topic
|
|
|
|
* @ORM\ManyToOne(targetEntity="ForumTopic", inversedBy="posts")
|
|
|
|
*/
|
2012-07-17 16:47:20 +00:00
|
|
|
protected $topic;
|
2012-07-13 10:07:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set topic
|
|
|
|
*
|
|
|
|
* @param ForumTopic $topic
|
|
|
|
* @return ForumPost
|
|
|
|
*/
|
|
|
|
public function setTopic(ForumTopic $topic)
|
|
|
|
{
|
|
|
|
$this->topic = $topic;
|
2012-07-31 08:14:26 +00:00
|
|
|
if (!$topic->getLastPost() || ($topic->getLastPost()->getCreatedAt() < $this->createdAt))
|
2012-07-15 13:30:08 +00:00
|
|
|
$topic->setLastPost($this);
|
2012-07-13 10:07:21 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get topic
|
|
|
|
*
|
2012-07-15 12:56:31 +00:00
|
|
|
* @return ForumTopic
|
2012-07-13 10:07:21 +00:00
|
|
|
*/
|
|
|
|
public function getTopic()
|
|
|
|
{
|
|
|
|
return $this->topic;
|
|
|
|
}
|
2012-07-31 08:14:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set createdAt before persisting
|
|
|
|
*
|
|
|
|
* @ORM\PrePersist
|
|
|
|
*/
|
|
|
|
public function setCreationTime()
|
|
|
|
{
|
|
|
|
if ($this->createdAt === null)
|
|
|
|
$this->createdAt = new \DateTime('now');
|
|
|
|
}
|
2012-07-13 10:07:21 +00:00
|
|
|
}
|
2012-07-15 12:56:31 +00:00
|
|
|
|