<?php
namespace App\Entity;
use App\Repository\PlatformRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Offer;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=PlatformRepository::class)
*/
class Platform
{
const WHITE = '#ffffff';
const WHITE_LIGHT = '#ced4da';
const BLACK = '#000000';
const BLACK_LIGHT = '#878787';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToOne(targetEntity=Image::class, inversedBy="logoPlatform", cascade={"persist", "remove"})
*/
private $logo;
/**
* @ORM\Column(type="string", length=255)
*/
private $domain;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="platform", orphanRemoval=true)
*/
private $users;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Email()
*/
private $email;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $emailPassword;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $smtpServer;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $smtpPort;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $imapServer;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $imapPort;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $deleted;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deletedAt;
/**
* @ORM\OneToMany(targetEntity=OfferCategory::class, mappedBy="platform")
*/
private $offerCategories;
/**
* @ORM\OneToMany(targetEntity=Offer::class, mappedBy="platform")
*/
private $offers;
/**
* @ORM\OneToMany(targetEntity=Subscription::class, mappedBy="platform")
*/
private $subscriptions;
/**
* @ORM\OneToMany(targetEntity=Image::class, mappedBy="platform")
*/
private $images;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $facebookPage;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $twitterPage;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $instagramPage;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $primaryColor;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $secondaryColor;
/**
* @ORM\Column(type="smallint", options={"default": 1})
*/
private $defaultPayoutType;
/**
* @ORM\OneToOne(targetEntity=Image::class, inversedBy="faviconPlatform", cascade={"persist", "remove"})
*/
private $favicon;
/**
* @ORM\ManyToOne(targetEntity=Currency::class, inversedBy="platforms")
*/
private $defaultCurrency;
/**
* @ORM\OneToMany(targetEntity=PhoneCall::class, mappedBy="platform")
*/
private $phoneCalls;
/**
* @ORM\OneToMany(targetEntity=Ticket::class, mappedBy="platform", orphanRemoval=true)
*/
private $tickets;
/**
* @ORM\OneToMany(targetEntity=Callback::class, mappedBy="platform")
*/
private $callbacks;
/**
* @ORM\OneToMany(targetEntity=Transaction::class, mappedBy="platform")
*/
private $transactions;
/**
* @ORM\Column(type="smallint", options={"default": 15})
*/
private $minCallDuration;
/**
* @ORM\OneToMany(targetEntity=LandingPage::class, mappedBy="platform", orphanRemoval=true)
*/
private $landingPages;
public function __construct()
{
$this->users = new ArrayCollection();
$this->deleted = false;
$this->offerCategories = new ArrayCollection();
$this->offers = new ArrayCollection();
$this->subscriptions = new ArrayCollection();
$this->images = new ArrayCollection();
$this->defaultPayoutType = Offer::PAYOUT_TYPE_CPI_ID;
$this->phoneCalls = new ArrayCollection();
$this->tickets = new ArrayCollection();
$this->callbacks = new ArrayCollection();
$this->transactions = new ArrayCollection();
$this->minCallDuration = 15;
$this->landingPages = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getLogo(): ?Image
{
return $this->logo;
}
public function setLogo(?Image $logo): self
{
$this->logo = $logo;
return $this;
}
public function getDomain(): ?string
{
return $this->domain;
}
public function setDomain(string $domain): self
{
$this->domain = $domain;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setPlatform($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getPlatform() === $this) {
$user->setPlatform(null);
}
}
return $this;
}
public function getSmtpServer(): ?string
{
return $this->smtpServer;
}
public function setSmtpServer(?string $smtpServer): self
{
$this->smtpServer = $smtpServer;
return $this;
}
public function getImapServer(): ?string
{
return $this->imapServer;
}
public function setImapServer(?string $imapServer): self
{
$this->imapServer = $imapServer;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getEmailPassword(): ?string
{
return $this->emailPassword;
}
public function setEmailPassword(?string $emailPassword): self
{
$this->emailPassword = $emailPassword;
return $this;
}
public function getImapPort(): ?int
{
return $this->imapPort;
}
public function setImapPort(?int $imapPort): self
{
$this->imapPort = $imapPort;
return $this;
}
public function getSmtpPort(): ?int
{
return $this->smtpPort;
}
public function setSmtpPort(int $smtpPort): self
{
$this->smtpPort = $smtpPort;
return $this;
}
public function getDeleted(): ?bool
{
return $this->deleted;
}
public function setDeleted(bool $deleted): self
{
$this->deleted = $deleted;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeInterface $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
/**
* @return Collection|OfferCategory[]
*/
public function getOfferCategories(): Collection
{
return $this->offerCategories;
}
public function addOfferCategory(OfferCategory $offerCategory): self
{
if (!$this->offerCategories->contains($offerCategory)) {
$this->offerCategories[] = $offerCategory;
$offerCategory->setPlatform($this);
}
return $this;
}
public function removeOfferCategory(OfferCategory $offerCategory): self
{
if ($this->offerCategories->removeElement($offerCategory)) {
// set the owning side to null (unless already changed)
if ($offerCategory->getPlatform() === $this) {
$offerCategory->setPlatform(null);
}
}
return $this;
}
/**
* @return Collection|Offer[]
*/
public function getOffers(): Collection
{
return $this->offers;
}
public function addOffer(Offer $offer): self
{
if (!$this->offers->contains($offer)) {
$this->offers[] = $offer;
$offer->setPlatform($this);
}
return $this;
}
public function removeOffer(Offer $offer): self
{
if ($this->offers->removeElement($offer)) {
// set the owning side to null (unless already changed)
if ($offer->getPlatform() === $this) {
$offer->setPlatform(null);
}
}
return $this;
}
/**
* @return Collection|Subscription[]
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setPlatform($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->removeElement($subscription)) {
// set the owning side to null (unless already changed)
if ($subscription->getPlatform() === $this) {
$subscription->setPlatform(null);
}
}
return $this;
}
/**
* @return Collection|Image[]
*/
public function getImages(): Collection
{
return $this->images;
}
public function addImage(Image $image): self
{
if (!$this->images->contains($image)) {
$this->images[] = $image;
$image->setPlatform($this);
}
return $this;
}
public function removeImage(Image $image): self
{
if ($this->images->removeElement($image)) {
// set the owning side to null (unless already changed)
if ($image->getPlatform() === $this) {
$image->setPlatform(null);
}
}
return $this;
}
public function getFacebookPage(): ?string
{
return $this->facebookPage;
}
public function setFacebookPage(?string $facebookPage): self
{
$this->facebookPage = $facebookPage;
return $this;
}
public function getTwitterPage(): ?string
{
return $this->twitterPage;
}
public function setTwitterPage(?string $twitterPage): self
{
$this->twitterPage = $twitterPage;
return $this;
}
public function getInstagramPage(): ?string
{
return $this->instagramPage;
}
public function setInstagramPage(?string $instagramPage): self
{
$this->instagramPage = $instagramPage;
return $this;
}
public function getPrimaryColor(): ?string
{
return $this->primaryColor;
}
public function setPrimaryColor(?string $primaryColor): self
{
$this->primaryColor = $primaryColor;
return $this;
}
public function getSecondaryColor(): ?string
{
return $this->secondaryColor;
}
public function setSecondaryColor(?string $secondaryColor): self
{
$this->secondaryColor = $secondaryColor;
return $this;
}
public function getContrastColor($hexColor, $light = false)
{
// hexColor RGB
$R1 = hexdec(substr($hexColor, 1, 2));
$G1 = hexdec(substr($hexColor, 3, 2));
$B1 = hexdec(substr($hexColor, 5, 2));
// Black RGB
$blackColor = "#000000";
$R2BlackColor = hexdec(substr($blackColor, 1, 2));
$G2BlackColor = hexdec(substr($blackColor, 3, 2));
$B2BlackColor = hexdec(substr($blackColor, 5, 2));
// Calc contrast ratio
$L1 = 0.2126 * pow($R1 / 255, 2.2) +
0.7152 * pow($G1 / 255, 2.2) +
0.0722 * pow($B1 / 255, 2.2);
$L2 = 0.2126 * pow($R2BlackColor / 255, 2.2) +
0.7152 * pow($G2BlackColor / 255, 2.2) +
0.0722 * pow($B2BlackColor / 255, 2.2);
$contrastRatio = 0;
if ($L1 > $L2) {
$contrastRatio = (int)(($L1 + 0.05) / ($L2 + 0.05));
} else {
$contrastRatio = (int)(($L2 + 0.05) / ($L1 + 0.05));
}
// If contrast is more than 5, return black color
if ($contrastRatio > 12) {
if ($light) {
return self::BLACK_LIGHT;
}
return self::BLACK;
} else {
// if not, return white color.
if ($light) {
return self::WHITE_LIGHT;
}
return self::WHITE;
}
}
public function getInversedPrimaryColor(): ?string
{
return $this->getContrastColor($this->primaryColor);
}
public function getInversedSecondaryColor(): ?string
{
return $this->getContrastColor($this->secondaryColor);
}
public function getInversedLightPrimaryColor(): ?string
{
return $this->getContrastColor($this->primaryColor, true);
}
public function getInversedLightSecondaryColor(): ?string
{
return $this->getContrastColor($this->secondaryColor, true);
}
public function getColorForPrimary(): ?string
{
$bg = $this->getInversedPrimaryColor();
if ($bg == self::WHITE) {
return $bg;
}
if ($this->getInversedSecondaryColor() == self::WHITE) {
return $this->secondaryColor;
}
return self::BLACK_LIGHT;
}
public function getColorForSecondary(): ?string
{
$bg = $this->getInversedSecondaryColor();
if ($bg == self::WHITE) {
return $bg;
}
if ($this->getInversedPrimaryColor() == self::WHITE) {
return $this->primaryColor;
}
return self::BLACK_LIGHT;
}
public function getLinkColor(): ?string
{
if ($this->getInversedPrimaryColor() == self::WHITE) {
return $this->primaryColor;
}
if ($this->getInversedSecondaryColor() == self::WHITE) {
return $this->secondaryColor;
}
return '#4285f4';
}
public function hasSocialNetworkPage(): ?bool
{
if ($this->facebookPage || $this->twitterPage || $this->instagramPage) {
return true;
}
return false;
}
public function getDefaultPayoutType(): ?int
{
return $this->defaultPayoutType;
}
public function setDefaultPayoutType(int $defaultPayoutType): self
{
$this->defaultPayoutType = $defaultPayoutType;
return $this;
}
public function getDefaultPayoutTypeLabel(): ?string
{
foreach(Offer::$payoutTypes as $name => $id) {
if ($this->defaultPayoutType == $id) {
return $name;
}
}
return $this->defaultPayoutType;
}
public function getFavicon(): ?Image
{
return $this->favicon;
}
public function setFavicon(?Image $favicon): self
{
$this->favicon = $favicon;
return $this;
}
public function getDefaultCurrency(): ?Currency
{
return $this->defaultCurrency;
}
public function setDefaultCurrency(?Currency $defaultCurrency): self
{
$this->defaultCurrency = $defaultCurrency;
return $this;
}
/**
* @return Collection|PhoneCall[]
*/
public function getPhoneCalls(): Collection
{
return $this->phoneCalls;
}
public function addPhoneCall(PhoneCall $phoneCall): self
{
if (!$this->phoneCalls->contains($phoneCall)) {
$this->phoneCalls[] = $phoneCall;
$phoneCall->setPlatform($this);
}
return $this;
}
public function removePhoneCall(PhoneCall $phoneCall): self
{
if ($this->phoneCalls->removeElement($phoneCall)) {
// set the owning side to null (unless already changed)
if ($phoneCall->getPlatform() === $this) {
$phoneCall->setPlatform(null);
}
}
return $this;
}
/**
* @return Collection|Ticket[]
*/
public function getTickets(): Collection
{
return $this->tickets;
}
public function addTicket(Ticket $ticket): self
{
if (!$this->tickets->contains($ticket)) {
$this->tickets[] = $ticket;
$ticket->setPlatform($this);
}
return $this;
}
public function removeTicket(Ticket $ticket): self
{
if ($this->tickets->removeElement($ticket)) {
// set the owning side to null (unless already changed)
if ($ticket->getPlatform() === $this) {
$ticket->setPlatform(null);
}
}
return $this;
}
/**
* @return Collection|Callback[]
*/
public function getCallbacks(): Collection
{
return $this->callbacks;
}
public function addCallback(Callback $callback): self
{
if (!$this->callbacks->contains($callback)) {
$this->callbacks[] = $callback;
$callback->setPlatform($this);
}
return $this;
}
public function removeCallback(Callback $callback): self
{
if ($this->callbacks->removeElement($callback)) {
// set the owning side to null (unless already changed)
if ($callback->getPlatform() === $this) {
$callback->setPlatform(null);
}
}
return $this;
}
/**
* @return Collection|Transaction[]
*/
public function getTransactions(): Collection
{
return $this->transactions;
}
public function addTransaction(Transaction $transaction): self
{
if (!$this->transactions->contains($transaction)) {
$this->transactions[] = $transaction;
$transaction->setPlatform($this);
}
return $this;
}
public function removeTransaction(Transaction $transaction): self
{
if ($this->transactions->removeElement($transaction)) {
// set the owning side to null (unless already changed)
if ($transaction->getPlatform() === $this) {
$transaction->setPlatform(null);
}
}
return $this;
}
public function getMinCallDuration(): ?int
{
return $this->minCallDuration;
}
public function setMinCallDuration(int $minCallDuration): self
{
$this->minCallDuration = $minCallDuration;
return $this;
}
/**
* @return Collection<int, LandingPage>
*/
public function getLandingPages(): Collection
{
return $this->landingPages;
}
public function addLandingPage(LandingPage $landingPage): self
{
if (!$this->landingPages->contains($landingPage)) {
$this->landingPages[] = $landingPage;
$landingPage->setPlatform($this);
}
return $this;
}
public function removeLandingPage(LandingPage $landingPage): self
{
if ($this->landingPages->removeElement($landingPage)) {
// set the owning side to null (unless already changed)
if ($landingPage->getPlatform() === $this) {
$landingPage->setPlatform(null);
}
}
return $this;
}
}