<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* Represents an HTTP link.
*
* @ORM\Entity(repositoryClass="App\Repository\LinkRepository")
*/
class Link
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="bigint")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Content")
*/
private $refContent;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Media")
*/
private $refMedia;
/**
* @ORM\Column(type="string", length=255)
*/
private $refExternal;
//added external_url because refExternal wasn't working in Sonata Admin for some reason... need to look into it more and remove one
/**
* @ORM\Column(type="string", length=255)
*/
private $external_url;
/**
* @ORM\Column(type="text")
*/
private $attributes;
/**
* @ORM\Column(type="datetime")
*/
private $modifiedAt;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Customer", inversedBy="links", cascade={"persist"})
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
*/
private $customer;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Traffic", mappedBy="link", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $traffic;
public function __construct ()
{
$this->title = "";
$this->description = "";
$this->attributes = "";
$this->refExternal = "";
$this->external_url = "";
$this->status = 1;
$this->modifiedAt = new \DateTime("now");
$this->createdAt = new \DateTime("now");
}
public function getId()
{
return $this->id;
}
public function getTitleDetails (): ?string
{
$type = ucfirst($this->getType());
return "{$type}: {$this->title}";
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title = null): self
{
$this->title = $title ? $title : "";
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description = null): self
{
$this->description = $description ? $description : "";
return $this;
}
public function getRefContent(): ?Content
{
return $this->refContent;
}
public function setRefContent(?Content $refContent): self
{
$this->refContent = $refContent;
return $this;
}
public function getRefMedia(): ?Media
{
return $this->refMedia;
}
public function setRefMedia(?Media $refMedia): self
{
$this->refMedia = $refMedia;
return $this;
}
public function getRefExternal(): ?string
{
return $this->refExternal ? $this->refExternal : $this->external_url;
}
public function setRefExternal(string $refExternal = null): self
{
$this->refExternal = $refExternal ? $refExternal : "";
$this->external_url = $refExternal ? $refExternal : "";
return $this;
}
public function getExternalUrl(): ?string
{
return $this->external_url ? $this->external_url : $this->refExternal;
}
public function setExternalUrl(string $external_url = null): self
{
$this->external_url = $external_url ? $external_url : "";
$this->refExternal = $external_url ? $external_url : "";
return $this;
}
public function getAttributes(): ?string
{
return $this->attributes;
}
public function setAttributes(string $attributes = null): self
{
$this->attributes = $attributes ? $attributes : "";
return $this;
}
public function getModifiedAt(): ?\DateTimeInterface
{
return $this->modifiedAt;
}
public function setModifiedAt(\DateTimeInterface $modifiedAt): self
{
$this->modifiedAt = $modifiedAt;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function __toString ()
{
return $this->getTitleDetails();
}
public function getType ()
{
if ($this->refContent) {
return "content";
}
if ($this->refMedia) {
return "media";
}
if ($this->refExternal) {
return "external";
}
return "empty";
}
public function getRef()
{
if ($this->refContent) {
return $this->refContent->getURL();
}
if ($this->refMedia) {
return $this->refMedia->getURL();
}
if ($this->refExternal) {
return $this->refExternal;
}
return "";
}
public function getCustomer(): ?Customer
{
return $this->customer;
}
public function setCustomer(?Customer $customer = null): self
{
$this->customer = $customer;
return $this;
}
/**
* @return Collection|Traffic[]
*/
public function getTraffic(): Collection
{
return $this->traffic;
}
public function addTraffic(Traffic $traffic): self
{
if (!$this->traffic->contains($traffic)) {
$this->traffic[] = $traffic;
$traffic->setLink($this);
}
return $this;
}
public function removeTraffic(Traffic $traffic): self
{
if ($this->traffic->contains($traffic)) {
$this->traffic->removeElement($traffic);
// set the owning side to null (unless already changed)
if ($traffic->getLink() === $this) {
$traffic->setLink(null);
}
}
return $this;
}
}