src/Entity/Association.php line 76

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  9. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  10. use App\Repository\AssociationRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Gedmo\Mapping\Annotation as Gedmo;
  15. use Symfony\Component\HttpFoundation\File\UploadedFile;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. /**
  19.  * @ORM\Entity(repositoryClass=AssociationRepository::class)
  20.  * @ApiResource(
  21.  *     normalizationContext={
  22.  *         "groups"={"association:read"}
  23.  *     },
  24.  *     denormalizationContext={
  25.  *          "groups"={"association:write"}
  26.  *     },
  27.  *     collectionOperations={
  28.  *          "get"={
  29.  *              "security"="is_granted('ROLE_USER')"
  30.  *          },
  31.  *          "post"={
  32.  *              "security"="is_granted('ROLE_ADMIN')"
  33.  *          },
  34.  *          "post_update"={
  35.  *              "security"="is_granted('ROLE_ADMIN')",
  36.  *              "path"="/associations/{id}",
  37.  *              "description"="Update an Association with method POST (using content-type: 'multipart')",
  38.  *              "method"="POST",
  39.  *              "controller"="App\Controller\Api\AssociationController::update"
  40.  *          }
  41.  *     },
  42.  *     itemOperations={
  43.  *          "get"={
  44.  *              "security"="is_granted('ROLE_USER')"
  45.  *          },
  46.  *          "patch"={
  47.  *              "security"="is_granted('ROLE_ADMIN')"
  48.  *          },
  49.  *          "delete"={
  50.  *              "security"="is_granted('ROLE_ADMIN')"
  51.  *          }
  52.  *     }
  53.  * )
  54.  * @ApiFilter(OrderFilter::class)
  55.  * @ApiFilter(SearchFilter::class, properties={"name": "partial"})
  56.  * @ApiFilter(BooleanFilter::class, properties={"active"})
  57.  * @ApiFilter(GroupFilter::class, 
  58.  *      arguments={
  59.  *          "parameterName": "groups", 
  60.  *          "overrideDefaultGroups": true, 
  61.  *          "whitelist": {
  62.  *              "homepage:read", "association_list", "association_form_complete", "association_form"
  63.  *          }
  64.  *      }
  65.  * )
  66.  * @ApiFilter(PropertyFilter::class, 
  67.  *      arguments={
  68.  *          "parameterName"="fields", 
  69.  *          "overrideDefaultProperties"=true
  70.  *     }
  71.  * )
  72.  */
  73. class Association
  74. {
  75.     /**
  76.      * @ORM\Id
  77.      * @ORM\GeneratedValue
  78.      * @ORM\Column(type="integer")
  79.      * @Groups({"association:read", "user:read", "company:read", "association_list", "teamplay:read"})
  80.      */
  81.     private $id;
  82.     /**
  83.      * @ORM\Column(type="string", length=255, nullable=true)
  84.      * @Groups({"association:read", "association:write", "user:read", "company:read", "association_list", "teamplay:read"})
  85.      * @Assert\NotNull
  86.      */
  87.     private $name;
  88.     /**
  89.      * @ORM\Column(type="string", length=510, nullable=true)
  90.      * @Groups({"association:read", "association:write", "user:read", "company:read"})
  91.      */
  92.     private $shortDescription;
  93.     /**
  94.      * @ORM\Column(type="text", nullable=true)
  95.      * @Groups({"association:read", "association:write", "user:read", "company:read"})
  96.      */
  97.     private $content;
  98.     /**
  99.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  100.      * @Groups({"association:read", "association:write", "user:read", "company:read", "teamplay:read"})
  101.      */
  102.     private $preview;
  103.     /**
  104.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  105.      * @Groups({"association:read", "association:write", "user:read", "company:read", "teamplay:read"})
  106.      */
  107.     private $picture;
  108.     /**
  109.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  110.      * @Groups({"association:read", "association:write", "user:read", "company:read", "teamplay:read"})
  111.      */
  112.     private $illustration;
  113.     /**
  114.      * @ORM\Column(type="string", length=255, nullable=true)
  115.      * @Groups({"association:read", "association:write", "user:read", "company:read", "teamplay:read"})
  116.      */
  117.     private $linkUrl;
  118.     /**
  119.      * @ORM\Column(type="boolean", options={"default": "0"})
  120.      * @Groups({"association:read", "association:write", "user:read", "company:read", "association_list", "teamplay:read"})
  121.      */
  122.     private $active false;
  123.     /**
  124.      * @ORM\Column(type="datetime")
  125.      * @Gedmo\Timestampable(on="create")
  126.      */
  127.     private $createdAt;
  128.     /**
  129.      * @ORM\Column(type="datetime")
  130.      * @Gedmo\Timestampable(on="update")
  131.      */
  132.     private $updatedAt;
  133.     /**
  134.      * @ORM\OneToMany(targetEntity=Teamplay::class, mappedBy="association", cascade={"persist", "refresh", "remove"})
  135.      */
  136.     private $teamplays;
  137.     /**
  138.      * @ORM\OneToMany(targetEntity=TvUser::class, mappedBy="association")
  139.      */
  140.     private $tvUsers;
  141.     /**
  142.      * @ORM\OneToMany(targetEntity=Client::class, mappedBy="association")
  143.      */
  144.     private $clients;
  145.     public function __construct()
  146.     {
  147.         $this->teamplays = new ArrayCollection();
  148.         $this->tvUsers = new ArrayCollection();
  149.         $this->clients = new ArrayCollection();
  150.     }
  151.     public function getId(): ?int
  152.     {
  153.         return $this->id;
  154.     }
  155.     public function getName(): ?string
  156.     {
  157.         return $this->name;
  158.     }
  159.     public function setName(?string $name): self
  160.     {
  161.         $this->name $name;
  162.         return $this;
  163.     }
  164.     public function getContent(): ?string
  165.     {
  166.         return $this->content;
  167.     }
  168.     public function setContent(?string $content): self
  169.     {
  170.         $this->content $content;
  171.         return $this;
  172.     }
  173.     public function getPreview(): ?MediaObject
  174.     {
  175.         return $this->preview;
  176.     }
  177.     public function setPreview(?MediaObject $preview): self
  178.     {
  179.         $this->preview $preview;
  180.         return $this;
  181.     }
  182.     /**
  183.      * @Groups({"association:write"})
  184.      */
  185.     public function setPreviewFile($file null): self
  186.     {
  187.         if($file instanceof UploadedFile) {
  188.             $preview = empty($this->preview) ? new MediaObject $this->preview;
  189.             $preview->setFile($file);
  190.             $this->setPreview($preview);
  191.         }
  192.         return $this;
  193.     }
  194.     public function getPicture(): ?MediaObject
  195.     {
  196.         return $this->picture;
  197.     }
  198.     public function setPicture(?MediaObject $picture): self
  199.     {
  200.         $this->picture $picture;
  201.         return $this;
  202.     }
  203.     /**
  204.      * @Groups({"association:write"})
  205.      */
  206.     public function setPictureFile($file null): self
  207.     {
  208.         if($file instanceof UploadedFile) {
  209.             $picture = empty($this->picture) ? new MediaObject $this->picture;
  210.             $picture->setFile($file);
  211.             $this->setPicture($picture);
  212.         }
  213.         return $this;
  214.     }
  215.     public function getIllustration(): ?MediaObject
  216.     {
  217.         return $this->illustration;
  218.     }
  219.     public function setIllustration(?MediaObject $illustration): self
  220.     {
  221.         $this->illustration $illustration;
  222.         return $this;
  223.     }
  224.     /**
  225.      * @Groups({"association:write"})
  226.      */
  227.     public function setIllustrationFile($file null): self
  228.     {
  229.         if($file instanceof UploadedFile) {
  230.             $illustration = empty($this->illustration) ? new MediaObject $this->illustration;
  231.             $illustration->setFile($file);
  232.             $this->setIllustration($illustration);
  233.         }
  234.         return $this;
  235.     }
  236.     public function getActive(): ?bool
  237.     {
  238.         return $this->active;
  239.     }
  240.     public function setActive(bool $active): self
  241.     {
  242.         $this->active $active;
  243.         return $this;
  244.     }
  245.     public function getCreatedAt(): ?\DateTimeInterface
  246.     {
  247.         return $this->createdAt;
  248.     }
  249.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  250.     {
  251.         $this->createdAt $createdAt;
  252.         return $this;
  253.     }
  254.     public function getUpdatedAt(): ?\DateTimeInterface
  255.     {
  256.         return $this->updatedAt;
  257.     }
  258.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  259.     {
  260.         $this->updatedAt $updatedAt;
  261.         return $this;
  262.     }
  263.     public function getLinkUrl(): ?string
  264.     {
  265.         return $this->linkUrl;
  266.     }
  267.     public function setLinkUrl(?string $linkUrl): self
  268.     {
  269.         $this->linkUrl $linkUrl;
  270.         return $this;
  271.     }
  272.     public function getShortDescription(): ?string
  273.     {
  274.         return $this->shortDescription;
  275.     }
  276.     public function setShortDescription(?string $shortDescription): self
  277.     {
  278.         $this->shortDescription $shortDescription;
  279.         return $this;
  280.     }
  281.     /**
  282.      * @return Collection|Teamplay[]
  283.      */
  284.     public function getTeamplays(): Collection
  285.     {
  286.         return $this->teamplays;
  287.     }
  288.     public function addTeamplay(Teamplay $teamplay): self
  289.     {
  290.         if (!$this->teamplays->contains($teamplay)) {
  291.             $this->teamplays[] = $teamplay;
  292.             $teamplay->setAssociation($this);
  293.         }
  294.         return $this;
  295.     }
  296.     public function removeTeamplay(Teamplay $teamplay): self
  297.     {
  298.         if ($this->teamplays->removeElement($teamplay)) {
  299.             // set the owning side to null (unless already changed)
  300.             if ($teamplay->getAssociation() === $this) {
  301.                 $teamplay->setAssociation(null);
  302.             }
  303.         }
  304.         return $this;
  305.     }
  306.     /**
  307.      * @return Collection|TvUser[]
  308.      */
  309.     public function getTvUsers(): Collection
  310.     {
  311.         return $this->tvUsers;
  312.     }
  313.     public function addTvUser(TvUser $tvUser): self
  314.     {
  315.         if (!$this->tvUsers->contains($tvUser)) {
  316.             $this->tvUsers[] = $tvUser;
  317.             $tvUser->setAssociation($this);
  318.         }
  319.         return $this;
  320.     }
  321.     public function removeTvUser(TvUser $tvUser): self
  322.     {
  323.         if ($this->tvUsers->removeElement($tvUser)) {
  324.             // set the owning side to null (unless already changed)
  325.             if ($tvUser->getAssociation() === $this) {
  326.                 $tvUser->setAssociation(null);
  327.             }
  328.         }
  329.         return $this;
  330.     }
  331.     /**
  332.      * @return Collection|Client[]
  333.      */
  334.     public function getClients(): Collection
  335.     {
  336.         return $this->clients;
  337.     }
  338.     public function addClient(Client $client): self
  339.     {
  340.         if (!$this->clients->contains($client)) {
  341.             $this->clients[] = $client;
  342.             $client->setAssociation($this);
  343.         }
  344.         return $this;
  345.     }
  346.     public function removeClient(Client $client): self
  347.     {
  348.         if ($this->clients->removeElement($client)) {
  349.             // set the owning side to null (unless already changed)
  350.             if ($client->getAssociation() === $this) {
  351.                 $client->setAssociation(null);
  352.             }
  353.         }
  354.         return $this;
  355.     }
  356.     
  357. }