src/Entity/TeamplayChallenge.php line 87

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\BooleanFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
  11. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  12. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  13. use App\Repository\TeamplayChallengeRepository;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Gedmo\Mapping\Annotation as Gedmo;
  18. use Symfony\Component\HttpFoundation\File\UploadedFile;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. /**
  22.  * @ApiResource(
  23.  *      normalizationContext={
  24.  *          "groups"={"teamplay_challenge:read"}
  25.  *      },
  26.  *      denormalizationContext={
  27.  *          "groups"={"teamplay_challenge:write"}
  28.  *      },
  29.  *      itemOperations={
  30.  *          "get"={
  31.  *              "security"="is_granted('ROLE_USER')"
  32.  *          },
  33.  *          "patch"={
  34.  *              "security"="is_granted('ROLE_ADMIN')"
  35.  *          },
  36.  *          "delete"={
  37.  *              "security"="is_granted('ROLE_ADMIN')"
  38.  *          }
  39.  *      },
  40.  *      collectionOperations={
  41.  *          "get"={
  42.  *              "security"="is_granted('ROLE_USER')"
  43.  *          }, 
  44.  *          "get_client_teamplay_collected"={
  45.  *              "security"="is_granted('ROLE_CLIENT')",
  46.  *              "method"="GET",
  47.  *              "description"="Get completed TeamplayChallenge by a Client",
  48.  *              "controller"="App\Controller\Api\TeamplayChallengeController::getClientTeamplayChallengeCompleted"
  49.  *          }, 
  50.  *          "post"={
  51.  *              "security"="is_granted('ROLE_ADMIN')"
  52.  *          },
  53.  *          "post_update"={
  54.  *              "security"="is_granted('ROLE_ADMIN')",
  55.  *              "path"="/teamplay_challenges/{id}",
  56.  *              "description"="Update a TeamplayChallenge with method POST (using content-type: 'multipart')",
  57.  *              "method"="POST",
  58.  *              "controller"="App\Controller\Api\TeamplayChallengeController::update"
  59.  *          }
  60.  *      }
  61.  * )
  62.  * @ORM\Entity(repositoryClass=TeamplayChallengeRepository::class)
  63.  * @ApiFilter(SearchFilter::class, 
  64.  *      strategy="exact", 
  65.  *      properties={"active", "teamplay.id", "name": "partial", "type", "company.id", "isTemplate"}
  66.  * )
  67.  * @ApiFilter(ExistsFilter::class, properties={"teamplay", "company", "video", "survey", "type"})
  68.  * @ApiFilter(BooleanFilter::class, properties={"active", "isTemplate"})
  69.  * @ApiFilter(DateFilter::class, properties={"dateStart", "dateEnd"})
  70.  * @ApiFilter(OrderFilter::class)
  71.  * @ApiFilter(GroupFilter::class, 
  72.  *      arguments={
  73.  *          "parameterName": "groups", 
  74.  *          "overrideDefaultGroups": true
  75.  *      }
  76.  * )
  77.  * @ApiFilter(PropertyFilter::class, 
  78.  *      arguments={
  79.  *          "parameterName"="fields", 
  80.  *          "overrideDefaultProperties"=true
  81.  *     }
  82.  * )
  83.  */
  84. class TeamplayChallenge
  85. {
  86.     const TYPE_STEP "step";
  87.     const TYPE_RECURRENT_STEP "recurrent_step";
  88.     const TYPE_RECURRENT_RANKING_AWARD "recurrent_ranking_award";
  89.     const TYPE_VIDEO_PHYSICAL "video_physical";
  90.     const TYPE_VIDEO_INTERVIEW "video_interview";
  91.     const TYPE_QUIZ "quiz";
  92.     const TYPES = [
  93.         self::TYPE_STEP,
  94.         self::TYPE_RECURRENT_STEP,
  95.         self::TYPE_RECURRENT_RANKING_AWARD,
  96.         self::TYPE_VIDEO_PHYSICAL,
  97.         self::TYPE_VIDEO_INTERVIEW,
  98.         self::TYPE_QUIZ,
  99.     ];
  100.     const STATUS_IN_PROGRESS "in_progress";
  101.     const STATUS_IN_COMING "in_coming";
  102.     const STATUS_PASSED"passed";
  103.     const STATUS = [
  104.         self::STATUS_IN_PROGRESS,
  105.         self::STATUS_IN_COMING,
  106.         self::STATUS_PASSED
  107.     ];
  108.     const EVERY_TYPE_HOUR "hour";
  109.     const EVERY_TYPE_DAY "day";
  110.     const EVERY_TYPE_WEEK "week";
  111.     const EVERY_TYPE_MONTH "month";
  112.     const EVERY_TYPE_YEAR "year";
  113.     const EVERY_DATE_TYPES = [
  114.         self::EVERY_TYPE_HOUR,
  115.         self::EVERY_TYPE_DAY,
  116.         self::EVERY_TYPE_WEEK,
  117.         self::EVERY_TYPE_MONTH,
  118.         self::EVERY_TYPE_YEAR,
  119.     ];
  120.     /**
  121.      * @ORM\Id
  122.      * @ORM\GeneratedValue
  123.      * @ORM\Column(type="integer")
  124.      * @Groups({"teamplay_challenge:read:id", "teamplay_challenge:read", "teamplay_challenge_simple", "teamplay:read", "challenge_form"})
  125.      */
  126.     private $id;
  127.     /**
  128.      * @ORM\Column(type="string", length=255, nullable=true)
  129.      * @Groups({"teamplay_challenge:read:name", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read", "challenge_form"})
  130.      */
  131.     private $name;
  132.     /**
  133.      * @ORM\Column(type="text", nullable=true)
  134.      * @Groups({"teamplay_challenge:read:description", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  135.      */
  136.     private $description;
  137.     /**
  138.      * @ORM\Column(type="string", length=255, nullable=true)
  139.      * @Assert\Choice(choices=self::TYPES)
  140.      * @Groups({"teamplay_challenge:read:type", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  141.      */
  142.     private $type;
  143.     /**
  144.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  145.      * @Groups({"teamplay_challenge:read:picture", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  146.      */
  147.     private $picture;
  148.     /**
  149.      * @ORM\Column(type="integer", nullable=true)
  150.      * @Groups({"teamplay_challenge:read:duration", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  151.      */
  152.     private $duration;
  153.     /**
  154.      * @ORM\Column(type="integer", nullable=true)
  155.      * @Groups({"teamplay_challenge:read:pointAmount", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  156.      */
  157.     private $pointAmount;
  158.     /**
  159.      * @ORM\Column(type="integer", nullable=true)
  160.      * @Groups({"teamplay_challenge:read:stepAmount", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  161.      */
  162.     private $stepAmount;
  163.     /**
  164.      * @ORM\Column(type="integer", nullable=true)
  165.      * @Groups({"teamplay_challenge:read:dayStart", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  166.      */
  167.     private $dayStart;
  168.     /**
  169.      * @ORM\Column(type="integer", nullable=true)
  170.      * @Groups({"teamplay_challenge:read:dayEnd", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  171.      */
  172.     private $dayEnd;
  173.     /**
  174.      * @ORM\Column(type="datetime", nullable=true)
  175.      * @Groups({"teamplay_challenge:read:dateStart", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  176.      */
  177.     private $dateStart;
  178.     /**
  179.      * @ORM\Column(type="datetime", nullable=true)
  180.      * @Groups({"teamplay_challenge:read:dateEnd", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  181.      */
  182.     private $dateEnd;
  183.     
  184.     /**
  185.      * @ORM\ManyToOne(targetEntity=Video::class, inversedBy="teamplayChallenges")
  186.      * @Groups({"teamplay_challenge:read:video", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  187.      */
  188.     private $video;
  189.     /**
  190.      * @ORM\ManyToOne(targetEntity=Survey::class, inversedBy="teamplayChallenges", cascade={"persist", "refresh", "remove"})
  191.      * @Groups({"teamplay_challenge:read:survey", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  192.      */
  193.     private $survey;
  194.     /**
  195.      * @ORM\Column(type="boolean", nullable=true, options={"default": "1"})
  196.      * @Groups({"teamplay_challenge:read:isTemplate", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  197.      */
  198.     private $isTemplate true;
  199.     /**
  200.      * @ORM\Column(type="integer", nullable=true)
  201.      * @Groups({"teamplay_challenge:read:awardAmount", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  202.      */
  203.     private $awardAmount;
  204.     /**
  205.      * @ORM\Column(type="boolean", options={"default": "0"})
  206.      * @Groups({"teamplay_challenge:read:isMultipleWinnable", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  207.      */
  208.     private $isMultipleWinnable false;
  209.     /**
  210.      * @ORM\Column(type="integer", nullable=true)
  211.      * @Groups({"teamplay_challenge:read:everyInt", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  212.      */
  213.     private $everyInt;
  214.     /**
  215.      * @ORM\Column(type="string", length=255, nullable=true)
  216.      * @Groups({"teamplay_challenge:read:everyDateType", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  217.      */
  218.     private $everyDateType;
  219.     /**
  220.      * @ORM\ManyToOne(targetEntity=TvCompany::class, inversedBy="teamplayChallenges")
  221.      */
  222.     private $tvCompany;
  223.     /**
  224.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="teamplayChallenges")
  225.      * @Groups({"teamplay_challenge:read:company", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  226.      */
  227.     private $company;
  228.     /**
  229.      * @ORM\Column(type="boolean", nullable=true, options={"default": "1"})
  230.      * @Groups({"teamplay_challenge:read:active", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
  231.      */
  232.     private $active true;
  233.     /**
  234.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  235.      * @Gedmo\Timestampable(on="create")
  236.      * @Groups({"teamplay_challenge:read:createdAt", "teamplay_challenge:read", "teamplay_challenge_simple"})
  237.      */
  238.     private $createdAt;
  239.     /**
  240.      * @ORM\Column(type="datetime", nullable=true)
  241.      * @Gedmo\Timestampable(on="update")
  242.      * @Groups({"teamplay_challenge:read:updatedAt", "teamplay_challenge:read", "teamplay_challenge_simple"})
  243.      */
  244.     private $updatedAt;
  245.     /**
  246.      * @ORM\ManyToOne(targetEntity=Teamplay::class, inversedBy="challenges", cascade={"refresh"})
  247.      * @Groups({"teamplay_challenge:read:teamplay", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple"})
  248.      */
  249.     private $teamplay;
  250.     /**
  251.      * @ORM\OneToMany(targetEntity=TeamplayLog::class, mappedBy="teamplayChallenge", cascade={"persist", "refresh", "remove"})
  252.      */
  253.     private $teamplayLogs;
  254.     /**
  255.      * Champ Custom (PostLoad)
  256.      * Permet de savoir si le TeamplayChallenge a été complété par le Client connecté
  257.      * @var ?bool
  258.      * @Groups({"teamplay_challenge:read:isCompleted", "teamplay_challenge:read"})
  259.      */
  260.     public $isCompleted null;
  261.     /**
  262.      * Champ Custom (PostLoad)
  263.      * Permet de savoir si le Client connct a récupéré les points du TeamplayChallenge
  264.      * @var ?bool
  265.      * @Groups({"teamplay_challenge:read:isCollected", "teamplay_challenge:read"})
  266.      */
  267.     public $isCollected null;
  268.     /**
  269.      * Champ Custom (PostLoad)
  270.      * Permet de savoir si le Client connct a récupéré les points du TeamplayChallenge
  271.      * @var ?int
  272.      * @Groups({"teamplay_challenge:read:userStepsAmount", "teamplay_challenge:read"})
  273.      */
  274.     public $userStepsAmount null;
  275.     public function __construct()
  276.     {
  277.         $this->teamplayLogs = new ArrayCollection();
  278.     }
  279.     public function getId(): ?int
  280.     {
  281.         return $this->id;
  282.     }
  283.     public function setId(?int $id): self
  284.     {
  285.         $this->id $id;
  286.         return $this;
  287.     }
  288.     public function getName(): ?string
  289.     {
  290.         return $this->name;
  291.     }
  292.     public function setName(?string $name): self
  293.     {
  294.         $this->name $name;
  295.         return $this;
  296.     }
  297.     public function getDescription(): ?string
  298.     {
  299.         return $this->description;
  300.     }
  301.     public function setDescription(?string $description): self
  302.     {
  303.         $this->description $description;
  304.         return $this;
  305.     }
  306.     public function getType(): ?string
  307.     {
  308.         return $this->type;
  309.     }
  310.     public function setType(?string $type): self
  311.     {
  312.         $this->type $type;
  313.         return $this;
  314.     }
  315.     
  316.     public function getPicture(): ?MediaObject
  317.     {
  318.         return $this->picture;
  319.     }
  320.     public function setPicture(?MediaObject $picture): self
  321.     {
  322.         $this->picture $picture;
  323.         return $this;
  324.     }
  325.     /**
  326.      * @Groups({"teamplay_challenge:write"})
  327.      */
  328.     public function setPictureFile($file null): self
  329.     {
  330.         if($file instanceof UploadedFile) {
  331.             $picture = empty($this->picture) ? new MediaObject $this->picture;
  332.             $picture->setFile($file);
  333.             $this->setPicture($picture);
  334.         }
  335.         return $this;
  336.     }
  337.     public function getDuration(): ?int
  338.     {
  339.         return $this->duration;
  340.     }
  341.     public function setDuration(?int $duration): self
  342.     {
  343.         $this->duration $duration;
  344.         return $this;
  345.     }
  346.     public function getPointAmount(): ?int
  347.     {
  348.         return $this->pointAmount;
  349.     }
  350.     public function setPointAmount(?int $pointAmount): self
  351.     {
  352.         $this->pointAmount $pointAmount;
  353.         return $this;
  354.     }
  355.     public function getStepAmount(): ?int
  356.     {
  357.         return $this->stepAmount;
  358.     }
  359.     public function setStepAmount(?int $stepAmount): self
  360.     {
  361.         $this->stepAmount $stepAmount;
  362.         return $this;
  363.     }
  364.     public function getDayStart(): ?int
  365.     {
  366.         return $this->dayStart;
  367.     }
  368.     public function setDayStart(?int $dayStart): self
  369.     {
  370.         $this->dayStart $dayStart;
  371.         return $this;
  372.     }
  373.     public function getDayEnd(): ?int
  374.     {
  375.         return $this->dayEnd;
  376.     }
  377.     public function setDayEnd(?int $dayEnd): self
  378.     {
  379.         $this->dayEnd $dayEnd;
  380.         return $this;
  381.     }
  382.     public function getDateStart(): ?\DateTimeInterface
  383.     {
  384.         return $this->dateStart;
  385.     }
  386.     public function setDateStart(?\DateTimeInterface $dateStart null): self
  387.     {
  388.         $this->dateStart $dateStart;
  389.         return $this;
  390.     }
  391.     public function getDateEnd(): ?\DateTimeInterface
  392.     {
  393.         return $this->dateEnd;
  394.     }
  395.     public function setDateEnd(?\DateTimeInterface $dateEnd): self
  396.     {
  397.         $this->dateEnd $dateEnd;
  398.         return $this;
  399.     }
  400.     public function getVideo(): ?Video
  401.     {
  402.         return $this->video;
  403.     }
  404.     public function setVideo(?Video $video): self
  405.     {
  406.         $this->video $video;
  407.         return $this;
  408.     }
  409.     public function getSurvey(): ?Survey
  410.     {
  411.         return $this->survey;
  412.     }
  413.     public function setSurvey(?Survey $survey): self
  414.     {
  415.         $this->survey $survey;
  416.         return $this;
  417.     }
  418.     /**
  419.      * Permet de savoir si c'est une modèle
  420.      * Critères d'un modèle :
  421.      * - Ne pas être lié à une Company 
  422.      * @return bool
  423.      */
  424.     public function isTemplate(): bool
  425.     {
  426.         return $this->getIsTemplate();
  427.     }
  428.     public function getIsTemplate(): ?bool
  429.     {
  430.         return $this->isTemplate;
  431.     }
  432.     public function setIsTemplate(?bool $isTemplate): self
  433.     {
  434.         $this->isTemplate $isTemplate;
  435.         return $this;
  436.     }
  437.     public function getTvCompany(): ?TvCompany
  438.     {
  439.         return $this->tvCompany;
  440.     }
  441.     public function setTvCompany(?TvCompany $tvCompany): self
  442.     {
  443.         $this->tvCompany $tvCompany;
  444.         return $this;
  445.     }
  446.     public function getCompany(): ?Company
  447.     {
  448.         return $this->company;
  449.     }
  450.     public function setCompany(?Company $company): self
  451.     {
  452.         $this->company $company;
  453.         return $this;
  454.     }
  455.     public function getTeamplay(): ?Teamplay
  456.     {
  457.         return $this->teamplay;
  458.     }
  459.     public function setTeamplay(?Teamplay $teamplay): self
  460.     {
  461.         $this->teamplay $teamplay;
  462.         return $this;
  463.     }
  464.     public function getActive(): ?bool
  465.     {
  466.         return $this->active;
  467.     }
  468.     public function setActive(?bool $active): self
  469.     {
  470.         $this->active $active;
  471.         return $this;
  472.     }
  473.     public function getCreatedAt(): ?\DateTimeInterface
  474.     {
  475.         return $this->createdAt;
  476.     }
  477.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  478.     {
  479.         $this->createdAt $createdAt;
  480.         return $this;
  481.     }
  482.     public function getUpdatedAt(): ?\DateTimeInterface
  483.     {
  484.         return $this->updatedAt;
  485.     }
  486.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  487.     {
  488.         $this->updatedAt $updatedAt;
  489.         return $this;
  490.     }
  491.     /**
  492.      * @Groups({"teamplay_challenge:read:isInProgress", "teamplay_challenge:read", "teamplay_challenge_simple"})
  493.      */
  494.     public function isInProgress(): ?bool
  495.     {
  496.         $today = new \DateTime("now");
  497.         if($this->getDateStart() <= $today && $this->getDateEnd() > $today) {
  498.             return true;
  499.         }
  500.         return false;
  501.     }
  502.     /**
  503.      * @Groups({"teamplay_challenge:read:isInComing", "teamplay_challenge:read", "teamplay_challenge_simple"})
  504.      */
  505.     public function isInComing(): ?bool
  506.     {
  507.         $today = new \DateTime("now");
  508.         if($this->getDateStart() > $today) {
  509.             return true;
  510.         }
  511.         return false;
  512.     }
  513.     /**
  514.      * @Groups({"teamplay_challenge:read:isPassed", "teamplay_challenge:read", "teamplay_challenge_simple"})
  515.      */
  516.     public function isPassed(): ?bool
  517.     {
  518.         $today = new \DateTime("now");
  519.         if($this->getDateEnd() < $today) {
  520.             return true;
  521.         }
  522.         return false;
  523.     }
  524.     /**
  525.      * @return Collection|TeamplayLog[]
  526.      */
  527.     public function getTeamplayLogs(): Collection
  528.     {
  529.         return $this->teamplayLogs;
  530.     }
  531.     public function addTeamplayLog(TeamplayLog $teamplayLog): self
  532.     {
  533.         if (!$this->teamplayLogs->contains($teamplayLog)) {
  534.             $this->teamplayLogs[] = $teamplayLog;
  535.             $teamplayLog->setTeamplayChallenge($this);
  536.         }
  537.         return $this;
  538.     }
  539.     public function removeTeamplayLog(TeamplayLog $teamplayLog): self
  540.     {
  541.         if ($this->teamplayLogs->removeElement($teamplayLog)) {
  542.             // set the owning side to null (unless already changed)
  543.             if ($teamplayLog->getTeamplayChallenge() === $this) {
  544.                 $teamplayLog->setTeamplayChallenge(null);
  545.             }
  546.         }
  547.         return $this;
  548.     }
  549.     public function getAwardAmount(): ?int
  550.     {
  551.         return $this->awardAmount;
  552.     }
  553.     public function setAwardAmount(?int $awardAmount): self
  554.     {
  555.         $this->awardAmount $awardAmount;
  556.         return $this;
  557.     }
  558.     public function getIsMultipleWinnable(): ?bool
  559.     {
  560.         return $this->isMultipleWinnable;
  561.     }
  562.     public function setIsMultipleWinnable(bool $isMultipleWinnable): self
  563.     {
  564.         $this->isMultipleWinnable $isMultipleWinnable;
  565.         return $this;
  566.     }
  567.     public function getEveryInt(): ?int
  568.     {
  569.         return $this->everyInt;
  570.     }
  571.     public function setEveryInt(?int $everyInt): self
  572.     {
  573.         $this->everyInt $everyInt;
  574.         return $this;
  575.     }
  576.     public function getEveryDateType(): ?string
  577.     {
  578.         return $this->everyDateType;
  579.     }
  580.     public function setEveryDateType(?string $everyDateType): self
  581.     {
  582.         $this->everyDateType $everyDateType;
  583.         return $this;
  584.     }
  585. }