1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| <?php
// src/MyProject/MyBundle/Entity/Comment.php
namespace MyApp\ForumBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\CommentBundle\Entity\Comment as BaseComment;
use FOS\CommentBundle\Model\SignedCommentInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use FOS\CommentBundle\Model\VotableCommentInterface;
/**
* @ORM\Entity
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
* @ORM\Entity(repositoryClass="MyApp\ForumBundle\Repository\CommentRepository")
*/
class Comment extends BaseComment implements SignedCommentInterface, VotableCommentInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Thread of this comment
*
* @var Thread
* @ORM\ManyToOne(targetEntity="MyApp\ForumBundle\Entity\Thread")
*/
protected $thread;
/**
* Author of the comment
*
* @ORM\ManyToOne(targetEntity="MyApp\UserBundle\Entity\User")
* @var User
*/
protected $author;
public function setAuthor(UserInterface $author)
{
$this->author = $author;
}
public function getAuthor()
{
return $this->author;
}
public function getAuthorName()
{
if (null === $this->getAuthor()) {
return 'Anonymous';
}
return $this->getAuthor()->getUsername();
}
public function getAuthorPicture()
{
if (null === $this->getAuthor()) {
return 'Anonymous';
}
return $this->getAuthor()->getImage();
}
/**
* @ORM\Column(type="integer")
* @var int
*/
protected $score = 0;
/**
* Sets the score of the comment.
*
* @param integer $score
*/
public function setScore($score)
{
$this->score = $score;
}
/**
* Returns the current score of the comment.
*
* @return integer
*/
public function getScore()
{
return $this->score;
}
/**
* Increments the comment score by the provided
* value.
*
* @param integer value
*
* @return integer The new comment score
*/
public function incrementScore($by = 1)
{
$this->score += $by;
}
/**
* @ORM\ManyToOne(targetEntity="MyApp\ForumBundle\Entity\Sujet")
* @ORM\JoinColumn(name="sujet_id", referencedColumnName="id",nullable=true)
*/
protected $sujet;
public function getSujet() {
return $this->sujet;
}
public function setSujet($sujet) {
$this->sujet = $sujet;
return $this;
}
} |
Partager