src/Entity/Poll.php line 14

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. use Doctrine\Common\Collections\Criteria;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\PollRepository")
  9.  */
  10. class Poll
  11. {
  12.     const STATUS_SCHEDULED 2;
  13.     const STATUS_ACTIVE 1;
  14.     const STATUS_INACTIVE 0;
  15.     const STATUS_EXPIRED = -2;
  16.     const STATUS_TRASH = -3;
  17.     
  18.     const SITE_RCS 1;
  19.     const SITE_AAR 2;
  20.     const SITE_MCS 3;
  21.     const SITE_CCS 4;
  22.     const TYPE_HOME 1;
  23.     const TYPE_POPUP 2;
  24.     
  25.     /**
  26.      * @ORM\Id()
  27.      * @ORM\GeneratedValue()
  28.      * @ORM\Column(type="bigint")
  29.      */
  30.     private $id;
  31.     
  32.     /**
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $version//Removed @ORM\Version as poll impressions are stored in the Entity. Should update this.
  36.     
  37.     /**
  38.      * @ORM\Column(type="string", length=255)
  39.      */
  40.     private $title;
  41.     
  42.     /**
  43.      * @ORM\Column(type="text")
  44.      */
  45.     private $description;
  46.     
  47.     /**
  48.      * @ORM\Column(type="datetime")
  49.      */
  50.     private $published_at;
  51.     /**
  52.      * @ORM\Column(type="datetime")
  53.      */
  54.     private $modified_at;
  55.     
  56.     /**
  57.      * @ORM\Column(type="datetime")
  58.      */
  59.     private $created_at;
  60.     
  61.     /**
  62.      * @ORM\Column(type="datetime", nullable=true)
  63.      */
  64.     private $response_close_date;
  65.     
  66.     /**
  67.      * @ORM\Column(type="datetime", nullable=true)
  68.      */
  69.     private $expires_at;
  70.     
  71.     /**
  72.      * @ORM\Column(type="integer")
  73.      */
  74.     private $status;
  75.     
  76.     /**
  77.      * @ORM\OneToMany(targetEntity="App\Entity\PollOption", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
  78.      */
  79.     private $pollOptions;
  80.     
  81.     /**
  82.      * @ORM\ManyToMany(targetEntity="App\Entity\Customer", mappedBy="polls", cascade={"persist"})
  83.      */
  84.     private $customers;
  85.     
  86.     /**
  87.      * @ORM\ManyToOne(targetEntity="App\Entity\Media", cascade={"persist"})
  88.      * @ORM\JoinColumn(nullable=true)
  89.      */
  90.     private $media;
  91.     /**
  92.      * @ORM\OneToOne(targetEntity="App\Entity\MediaGroupItem", inversedBy="poll", cascade={"persist"})
  93.      */
  94.     private $ad;
  95.     /**
  96.      * @ORM\OneToOne(targetEntity="App\Entity\MediaGroupItem", mappedBy="popOutPoll", cascade={"persist"})
  97.      */
  98.     private $popOutAd;
  99.     
  100.     /**
  101.      * @ORM\Column(type="string", length=255)
  102.      */
  103.     private $info_url;
  104.     
  105.     /**
  106.      * @ORM\Column(type="integer")
  107.      */
  108.     private $total_impressions;
  109.     /**
  110.      * @ORM\Column(type="integer")
  111.      */
  112.     private $requires_login;
  113.     
  114.     /**
  115.      * @ORM\ManyToMany(targetEntity="App\Entity\Site", inversedBy="polls")
  116.      */
  117.     private $site;
  118.     /**
  119.      * @ORM\Column(type="integer")
  120.      */
  121.     private $type;
  122.     
  123.     
  124.     public function __construct ()
  125.     {
  126.         $this->title "";
  127.         $this->description "";
  128.         $this->published_at = new \DateTime();
  129.         $this->modified_at = new \DateTime();
  130.         $this->created_at = new \DateTime ();
  131.         $this->status SELF::STATUS_INACTIVE;
  132.         $this->pollOptions = new ArrayCollection();
  133.         $this->customers = new ArrayCollection();
  134.         $this->info_url "";
  135.         $this->total_impressions 0;
  136.         $this->requires_login 0;
  137.         $this->version 0;
  138.         $this->site = new ArrayCollection();
  139.         $this->type 1;
  140.     }
  141.     public function getId()
  142.     {
  143.         return $this->id;
  144.     }
  145.     
  146.     public function getTitle(): ?string
  147.     {
  148.         return $this->title;
  149.     }
  150.     
  151.     public function setTitle(string $title null): self
  152.     {
  153.         $this->title $title $title "";
  154.         return $this;
  155.     }
  156.     
  157.     public function getDescription(): ?string
  158.     {
  159.         return $this->description;
  160.     }
  161.     
  162.     public function setDescription (string $description null): ?self
  163.     {
  164.         $this->description $description $description "";
  165.         return $this;
  166.     }
  167.     
  168.     public function getPublishedAt(): ?\DateTimeInterface
  169.     {
  170.         return $this->published_at;
  171.     }
  172.     
  173.     public function setPublishedAt(\DateTimeInterface $published_at): self
  174.     {
  175.         $this->published_at $published_at;
  176.         return $this;
  177.     }
  178.     
  179.     public function getModifiedAt(): ?\DateTimeInterface
  180.     {
  181.         return $this->modified_at;
  182.     }
  183.     
  184.     public function setModifiedAt(\DateTimeInterface $modified_at): self
  185.     {
  186.         $this->modified_at $modified_at;
  187.         return $this;
  188.     }
  189.     
  190.     public function getCreatedAt(): ?\DateTimeInterface
  191.     {
  192.         return $this->created_at;
  193.     }
  194.     
  195.     public function setCreatedAt(\DateTimeInterface $created_at): self
  196.     {
  197.         $this->created_at $created_at;
  198.         return $this;
  199.     }
  200.     
  201.     public function getExpiresAt(): ?\DateTimeInterface
  202.     {
  203.         return $this->expires_at;
  204.     }
  205.     
  206.     public function setExpiresAt(?\DateTimeInterface $expires_at): self
  207.     {
  208.         $this->expires_at $expires_at;
  209.         return $this;
  210.     }
  211.     
  212.     public function getResponseCloseDate(): ?\DateTimeInterface
  213.     {
  214.         return $this->response_close_date;
  215.     }
  216.     
  217.     public function setResponseCloseDate(?\DateTimeInterface $response_close_date): self
  218.     {
  219.         $this->response_close_date $response_close_date;
  220.         return $this;
  221.     }
  222.     
  223.     public function getStatus(): ?int
  224.     {
  225.         return $this->status;
  226.     }
  227.     
  228.     public function setStatus(int $status): self
  229.     {
  230.         $this->status $status;
  231.         return $this;
  232.     }
  233.     
  234.     /**
  235.      * @return Collection|PollOption[]
  236.      */
  237.     public function getPollOptions(): Collection
  238.     {
  239.         return $this->pollOptions;
  240.     }
  241.     public function getActivePollOptions(): Collection
  242.     {
  243.         $criteria Criteria::create()
  244.             ->where(Criteria::expr()->eq("status"1))
  245.         ;
  246.         
  247.         return $this->pollOptions->matching($criteria);
  248.     }
  249.     public function setPollOptions (Collection $pollOptions): self {
  250.         foreach ($pollOptions as $pollOption) {
  251.             $this->addPollOption($pollOption);
  252.         }
  253.         return $this;
  254.     }
  255.     
  256.     public function addPollOption(PollOption $pollOption): self
  257.     {
  258.         if (!$this->pollOptions->contains($pollOption)) {
  259.             $this->pollOptions[] = $pollOption;
  260.             $pollOption->setPoll($this);
  261.         }
  262.         
  263.         return $this;
  264.     }
  265.     
  266.     public function removePollOption(PollOption $pollOption): self
  267.     {
  268.         if ($this->pollOptions->contains($pollOption)) {
  269.             $this->pollOptions->removeElement($pollOption);
  270.             // set the owning side to null (unless already changed)
  271.             if ($pollOption->getPoll() === $this) {
  272.                 $pollOption->setPoll(null);
  273.             }
  274.         }
  275.         
  276.         return $this;
  277.     }
  278.     public function resetPollOptions(): self
  279.     {
  280.         foreach($this->pollOptions as $pollOption) {
  281.             $this->removePollOption($pollOption);
  282.         }
  283.         return $this;
  284.     }
  285.     
  286.     public function getPollOptionsArray() {
  287.         $return = [];
  288.         foreach($this->getPollOptions() as $pollOption) {
  289.             $return[$pollOption->getId()] = $pollOption->getText();
  290.         }
  291.         return $return;
  292.     }
  293.     
  294.     public function getActivePollOptionsArray() {
  295.         $return = [];
  296.         foreach($this->getActivePollOptions() as $pollOption) {
  297.             $return[$pollOption->getId()] = $pollOption->getText();
  298.         }
  299.         return $return;
  300.     }
  301.     
  302.     public function getResults() {
  303.         $return = [];
  304.         foreach($this->getPollOptions() as $pollOption) {
  305.             //$return[$pollOption->getId()] = $pollOption->countResponses();
  306.             $return[$pollOption->getText()] = $pollOption->countResponses();
  307.         }
  308.         return $return;
  309.     }
  310.     
  311.     public function getPollResponses() {
  312.         $return = [];
  313.         foreach($this->getPollOptions() as $pollOption) {
  314.             foreach($pollOption->getPollResponses() as $pollResponse) {
  315.                 $return[] = $pollResponse;
  316.             }
  317.         }
  318.         return $return;
  319.     }
  320.     public function countResponses() {
  321.         return count($this->getPollResponses());
  322.     }
  323.     
  324.     /**
  325.      * @return Collection|Customer[]
  326.      */
  327.     public function getCustomers(): Collection
  328.     {
  329.         return $this->customers;
  330.     }
  331.     
  332.     //don't think Sonata is using this
  333.     public function addCustomers($customers): self
  334.     {
  335.         if(is_array($customers)) {
  336.             foreach($customers as $customer) {
  337.                 $this->addCustomer($customer);
  338.             }
  339.         }
  340.         else {
  341.             $this->customers->clear();
  342.             $this->addCustomer($customers);
  343.         }
  344.         
  345.         
  346.         return $this;
  347.     }
  348.     public function addCustomer(Customer $customer): self
  349.     {
  350.         if (!$this->customers->contains($customer)) {
  351.             $this->customers[] = $customer;
  352.             $customer->addPoll($this);
  353.         }
  354.         return $this;
  355.     }
  356.     public function removeCustomer(Customer $customer): self
  357.     {
  358.         if ($this->customers->contains($customer)) {
  359.             $this->customers->removeElement($customer);
  360.             $customer->removePoll($this);
  361.         }
  362.         return $this;
  363.     }
  364.     
  365.     public function resetCustomers(): self
  366.     {
  367.         foreach($this->customers as $customer) {
  368.             $this->removeCustomer($customer);
  369.         }
  370.         return $this;
  371.     }
  372.     
  373.     public function getMedia (): ?Media
  374.     {
  375.         return $this->media;
  376.     }
  377.     
  378.     public function setMedia (Media $media null): self
  379.     {
  380.         $this->media $media;
  381.         return $this;
  382.     }
  383.     public function getAd (): ?MediaGroupItem
  384.     {
  385.         return $this->ad;
  386.     }
  387.     
  388.     public function setAd (MediaGroupItem $ad null): self
  389.     {
  390.         $this->ad $ad;
  391.         return $this;
  392.     }
  393.     public function getPopOutAd (): ?MediaGroupItem
  394.     {
  395.         return $this->popOutAd;
  396.     }
  397.     
  398.     public function setPopOutAd (MediaGroupItem $popOutAd null): self
  399.     {
  400.         $this->popOutAd $popOutAd;
  401.         return $this;
  402.     }
  403.     
  404.     public function getInfoUrl(): ?string
  405.     {
  406.         return $this->info_url;
  407.     }
  408.     public function setInfoUrl(string $info_url null): self
  409.     {
  410.         $this->info_url $info_url $info_url "";
  411.         return $this;
  412.     }
  413.     
  414.     public function getTotalImpressions(): ?int
  415.     {
  416.         return $this->total_impressions;
  417.     }
  418.     
  419.     public function setTotalImpressions(int $total_impressions): self
  420.     {
  421.         $this->total_impressions $total_impressions;
  422.         return $this;
  423.     }
  424.     
  425.     public function incrementTotalImpressions(): self
  426.     {
  427.         $this->total_impressions $this->total_impressions 1;
  428.         return $this;
  429.     }
  430.     public function getRequiresLogin(): ?bool
  431.     {
  432.         return $this->requires_login == 1;
  433.     }
  434.     
  435.     public function setRequiresLogin(bool $value): self
  436.     {
  437.         $this->requires_login $value 0;
  438.         return $this;
  439.     }
  440.     
  441.     /**
  442.        * @return Collection|Site[]
  443.        */
  444.       public function getSite(): Collection
  445.       {
  446.           return $this->site;
  447.       }
  448.       
  449.       public function getSites(): Collection
  450.       {
  451.           return $this->site;
  452.       }
  453.       public function addSite(Site $site): self
  454.       {
  455.           if (!$this->site->contains($site)) {
  456.               $this->site[] = $site;
  457.               $site->addPoll($this);
  458.             }
  459.             return $this;
  460.         }
  461.       
  462.       public function resetSite(): self
  463.       {
  464.           $this->site = new ArrayCollection();
  465.           return $this;
  466.       }
  467.       
  468.       public function removeSite(Site $site): self
  469.   {
  470.       if ($this->site->contains($site)) {
  471.           $this->site->removeElement($site);
  472.           $site->removePoll($this);
  473.       }
  474.       return $this;
  475.   }
  476.       
  477.       
  478.       public function getSiteTextShort()
  479.       {
  480.           $site_texts = [];
  481.           foreach($this->getSite() as $s) {
  482.               $site_texts[] = $s->getSiteTextShort();
  483.           }
  484.           return implode(", "$site_texts);
  485.       }
  486.       
  487.       public function getSiteIds()
  488.       {
  489.           $site_ids = [];
  490.           foreach($this->getSite() as $s) {
  491.               $site_ids[] = $s->getId();
  492.           }
  493.           return $site_ids;
  494.       }
  495.     public function getType(): ?int
  496.     {
  497.         return $this->type;
  498.     }
  499.     
  500.     public function setType(int $type): self
  501.     {
  502.         $this->type $type;
  503.         return $this;
  504.     }
  505.     public function isReallyActive(): bool {
  506.         return ($this->getStatus() == self::STATUS_ACTIVE) && $this->getTitle() && ($this->getPollOptions()->count() > 1);
  507.     }
  508.     
  509.     public function __toString ()
  510.     {
  511.         return $this->title "Poll: " $this->title "";
  512.     }
  513.     
  514. }