Bug fixes

Signed-off-by: Polonkai Gergely <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely
2012-07-31 10:14:26 +02:00
parent f21d48c6a8
commit b82eb93bf7
8 changed files with 41 additions and 34 deletions

View File

@@ -2,12 +2,13 @@
namespace KekRozsak\FrontBundle\Entity;
use Doctrine\Orm\Mapping as ORM;
use Doctrine\ORM\Mapping as ORM;
use KekRozsak\FrontBundle\Entity\ForumTopic;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="forum_posts")
*/
class ForumPost
@@ -128,7 +129,7 @@ class ForumPost
public function setTopic(ForumTopic $topic)
{
$this->topic = $topic;
if ($topic->getLastPost()->getCreatedAt() < $this->createdAt)
if (!$topic->getLastPost() || ($topic->getLastPost()->getCreatedAt() < $this->createdAt))
$topic->setLastPost($this);
return $this;
}
@@ -142,5 +143,16 @@ class ForumPost
{
return $this->topic;
}
/**
* Set createdAt before persisting
*
* @ORM\PrePersist
*/
public function setCreationTime()
{
if ($this->createdAt === null)
$this->createdAt = new \DateTime('now');
}
}