src/Entity/TeamUser.php line 68

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\Annotation\ApiSubresource;
  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\TeamUserRepository;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. use Symfony\Component\HttpFoundation\File\UploadedFile;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. /**
  18.  * POST : contrĂ´les d'inscription dans App\EventSubscriber\TeamUserJoinSubscriber.
  19.  * PATCH : seul le pseudo est modifiable (groupe team_user:patch).
  20.  *
  21.  * @ORM\Entity(repositoryClass=TeamUserRepository::class)
  22.  * @ApiResource(
  23.  *      normalizationContext={
  24.  *          "groups"={"team_user:read"}
  25.  *      },
  26.  *      denormalizationContext={
  27.  *          "groups"={"team_user:write"}
  28.  *      },
  29.  *      itemOperations={
  30.  *          "get"={
  31.  *              "security"="is_granted('ROLE_USER') and is_granted('TEAM_USER_VIEW', object)",
  32.  *          }, 
  33.  *          "patch"={
  34.  *              "security"="is_granted('ROLE_ADMIN') or object.getUser() == user",
  35.  *              "denormalization_context"={"groups"={"team_user:patch"}},
  36.  *          },
  37.  *          "delete"={
  38.  *              "security"="is_granted('ROLE_ADMIN') or object.getUser() == user",
  39.  *          }
  40.  *      },
  41.  *      collectionOperations={
  42.  *          "get"={
  43.  *              "security"="is_granted('ROLE_USER')",
  44.  *          }, 
  45.  *          "post"={
  46.  *              "security"="is_granted('ROLE_USER')",
  47.  *          }
  48.  *      }
  49.  * )
  50.  * @ApiFilter(SearchFilter::class, properties={"user.id", "team.id", "teamplay.id", "type", "pseudo"})
  51.  * @ApiFilter(OrderFilter::class)
  52.  * @ApiFilter(PropertyFilter::class, 
  53.  *      arguments={
  54.  *          "parameterName"="fields", 
  55.  *          "overrideDefaultProperties"=true
  56.  *     }
  57.  * )
  58.  * @UniqueEntity(
  59.  *     fields={"user", "team"},
  60.  *     errorPath="team",
  61.  *     message="team.user_already_in_team",
  62.  *     ignoreNull=false
  63.  * )
  64.  */
  65. class TeamUser
  66. {
  67.     /**
  68.      * @ORM\Id
  69.      * @ORM\GeneratedValue
  70.      * @ORM\Column(type="integer")
  71.      * @Groups({"team_user:read", "team:read"})
  72.      */
  73.     private $id;
  74.     /**
  75.      * @ORM\ManyToOne(targetEntity=Team::class, inversedBy="teamUsers", cascade={"persist", "refresh"} )
  76.      * @ORM\JoinColumn(nullable=false)
  77.      * @Groups({"team_user:read", "team_user:write"})
  78.      */
  79.     private $team;
  80.     /**
  81.      * @ORM\Column(type="string", length=255, nullable=true)
  82.      * @Groups({"team_user:read"})
  83.      */
  84.     private $type;
  85.     /**
  86.      * @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="teamUsers")
  87.      * @ORM\JoinColumn(nullable=true)
  88.      */
  89.     private $tvUser;
  90.     /**
  91.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="teamUsers")
  92.      * @ORM\JoinColumn(nullable=true)
  93.      * @Assert\NotNull
  94.      * @Groups({"team_user:read", "team_user:write", "team:read"})
  95.      */
  96.     private $user;
  97.     /**
  98.      * @ORM\Column(type="string", length=255, nullable=true)
  99.      * @Groups({"team_user:read", "team_user:write", "team_user:patch", "team:read"})
  100.      */
  101.     private $pseudo;
  102.     /**
  103.      * @ORM\ManyToOne(targetEntity=Teamplay::class, inversedBy="teams", cascade={"refresh"})
  104.      * @Groups({"team_user:read", "team_user:write", "team_user:read:teamplay", "team:read"})
  105.      */
  106.     private $teamplay;
  107.     /**
  108.      * @ORM\Column(type="integer", nullable=true)
  109.      * @Groups({"team_user:read", "team_user:read:points", "team:read"})
  110.      */
  111.     private $points;
  112.     /**
  113.      * @ORM\Column(name="`rank`", type="integer", nullable=true)
  114.      * @Groups({"team_user:read", "team_user:read:rank", "team:read"})
  115.      */
  116.     private $rank = null;
  117.     /**
  118.      * @ORM\Column(type="integer", nullable=true)
  119.      * @Groups({"team_user:read", "team_user:read:globalRank", "team:read"})
  120.      */
  121.     private $globalRank = null;
  122.     /**
  123.      * @ORM\Column(type="datetime")
  124.      * @Gedmo\Timestampable(on="create")
  125.      * @Groups({"team_user:read"})
  126.      */
  127.     private $createdAt;
  128.     /**
  129.      * @ORM\Column(type="datetime")
  130.      * @Gedmo\Timestampable(on="update")
  131.      * @Groups({"team_user:read"})
  132.      */
  133.     private $updatedAt;
  134.     /**
  135.      * Custom field
  136.      * Nombre de pas effectuer depuis que le teamUser existe et durant le Teamplay
  137.      * @Groups({"team_user:read"})
  138.      */
  139.     public $stepAmount = 0;
  140.     /**
  141.      * Custom field
  142.      * Quiz : Nombre de bonne rĂ©ponse durant le Teamplay
  143.      * @Groups({"team_user:read"})
  144.      */
  145.     public $quizAskedSuccessCount;
  146.     /**
  147.      * Custom field
  148.      * @var ?Chat
  149.      * @Groups({"team_user:read", "team_user:read:chat"})
  150.      */
  151.     public $chat;
  152.     public function getId(): ?int
  153.     {
  154.         return $this->id;
  155.     }
  156.     public function getTeam(): ?Team
  157.     {
  158.         return $this->team;
  159.     }
  160.     public function setTeam(?Team $team): self
  161.     {
  162.         $this->team = $team;
  163.         return $this;
  164.     }
  165.     public function getType(): ?string
  166.     {
  167.         return $this->type;
  168.     }
  169.     public function setType(?string $type): self
  170.     {
  171.         $this->type = $type;
  172.         return $this;
  173.     }
  174.     public function getTvUser(): ?TvUser
  175.     {
  176.         return $this->tvUser;
  177.     }
  178.     public function setTvUser(?TvUser $tvUser): self
  179.     {
  180.         $this->tvUser = $tvUser;
  181.         return $this;
  182.     }
  183.     public function getUser(): ?User
  184.     {
  185.         return $this->user;
  186.     }
  187.     public function setUser(?User $user): self
  188.     {
  189.         $this->user = $user;
  190.         return $this;
  191.     }
  192.     public function getPseudo(): ?string
  193.     {
  194.         return $this->pseudo;
  195.     }
  196.     public function setPseudo(?string $pseudo): self
  197.     {
  198.         $this->pseudo = $pseudo;
  199.         return $this;
  200.     }
  201.     public function getTeamplay(): ?Teamplay
  202.     {
  203.         return $this->teamplay;
  204.     }
  205.     public function setTeamplay(?Teamplay $teamplay): self
  206.     {
  207.         $this->teamplay = $teamplay;
  208.         return $this;
  209.     }
  210.     public function getPoints(): ?int
  211.     {
  212.         return $this->points;
  213.     }
  214.     public function setPoints(?int $points): self
  215.     {
  216.         $this->points = $points;
  217.         return $this;
  218.     }
  219.     public function getRank(): ?int
  220.     {
  221.         return $this->rank;
  222.     }
  223.     public function setRank(?int $rank): self
  224.     {
  225.         $this->rank = $rank;
  226.         return $this;
  227.     }
  228.     public function getGlobalRank(): ?int
  229.     {
  230.         return $this->globalRank;
  231.     }
  232.     public function setGlobalRank(?int $globalRank): self
  233.     {
  234.         $this->globalRank = $globalRank;
  235.         return $this;
  236.     }
  237.     public function getCreatedAt(): ?\DateTimeInterface
  238.     {
  239.         return $this->createdAt;
  240.     }
  241.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  242.     {
  243.         $this->createdAt = $createdAt;
  244.         return $this;
  245.     }
  246.     public function getUpdatedAt(): ?\DateTimeInterface
  247.     {
  248.         return $this->updatedAt;
  249.     }
  250.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  251.     {
  252.         $this->updatedAt = $updatedAt;
  253.         return $this;
  254.     }
  255. }