<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Repository\TeamplayChallengeRepository;
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;
/**
* @ApiResource(
* normalizationContext={
* "groups"={"teamplay_challenge:read"}
* },
* denormalizationContext={
* "groups"={"teamplay_challenge:write"}
* },
* itemOperations={
* "get"={
* "security"="is_granted('ROLE_USER')"
* },
* "patch"={
* "security"="is_granted('ROLE_ADMIN')"
* },
* "delete"={
* "security"="is_granted('ROLE_ADMIN')"
* }
* },
* collectionOperations={
* "get"={
* "security"="is_granted('ROLE_USER')"
* },
* "get_client_teamplay_collected"={
* "security"="is_granted('ROLE_CLIENT')",
* "method"="GET",
* "description"="Get completed TeamplayChallenge by a Client",
* "controller"="App\Controller\Api\TeamplayChallengeController::getClientTeamplayChallengeCompleted"
* },
* "post"={
* "security"="is_granted('ROLE_ADMIN')"
* },
* "post_update"={
* "security"="is_granted('ROLE_ADMIN')",
* "path"="/teamplay_challenges/{id}",
* "description"="Update a TeamplayChallenge with method POST (using content-type: 'multipart')",
* "method"="POST",
* "controller"="App\Controller\Api\TeamplayChallengeController::update"
* }
* }
* )
* @ORM\Entity(repositoryClass=TeamplayChallengeRepository::class)
* @ApiFilter(SearchFilter::class,
* strategy="exact",
* properties={"active", "teamplay.id", "name": "partial", "type", "company.id", "isTemplate"}
* )
* @ApiFilter(ExistsFilter::class, properties={"teamplay", "company", "video", "survey", "type"})
* @ApiFilter(BooleanFilter::class, properties={"active", "isTemplate"})
* @ApiFilter(DateFilter::class, properties={"dateStart", "dateEnd"})
* @ApiFilter(OrderFilter::class)
* @ApiFilter(GroupFilter::class,
* arguments={
* "parameterName": "groups",
* "overrideDefaultGroups": true
* }
* )
* @ApiFilter(PropertyFilter::class,
* arguments={
* "parameterName"="fields",
* "overrideDefaultProperties"=true
* }
* )
*/
class TeamplayChallenge
{
const TYPE_STEP = "step";
const TYPE_RECURRENT_STEP = "recurrent_step";
const TYPE_RECURRENT_RANKING_AWARD = "recurrent_ranking_award";
const TYPE_VIDEO_PHYSICAL = "video_physical";
const TYPE_VIDEO_INTERVIEW = "video_interview";
const TYPE_QUIZ = "quiz";
const TYPES = [
self::TYPE_STEP,
self::TYPE_RECURRENT_STEP,
self::TYPE_RECURRENT_RANKING_AWARD,
self::TYPE_VIDEO_PHYSICAL,
self::TYPE_VIDEO_INTERVIEW,
self::TYPE_QUIZ,
];
const STATUS_IN_PROGRESS = "in_progress";
const STATUS_IN_COMING = "in_coming";
const STATUS_PASSED= "passed";
const STATUS = [
self::STATUS_IN_PROGRESS,
self::STATUS_IN_COMING,
self::STATUS_PASSED
];
const EVERY_TYPE_HOUR = "hour";
const EVERY_TYPE_DAY = "day";
const EVERY_TYPE_WEEK = "week";
const EVERY_TYPE_MONTH = "month";
const EVERY_TYPE_YEAR = "year";
const EVERY_DATE_TYPES = [
self::EVERY_TYPE_HOUR,
self::EVERY_TYPE_DAY,
self::EVERY_TYPE_WEEK,
self::EVERY_TYPE_MONTH,
self::EVERY_TYPE_YEAR,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"teamplay_challenge:read:id", "teamplay_challenge:read", "teamplay_challenge_simple", "teamplay:read", "challenge_form"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"teamplay_challenge:read:name", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read", "challenge_form"})
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"teamplay_challenge:read:description", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Choice(choices=self::TYPES)
* @Groups({"teamplay_challenge:read:type", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $type;
/**
* @ORM\ManyToOne(targetEntity=MediaObject::class)
* @Groups({"teamplay_challenge:read:picture", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $picture;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"teamplay_challenge:read:duration", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $duration;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"teamplay_challenge:read:pointAmount", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $pointAmount;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"teamplay_challenge:read:stepAmount", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $stepAmount;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"teamplay_challenge:read:dayStart", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $dayStart;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"teamplay_challenge:read:dayEnd", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $dayEnd;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"teamplay_challenge:read:dateStart", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $dateStart;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"teamplay_challenge:read:dateEnd", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $dateEnd;
/**
* @ORM\ManyToOne(targetEntity=Video::class, inversedBy="teamplayChallenges")
* @Groups({"teamplay_challenge:read:video", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $video;
/**
* @ORM\ManyToOne(targetEntity=Survey::class, inversedBy="teamplayChallenges", cascade={"persist", "refresh", "remove"})
* @Groups({"teamplay_challenge:read:survey", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $survey;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": "1"})
* @Groups({"teamplay_challenge:read:isTemplate", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $isTemplate = true;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"teamplay_challenge:read:awardAmount", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $awardAmount;
/**
* @ORM\Column(type="boolean", options={"default": "0"})
* @Groups({"teamplay_challenge:read:isMultipleWinnable", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $isMultipleWinnable = false;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"teamplay_challenge:read:everyInt", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $everyInt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"teamplay_challenge:read:everyDateType", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $everyDateType;
/**
* @ORM\ManyToOne(targetEntity=TvCompany::class, inversedBy="teamplayChallenges")
*/
private $tvCompany;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="teamplayChallenges")
* @Groups({"teamplay_challenge:read:company", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $company;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": "1"})
* @Groups({"teamplay_challenge:read:active", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple", "teamplay:read"})
*/
private $active = true;
/**
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
* @Gedmo\Timestampable(on="create")
* @Groups({"teamplay_challenge:read:createdAt", "teamplay_challenge:read", "teamplay_challenge_simple"})
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
* @Groups({"teamplay_challenge:read:updatedAt", "teamplay_challenge:read", "teamplay_challenge_simple"})
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=Teamplay::class, inversedBy="challenges", cascade={"refresh"})
* @Groups({"teamplay_challenge:read:teamplay", "teamplay_challenge:read", "teamplay_challenge:write", "teamplay_challenge_simple"})
*/
private $teamplay;
/**
* @ORM\OneToMany(targetEntity=TeamplayLog::class, mappedBy="teamplayChallenge", cascade={"persist", "refresh", "remove"})
*/
private $teamplayLogs;
/**
* Champ Custom (PostLoad)
* Permet de savoir si le TeamplayChallenge a été complété par le Client connecté
* @var ?bool
* @Groups({"teamplay_challenge:read:isCompleted", "teamplay_challenge:read"})
*/
public $isCompleted = null;
/**
* Champ Custom (PostLoad)
* Permet de savoir si le Client connct a récupéré les points du TeamplayChallenge
* @var ?bool
* @Groups({"teamplay_challenge:read:isCollected", "teamplay_challenge:read"})
*/
public $isCollected = null;
/**
* Champ Custom (PostLoad)
* Permet de savoir si le Client connct a récupéré les points du TeamplayChallenge
* @var ?int
* @Groups({"teamplay_challenge:read:userStepsAmount", "teamplay_challenge:read"})
*/
public $userStepsAmount = null;
public function __construct()
{
$this->teamplayLogs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(?int $id): self
{
$this->id = $id;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getPicture(): ?MediaObject
{
return $this->picture;
}
public function setPicture(?MediaObject $picture): self
{
$this->picture = $picture;
return $this;
}
/**
* @Groups({"teamplay_challenge: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 getDuration(): ?int
{
return $this->duration;
}
public function setDuration(?int $duration): self
{
$this->duration = $duration;
return $this;
}
public function getPointAmount(): ?int
{
return $this->pointAmount;
}
public function setPointAmount(?int $pointAmount): self
{
$this->pointAmount = $pointAmount;
return $this;
}
public function getStepAmount(): ?int
{
return $this->stepAmount;
}
public function setStepAmount(?int $stepAmount): self
{
$this->stepAmount = $stepAmount;
return $this;
}
public function getDayStart(): ?int
{
return $this->dayStart;
}
public function setDayStart(?int $dayStart): self
{
$this->dayStart = $dayStart;
return $this;
}
public function getDayEnd(): ?int
{
return $this->dayEnd;
}
public function setDayEnd(?int $dayEnd): self
{
$this->dayEnd = $dayEnd;
return $this;
}
public function getDateStart(): ?\DateTimeInterface
{
return $this->dateStart;
}
public function setDateStart(?\DateTimeInterface $dateStart = null): self
{
$this->dateStart = $dateStart;
return $this;
}
public function getDateEnd(): ?\DateTimeInterface
{
return $this->dateEnd;
}
public function setDateEnd(?\DateTimeInterface $dateEnd): self
{
$this->dateEnd = $dateEnd;
return $this;
}
public function getVideo(): ?Video
{
return $this->video;
}
public function setVideo(?Video $video): self
{
$this->video = $video;
return $this;
}
public function getSurvey(): ?Survey
{
return $this->survey;
}
public function setSurvey(?Survey $survey): self
{
$this->survey = $survey;
return $this;
}
/**
* Permet de savoir si c'est une modèle
* Critères d'un modèle :
* - Ne pas être lié à une Company
* @return bool
*/
public function isTemplate(): bool
{
return $this->getIsTemplate();
}
public function getIsTemplate(): ?bool
{
return $this->isTemplate;
}
public function setIsTemplate(?bool $isTemplate): self
{
$this->isTemplate = $isTemplate;
return $this;
}
public function getTvCompany(): ?TvCompany
{
return $this->tvCompany;
}
public function setTvCompany(?TvCompany $tvCompany): self
{
$this->tvCompany = $tvCompany;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getTeamplay(): ?Teamplay
{
return $this->teamplay;
}
public function setTeamplay(?Teamplay $teamplay): self
{
$this->teamplay = $teamplay;
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;
}
/**
* @Groups({"teamplay_challenge:read:isInProgress", "teamplay_challenge:read", "teamplay_challenge_simple"})
*/
public function isInProgress(): ?bool
{
$today = new \DateTime("now");
if($this->getDateStart() <= $today && $this->getDateEnd() > $today) {
return true;
}
return false;
}
/**
* @Groups({"teamplay_challenge:read:isInComing", "teamplay_challenge:read", "teamplay_challenge_simple"})
*/
public function isInComing(): ?bool
{
$today = new \DateTime("now");
if($this->getDateStart() > $today) {
return true;
}
return false;
}
/**
* @Groups({"teamplay_challenge:read:isPassed", "teamplay_challenge:read", "teamplay_challenge_simple"})
*/
public function isPassed(): ?bool
{
$today = new \DateTime("now");
if($this->getDateEnd() < $today) {
return true;
}
return false;
}
/**
* @return Collection|TeamplayLog[]
*/
public function getTeamplayLogs(): Collection
{
return $this->teamplayLogs;
}
public function addTeamplayLog(TeamplayLog $teamplayLog): self
{
if (!$this->teamplayLogs->contains($teamplayLog)) {
$this->teamplayLogs[] = $teamplayLog;
$teamplayLog->setTeamplayChallenge($this);
}
return $this;
}
public function removeTeamplayLog(TeamplayLog $teamplayLog): self
{
if ($this->teamplayLogs->removeElement($teamplayLog)) {
// set the owning side to null (unless already changed)
if ($teamplayLog->getTeamplayChallenge() === $this) {
$teamplayLog->setTeamplayChallenge(null);
}
}
return $this;
}
public function getAwardAmount(): ?int
{
return $this->awardAmount;
}
public function setAwardAmount(?int $awardAmount): self
{
$this->awardAmount = $awardAmount;
return $this;
}
public function getIsMultipleWinnable(): ?bool
{
return $this->isMultipleWinnable;
}
public function setIsMultipleWinnable(bool $isMultipleWinnable): self
{
$this->isMultipleWinnable = $isMultipleWinnable;
return $this;
}
public function getEveryInt(): ?int
{
return $this->everyInt;
}
public function setEveryInt(?int $everyInt): self
{
$this->everyInt = $everyInt;
return $this;
}
public function getEveryDateType(): ?string
{
return $this->everyDateType;
}
public function setEveryDateType(?string $everyDateType): self
{
$this->everyDateType = $everyDateType;
return $this;
}
}