setCreatedAt( new DateTime() ); $this->votes = new ArrayCollection(); } public function display() { $tab = [ 'id' => $this->getId(), 'pseudo' => $this->getPseudo(), 'created_at' => $this->getCreatedAtAsString(), 'votes' => [], ]; foreach ( $this->getVotes() as $vote ) { $tab[ 'votes' ][] = $vote->display(); } $tab[ 'owner' ] = $this->getOwner()->display(); return $tab; } public function displayForAdmin() { $tab = $this->display(); $tab[ 'owner' ] = $this->getOwner()->displayForAdmin(); return $tab; } /** * @return Collection|poll[] */ public function getVotes(): Collection { return $this->votes; } public function getPseudo(): ?string { return $this->pseudo; } public function setPseudo( ?string $pseudo ): self { $this->pseudo = $pseudo; return $this; } /** * @ORM\PrePersist */ public function prePersist() { $this->setPseudo( $this->getOwner()->getPseudo() ); } public function getOwner(): ?Owner { return $this->owner; } public function setOwner( ?Owner $owner ): self { $this->owner = $owner; return $this; } public function getId(): ?int { return $this->id; } public function addVote( Vote $vote ): self { if ( ! $this->votes->contains( $vote ) ) { $vote->setPoll( $this->getPoll() ); $this->votes[] = $vote; $vote->setStacksOfVotes( $this ); } return $this; } public function getPoll(): ?Poll { return $this->poll; } public function setPoll( ?Poll $poll ): self { $this->poll = $poll; return $this; } public function removeVote( Vote $vote ): self { if ( $this->votes->contains( $vote ) ) { $this->votes->removeElement( $vote ); // set the owning side to null (unless already changed) if ( $vote->getStacksOfVotes() === $this ) { $vote->setStacksOfVotes( null ); } } return $this; } public function getIp(): ?string { return $this->ip; } public function setIp( string $ip ): self { $this->ip = $ip; return $this; } }