<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Repository\AwardOperationRepository;
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\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=AwardOperationRepository::class)
* @ApiResource(
* normalizationContext={
* "groups"={"award_operation:read"}
* },
* denormalizationContext={
* "groups"={"award_operation:write"}
* },
* collectionOperations={
* "get"={"security"="is_granted('ROLE_USER')"}
* },
* itemOperations={
* "get"={"security"="is_granted('ROLE_USER')"},
* "patch"={"security"="is_granted('ROLE_ADMIN')"}
* }
* )
* @ApiFilter(SearchFilter::class)
* @ApiFilter(PropertyFilter::class,
* arguments={
* "parameterName"="fields",
* "overrideDefaultProperties"=true
* }
* )
*/
class AwardOperation
{
const GLOBAL_TYPE = "global";
const ACTION_TYPE = "action";
const TEAMPLAY_ACTION_TYPE = "teamplay_action";
// Global objectives
const MAIN_OBJECTIVE = "main_objective";
// Actions disponibles
const THEMATIC_START = "thematic_start";
const PROGRAM_START = "program_start";
const PROGRAM_END = "program_end";
const SURVEY_HOMEPAGE = "survey_homepage";
const SURVEY_PROGRAM = "survey_program";
const VIDEO_PLAY = "video_play";
const VIDEO_PLAY_10_TIMES = "video_play_10_times";
const MOOD_SUBMIT = "mood_submit";
const MOOD_SUBMIT_7_DAYS = "mood_submit_7_days";
const TYPES = [
self::GLOBAL_TYPE,
self::ACTION_TYPE,
self::TEAMPLAY_ACTION_TYPE,
];
const SUB_TYPES = [
self::MAIN_OBJECTIVE,
self::THEMATIC_START,
self::PROGRAM_START,
self::PROGRAM_END,
self::SURVEY_HOMEPAGE,
self::SURVEY_PROGRAM,
self::VIDEO_PLAY,
self::VIDEO_PLAY_10_TIMES,
self::MOOD_SUBMIT,
self::MOOD_SUBMIT_7_DAYS,
TeamplayChallenge::TYPE_RECURRENT_RANKING_AWARD,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"award_operation:read", "award_config:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Choice(choices=self::TYPES)
* @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
*/
private $type = self::GLOBAL_TYPE;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Choice(choices=self::SUB_TYPES)
* @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
*/
private $subType = self::MAIN_OBJECTIVE;
/**
* @ORM\Column(name="`rank`", type="integer", nullable=true)
* @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
*/
private $rank;
/**
* @ORM\OneToMany(targetEntity=AwardConfig::class, mappedBy="operation")
* @Groups({"award_operation:read", "award_operation:write"})
*/
private $configs;
/**
* @ORM\Column(type="boolean", options={"default": "1"})
* @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
*/
private $active = true;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
public function __construct()
{
$this->configs = new ArrayCollection();
$this->createdAt = new \DateTime("now");
$this->updatedAt = new \DateTime("now");
$this->active = true;
}
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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
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 getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getRank(): ?int
{
return $this->rank;
}
public function setRank(?int $rank): self
{
$this->rank = $rank;
return $this;
}
/**
* @return Collection|AwardConfig[]
*/
public function getConfigs(): Collection
{
return $this->configs;
}
public function addConfig(AwardConfig $config): self
{
if (!$this->configs->contains($config)) {
$this->configs[] = $config;
$config->setOperation($this);
}
return $this;
}
public function removeConfig(AwardConfig $config): self
{
if ($this->configs->removeElement($config)) {
// set the owning side to null (unless already changed)
if ($config->getOperation() === $this) {
$config->setOperation(null);
}
}
return $this;
}
public function getSubType(): ?string
{
return $this->subType;
}
public function setSubType(?string $subType): self
{
$this->subType = $subType;
return $this;
}
}