<?php
namespace App\Entity\Federation;
use App\Entity\Media\Document;
use App\Entity\Site\Site;
use App\Entity\ThirdParty\Address;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Media\DocumentType;
use App\Entity\Media\Category;
use Symfony\Component\Validator\Context\ExecutionContext;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use App\Entity\Media\Quality;
/**
* @ORM\Entity(repositoryClass="App\Repository\Federation\RaceRepository")
* @ORM\Table(name="races")
* @UniqueEntity("name")
*/
class Race
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(length=255, unique=true)
*/
private $url;
/**
* @ORM\Column(type="string", length=255, nullable=false)
* @Assert\NotBlank()
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $facebookPage;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $copyright;
/**
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
*/
private $directoryName;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $pipelineConverter;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $bucketUser;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $bucketAdminUser;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $policy = false;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Assert\NotBlank()
*/
private $startDate;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Media\DocumentType", mappedBy="races")
*/
private $documentTypes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Media\Document", mappedBy="race", cascade={"remove"})
*/
private $documents;
/**
* @ORM\Column(type="datetime", nullable=false, name="created_date")
* @Gedmo\Timestampable(on="create")
*/
private $createdDate;
/**
* @ORM\Column(type="datetime", nullable=true, name="updated_date")
* @Gedmo\Timestampable(on="update")
*/
private $updatedDate;
/**
* @ORM\Column(type="integer", nullable=true, name="status")
*/
private $status = 1;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Federation\Participation", mappedBy="race", cascade={"remove"})
*/
private $participations;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Site\Site", mappedBy="race")
*/
private $sites;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ThirdParty\Address")
* @ORM\JoinColumn(name="address_id", referencedColumnName="id")
*/
private $address;
/**
* @var array
*
* @ORM\Column(name="contacts", type="json", nullable=true)
*/
private $contacts;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Media\Category", mappedBy="races")
*/
private $categories;
public function __construct()
{
$this->documentTypes = new ArrayCollection();
$this->participations = new ArrayCollection();
$this->sites = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->documents = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUrl(): ?string
{
return $this->url;
}
public function getDirectoryName(): ?string
{
return $this->directoryName;
}
public function setDirectoryName(?string $directoryName): self
{
$this->directoryName = $directoryName;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getFacebookPage(): ?string
{
return $this->facebookPage;
}
public function setFacebookPage(string $facebookPage): ?self
{
$this->facebookPage = $facebookPage;
return $this;
}
public function getCopyright(): ?string
{
return $this->copyright;
}
public function setCopyright(string $copyright): self
{
$this->copyright = $copyright;
return $this;
}
public function getPipelineConverter(): ?array
{
return $this->pipelineConverter;
}
public function setPipelineConverter(?array $pipelineConverter): self
{
$this->pipelineConverter = $pipelineConverter;
return $this;
}
public function getBucketUser(): ?array
{
return $this->bucketUser;
}
public function setBucketUser(?array $raceUser): self
{
$this->bucketUser = $raceUser;
return $this;
}
public function getBucketAdminUser(): ?array
{
return $this->bucketAdminUser;
}
public function setBucketAdminUser(?array $raceAdminUser): self
{
$this->bucketAdminUser = $raceAdminUser;
return $this;
}
public function hasPolicy(): ?bool
{
return $this->policy;
}
public function setPolicy(?bool $policy): self
{
$this->policy = $policy;
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
public function setStartDate(?\DateTimeInterface $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function getCreatedDate(): ?\DateTimeInterface
{
return $this->createdDate;
}
public function getUpdatedDate(): ?\DateTimeInterface
{
return $this->updatedDate;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(?int $status): self
{
$this->status = $status;
return $this;
}
/**
* @return Collection|DocumentType[]
*/
public function getDocumentTypes(): Collection
{
return $this->documentTypes;
}
public function addDocumentType(DocumentType $documentType): self
{
if (!$this->documentTypes->contains($documentType)) {
$this->documentTypes[] = $documentType;
$documentType->addRace($this);
}
return $this;
}
public function removeDocumentType(DocumentType $documentType): self
{
if ($this->documentTypes->contains($documentType)) {
$this->documentTypes->removeElement($documentType);
$documentType->removeRace($this);
}
return $this;
}
/**
* @return Collection|Participation[]
*/
public function getParticipations(): Collection
{
return $this->participations;
}
public function addParticipation(Participation $participation): self
{
if (!$this->participations->contains($participation)) {
$this->participations[] = $participation;
$participation->setRace($this);
}
return $this;
}
public function removeParticipation(Participation $participation): self
{
if ($this->participations->contains($participation)) {
$this->participations->removeElement($participation);
// set the owning side to null (unless already changed)
if ($participation->getRace() === $this) {
$participation->setRace(null);
}
}
return $this;
}
/**
* @return Collection|Site[]
*/
public function getSites(): Collection
{
return $this->sites;
}
public function addSite(Site $site): self
{
if (!$this->sites->contains($site)) {
$this->sites[] = $site;
$site->setRace($this);
}
return $this;
}
public function removeSite(Site $site): self
{
if ($this->sites->contains($site)) {
$this->sites->removeElement($site);
// set the owning side to null (unless already changed)
if ($site->getRace() === $this) {
$site->setRace(null);
}
}
return $this;
}
public function getAddress(): ?Address
{
return $this->address;
}
public function setAddress(?Address $address): self
{
$this->address = $address;
return $this;
}
/**
* @return Collection|Category[]
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
$category->addRace($this);
}
return $this;
}
public function removeCategory(Category $category): self
{
if ($this->categories->contains($category)) {
$this->categories->removeElement($category);
$category->removeRace($this);
}
return $this;
}
public function getContacts(): ?array
{
return $this->contacts;
}
public function setContacts(?array $contacts)
{
$this->contacts = $contacts;
return $this;
}
/**
* @Assert\Callback
*/
public function valiate(ExecutionContextInterface $context)
{
if ($this->documentTypes->count() == 0) {
$context->addViolation('Vous devez sélectionner au moins un type de document', array(), null);
}
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setRace($this);
}
return $this;
}
public function removeDocument(Document $document): self
{
if ($this->documents->contains($document)) {
$this->documents->removeElement($document);
// set the owning side to null (unless already changed)
if ($document->getRace() === $this) {
$document->setRace(null);
}
}
return $this;
}
public function allowUploadPicture()
{
$result = false;
foreach($this->getDocumentTypes() as $documentType)
if($documentType->getDirectoryName() == 'pictures')
$result = true;
return $result;
}
}