src/Entity/Site/AccessSite.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Site;
  3. use App\Entity\Federation\Classe;
  4. use App\Entity\Federation\Skipper;
  5. use App\Entity\Federation\Team;
  6. use App\Entity\Media\DocumentType;
  7. use App\Entity\User\User;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  15. use App\Entity\Federation\Boat;
  16. use App\Entity\Media\Category;
  17. use App\Entity\Media\Quality;
  18. use App\Entity\Media\ShareCart;
  19. /**
  20.  * @ORM\Entity(repositoryClass="App\Repository\Site\AccessSiteRepository")
  21.  * @ORM\Table(name="access_sites")
  22.  * @UniqueEntity(fields={"user", "site"}, message="accessSite.userSite")
  23.  */
  24. class AccessSite
  25. {
  26.     /**
  27.      * @ORM\Id
  28.      * @ORM\Column(type="integer")
  29.      * @ORM\GeneratedValue(strategy="AUTO")
  30.      */
  31.     private $id;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity="App\Entity\User\User", inversedBy="accessSites")
  34.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  35.      * @Assert\NotBlank()
  36.      */
  37.     private $user;
  38.     /**
  39.      * @ORM\ManyToOne(targetEntity="App\Entity\Site\Site", inversedBy="accessSites")
  40.      * @ORM\JoinColumn(name="site_id", referencedColumnName="id")
  41.      * @Assert\NotBlank()
  42.      */
  43.     private $site;
  44.     
  45.     /**
  46.      * @ORM\ManyToMany(targetEntity="App\Entity\Media\DocumentType", inversedBy="accessSites")
  47.      * @ORM\JoinTable(
  48.      *     name="access_site_document_types",
  49.      *     joinColumns={@ORM\JoinColumn(name="access_site_id", referencedColumnName="id", nullable=false)},
  50.      *     inverseJoinColumns={@ORM\JoinColumn(name="document_type_id", referencedColumnName="id", nullable=false)}
  51.      * )
  52.      * @Assert\NotBlank()
  53.      */
  54.     private $documentTypes;
  55.     
  56.     /**
  57.      * @ORM\Column(type="integer")
  58.      */
  59.     private $notification 0;
  60.     
  61.     /**
  62.      * @ORM\Column(type="integer")
  63.      */
  64.     private $pressReleaseSubscription 0;
  65.     /**
  66.      * @ORM\ManyToMany(targetEntity="App\Entity\Media\Category", inversedBy="accessSites")
  67.      * @ORM\JoinTable(
  68.      *     name="access_site_categories",
  69.      *     joinColumns={@ORM\JoinColumn(name="access_site_id", referencedColumnName="id", nullable=false)},
  70.      *     inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=false)}
  71.      * )
  72.      */
  73.     private $categories;
  74.     
  75.     /**
  76.      * @ORM\ManyToMany(targetEntity="App\Entity\Federation\Skipper", inversedBy="accessSites")
  77.      * @ORM\JoinTable(
  78.      *     name="access_site_skippers",
  79.      *     joinColumns={@ORM\JoinColumn(name="access_site_id", referencedColumnName="id", nullable=false)},
  80.      *     inverseJoinColumns={@ORM\JoinColumn(name="skipper_id", referencedColumnName="id", nullable=false)}
  81.      * )
  82.      */
  83.     private $skippers;
  84.     
  85.     /**
  86.      * @ORM\ManyToMany(targetEntity="App\Entity\Federation\Boat", inversedBy="accessSites")
  87.      * @ORM\JoinTable(
  88.      *     name="access_site_boats",
  89.      *     joinColumns={@ORM\JoinColumn(name="access_site_id", referencedColumnName="id", nullable=false)},
  90.      *     inverseJoinColumns={@ORM\JoinColumn(name="boat_id", referencedColumnName="id", nullable=false)}
  91.      * )
  92.      */
  93.     private $boats;
  94.     
  95.     /**
  96.      * @ORM\ManyToMany(targetEntity="App\Entity\Federation\Team", inversedBy="accessSites")
  97.      * @ORM\JoinTable(
  98.      *     name="access_site_teams",
  99.      *     joinColumns={@ORM\JoinColumn(name="access_siteid", referencedColumnName="id", nullable=false)},
  100.      *     inverseJoinColumns={@ORM\JoinColumn(name="team_id", referencedColumnName="id", nullable=false)}
  101.      * )
  102.      */
  103.     private $teams;
  104.     
  105.     /**
  106.      * @ORM\ManyToMany(targetEntity="App\Entity\Federation\Classe", inversedBy="accessSites")
  107.      * @ORM\JoinTable(
  108.      *     name="access_site_classes",
  109.      *     joinColumns={@ORM\JoinColumn(name="access_site_id", referencedColumnName="id", nullable=false)},
  110.      *     inverseJoinColumns={@ORM\JoinColumn(name="classe_id", referencedColumnName="id", nullable=false)}
  111.      * )
  112.      */
  113.     private $classes;
  114.     
  115.     /**
  116.      * @ORM\ManyToMany(targetEntity="App\Entity\Media\Quality")
  117.      * @ORM\JoinTable(
  118.      *     name="access_site_qualities",
  119.      *     joinColumns={@ORM\JoinColumn(name="access_site_id", referencedColumnName="id", nullable=false)},
  120.      *     inverseJoinColumns={@ORM\JoinColumn(name="quality_id", referencedColumnName="id", nullable=false)}
  121.      * )
  122.      */
  123.     private $qualities;
  124.     /**
  125.      * @ORM\OneToMany(targetEntity="App\Entity\Media\ShareCart", mappedBy="accessSite", cascade={"remove"})
  126.      */
  127.     private $shareCarts;
  128.     
  129.     /**
  130.      * @ORM\Column(type="text", nullable=true) 
  131.      */
  132.     private $refusalReason;
  133.     
  134.     /**
  135.      * @ORM\Column(type="text", nullable=true) 
  136.      */
  137.     private $complement;
  138.     
  139.     /**
  140.      * @ORM\Column(type="datetime", nullable=false, name="created_date")
  141.      * @Gedmo\Timestampable(on="create")
  142.      */
  143.     private $createdDate;
  144.     
  145.     /**
  146.      * @ORM\Column(type="datetime", nullable=true, name="updated_date")
  147.      * @Gedmo\Timestampable(on="update")
  148.      */
  149.     private $updatedDate;
  150.     
  151.     /**
  152.      * @ORM\Column(type="integer", nullable=false, name="status")
  153.      */
  154.     private $status 2;
  155.     public function __construct()
  156.     {
  157.         $this->documentTypes = new ArrayCollection();
  158.         $this->categories = new ArrayCollection();
  159.         $this->skippers = new ArrayCollection();
  160.         $this->boats = new ArrayCollection();
  161.         $this->teams = new ArrayCollection();
  162.         $this->classes = new ArrayCollection();
  163.         $this->qualities = new ArrayCollection();
  164.         $this->shareCarts = new ArrayCollection();
  165.     }
  166.     public function getId(): ?int
  167.     {
  168.         return $this->id;
  169.     }
  170.     public function getNotification(): ?int
  171.     {
  172.         return $this->notification;
  173.     }
  174.     public function setNotification(int $notification): self
  175.     {
  176.         $this->notification $notification;
  177.         return $this;
  178.     }
  179.     
  180.     public function getPressReleaseSubscription(): ?int
  181.     {
  182.         return $this->pressReleaseSubscription;
  183.     }
  184.     public function setPressReleaseSubscription(int $pressReleaseSubscription): self
  185.     {
  186.         $this->pressReleaseSubscription $pressReleaseSubscription;
  187.         return $this;
  188.     }
  189.     public function getCreatedDate(): ?\DateTimeInterface
  190.     {
  191.         return $this->createdDate;
  192.     }
  193.     public function getUpdatedDate(): ?\DateTimeInterface
  194.     {
  195.         return $this->updatedDate;
  196.     }
  197.    
  198.     public function getStatus(): ?int
  199.     {
  200.         return $this->status;
  201.     }
  202.     public function setStatus(int $status): self
  203.     {
  204.         $this->status $status;
  205.         return $this;
  206.     }
  207.     public function getUser(): ?User
  208.     {
  209.         return $this->user;
  210.     }
  211.     public function setUser(?User $user): self
  212.     {
  213.         $this->user $user;
  214.         return $this;
  215.     }
  216.     public function getSite(): ?Site
  217.     {
  218.         return $this->site;
  219.     }
  220.     public function setSite(?Site $site): self
  221.     {
  222.         $this->site $site;
  223.         return $this;
  224.     }
  225.     
  226.     public function getRefusalReason(): ?string
  227.     {
  228.         return $this->refusalReason;
  229.     }
  230.     
  231.     public function setRefusalReason(string $refusalReason null): self
  232.     {
  233.         $this->refusalReason $refusalReason;
  234.         
  235.         return $this;
  236.     }
  237.     
  238.     public function getComplement(): ?string
  239.     {
  240.         return $this->complement;
  241.     }
  242.     
  243.     public function setComplement(string $complement null): self
  244.     {
  245.         $this->complement $complement;
  246.         
  247.         return $this;
  248.     }
  249.     /**
  250.      * @return Collection|DocumentType[]
  251.      */
  252.     public function getDocumentTypes(): Collection
  253.     {
  254.         return $this->documentTypes;
  255.     }
  256.     public function addDocumentType(DocumentType $documentType): self
  257.     {
  258.         if (!$this->documentTypes->contains($documentType)) {
  259.             $this->documentTypes[] = $documentType;
  260.         }
  261.         return $this;
  262.     }
  263.     public function removeDocumentType(DocumentType $documentType): self
  264.     {
  265.         if ($this->documentTypes->contains($documentType)) {
  266.             $this->documentTypes->removeElement($documentType);
  267.         }
  268.         return $this;
  269.     }
  270.     
  271.     /**
  272.      * @return Collection|Category[]
  273.      */
  274.     public function getCategories(): Collection
  275.     {
  276.         return $this->categories;
  277.     }
  278.     
  279.     public function addCategory(Category $category): self
  280.     {
  281.         if (!$this->categories->contains($category)) {
  282.             $this->categories[] = $category;
  283.         }
  284.          
  285.         return $this;
  286.     }
  287.     
  288.     public function removeCategory(Category $category): self
  289.     {
  290.         if ($this->categories->contains($category)) {
  291.             $this->categories->removeElement($category);
  292.         }
  293.         
  294.         return $this;
  295.     }
  296.     /**
  297.      * @return Collection|Skipper[]
  298.      */
  299.     public function getSkippers(): Collection
  300.     {
  301.         return $this->skippers;
  302.     }
  303.     public function addSkipper(Skipper $skipper): self
  304.     {
  305.         if (!$this->skippers->contains($skipper)) {
  306.             $this->skippers[] = $skipper;
  307.         }
  308.         return $this;
  309.     }
  310.     public function removeSkipper(Skipper $skipper): self
  311.     {
  312.         if ($this->skippers->contains($skipper)) {
  313.             $this->skippers->removeElement($skipper);
  314.         }
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return Collection|Boat[]
  319.      */
  320.     public function getBoats(): Collection
  321.     {
  322.         return $this->boats;
  323.     }
  324.     public function addBoat(Boat $boat): self
  325.     {
  326.         if (!$this->boats->contains($boat)) {
  327.             $this->boats[] = $boat;
  328.         }
  329.         return $this;
  330.     }
  331.     public function removeBoat(Boat $boat): self
  332.     {
  333.         if ($this->boats->contains($boat)) {
  334.             $this->boats->removeElement($boat);
  335.         }
  336.         return $this;
  337.     }
  338.     /**
  339.      * @return Collection|Team[]
  340.      */
  341.     public function getTeams(): Collection
  342.     {
  343.         return $this->teams;
  344.     }
  345.     public function addTeam(Team $team): self
  346.     {
  347.         if (!$this->teams->contains($team)) {
  348.             $this->teams[] = $team;
  349.         }
  350.         return $this;
  351.     }
  352.     public function removeTeam(Team $team): self
  353.     {
  354.         if ($this->teams->contains($team)) {
  355.             $this->teams->removeElement($team);
  356.         }
  357.         return $this;
  358.     }
  359.     /**
  360.      * @return Collection|Classe[]
  361.      */
  362.     public function getClasses(): Collection
  363.     {
  364.         return $this->classes;
  365.     }
  366.     public function addClass(Classe $class): self
  367.     {
  368.         if (!$this->classes->contains($class)) {
  369.             $this->classes[] = $class;
  370.         }
  371.         return $this;
  372.     }
  373.     public function removeClass(Classe $class): self
  374.     {
  375.         if ($this->classes->contains($class)) {
  376.             $this->classes->removeElement($class);
  377.         }
  378.         return $this;
  379.     }
  380.     
  381.     /**
  382.      * @return Collection|Quality[]
  383.      */
  384.     public function getQualities(): Collection
  385.     {
  386.         return $this->qualities;
  387.     }
  388.     public function addQuality(Quality $quality): self
  389.     {
  390.         if (!$this->qualities->contains($quality)) {
  391.             $this->qualities[] = $quality;
  392.         }
  393.         return $this;
  394.     }
  395.     public function removeQuality(Quality $quality): self
  396.     {
  397.         if ($this->qualities->contains($quality)) {
  398.             $this->qualities->removeElement($quality);
  399.         }
  400.         return $this;
  401.     }
  402.     /**
  403.      * @return Collection|ShareCart[]
  404.      */
  405.     public function getShareCarts(): Collection
  406.     {
  407.         return $this->shareCarts;
  408.     }
  409.     public function addShareCart(ShareCart $shareCart): self
  410.     {
  411.         if (!$this->shareCarts->contains($shareCart)) {
  412.             $this->shareCarts[] = $shareCart;
  413.         }
  414.         return $this;
  415.     }
  416.     public function removeShareCart(AccessSite $shareCart): self
  417.     {
  418.         if ($this->shareCarts->contains($shareCart)) {
  419.             $this->shareCarts->removeElement($shareCart);
  420.         }
  421.         return $this;
  422.     }
  423.     
  424.     /**
  425.      * @Assert\Callback
  426.      */
  427.     
  428.     public function valiate(ExecutionContextInterface $context)
  429.     {
  430.         if ($this->documentTypes->count() == 0) {
  431.             $context->addViolation('Vous devez sélectionner au moins un type de document', array(), null);
  432.         }
  433.     }
  434.     public function allowToDownloadPictures(): bool
  435.     {
  436.         if($this->qualities->count() == 0)
  437.             return false;
  438.         return true;
  439.     }
  440. }