src/Entity/Knowledge/Knowledge.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Knowledge;
  3. use App\Repository\Knowledge\KnowledgeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. use Ramsey\Uuid\Doctrine\UuidGenerator;
  9. use Ramsey\Uuid\Uuid;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Serializer\Annotation\SerializedName;
  12. use ApiPlatform\Core\Annotation\ApiFilter;
  13. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  14. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  15. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  16. use ApiPlatform\Core\Annotation\ApiResource;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. /**
  19.  * @ApiResource(
  20.  *     attributes={
  21.             "order"={"registerPosition":"ASC"}
  22.  *     },
  23.  *     collectionOperations={
  24.  *           "public-get"={
  25.  *              "method"="GET",
  26.  *              "path"="/public/knowledges",
  27.  *              "normalization_context"={"groups"={"Knowledge:output"}},
  28.  *              "pagination_enabled"=false
  29.  *          }
  30.  *     }
  31.  * )
  32.  * @ApiFilter(SearchFilter::class, properties={"place": "partial"})
  33.  * @ApiFilter(BooleanFilter::class, properties={"online"})
  34.  * @ApiFilter(OrderFilter::class, properties={"registerPosition": "ASC"})
  35.  *
  36.  * @ORM\Entity(repositoryClass=KnowledgeRepository::class)
  37.  * @UniqueEntity(fields={"code"}, message="Ce code est déjà utilisé.")
  38.  */
  39. class Knowledge
  40. {
  41.     const FIELD_TYPE_NUMBER 'Nombre';
  42.     const FIELD_TYPE_IMAGE_TEXT 'Image + texte';
  43.     const PLACE_MYACCOUNT 'Mon compte';
  44.     const PLACE_INSCRIPTION_MYACCOUNT 'Inscription + ' self::PLACE_MYACCOUNT;
  45.     use TimestampableEntity;
  46.     /**
  47.      * @ORM\Id
  48.      * @ORM\Column(type="uuid", unique=true)
  49.      * @ORM\GeneratedValue(strategy="CUSTOM")
  50.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  51.      * @SerializedName("id")
  52.      * @Groups({"Knowledge:output"})
  53.      */
  54.     private string $id;
  55.     /**
  56.      * @ORM\Column(type="string", length=20, nullable=true, unique=true)
  57.      * @Groups({"Knowledge:output"})
  58.      */
  59.     private ?string $code;
  60.     /**
  61.      * @ORM\Column(type="string", length=255, nullable=true)
  62.      */
  63.     private ?string $title;
  64.     /**
  65.      * @SerializedName("field_type")
  66.      * @ORM\Column(type="string", length=20, nullable=true)
  67.      * @Groups({"Knowledge:output"})
  68.      */
  69.     private ?string $fieldType;
  70.     /**
  71.      * @ORM\Column(type="string", length=255, nullable=true)
  72.      * @Groups({"Knowledge:output"})
  73.      */
  74.     private ?string $question;
  75.     /**
  76.      * @ORM\Column(type="string", length=255, nullable=true)
  77.      * @Groups({"Knowledge:output"})
  78.      */
  79.     private ?string $place;
  80.     /**
  81.      * @ORM\Column(type="boolean", options={"default": false})
  82.      * @Groups({"Knowledge:output"})
  83.      */
  84.     private bool $required false;
  85.     /**
  86.      * @ORM\Column(type="boolean", options={"default": false})
  87.      */
  88.     private bool $online false;
  89.     /**
  90.      * @ORM\Column(type="integer", nullable=true)
  91.      * @Groups({
  92.      *     "Knowledge:output"
  93.      * })
  94.      * @SerializedName("register_position")
  95.      */
  96.     private ?int $registerPosition null;
  97.     /**
  98.      * @ORM\Column(type="integer")
  99.      * @Groups({
  100.      *     "Knowledge:output"
  101.      * })
  102.      * @SerializedName("account_position")
  103.      */
  104.     private int $accountPosition 0;
  105.     /**
  106.      * @SerializedName("knowledge_responses")
  107.      * @ORM\OneToMany(targetEntity=KnowledgeResponse::class, mappedBy="knowledge", cascade={"persist", "remove"})
  108.      * @Groups({"Knowledge:output"})
  109.      */
  110.     private Collection $knowledgeResponses;
  111.     public function __construct()
  112.     {
  113.         $this->id Uuid::uuid4();
  114.         $this->knowledgeResponses = new ArrayCollection();
  115.     }
  116.     public function getId(): ?string
  117.     {
  118.         return $this->id;
  119.     }
  120.     public function getCode(): ?string
  121.     {
  122.         return $this->code;
  123.     }
  124.     public function setCode(?string $code): self
  125.     {
  126.         $this->code $code;
  127.         return $this;
  128.     }
  129.     public function getTitle(): ?string
  130.     {
  131.         return $this->title;
  132.     }
  133.     public function setTitle(?string $title): self
  134.     {
  135.         $this->title $title;
  136.         return $this;
  137.     }
  138.     public function getFieldType(): ?string
  139.     {
  140.         return $this->fieldType;
  141.     }
  142.     public function setFieldType(?string $fieldType): self
  143.     {
  144.         $this->fieldType $fieldType;
  145.         return $this;
  146.     }
  147.     public function getQuestion(): ?string
  148.     {
  149.         return $this->question;
  150.     }
  151.     public function setQuestion(?string $question): self
  152.     {
  153.         $this->question $question;
  154.         return $this;
  155.     }
  156.     public function getPlace(): ?string
  157.     {
  158.         return $this->place;
  159.     }
  160.     public function setPlace(?string $place): self
  161.     {
  162.         $this->place $place;
  163.         return $this;
  164.     }
  165.     public function isRequired(): ?bool
  166.     {
  167.         return $this->required;
  168.     }
  169.     public function setRequired(bool $required): self
  170.     {
  171.         $this->required $required;
  172.         return $this;
  173.     }
  174.     public function isOnline(): ?bool
  175.     {
  176.         return $this->online;
  177.     }
  178.     public function setOnline(bool $online): self
  179.     {
  180.         $this->online $online;
  181.         return $this;
  182.     }
  183.     public function getRegisterPosition(): ?int
  184.     {
  185.         return $this->registerPosition;
  186.     }
  187.     public function setRegisterPosition(?int $registerPosition): void
  188.     {
  189.         $this->registerPosition $registerPosition;
  190.     }
  191.     public function getAccountPosition(): int
  192.     {
  193.         return $this->accountPosition;
  194.     }
  195.     public function setAccountPosition(int $accountPosition): void
  196.     {
  197.         $this->accountPosition $accountPosition;
  198.     }
  199.     /**
  200.      * @return Collection<int, KnowledgeResponse>
  201.      */
  202.     public function getKnowledgeResponses(): Collection
  203.     {
  204.         return $this->knowledgeResponses;
  205.     }
  206.     public function addKnowledgeResponse(KnowledgeResponse $knowledgeResponse): self
  207.     {
  208.         if (!$this->knowledgeResponses->contains($knowledgeResponse)) {
  209.             $this->knowledgeResponses[] = $knowledgeResponse;
  210.             $knowledgeResponse->setKnowledge($this);
  211.         }
  212.         return $this;
  213.     }
  214.     public function removeKnowledgeResponse(KnowledgeResponse $knowledgeResponse): self
  215.     {
  216.         if ($this->knowledgeResponses->removeElement($knowledgeResponse)) {
  217.             // set the owning side to null (unless already changed)
  218.             if ($knowledgeResponse->getKnowledge() === $this) {
  219.                 $knowledgeResponse->setKnowledge(null);
  220.             }
  221.         }
  222.         return $this;
  223.     }
  224. }