src/Entity/Link.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. /**
  7.  * Represents an HTTP link.
  8.  * 
  9.  * @ORM\Entity(repositoryClass="App\Repository\LinkRepository")
  10.  */
  11. class Link
  12. {
  13.     /**
  14.      * @ORM\Id()
  15.      * @ORM\GeneratedValue()
  16.      * @ORM\Column(type="bigint")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $title;
  23.     /**
  24.      * @ORM\Column(type="text")
  25.      */
  26.     private $description;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity="App\Entity\Content")
  29.      */
  30.     private $refContent;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity="App\Entity\Media")
  33.      */
  34.     private $refMedia;
  35.     /**
  36.      * @ORM\Column(type="string", length=255)
  37.      */
  38.     private $refExternal;
  39.     
  40.     //added external_url because refExternal wasn't working in Sonata Admin for some reason... need to look into it more and remove one
  41.     /**
  42.      * @ORM\Column(type="string", length=255)
  43.      */
  44.     private $external_url;
  45.     /**
  46.      * @ORM\Column(type="text")
  47.      */
  48.     private $attributes;
  49.     /**
  50.      * @ORM\Column(type="datetime")
  51.      */
  52.     private $modifiedAt;
  53.     /**
  54.      * @ORM\Column(type="datetime")
  55.      */
  56.     private $createdAt;
  57.     /**
  58.      * @ORM\Column(type="integer")
  59.      */
  60.     private $status;
  61.     
  62.     /**
  63.      * @ORM\ManyToOne(targetEntity="App\Entity\Customer", inversedBy="links", cascade={"persist"})
  64.      * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
  65.      */
  66.     private $customer;
  67.     
  68.     /**
  69.      * @ORM\OneToMany(targetEntity="App\Entity\Traffic", mappedBy="link", orphanRemoval=true, cascade={"persist", "remove"})
  70.      */
  71.     private $traffic;
  72.     
  73.     public function __construct ()
  74.     {
  75.         $this->title "";
  76.         $this->description "";
  77.         $this->attributes "";
  78.         $this->refExternal "";
  79.         $this->external_url "";
  80.         $this->status 1;
  81.         $this->modifiedAt = new \DateTime("now");
  82.         $this->createdAt = new \DateTime("now");
  83.     }
  84.     public function getId()
  85.     {
  86.         return $this->id;
  87.     }
  88.     
  89.     public function getTitleDetails (): ?string
  90.     {
  91.         $type ucfirst($this->getType());
  92.         return "{$type}{$this->title}";
  93.     }
  94.     public function getTitle(): ?string
  95.     {
  96.         return $this->title;
  97.     }
  98.     public function setTitle(string $title null): self
  99.     {
  100.         $this->title $title $title "";
  101.         return $this;
  102.     }
  103.     public function getDescription(): ?string
  104.     {
  105.         return $this->description;
  106.     }
  107.     public function setDescription(string $description null): self
  108.     {
  109.         $this->description $description $description "";
  110.         return $this;
  111.     }
  112.     public function getRefContent(): ?Content
  113.     {
  114.         return $this->refContent;
  115.     }
  116.     public function setRefContent(?Content $refContent): self
  117.     {
  118.         $this->refContent $refContent;
  119.         return $this;
  120.     }
  121.     public function getRefMedia(): ?Media
  122.     {
  123.         return $this->refMedia;
  124.     }
  125.     public function setRefMedia(?Media $refMedia): self
  126.     {
  127.         $this->refMedia $refMedia;
  128.         return $this;
  129.     }
  130.     public function getRefExternal(): ?string
  131.     {
  132.         return $this->refExternal $this->refExternal $this->external_url;
  133.     }
  134.     public function setRefExternal(string $refExternal null): self
  135.     {
  136.         $this->refExternal $refExternal $refExternal "";
  137.         $this->external_url $refExternal $refExternal "";
  138.         return $this;
  139.     }
  140.     
  141.     public function getExternalUrl(): ?string
  142.     {
  143.         return $this->external_url $this->external_url $this->refExternal;
  144.     }
  145.     public function setExternalUrl(string $external_url null): self
  146.     {
  147.         $this->external_url $external_url $external_url "";
  148.         $this->refExternal $external_url $external_url "";
  149.         return $this;
  150.     }
  151.     
  152.     public function getAttributes(): ?string
  153.     {
  154.         return $this->attributes;
  155.     }
  156.     public function setAttributes(string $attributes null): self
  157.     {
  158.         $this->attributes $attributes $attributes "";
  159.         return $this;
  160.     }
  161.     public function getModifiedAt(): ?\DateTimeInterface
  162.     {
  163.         return $this->modifiedAt;
  164.     }
  165.     public function setModifiedAt(\DateTimeInterface $modifiedAt): self
  166.     {
  167.         $this->modifiedAt $modifiedAt;
  168.         return $this;
  169.     }
  170.     public function getCreatedAt(): ?\DateTimeInterface
  171.     {
  172.         return $this->createdAt;
  173.     }
  174.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  175.     {
  176.         $this->createdAt $createdAt;
  177.         return $this;
  178.     }
  179.     public function getStatus(): ?int
  180.     {
  181.         return $this->status;
  182.     }
  183.     public function setStatus(int $status): self
  184.     {
  185.         $this->status $status;
  186.         return $this;
  187.     }
  188.     
  189.     public function __toString ()
  190.     {
  191.         return $this->getTitleDetails();
  192.     }
  193.     
  194.     public function getType ()
  195.     {
  196.         if ($this->refContent) {
  197.             return "content";
  198.         }
  199.         
  200.         if ($this->refMedia) {
  201.             return "media";
  202.         }
  203.         
  204.         if ($this->refExternal) {
  205.             return "external";
  206.         }
  207.         
  208.         return "empty";
  209.     }
  210.     
  211.     public function getRef()
  212.     {
  213.         if ($this->refContent) {
  214.             return $this->refContent->getURL();
  215.         }
  216.         
  217.         if ($this->refMedia) {
  218.             return $this->refMedia->getURL();
  219.         }
  220.         
  221.         if ($this->refExternal) {
  222.             return $this->refExternal;
  223.         }
  224.         
  225.         return "";
  226.     }
  227.     
  228.     public function getCustomer(): ?Customer
  229.     {
  230.         return $this->customer;
  231.     }
  232.     public function setCustomer(?Customer $customer null): self
  233.     {
  234.         $this->customer $customer;
  235.         return $this;
  236.     }
  237.     
  238.     /**
  239.      * @return Collection|Traffic[]
  240.      */
  241.     public function getTraffic(): Collection
  242.     {
  243.         return $this->traffic;
  244.     }
  245.     public function addTraffic(Traffic $traffic): self
  246.     {
  247.         if (!$this->traffic->contains($traffic)) {
  248.             $this->traffic[] = $traffic;
  249.             $traffic->setLink($this);
  250.         }
  251.         return $this;
  252.     }
  253.     public function removeTraffic(Traffic $traffic): self
  254.     {
  255.         if ($this->traffic->contains($traffic)) {
  256.             $this->traffic->removeElement($traffic);
  257.             // set the owning side to null (unless already changed)
  258.             if ($traffic->getLink() === $this) {
  259.                 $traffic->setLink(null);
  260.             }
  261.         }
  262.         return $this;
  263.     }
  264. }