<?php
namespace App\Entity\Knowledge;
use App\Repository\Knowledge\KnowledgeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Ramsey\Uuid\Uuid;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\SerializedName;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* attributes={
"order"={"registerPosition":"ASC"}
* },
* collectionOperations={
* "public-get"={
* "method"="GET",
* "path"="/public/knowledges",
* "normalization_context"={"groups"={"Knowledge:output"}},
* "pagination_enabled"=false
* }
* }
* )
* @ApiFilter(SearchFilter::class, properties={"place": "partial"})
* @ApiFilter(BooleanFilter::class, properties={"online"})
* @ApiFilter(OrderFilter::class, properties={"registerPosition": "ASC"})
*
* @ORM\Entity(repositoryClass=KnowledgeRepository::class)
* @UniqueEntity(fields={"code"}, message="Ce code est déjà utilisé.")
*/
class Knowledge
{
const FIELD_TYPE_NUMBER = 'Nombre';
const FIELD_TYPE_IMAGE_TEXT = 'Image + texte';
const PLACE_MYACCOUNT = 'Mon compte';
const PLACE_INSCRIPTION_MYACCOUNT = 'Inscription + ' . self::PLACE_MYACCOUNT;
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @SerializedName("id")
* @Groups({"Knowledge:output"})
*/
private string $id;
/**
* @ORM\Column(type="string", length=20, nullable=true, unique=true)
* @Groups({"Knowledge:output"})
*/
private ?string $code;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $title;
/**
* @SerializedName("field_type")
* @ORM\Column(type="string", length=20, nullable=true)
* @Groups({"Knowledge:output"})
*/
private ?string $fieldType;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Knowledge:output"})
*/
private ?string $question;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"Knowledge:output"})
*/
private ?string $place;
/**
* @ORM\Column(type="boolean", options={"default": false})
* @Groups({"Knowledge:output"})
*/
private bool $required = false;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private bool $online = false;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({
* "Knowledge:output"
* })
* @SerializedName("register_position")
*/
private ?int $registerPosition = null;
/**
* @ORM\Column(type="integer")
* @Groups({
* "Knowledge:output"
* })
* @SerializedName("account_position")
*/
private int $accountPosition = 0;
/**
* @SerializedName("knowledge_responses")
* @ORM\OneToMany(targetEntity=KnowledgeResponse::class, mappedBy="knowledge", cascade={"persist", "remove"})
* @Groups({"Knowledge:output"})
*/
private Collection $knowledgeResponses;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->knowledgeResponses = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getFieldType(): ?string
{
return $this->fieldType;
}
public function setFieldType(?string $fieldType): self
{
$this->fieldType = $fieldType;
return $this;
}
public function getQuestion(): ?string
{
return $this->question;
}
public function setQuestion(?string $question): self
{
$this->question = $question;
return $this;
}
public function getPlace(): ?string
{
return $this->place;
}
public function setPlace(?string $place): self
{
$this->place = $place;
return $this;
}
public function isRequired(): ?bool
{
return $this->required;
}
public function setRequired(bool $required): self
{
$this->required = $required;
return $this;
}
public function isOnline(): ?bool
{
return $this->online;
}
public function setOnline(bool $online): self
{
$this->online = $online;
return $this;
}
public function getRegisterPosition(): ?int
{
return $this->registerPosition;
}
public function setRegisterPosition(?int $registerPosition): void
{
$this->registerPosition = $registerPosition;
}
public function getAccountPosition(): int
{
return $this->accountPosition;
}
public function setAccountPosition(int $accountPosition): void
{
$this->accountPosition = $accountPosition;
}
/**
* @return Collection<int, KnowledgeResponse>
*/
public function getKnowledgeResponses(): Collection
{
return $this->knowledgeResponses;
}
public function addKnowledgeResponse(KnowledgeResponse $knowledgeResponse): self
{
if (!$this->knowledgeResponses->contains($knowledgeResponse)) {
$this->knowledgeResponses[] = $knowledgeResponse;
$knowledgeResponse->setKnowledge($this);
}
return $this;
}
public function removeKnowledgeResponse(KnowledgeResponse $knowledgeResponse): self
{
if ($this->knowledgeResponses->removeElement($knowledgeResponse)) {
// set the owning side to null (unless already changed)
if ($knowledgeResponse->getKnowledge() === $this) {
$knowledgeResponse->setKnowledge(null);
}
}
return $this;
}
}