src/Entity/PollOption.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\PollOptionRepository")
  8.  */
  9. class PollOption
  10. {
  11.     const TYPE_STANDARD 1;
  12.     const TYPE_AUTO 2;
  13.     const STATUS_INACTIVE 0;
  14.     const STATUS_ACTIVE 1;
  15.     /**
  16.      * @ORM\Id()
  17.      * @ORM\GeneratedValue()
  18.      * @ORM\Column(type="bigint")
  19.      */
  20.     private $id;
  21.     
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $text;
  26.     
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity="App\Entity\Poll", inversedBy="pollOptions")
  29.      * @ORM\JoinColumn(name="poll_id", referencedColumnName="id", onDelete="SET NULL")
  30.      */
  31.     private $poll;
  32.     
  33.     /**
  34.      * @ORM\OneToMany(targetEntity="App\Entity\PollResponse", mappedBy="pollOption", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
  35.      */
  36.     private $pollResponses;
  37.     //  Temporary until I can figure out how to properly display in SonataAdmin without this hack.
  38.     /**
  39.      * @ORM\ManyToOne(targetEntity="App\Entity\MediaGroupItem", inversedBy="pollOptions")
  40.      * @ORM\JoinColumn(name="media_group_item_id", referencedColumnName="id", onDelete="SET NULL")
  41.      */
  42.     private $ad;
  43.     /**
  44.      * @ORM\Column(type="integer")
  45.      */
  46.     private $type;
  47.     /**
  48.      * @ORM\Column(type="integer")
  49.      */
  50.     private $status;
  51.     
  52.     
  53.     public function __construct ()
  54.     {
  55.         $this->text "";
  56.         $this->pollResponses = new ArrayCollection();
  57.         $this->type 1;
  58.         $this->status 1;
  59.     }
  60.     public function getId()
  61.     {
  62.         return $this->id;
  63.     }
  64.     
  65.     public function getText(): ?string
  66.     {
  67.         return $this->text;
  68.     }
  69.     
  70.     public function setText (string $text null): ?self
  71.     {
  72.         $this->text = !is_null($text) ? $text "";
  73.         return $this;
  74.     }
  75.     
  76.     public function getPoll(): ?Poll
  77.     {
  78.         return $this->poll;
  79.     }
  80.     
  81.     public function setPoll(?Poll $poll null): self
  82.     {
  83.         $this->poll $poll;
  84.         return $this;
  85.     }
  86.     
  87.     
  88.     /**
  89.      * @return Collection|PollResponse[]
  90.      */
  91.     public function getPollResponses(): Collection
  92.     {
  93.         return $this->pollResponses;
  94.     }
  95.     
  96.     public function addPollResponse(PollResponse $pollResponse): self
  97.     {
  98.         if (!$this->pollResponses->contains($pollResponse)) {
  99.             $this->pollResponses[] = $pollResponse;
  100.             $pollResponse->setPollOption($this);
  101.         }
  102.         
  103.         return $this;
  104.     }
  105.     
  106.     public function removePollResponse(PollResponse $pollResponse): self
  107.     {
  108.         if ($this->pollResponses->contains($pollResponse)) {
  109.             $this->pollResponses->removeElement($pollResponse);
  110.             // set the owning side to null (unless already changed)
  111.             if ($pollResponse->getPollOption() === $this) {
  112.                 $pollResponse->setPollOption(null);
  113.             }
  114.         }
  115.         
  116.         return $this;
  117.     }
  118.     
  119.     public function countResponses() {
  120.         return count($this->getPollResponses());
  121.     }
  122.     public function getAd(): ?MediaGroupItem
  123.     {
  124.         return $this->ad;
  125.     }
  126.     
  127.     public function setAd(?MediaGroupItem $ad null): self
  128.     {
  129.         $this->ad $ad;
  130.         return $this;
  131.     }
  132.     public function getType(): int
  133.     {
  134.         return $this->type;
  135.     }
  136.     public function setType(int $type): self
  137.     {
  138.         $this->type $type;
  139.         return $this;
  140.     }
  141.     
  142.     public function getStatus(): int
  143.     {
  144.         return $this->status;
  145.     }
  146.     public function setStatus(int $status): self
  147.     {
  148.         $this->status $status;
  149.         return $this;
  150.     }
  151.     /*
  152.     public function getAd(): ?MediaGroupItem
  153.     {
  154.         $poll = $this->poll;
  155.         if($poll) {
  156.             return $poll->getAd();
  157.         }
  158.         return null;
  159.     }
  160.     
  161.     public function setAd(?MediaGroupItem $ad = null): self
  162.     {
  163.         $poll = $this->poll;
  164.         if($poll) {
  165.             //$this->poll->setAd($ad);
  166.         }
  167.         return $this;
  168.     }
  169.     */
  170.     
  171.     
  172.     public function __toString ()
  173.     {
  174.         return $this->getText();
  175.     }
  176.     
  177. }