src/Entity/Federation/Race.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Federation;
  3. use App\Entity\Media\Document;
  4. use App\Entity\Site\Site;
  5. use App\Entity\ThirdParty\Address;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use App\Entity\Media\DocumentType;
  12. use App\Entity\Media\Category;
  13. use Symfony\Component\Validator\Context\ExecutionContext;
  14. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. use App\Entity\Media\Quality;
  17. /**
  18.  * @ORM\Entity(repositoryClass="App\Repository\Federation\RaceRepository")
  19.  * @ORM\Table(name="races")
  20.  * @UniqueEntity("name")
  21.  */
  22. class Race
  23. {
  24.     /**
  25.      * @ORM\Id
  26.      * @ORM\Column(type="integer")
  27.      * @ORM\GeneratedValue(strategy="AUTO")
  28.      */
  29.     private $id;
  30.     
  31.     /**
  32.      * @Gedmo\Slug(fields={"name"})
  33.      * @ORM\Column(length=255, unique=true)
  34.      */
  35.     private $url;
  36.     /**
  37.      * @ORM\Column(type="string", length=255, nullable=false)
  38.      * @Assert\NotBlank()
  39.      */
  40.     private $name;
  41.     
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      */
  45.     private $facebookPage;
  46.     
  47.     /**
  48.      * @ORM\Column(type="string", length=255, nullable=true)
  49.      */
  50.     private $copyright;
  51.     
  52.     /**
  53.      * @ORM\Column(type="string", length=255, nullable=true, unique=true)
  54.      */
  55.     private $directoryName;
  56.     
  57.     /**
  58.      * @ORM\Column(type="array", nullable=true)
  59.      */
  60.     private $pipelineConverter;
  61.     
  62.     /**
  63.      * @ORM\Column(type="array", nullable=true)
  64.      */
  65.     private $bucketUser;
  66.     
  67.     /**
  68.      * @ORM\Column(type="array", nullable=true)
  69.      */
  70.     private $bucketAdminUser;
  71.     
  72.     /**
  73.      * @ORM\Column(type="boolean", nullable=true)
  74.      */
  75.     private $policy false;
  76.     /**
  77.      * @ORM\Column(type="datetime", nullable=true)
  78.      * @Assert\NotBlank()
  79.      */
  80.     private $startDate;
  81.     
  82.     /**
  83.      * @ORM\ManyToMany(targetEntity="App\Entity\Media\DocumentType", mappedBy="races")
  84.      */
  85.     private $documentTypes;
  86.     
  87.     /**
  88.      * @ORM\OneToMany(targetEntity="App\Entity\Media\Document", mappedBy="race", cascade={"remove"})
  89.      */
  90.     private $documents;
  91.     /**
  92.      * @ORM\Column(type="datetime", nullable=false, name="created_date")
  93.      * @Gedmo\Timestampable(on="create")
  94.      */
  95.     private $createdDate;
  96.     /**
  97.      * @ORM\Column(type="datetime", nullable=true, name="updated_date")
  98.      * @Gedmo\Timestampable(on="update")
  99.      */
  100.     private $updatedDate;
  101.     /**
  102.      * @ORM\Column(type="integer", nullable=true, name="status")
  103.      */
  104.     private $status 1;
  105.     /**
  106.      * @ORM\OneToMany(targetEntity="App\Entity\Federation\Participation", mappedBy="race", cascade={"remove"})
  107.      */
  108.     private $participations;
  109.    
  110.     /**
  111.      * @ORM\OneToMany(targetEntity="App\Entity\Site\Site", mappedBy="race")
  112.      */
  113.     private $sites;
  114.     /**
  115.      * @ORM\ManyToOne(targetEntity="App\Entity\ThirdParty\Address")
  116.      * @ORM\JoinColumn(name="address_id", referencedColumnName="id")
  117.      */
  118.     private $address;
  119.     
  120.     /**
  121.      * @var array
  122.      *
  123.      * @ORM\Column(name="contacts", type="json", nullable=true)
  124.      */
  125.     private $contacts;
  126.     
  127.     /**
  128.      * @ORM\ManyToMany(targetEntity="App\Entity\Media\Category", mappedBy="races")
  129.      */
  130.     private $categories;
  131.     public function __construct()
  132.     {
  133.         $this->documentTypes = new ArrayCollection();
  134.         $this->participations = new ArrayCollection();
  135.         $this->sites = new ArrayCollection();
  136.         $this->categories = new ArrayCollection();
  137.         $this->documents = new ArrayCollection();
  138.     }
  139.     public function getId(): ?int
  140.     {
  141.         return $this->id;
  142.     }
  143.     public function getUrl(): ?string
  144.     {
  145.         return $this->url;
  146.     }
  147.      
  148.     public function getDirectoryName(): ?string
  149.     {
  150.         return $this->directoryName;
  151.     }
  152.     
  153.     public function setDirectoryName(?string $directoryName): self
  154.     {
  155.         $this->directoryName $directoryName;
  156.         
  157.         return $this;
  158.     }
  159.     public function getName(): ?string
  160.     {
  161.         return $this->name;
  162.     }
  163.     public function setName(string $name): self
  164.     {
  165.         $this->name $name;
  166.         return $this;
  167.     }
  168.     
  169.     public function getFacebookPage(): ?string
  170.     {
  171.         return $this->facebookPage;
  172.     }
  173.     
  174.     public function setFacebookPage(string $facebookPage): ?self
  175.     {
  176.         $this->facebookPage $facebookPage;
  177.         
  178.         return $this;
  179.     }
  180.     
  181.     public function getCopyright(): ?string
  182.     {
  183.         return $this->copyright;
  184.     }
  185.     
  186.     public function setCopyright(string $copyright): self
  187.     {
  188.         $this->copyright $copyright;
  189.         
  190.         return $this;
  191.     }
  192.     
  193.     public function getPipelineConverter(): ?array
  194.     {
  195.         return $this->pipelineConverter;
  196.     }
  197.     
  198.     public function setPipelineConverter(?array $pipelineConverter): self
  199.     {
  200.         $this->pipelineConverter $pipelineConverter;
  201.         
  202.         return $this;
  203.     }
  204.     
  205.     public function getBucketUser(): ?array
  206.     {
  207.         return $this->bucketUser;
  208.     }
  209.     
  210.     public function setBucketUser(?array $raceUser): self
  211.     {
  212.         $this->bucketUser $raceUser;
  213.         
  214.         return $this;
  215.     }
  216.     
  217.     public function getBucketAdminUser(): ?array
  218.     {
  219.         return $this->bucketAdminUser;
  220.     }
  221.     
  222.     public function setBucketAdminUser(?array $raceAdminUser): self
  223.     {
  224.         $this->bucketAdminUser $raceAdminUser;
  225.         
  226.         return $this;
  227.     }
  228.     
  229.     public function hasPolicy(): ?bool
  230.     {
  231.         return $this->policy;
  232.     }
  233.     
  234.     public function setPolicy(?bool $policy): self
  235.     {
  236.         $this->policy $policy;
  237.         
  238.         return $this;
  239.     }
  240.     public function getStartDate(): ?\DateTimeInterface
  241.     {
  242.         return $this->startDate;
  243.     }
  244.     public function setStartDate(?\DateTimeInterface $startDate): self
  245.     {
  246.         $this->startDate $startDate;
  247.         return $this;
  248.     }
  249.    
  250.     public function getCreatedDate(): ?\DateTimeInterface
  251.     {
  252.         return $this->createdDate;
  253.     }
  254.    
  255.     public function getUpdatedDate(): ?\DateTimeInterface
  256.     {
  257.         return $this->updatedDate;
  258.     }
  259.    
  260.     public function getStatus(): ?int
  261.     {
  262.         return $this->status;
  263.     }
  264.     public function setStatus(?int $status): self
  265.     {
  266.         $this->status $status;
  267.         return $this;
  268.     }
  269.     /**
  270.      * @return Collection|DocumentType[]
  271.      */
  272.     public function getDocumentTypes(): Collection
  273.     {
  274.         return $this->documentTypes;
  275.     }
  276.     public function addDocumentType(DocumentType $documentType): self
  277.     {
  278.         if (!$this->documentTypes->contains($documentType)) {
  279.             $this->documentTypes[] = $documentType;
  280.             $documentType->addRace($this);
  281.         }
  282.         return $this;
  283.     }
  284.     public function removeDocumentType(DocumentType $documentType): self
  285.     {
  286.         if ($this->documentTypes->contains($documentType)) {
  287.             $this->documentTypes->removeElement($documentType);
  288.             $documentType->removeRace($this);
  289.         }
  290.         return $this;
  291.     }
  292.     /**
  293.      * @return Collection|Participation[]
  294.      */
  295.     public function getParticipations(): Collection
  296.     {
  297.         return $this->participations;
  298.     }
  299.     public function addParticipation(Participation $participation): self
  300.     {
  301.         if (!$this->participations->contains($participation)) {
  302.             $this->participations[] = $participation;
  303.             $participation->setRace($this);
  304.         }
  305.         return $this;
  306.     }
  307.     public function removeParticipation(Participation $participation): self
  308.     {
  309.         if ($this->participations->contains($participation)) {
  310.             $this->participations->removeElement($participation);
  311.             // set the owning side to null (unless already changed)
  312.             if ($participation->getRace() === $this) {
  313.                 $participation->setRace(null);
  314.             }
  315.         }
  316.         return $this;
  317.     }
  318.     /**
  319.      * @return Collection|Site[]
  320.      */
  321.     public function getSites(): Collection
  322.     {
  323.         return $this->sites;
  324.     }
  325.     public function addSite(Site $site): self
  326.     {
  327.         if (!$this->sites->contains($site)) {
  328.             $this->sites[] = $site;
  329.             $site->setRace($this);
  330.         }
  331.         return $this;
  332.     }
  333.     public function removeSite(Site $site): self
  334.     {
  335.         if ($this->sites->contains($site)) {
  336.             $this->sites->removeElement($site);
  337.             // set the owning side to null (unless already changed)
  338.             if ($site->getRace() === $this) {
  339.                 $site->setRace(null);
  340.             }
  341.         }
  342.         return $this;
  343.     }
  344.     public function getAddress(): ?Address
  345.     {
  346.         return $this->address;
  347.     }
  348.     public function setAddress(?Address $address): self
  349.     {
  350.         $this->address $address;
  351.         return $this;
  352.     }
  353.     /**
  354.      * @return Collection|Category[]
  355.      */
  356.     public function getCategories(): Collection
  357.     {
  358.         return $this->categories;
  359.     }
  360.     public function addCategory(Category $category): self
  361.     {
  362.         if (!$this->categories->contains($category)) {
  363.             $this->categories[] = $category;
  364.             $category->addRace($this);
  365.         }
  366.         return $this;
  367.     } 
  368.     public function removeCategory(Category $category): self
  369.     {
  370.         if ($this->categories->contains($category)) {
  371.             $this->categories->removeElement($category);
  372.             $category->removeRace($this);
  373.         }
  374.         return $this;
  375.     }
  376.     
  377.     public function getContacts(): ?array
  378.     {
  379.         return $this->contacts;
  380.     }
  381.     
  382.     public function setContacts(?array $contacts)
  383.     {
  384.         $this->contacts $contacts;
  385.         
  386.         return $this;
  387.     } 
  388.     
  389.     /**
  390.      * @Assert\Callback
  391.      */
  392.     
  393.     public function valiate(ExecutionContextInterface $context)
  394.     {
  395.         if ($this->documentTypes->count() == 0) {
  396.             $context->addViolation('Vous devez sélectionner au moins un type de document', array(), null);
  397.         }
  398.     }
  399.   
  400.     /**
  401.      * @return Collection|Document[]
  402.      */
  403.     public function getDocuments(): Collection
  404.     {
  405.         return $this->documents;
  406.     }
  407.     public function addDocument(Document $document): self
  408.     {
  409.         if (!$this->documents->contains($document)) {
  410.             $this->documents[] = $document;
  411.             $document->setRace($this);
  412.         }
  413.         return $this;
  414.     }
  415.     public function removeDocument(Document $document): self
  416.     {
  417.         if ($this->documents->contains($document)) {
  418.             $this->documents->removeElement($document);
  419.             // set the owning side to null (unless already changed)
  420.             if ($document->getRace() === $this) {
  421.                 $document->setRace(null);
  422.             }
  423.         }
  424.         return $this;
  425.     }
  426.     public function allowUploadPicture()
  427.     {
  428.         $result false;
  429.         foreach($this->getDocumentTypes() as $documentType)
  430.             if($documentType->getDirectoryName() == 'pictures')
  431.                 $result true;
  432.         return $result;
  433.     }
  434. }