<?php
namespace App\Entity;
use App\Repository\AffiliateRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Vich\Uploadable
*/
#[ORM\Entity(repositoryClass: AffiliateRepository::class)]
class Affiliate
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'string', length: 255)]
private $code;
#[ORM\OneToMany(mappedBy: 'affiliate', targetEntity: AccountingFirm::class)]
private $accountingFirms;
/**
* @Vich\UploadableField(mapping="podcast_middle_file", fileNameProperty="contractFilename")
* @var File|null
*/
private ?File $contractFile = null;
#[ORM\Column(nullable: true)]
private ?string $contractFilename = null;
#[ORM\Column(type: 'datetime_immutable')]
private ?DateTimeImmutable $updateAt;
#[ORM\OneToMany(mappedBy: 'affiliate', targetEntity: AffiliateRequest::class)]
private $affiliateRequests;
#[ORM\OneToMany(mappedBy: 'affiliate', targetEntity: AffiliateClient::class)]
private $affiliateClients;
#[ORM\OneToMany(mappedBy: 'affiliate', targetEntity: User::class, cascade: ['remove'])]
private $users;
#[ORM\Column(type: 'string', length: 50, nullable: true)]
private $primaryColor;
#[ORM\Column(type: 'string', length: 50, nullable: true)]
private $secondaryColor;
public function __construct()
{
$this->accountingFirms = new ArrayCollection();
$this->affiliateRequests = new ArrayCollection();
$this->affiliateClients = new ArrayCollection();
$this->users = new ArrayCollection();
}
public function __toString(): string
{
return $this->name;
}
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 getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
/**
* @return Collection<int, AccountingFirm>
*/
public function getAccountingFirms(): Collection
{
return $this->accountingFirms;
}
public function addAccountingFirm(AccountingFirm $accountingFirm): self
{
if (!$this->accountingFirms->contains($accountingFirm)) {
$this->accountingFirms[] = $accountingFirm;
$accountingFirm->setAffiliate($this);
}
return $this;
}
public function removeAccountingFirm(AccountingFirm $accountingFirm): self
{
if ($this->accountingFirms->removeElement($accountingFirm)) {
// set the owning side to null (unless already changed)
if ($accountingFirm->getAffiliate() === $this) {
$accountingFirm->setAffiliate(null);
}
}
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|UploadedFile|null $imageFile
*/
public function setContractFile(?File $contractFile = null): void
{
$this->contractFile = $contractFile;
if (null !== $contractFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updateAt = new DateTimeImmutable();
}
}
public function getContractFile(): ?File
{
return $this->contractFile;
}
public function setContractFileName(?string $contractFilename): void
{
$this->contractFilename = $contractFilename;
}
public function getContractFileName(): ?string
{
return $this->contractFilename;
}
public function getUpdateAt(): ?DateTimeImmutable
{
return $this->updateAt;
}
public function setUpdateAt(DateTimeImmutable $updateAt): self
{
$this->updateAt = $updateAt;
return $this;
}
/**
* @return Collection<int, AffiliateRequest>
*/
public function getAffiliateRequests(): Collection
{
return $this->affiliateRequests;
}
public function addAffiliateRequest(AffiliateRequest $affiliateRequest): self
{
if (!$this->affiliateRequests->contains($affiliateRequest)) {
$this->affiliateRequests[] = $affiliateRequest;
$affiliateRequest->setAffiliate($this);
}
return $this;
}
public function removeAffiliateRequest(AffiliateRequest $affiliateRequest): self
{
if ($this->affiliateRequests->removeElement($affiliateRequest)) {
// set the owning side to null (unless already changed)
if ($affiliateRequest->getAffiliate() === $this) {
$affiliateRequest->setAffiliate(null);
}
}
return $this;
}
/**
* @return Collection<int, AffiliateClient>
*/
public function getAffiliateClients(): Collection
{
return $this->affiliateClients;
}
public function addAffiliateClient(AffiliateClient $affiliateClient): self
{
if (!$this->affiliateClients->contains($affiliateClient)) {
$this->affiliateClients[] = $affiliateClient;
$affiliateClient->setAffiliate($this);
}
return $this;
}
public function removeAffiliateClient(AffiliateClient $affiliateClient): self
{
if ($this->affiliateClients->removeElement($affiliateClient)) {
// set the owning side to null (unless already changed)
if ($affiliateClient->getAffiliate() === $this) {
$affiliateClient->setAffiliate(null);
}
}
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setAffiliate($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->getAffiliate() === $this) {
$user->setAffiliate(null);
}
}
return $this;
}
/**
* @return string
*/
public function getPrimaryColor(): ?string
{
return $this->primaryColor;
}
/**
* @param string $primaryColor
* @return Affiliate
*/
public function setPrimaryColor(?string $primaryColor): Affiliate
{
$this->primaryColor = $primaryColor;
return $this;
}
/**
* @return string
*/
public function getSecondaryColor(): ?string
{
return $this->secondaryColor;
}
/**
* @param string $secondaryColor
* @return Affiliate
*/
public function setSecondaryColor(?string $secondaryColor): Affiliate
{
$this->secondaryColor = $secondaryColor;
return $this;
}
}