src/Entity/Club.php line 95

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\Api\Ad\GetAdsFromClubController;
  5. use App\Controller\Api\Club\GetClubHomepageController;
  6. use App\Controller\Api\Club\GetClubLocalizeController;
  7. use App\Controller\Api\Club\GetClubWidgetController;
  8. use App\Controller\Api\Company\GetCompaniesFromClubController;
  9. use App\Controller\Api\Post\GetPostsFromClubController;
  10. use App\Controller\Api\User\GetUsersFromClubController;
  11. use App\Repository\ClubRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\DBAL\Types\Types;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. #[ORM\Entity(repositoryClassClubRepository::class)]
  19. #[ApiResource(
  20.     itemOperations: [
  21.         'get',
  22.         'put',
  23.         'delete',
  24.         'get_companies' => [
  25.             'normalization_context' => [
  26.                 'groups' => 'read:club:collection:getCompanies',
  27.             ],
  28.             'controller' => GetCompaniesFromClubController::class,
  29.             'method' => 'POST',
  30.             'path' => '/public/clubs/{id}/companies',
  31.         ],
  32.         'get_club_localize' => [
  33.             'normalization_context' => [
  34.                 'groups' => 'read:club:collection:getClubLocalize',
  35.             ],
  36.             'controller' => GetClubLocalizeController::class,
  37.             'method' => 'POST',
  38.             'path' => '/public/localize',
  39.             'read' => false,
  40.         ],
  41.         'get_posts' => [
  42.             'normalization_context' => [
  43.                 'groups' => 'read:club:collection:getPosts',
  44.             ],
  45.             'controller' => GetPostsFromClubController::class,
  46.             'method' => 'POST',
  47.             'path' => '/public/clubs/{id}/posts',
  48.         ],
  49.         'get_widgets' => [
  50.             'normalization_context' => [
  51.                 'groups' => 'read:club:collection:getWidgets',
  52.             ],
  53.             'controller' => GetClubWidgetController::class,
  54.             'method' => 'POST',
  55.             'path' => '/public/clubs/{id}/widgets',
  56.         ],
  57.         'get_homepage' => [
  58.             'controller' => GetClubHomepageController::class,
  59.             'method' => 'POST',
  60.             'path' => '/public/clubs/{id}/homepage',
  61.             'read' => false,
  62.         ],
  63.         'get_ads' => [
  64.             'normalization_context' => [
  65.                 'groups' => 'read:club:collection:getAds',
  66.             ],
  67.             'controller' => GetAdsFromClubController::class,
  68.             'method' => 'POST',
  69.             'path' => '/public/clubs/{id}/ads',
  70.         ],
  71.         'post_alert' => [
  72.             'normalization_context' => [
  73.                 'groups' => 'read:club:collection:getUsers',
  74.             ],
  75.             'controller' => GetUsersFromClubController::class,
  76.             'method' => 'POST',
  77.             'path' => '/clubs/{id}/users',
  78.         ],
  79.         'get_users' => [
  80.             'normalization_context' => [
  81.                 'groups' => 'read:club:collection:getUsers',
  82.             ],
  83.             'controller' => GetUsersFromClubController::class,
  84.             'method' => 'POST',
  85.             'path' => '/clubs/{id}/users',
  86.         ],
  87.     ],
  88.     normalizationContext: [
  89.         'groups' => 'read:club:collection',
  90.     ]
  91. )]
  92. class Club
  93. {
  94.     #[ORM\Id]
  95.     #[ORM\GeneratedValue]
  96.     #[ORM\Column]
  97.     #[Groups([
  98.         'read:user:item:me',
  99.         'read:club:collection:getCompanies',
  100.         'read:club:collection',
  101.         'read:club:collection:getClubLocalize',
  102.         'read:company:collection:get',
  103.     ])]
  104.     private ?int $id null;
  105.     #[ORM\Column(length255)]
  106.     #[Groups([
  107.         'read:user:item:me',
  108.         'read:club:collection:getCompanies',
  109.         'read:club:collection:getClubLocalize',
  110.         'read:company:collection:get',
  111.     ])]
  112.     #[Assert\Length(
  113.         max255,
  114.         maxMessage"Le lien doit faire maximum 255 caractères.",
  115.     )]
  116.     private ?string $name null;
  117.     #[ORM\OneToMany(mappedBy'club'targetEntityPost::class, cascade: ["persist"])]
  118.     private Collection $posts;
  119.     #[ORM\OneToMany(mappedBy'club'targetEntityMembership::class, cascade: ["persist"])]
  120.     private Collection $memberships;
  121.     #[ORM\OneToMany(mappedBy'club'targetEntityPhoto::class, cascade: ["persist"])]
  122.     private Collection $photos;
  123.     #[ORM\OneToMany(mappedBy'club'targetEntityAd::class)]
  124.     private Collection $ads;
  125.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  126.     private ?string $theme null;
  127.     #[ORM\ManyToOne(inversedBy'clubs'cascade: ["remove"])]
  128.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  129.     #[Groups([
  130.         'read:user:item:me',
  131.         'read:club:collection:getClubLocalize',
  132.     ])]
  133.     private ?Address $address null;
  134.     #[Groups([
  135.         'read:user:item:me',
  136.         'read:club:collection:getClubLocalize',
  137.     ])]
  138.     private ?float $distance null;
  139.     #[ORM\OneToMany(mappedBy'club'targetEntityUserClub::class)]
  140.     private Collection $userClubs;
  141.     #[ORM\OneToMany(mappedBy'club'targetEntityWidget::class)]
  142.     #[Groups([
  143.         'read:club:collection:getWidgets',
  144.     ])]
  145.     private Collection $widgets;
  146.     #[Groups([
  147.         'read:user:item:me',
  148.         'read:club:collection:getClubLocalize',
  149.     ])]
  150.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  151.     private ?string $homeMessage null;
  152.     #[ORM\OneToMany(mappedBy'club'targetEntityDeal::class)]
  153.     private Collection $deals;
  154.     #[ORM\OneToMany(mappedBy'club'targetEntityClubManager::class, cascade: ["persist"])]
  155.     private Collection $clubManagers;
  156.     #[ORM\OneToMany(mappedBy'club'targetEntityAlert::class, orphanRemovaltrue)]
  157.     private Collection $alerts;
  158.     #[ORM\OneToMany(mappedBy'club'targetEntityClubPresentation::class, orphanRemovaltrue)]
  159.     private Collection $clubPresentations;
  160.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  161.     #[Groups([
  162.         'read:user:item:me',
  163.         'read:club:collection:getClubLocalize',
  164.     ])]
  165.     #[Assert\Url(
  166.         message"Ce lien {{ value }} n'est pas un lien valide.",
  167.     )]
  168.     private ?string $website null;
  169.     #[ORM\Column(length255nullabletrue)]
  170.     #[Groups([
  171.         'read:user:item:me',
  172.         'read:club:collection:getClubLocalize',
  173.     ])]
  174.     #[Assert\Regex(
  175.         pattern'/^[0-9]{10}$/',
  176.         message'Doit être composé de 10 chiffres sans espace ni point'
  177.     )]
  178.     private ?string $phone null;
  179.     #[ORM\Column(length255nullabletrue)]
  180.     #[Groups([
  181.         'read:user:item:me',
  182.         'read:club:collection:getClubLocalize',
  183.     ])]
  184.     #[Assert\Email(
  185.         message"Cet Email {{ value }} n'est pas un email valide.",
  186.     )]
  187.     private ?string $email null;
  188.     public function __construct()
  189.     {
  190.         $this->posts = new ArrayCollection();
  191.         $this->memberships = new ArrayCollection();
  192.         $this->photos = new ArrayCollection();
  193.         $this->ads = new ArrayCollection();
  194.         $this->userClubs = new ArrayCollection();
  195.         $this->widgets = new ArrayCollection();
  196.         $this->deals = new ArrayCollection();
  197.         $this->clubManagers = new ArrayCollection();
  198.         $this->alerts = new ArrayCollection();
  199.         $this->clubPresentations = new ArrayCollection();
  200.     }
  201.     public function __toString(): string
  202.     {
  203.         return $this->name;
  204.     }
  205.     public function getDistance(): ?float
  206.     {
  207.         return $this->distance;
  208.     }
  209.     public function setDistance(?float $distance): self
  210.     {
  211.         $this->distance $distance;
  212.         return $this;
  213.     }
  214.     #[Groups([
  215.         'read:user:item:me',
  216.         'read:club:collection:getCompanies',
  217.         'read:club:collection:getClubLocalize',
  218.     ])]
  219.     public function getLogoUrl(): string
  220.     {
  221.         $mainPhoto $this->getMainPhoto();
  222.         if ($mainPhoto) {
  223.             return $mainPhoto->getImageLarge()->getUrl();
  224.         }
  225.         return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
  226.     }
  227.     public function getMainPhoto()
  228.     {
  229.         foreach ($this->photos as $p) {
  230.             if ($p->isMain()) {
  231.                 return $p;
  232.             }
  233.         }
  234.         if (sizeof($this->photos) > 0) {
  235.             return $this->photos[0];
  236.         }
  237.         return false;
  238.     }
  239.     #[Groups([
  240.         'read:user:item:me',
  241.         'read:club:collection:getClubLocalize',
  242.         'read:company:collection:get',
  243.     ])]
  244.     public function getSmallLogoUrl(): string
  245.     {
  246.         $mainPhoto $this->getMainPhoto();
  247.         if ($mainPhoto) {
  248.             return $mainPhoto->getImageMedium()->getUrl();
  249.         }
  250.         return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
  251.     }
  252.     #[Groups([
  253.         'read:user:item:me',
  254.     ])]
  255.     public function getMediumLogoUrl(): string
  256.     {
  257.         $mainPhoto $this->getMainPhoto();
  258.         if ($mainPhoto) {
  259.             return $mainPhoto->getImageMedium()->getUrl();
  260.         }
  261.         return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
  262.     }
  263.     #[Groups([
  264.         'read:user:item:me',
  265.         'read:club:collection:getClubLocalize',
  266.     ])]
  267.     public function getJsonTheme(): mixed
  268.     {
  269.         return json_decode($this->themetrue);
  270.     }
  271.     public function getId(): ?int
  272.     {
  273.         return $this->id;
  274.     }
  275.     public function getName(): ?string
  276.     {
  277.         return $this->name;
  278.     }
  279.     public function setName(string $name): self
  280.     {
  281.         $this->name $name;
  282.         return $this;
  283.     }
  284.     /**
  285.      * @return Collection<int, Post>
  286.      */
  287.     public function getPosts(): Collection
  288.     {
  289.         return $this->posts;
  290.     }
  291.     public function addPost(Post $post): self
  292.     {
  293.         if (!$this->posts->contains($post)) {
  294.             $this->posts->add($post);
  295.             $post->setClub($this);
  296.         }
  297.         return $this;
  298.     }
  299.     public function removePost(Post $post): self
  300.     {
  301.         if ($this->posts->removeElement($post)) {
  302.             // set the owning side to null (unless already changed)
  303.             if ($post->getClub() === $this) {
  304.                 $post->setClub(null);
  305.             }
  306.         }
  307.         return $this;
  308.     }
  309.     /**
  310.      * @return Collection<int, Membership>
  311.      */
  312.     public function getMemberships(): Collection
  313.     {
  314.         return $this->memberships;
  315.     }
  316.     public function addMembership(Membership $membership): self
  317.     {
  318.         if (!$this->memberships->contains($membership)) {
  319.             $this->memberships->add($membership);
  320.             $membership->setClub($this);
  321.         }
  322.         return $this;
  323.     }
  324.     public function removeMembership(Membership $membership): self
  325.     {
  326.         if ($this->memberships->removeElement($membership)) {
  327.             // set the owning side to null (unless already changed)
  328.             if ($membership->getClub() === $this) {
  329.                 $membership->setClub(null);
  330.             }
  331.         }
  332.         return $this;
  333.     }
  334.     /**
  335.      * @return Collection<int, Photo>
  336.      */
  337.     public function getPhotos(): Collection
  338.     {
  339.         return $this->photos;
  340.     }
  341.     public function addPhoto(Photo $photo): self
  342.     {
  343.         if (!$this->photos->contains($photo)) {
  344.             $this->photos->add($photo);
  345.             $photo->setClub($this);
  346.         }
  347.         return $this;
  348.     }
  349.     public function removePhoto(Photo $photo): self
  350.     {
  351.         if ($this->photos->removeElement($photo)) {
  352.             // set the owning side to null (unless already changed)
  353.             if ($photo->getClub() === $this) {
  354.                 $photo->setClub(null);
  355.             }
  356.         }
  357.         return $this;
  358.     }
  359.     /**
  360.      * @return Collection<int, Ad>
  361.      */
  362.     public function getAds(): Collection
  363.     {
  364.         return $this->ads;
  365.     }
  366.     public function addAd(Ad $ad): self
  367.     {
  368.         if (!$this->ads->contains($ad)) {
  369.             $this->ads->add($ad);
  370.             $ad->setClub($this);
  371.         }
  372.         return $this;
  373.     }
  374.     public function removeAd(Ad $ad): self
  375.     {
  376.         if ($this->ads->removeElement($ad)) {
  377.             // set the owning side to null (unless already changed)
  378.             if ($ad->getClub() === $this) {
  379.                 $ad->setClub(null);
  380.             }
  381.         }
  382.         return $this;
  383.     }
  384.     public function getTheme(): mixed
  385.     {
  386.         return $this->theme;
  387.     }
  388.     public function setTheme(?string $theme): self
  389.     {
  390.         $this->theme $theme;
  391.         return $this;
  392.     }
  393.     public function getAddress(): ?Address
  394.     {
  395.         return $this->address;
  396.     }
  397.     public function setAddress(?Address $address): self
  398.     {
  399.         $this->address $address;
  400.         return $this;
  401.     }
  402.     /**
  403.      * @return Collection<int, UserClub>
  404.      */
  405.     public function getUserClubs(): Collection
  406.     {
  407.         return $this->userClubs;
  408.     }
  409.     public function addUserClub(UserClub $userClub): self
  410.     {
  411.         if (!$this->userClubs->contains($userClub)) {
  412.             $this->userClubs->add($userClub);
  413.             $userClub->setClub($this);
  414.         }
  415.         return $this;
  416.     }
  417.     public function removeUserClub(UserClub $userClub): self
  418.     {
  419.         if ($this->userClubs->removeElement($userClub)) {
  420.             // set the owning side to null (unless already changed)
  421.             if ($userClub->getClub() === $this) {
  422.                 $userClub->setClub(null);
  423.             }
  424.         }
  425.         return $this;
  426.     }
  427.     /**
  428.      * @return Collection<int, Widget>
  429.      */
  430.     public function getWidgets(): Collection
  431.     {
  432.         return $this->widgets;
  433.     }
  434.     public function addWidget(Widget $widget): self
  435.     {
  436.         if (!$this->widgets->contains($widget)) {
  437.             $this->widgets->add($widget);
  438.             $widget->setClub($this);
  439.         }
  440.         return $this;
  441.     }
  442.     public function removeWidget(Widget $widget): self
  443.     {
  444.         if ($this->widgets->removeElement($widget)) {
  445.             // set the owning side to null (unless already changed)
  446.             if ($widget->getClub() === $this) {
  447.                 $widget->setClub(null);
  448.             }
  449.         }
  450.         return $this;
  451.     }
  452.     public function getHomeMessage(): ?string
  453.     {
  454.         return $this->homeMessage;
  455.     }
  456.     public function setHomeMessage(?string $homeMessage): self
  457.     {
  458.         $this->homeMessage $homeMessage;
  459.         return $this;
  460.     }
  461.     /**
  462.      * @return Collection<int, Deal>
  463.      */
  464.     public function getDeals(): Collection
  465.     {
  466.         return $this->deals;
  467.     }
  468.     public function addDeal(Deal $deal): self
  469.     {
  470.         if (!$this->deals->contains($deal)) {
  471.             $this->deals->add($deal);
  472.             $deal->setClub($this);
  473.         }
  474.         return $this;
  475.     }
  476.     public function removeDeal(Deal $deal): self
  477.     {
  478.         if ($this->deals->removeElement($deal)) {
  479.             // set the owning side to null (unless already changed)
  480.             if ($deal->getClub() === $this) {
  481.                 $deal->setClub(null);
  482.             }
  483.         }
  484.         return $this;
  485.     }
  486.     /**
  487.      * @return Collection<int, ClubManager>
  488.      */
  489.     public function getClubManagers(): Collection
  490.     {
  491.         return $this->clubManagers;
  492.     }
  493.     public function addClubManager(ClubManager $clubManager): static
  494.     {
  495.         if (!$this->clubManagers->contains($clubManager)) {
  496.             $this->clubManagers->add($clubManager);
  497.             $clubManager->setClub($this);
  498.         }
  499.         return $this;
  500.     }
  501.     public function removeClubManager(ClubManager $clubManager): static
  502.     {
  503.         if ($this->clubManagers->removeElement($clubManager)) {
  504.             // set the owning side to null (unless already changed)
  505.             if ($clubManager->getClub() === $this) {
  506.                 $clubManager->setClub(null);
  507.             }
  508.         }
  509.         return $this;
  510.     }
  511.     /**
  512.      * @return Collection<int, Alert>
  513.      */
  514.     public function getAlerts(): Collection
  515.     {
  516.         return $this->alerts;
  517.     }
  518.     public function addAlert(Alert $alert): static
  519.     {
  520.         if (!$this->alerts->contains($alert)) {
  521.             $this->alerts->add($alert);
  522.             $alert->setClub($this);
  523.         }
  524.         return $this;
  525.     }
  526.     public function removeAlert(Alert $alert): static
  527.     {
  528.         if ($this->alerts->removeElement($alert)) {
  529.             // set the owning side to null (unless already changed)
  530.             if ($alert->getClub() === $this) {
  531.                 $alert->setClub(null);
  532.             }
  533.         }
  534.         return $this;
  535.     }
  536.     /**
  537.      * @return Collection<int, ClubPresentation>
  538.      */
  539.     public function getClubPresentations(): Collection
  540.     {
  541.         return $this->clubPresentations;
  542.     }
  543.     public function addClubPresentation(ClubPresentation $clubPresentation): static
  544.     {
  545.         if (!$this->clubPresentations->contains($clubPresentation)) {
  546.             $this->clubPresentations->add($clubPresentation);
  547.             $clubPresentation->setClub($this);
  548.         }
  549.         return $this;
  550.     }
  551.     public function removeClubPresentation(ClubPresentation $clubPresentation): static
  552.     {
  553.         if ($this->clubPresentations->removeElement($clubPresentation)) {
  554.             // set the owning side to null (unless already changed)
  555.             if ($clubPresentation->getClub() === $this) {
  556.                 $clubPresentation->setClub(null);
  557.             }
  558.         }
  559.         return $this;
  560.     }
  561.     public function getWebsite(): ?string
  562.     {
  563.         return $this->website;
  564.     }
  565.     public function setWebsite(?string $website): static
  566.     {
  567.         $this->website $website;
  568.         return $this;
  569.     }
  570.     public function getPhone(): ?string
  571.     {
  572.         return $this->phone;
  573.     }
  574.     public function setPhone(?string $phone): static
  575.     {
  576.         $this->phone $phone;
  577.         return $this;
  578.     }
  579.     public function getEmail(): ?string
  580.     {
  581.         return $this->email;
  582.     }
  583.     public function setEmail(?string $email): static
  584.     {
  585.         $this->email $email;
  586.         return $this;
  587.     }
  588. }