date-poll-api/src/Entity/Comment.php

119 lines
2.1 KiB
PHP
Raw Normal View History

2019-11-06 14:54:04 +01:00
<?php
namespace App\Entity;
use App\Traits\TimeStampableTrait;
2021-04-27 10:22:16 +02:00
use DateTime;
2019-11-12 11:26:19 +01:00
use DateTimeInterface;
2019-11-06 14:54:04 +01:00
use Doctrine\ORM\Mapping as ORM;
2020-01-20 17:27:59 +01:00
use JMS\Serializer\Annotation as Serializer;
2019-11-06 14:54:04 +01:00
/**
* @ORM\Entity(repositoryClass="App\Repository\CommentRepository")
2020-01-20 17:27:59 +01:00
* @Serializer\ExclusionPolicy("all")
2019-11-06 14:54:04 +01:00
*/
class Comment {
use TimeStampableTrait;
2019-11-06 14:54:04 +01:00
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Owner", inversedBy="comments")
2020-01-20 17:27:59 +01:00
* @Serializer\Type("App\Entity\Owner")
* @Serializer\Expose()
2019-11-06 14:54:04 +01:00
*/
private $owner;
/**
* @ORM\Column(type="string")
* @Serializer\Type("string")
* @Serializer\Expose()
*/
private $pseudo;
2019-11-06 14:54:04 +01:00
/**
* @ORM\Column(type="text")
2020-01-20 17:27:59 +01:00
* @Serializer\Type("string")
* @Serializer\Expose()
2019-11-06 14:54:04 +01:00
*/
private $text;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="comments")
*/
private $poll;
2019-11-27 16:14:49 +01:00
function __construct() {
2021-04-27 10:22:16 +02:00
$this->setCreatedAt( new DateTime() );
}
public function setCreatedAt( DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
return $this;
}
2021-04-27 12:51:21 +02:00
public function getCreatedAt(): ?DateTimeInterface {
return $this->createdAt;
}
2021-04-27 10:22:16 +02:00
function display() {
return [
'id' => $this->getId(),
'text' => $this->getText(),
'pseudo' => $this->getOwner()->getPseudo(),
'created_at' => $this->getCreatedAtAsString(),
2021-04-27 10:22:16 +02:00
];
}
2019-11-27 16:14:49 +01:00
2019-11-06 14:54:04 +01:00
public function getId(): ?int {
2021-04-27 10:22:16 +02:00
return $this->id;
}
public function getText(): ?string {
return $this->text;
}
public function setText( string $text ): self {
$this->text = $text;
return $this;
}
2019-11-06 14:54:04 +01:00
public function getOwner(): ?Owner {
2021-04-27 10:22:16 +02:00
return $this->owner;
}
2019-11-06 14:54:04 +01:00
public function setOwner( ?Owner $owner ): self {
2021-04-27 10:22:16 +02:00
$this->owner = $owner;
2019-11-06 14:54:04 +01:00
2021-04-27 10:22:16 +02:00
return $this;
}
2019-11-06 14:54:04 +01:00
public function getPoll(): ?Poll {
2021-04-27 10:22:16 +02:00
return $this->poll;
}
2019-11-06 14:54:04 +01:00
public function setPoll( ?Poll $poll ): self {
2021-04-27 10:22:16 +02:00
$this->poll = $poll;
return $this;
}
public function getPseudo(): ?string {
return $this->pseudo;
}
public function setPseudo( string $pseudo ): self {
$this->pseudo = $pseudo;
return $this;
}
2019-11-06 14:54:04 +01:00
}