<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\PollOptionRepository")
*/
class PollOption
{
const TYPE_STANDARD = 1;
const TYPE_AUTO = 2;
const STATUS_INACTIVE = 0;
const STATUS_ACTIVE = 1;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="bigint")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $text;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="pollOptions")
* @ORM\JoinColumn(name="poll_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $poll;
/**
* @ORM\OneToMany(targetEntity="App\Entity\PollResponse", mappedBy="pollOption", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
*/
private $pollResponses;
// Temporary until I can figure out how to properly display in SonataAdmin without this hack.
/**
* @ORM\ManyToOne(targetEntity="App\Entity\MediaGroupItem", inversedBy="pollOptions")
* @ORM\JoinColumn(name="media_group_item_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $ad;
/**
* @ORM\Column(type="integer")
*/
private $type;
/**
* @ORM\Column(type="integer")
*/
private $status;
public function __construct ()
{
$this->text = "";
$this->pollResponses = new ArrayCollection();
$this->type = 1;
$this->status = 1;
}
public function getId()
{
return $this->id;
}
public function getText(): ?string
{
return $this->text;
}
public function setText (string $text = null): ?self
{
$this->text = !is_null($text) ? $text : "";
return $this;
}
public function getPoll(): ?Poll
{
return $this->poll;
}
public function setPoll(?Poll $poll = null): self
{
$this->poll = $poll;
return $this;
}
/**
* @return Collection|PollResponse[]
*/
public function getPollResponses(): Collection
{
return $this->pollResponses;
}
public function addPollResponse(PollResponse $pollResponse): self
{
if (!$this->pollResponses->contains($pollResponse)) {
$this->pollResponses[] = $pollResponse;
$pollResponse->setPollOption($this);
}
return $this;
}
public function removePollResponse(PollResponse $pollResponse): self
{
if ($this->pollResponses->contains($pollResponse)) {
$this->pollResponses->removeElement($pollResponse);
// set the owning side to null (unless already changed)
if ($pollResponse->getPollOption() === $this) {
$pollResponse->setPollOption(null);
}
}
return $this;
}
public function countResponses() {
return count($this->getPollResponses());
}
public function getAd(): ?MediaGroupItem
{
return $this->ad;
}
public function setAd(?MediaGroupItem $ad = null): self
{
$this->ad = $ad;
return $this;
}
public function getType(): int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
public function getStatus(): int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
/*
public function getAd(): ?MediaGroupItem
{
$poll = $this->poll;
if($poll) {
return $poll->getAd();
}
return null;
}
public function setAd(?MediaGroupItem $ad = null): self
{
$poll = $this->poll;
if($poll) {
//$this->poll->setAd($ad);
}
return $this;
}
*/
public function __toString ()
{
return $this->getText();
}
}