<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Repository\AssociationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=AssociationRepository::class)
* @ApiResource(
* normalizationContext={
* "groups"={"association:read"}
* },
* denormalizationContext={
* "groups"={"association:write"}
* },
* collectionOperations={
* "get"={
* "security"="is_granted('ROLE_USER')"
* },
* "post"={
* "security"="is_granted('ROLE_ADMIN')"
* },
* "post_update"={
* "security"="is_granted('ROLE_ADMIN')",
* "path"="/associations/{id}",
* "description"="Update an Association with method POST (using content-type: 'multipart')",
* "method"="POST",
* "controller"="App\Controller\Api\AssociationController::update"
* }
* },
* itemOperations={
* "get"={
* "security"="is_granted('ROLE_USER')"
* },
* "patch"={
* "security"="is_granted('ROLE_ADMIN')"
* },
* "delete"={
* "security"="is_granted('ROLE_ADMIN')"
* }
* }
* )
* @ApiFilter(OrderFilter::class)
* @ApiFilter(SearchFilter::class, properties={"name": "partial"})
* @ApiFilter(BooleanFilter::class, properties={"active"})
* @ApiFilter(GroupFilter::class,
* arguments={
* "parameterName": "groups",
* "overrideDefaultGroups": true,
* "whitelist": {
* "homepage:read", "association_list", "association_form_complete", "association_form"
* }
* }
* )
* @ApiFilter(PropertyFilter::class,
* arguments={
* "parameterName"="fields",
* "overrideDefaultProperties"=true
* }
* )
*/
class Association
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"association:read", "user:read", "company:read", "association_list", "teamplay:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"association:read", "association:write", "user:read", "company:read", "association_list", "teamplay:read"})
* @Assert\NotNull
*/
private $name;
/**
* @ORM\Column(type="string", length=510, nullable=true)
* @Groups({"association:read", "association:write", "user:read", "company:read"})
*/
private $shortDescription;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"association:read", "association:write", "user:read", "company:read"})
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity=MediaObject::class)
* @Groups({"association:read", "association:write", "user:read", "company:read", "teamplay:read"})
*/
private $preview;
/**
* @ORM\ManyToOne(targetEntity=MediaObject::class)
* @Groups({"association:read", "association:write", "user:read", "company:read", "teamplay:read"})
*/
private $picture;
/**
* @ORM\ManyToOne(targetEntity=MediaObject::class)
* @Groups({"association:read", "association:write", "user:read", "company:read", "teamplay:read"})
*/
private $illustration;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"association:read", "association:write", "user:read", "company:read", "teamplay:read"})
*/
private $linkUrl;
/**
* @ORM\Column(type="boolean", options={"default": "0"})
* @Groups({"association:read", "association:write", "user:read", "company:read", "association_list", "teamplay:read"})
*/
private $active = false;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity=Teamplay::class, mappedBy="association", cascade={"persist", "refresh", "remove"})
*/
private $teamplays;
/**
* @ORM\OneToMany(targetEntity=TvUser::class, mappedBy="association")
*/
private $tvUsers;
/**
* @ORM\OneToMany(targetEntity=Client::class, mappedBy="association")
*/
private $clients;
public function __construct()
{
$this->teamplays = new ArrayCollection();
$this->tvUsers = new ArrayCollection();
$this->clients = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
public function getPreview(): ?MediaObject
{
return $this->preview;
}
public function setPreview(?MediaObject $preview): self
{
$this->preview = $preview;
return $this;
}
/**
* @Groups({"association:write"})
*/
public function setPreviewFile($file = null): self
{
if($file instanceof UploadedFile) {
$preview = empty($this->preview) ? new MediaObject : $this->preview;
$preview->setFile($file);
$this->setPreview($preview);
}
return $this;
}
public function getPicture(): ?MediaObject
{
return $this->picture;
}
public function setPicture(?MediaObject $picture): self
{
$this->picture = $picture;
return $this;
}
/**
* @Groups({"association:write"})
*/
public function setPictureFile($file = null): self
{
if($file instanceof UploadedFile) {
$picture = empty($this->picture) ? new MediaObject : $this->picture;
$picture->setFile($file);
$this->setPicture($picture);
}
return $this;
}
public function getIllustration(): ?MediaObject
{
return $this->illustration;
}
public function setIllustration(?MediaObject $illustration): self
{
$this->illustration = $illustration;
return $this;
}
/**
* @Groups({"association:write"})
*/
public function setIllustrationFile($file = null): self
{
if($file instanceof UploadedFile) {
$illustration = empty($this->illustration) ? new MediaObject : $this->illustration;
$illustration->setFile($file);
$this->setIllustration($illustration);
}
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getLinkUrl(): ?string
{
return $this->linkUrl;
}
public function setLinkUrl(?string $linkUrl): self
{
$this->linkUrl = $linkUrl;
return $this;
}
public function getShortDescription(): ?string
{
return $this->shortDescription;
}
public function setShortDescription(?string $shortDescription): self
{
$this->shortDescription = $shortDescription;
return $this;
}
/**
* @return Collection|Teamplay[]
*/
public function getTeamplays(): Collection
{
return $this->teamplays;
}
public function addTeamplay(Teamplay $teamplay): self
{
if (!$this->teamplays->contains($teamplay)) {
$this->teamplays[] = $teamplay;
$teamplay->setAssociation($this);
}
return $this;
}
public function removeTeamplay(Teamplay $teamplay): self
{
if ($this->teamplays->removeElement($teamplay)) {
// set the owning side to null (unless already changed)
if ($teamplay->getAssociation() === $this) {
$teamplay->setAssociation(null);
}
}
return $this;
}
/**
* @return Collection|TvUser[]
*/
public function getTvUsers(): Collection
{
return $this->tvUsers;
}
public function addTvUser(TvUser $tvUser): self
{
if (!$this->tvUsers->contains($tvUser)) {
$this->tvUsers[] = $tvUser;
$tvUser->setAssociation($this);
}
return $this;
}
public function removeTvUser(TvUser $tvUser): self
{
if ($this->tvUsers->removeElement($tvUser)) {
// set the owning side to null (unless already changed)
if ($tvUser->getAssociation() === $this) {
$tvUser->setAssociation(null);
}
}
return $this;
}
/**
* @return Collection|Client[]
*/
public function getClients(): Collection
{
return $this->clients;
}
public function addClient(Client $client): self
{
if (!$this->clients->contains($client)) {
$this->clients[] = $client;
$client->setAssociation($this);
}
return $this;
}
public function removeClient(Client $client): self
{
if ($this->clients->removeElement($client)) {
// set the owning side to null (unless already changed)
if ($client->getAssociation() === $this) {
$client->setAssociation(null);
}
}
return $this;
}
}