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

246 lines
5.4 KiB
PHP
Raw Normal View History

2019-10-25 14:59:20 +02:00
<?php
namespace App\Entity;
use App\Traits\TimeStampableTrait;
2021-04-27 10:22:16 +02:00
use DateTime;
use DateTimeInterface;
2019-10-25 14:59:20 +02:00
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
2019-11-06 12:27:46 +01:00
use JMS\Serializer\Annotation as Serializer;
2019-10-25 14:59:20 +02:00
/**
* @ORM\Entity(repositoryClass="App\Repository\OwnerRepository")
*/
2019-11-06 12:27:46 +01:00
class Owner {
use TimeStampableTrait;
2019-11-12 11:26:19 +01:00
/**
* @ORM\Column(type="string", length=255)
* @Serializer\Type("string")
* @Serializer\Expose()
*/
2021-04-28 18:49:40 +02:00
public $pseudo = 'anonyme';
2019-11-06 12:27:46 +01:00
/**
* @ORM\Column(type="string", length=255)
* @Serializer\Type("string")
* @Serializer\Expose()
2019-11-06 12:27:46 +01:00
*/
2021-04-28 18:49:40 +02:00
public $email = "anonyme@anonyme.com";
2021-04-27 10:22:16 +02:00
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
2019-11-06 12:27:46 +01:00
/**
2019-11-20 11:24:54 +01:00
* @ORM\OneToMany(targetEntity="App\Entity\Poll", mappedBy="owner",cascade={"persist","remove"},orphanRemoval=true)
2019-11-06 12:27:46 +01:00
* @Serializer\Type("App\Entity\Poll")
*/
private $polls;
2019-11-06 14:54:04 +01:00
/**
2019-11-20 11:24:54 +01:00
* @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="owner", cascade={"persist","remove"},orphanRemoval=true)
2019-11-06 14:54:04 +01:00
*/
private $comments;
2019-11-12 11:26:19 +01:00
/**
2019-11-20 11:24:54 +01:00
* @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="owner", cascade={"persist","remove"},orphanRemoval=true)
2019-11-12 11:26:19 +01:00
*/
private $stackOfVotes;
/**
* @ORM\Column(type="string", length=255)
*/
private $modifierToken;
/**
2020-01-15 16:46:56 +01:00
* @ORM\Column(type="datetime" , options={"default"="CURRENT_TIMESTAMP"},nullable=true)
*/
private $requestedPollsDate;
2019-11-11 10:44:19 +01:00
2019-11-06 12:27:46 +01:00
public function __construct() {
2020-01-15 16:46:56 +01:00
$this->polls = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->stackOfVotes = new ArrayCollection();
2021-04-27 10:22:16 +02:00
$this->setCreatedAt( new DateTime() );
2020-01-15 16:46:56 +01:00
$this->setModifierToken( uniqid() );
2021-04-27 12:51:21 +02:00
$this->setCreatedAt( new DateTime() );
2020-01-15 16:46:56 +01:00
}
2019-11-06 12:27:46 +01:00
public function setCreatedAt( DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
2019-11-27 16:39:52 +01:00
return $this;
2020-01-15 16:46:56 +01:00
}
2019-11-06 12:27:46 +01:00
2021-04-27 12:51:21 +02:00
public function getCreatedAt(): ?DateTimeInterface {
return $this->createdAt;
}
public function display() {
return [
'pseudo' => $this->getPseudo(),
];
2020-01-15 16:46:56 +01:00
}
2019-11-06 12:27:46 +01:00
public function getPseudo(): ?string {
2020-01-15 16:46:56 +01:00
return $this->pseudo;
}
2019-11-06 12:27:46 +01:00
public function setPseudo( string $pseudo ): self {
2020-01-15 16:46:56 +01:00
$this->pseudo = $pseudo;
return $this;
}
2019-11-06 12:27:46 +01:00
public function displayForAdmin() {
return [
'pseudo' => $this->getPseudo(),
'email' => $this->getEmail(),
'modifier_token' => $this->getModifierToken(),
'created_at' => $this->getCreatedAtAsString(),
];
}
public function getModifierToken(): ?string {
return $this->modifierToken;
}
public function setModifierToken( string $modifierToken ): self {
$this->modifierToken = $modifierToken;
return $this;
}
public function getId(): ?int {
return $this->id;
}
public function getEmail(): ?string {
return $this->email;
}
public function setEmail( string $email ): self {
$this->email = $email;
return $this;
}
2019-11-06 12:27:46 +01:00
/**
* @return Collection|Poll[]
*/
public function getPolls(): Collection {
2020-01-15 16:46:56 +01:00
return $this->polls;
}
2019-11-06 12:27:46 +01:00
public function addPoll( Poll $poll ): self {
2020-01-15 16:46:56 +01:00
if ( ! $this->polls->contains( $poll ) ) {
$this->polls[] = $poll;
$poll->setOwner( $this );
}
return $this;
}
2019-11-06 12:27:46 +01:00
public function removePoll( Poll $poll ): self {
2020-01-15 16:46:56 +01:00
if ( $this->polls->contains( $poll ) ) {
$this->polls->removeElement( $poll );
// set the owning side to null (unless already changed)
if ( $poll->getOwner() === $this ) {
$poll->setOwner( null );
}
}
return $this;
}
2019-11-06 14:54:04 +01:00
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection {
2020-01-15 16:46:56 +01:00
return $this->comments;
}
2019-11-06 14:54:04 +01:00
public function addText( Comment $text ): self {
2020-01-15 16:46:56 +01:00
if ( ! $this->comments->contains( $text ) ) {
$this->comments[] = $text;
$text->setOwner( $this );
}
return $this;
}
2019-11-06 14:54:04 +01:00
public function removeText( Comment $text ): self {
2020-01-15 16:46:56 +01:00
if ( $this->comments->contains( $text ) ) {
$this->comments->removeElement( $text );
// set the owning side to null (unless already changed)
if ( $text->getOwner() === $this ) {
$text->setOwner( null );
}
}
return $this;
}
2019-11-12 11:26:19 +01:00
/**
* @return Collection|StackOfVotes[]
*/
public function getStackOfVotes(): Collection {
2020-01-15 16:46:56 +01:00
return $this->stackOfVotes;
}
2019-11-12 11:26:19 +01:00
public function addStackOfVote( StackOfVotes $stackOfVote ): self {
2020-01-15 16:46:56 +01:00
if ( ! $this->stackOfVotes->contains( $stackOfVote ) ) {
$this->stackOfVotes[] = $stackOfVote;
$stackOfVote->setOwner( $this );
}
return $this;
}
2019-11-12 11:26:19 +01:00
public function removeStackOfVote( StackOfVotes $stackOfVote ): self {
2020-01-15 16:46:56 +01:00
if ( $this->stackOfVotes->contains( $stackOfVote ) ) {
$this->stackOfVotes->removeElement( $stackOfVote );
// set the owning side to null (unless already changed)
if ( $stackOfVote->getOwner() === $this ) {
$stackOfVote->setOwner( null );
}
}
return $this;
}
2019-11-12 11:26:19 +01:00
public function addComment( Comment $comment ): self {
2020-01-15 16:46:56 +01:00
if ( ! $this->comments->contains( $comment ) ) {
$this->comments[] = $comment;
$comment->setOwner( $this );
}
return $this;
}
2019-11-12 11:26:19 +01:00
public function removeComment( Comment $comment ): self {
2020-01-15 16:46:56 +01:00
if ( $this->comments->contains( $comment ) ) {
$this->comments->removeElement( $comment );
// set the owning side to null (unless already changed)
if ( $comment->getOwner() === $this ) {
$comment->setOwner( null );
}
}
return $this;
}
2019-11-27 16:14:49 +01:00
2020-01-15 16:46:56 +01:00
public function getRequestedPollsDate() {
return $this->requestedPollsDate;
}
public function setRequestedPollsDate( $requestedPollsDate ): self {
$this->requestedPollsDate = $requestedPollsDate;
return $this;
}
2019-10-25 14:59:20 +02:00
}