src/Entity/Section.php line 71

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use App\Controller\Action\SectionRankedController;
  6. use App\Repository\EvaluationRepository;
  7. use App\State\SectionDeleteProcessor;
  8. use App\State\SectionRankedProcessor;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\DBAL\Types\Types;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use ApiPlatform\Metadata\ApiResource;
  14. use ApiPlatform\Metadata\Delete;
  15. use ApiPlatform\Metadata\Get;
  16. use ApiPlatform\Metadata\GetCollection;
  17. use ApiPlatform\Metadata\Post;
  18. use ApiPlatform\Metadata\Put;
  19. use App\Controller\Action\SectionWithEvaluationStatAction;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. use Doctrine\Common\Collections\Criteria;
  22. #[ORM\Table(name'section')]
  23. #[ORM\Index(name'document_id'columns: ['document_id'])]
  24. #[ORM\Entity]
  25. #[ApiResource(
  26.     order: ['ranked' => 'ASC'],
  27.     normalizationContext: ['groups' => ['section.get']],
  28.     denormalizationContext: ['groups' => ['section.post']],
  29.     operations: [
  30.         new GetCollection(),
  31.         new GetCollection(
  32.             name'_api_/sections/with_stat',
  33.             uriTemplate'/sections/with_stat',
  34.             controllerSectionWithEvaluationStatAction::class,
  35.             writefalse,
  36.             readfalse
  37.         ),
  38.         new Post(
  39.             security'user.isMasterAdmin()',
  40.             securityMessage'You do not have permission to create a section.',
  41.         ),
  42.         new Post(
  43.             name'_api_/sections/reorder',
  44.             uriTemplate'/sections/reorder',
  45.             processorSectionRankedProcessor::class
  46.         ),
  47.         new Get(),
  48.         new Put(
  49.             name'_api_/sections/reorder/{id}',
  50.             uriTemplate'/sections/reorder/{id}',
  51.             processorSectionRankedProcessor::class,
  52.             security'user.isMasterAdmin()',
  53.             securityMessage'You do not have permission to reorder this section.',
  54.         ),
  55.         new Delete(
  56.             processorSectionDeleteProcessor::class,
  57.             security'user.isMasterAdmin()',
  58.             securityMessage'You do not have permission to delete this section.',
  59.         )
  60.     ])
  61. ]
  62. #[ApiFilter(
  63.     SearchFilter::class, properties: [
  64.         'title' => 'partial',
  65.         'document' => 'exact',
  66.     ]
  67. )]
  68. class Section
  69. {
  70.     #[ORM\Column(name'id'type'integer'nullablefalse)]
  71.     #[ORM\Id]
  72.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  73.     #[Groups(['section.get''plan.get'])]
  74.     private int $id;
  75.     #[ORM\Column(name'old_id'type'string'length255nullabletrue)]
  76.     private ?string $oldId null;
  77.     #[ORM\Column(name'title'type'string'length16777215nullabletrue)]
  78.     #[Groups(['section.get''plan.get''section.post'])]
  79.     private string $title;
  80.     #[ORM\Column(name'name'type'string'length16777215nullabletrue)]
  81.     #[Groups('section.get')]
  82.     private string $name;
  83.     #[ORM\Column(name'ranked'type'integer')]
  84.     #[Groups(['section.get''section.post'])]
  85.     private int $ranked 1;
  86.     #[ORM\JoinColumn(name'document_id'referencedColumnName'id')]
  87.     #[ORM\ManyToOne(targetEntity'Document'inversedBy'sections')]
  88.     #[Groups(['plan.get','section.post'])]
  89.     private Document $document;
  90.     #[ORM\OneToMany(mappedBy'section'targetEntityEvaluation::class)]
  91.     private Collection $evaluations;
  92.     #[ORM\OneToMany(mappedBy'section'targetEntityCompliance::class)]
  93.     private Collection $compliances;
  94.     #[ORM\Column(name'last_update_compliance'type'datetime'nullabletrue)]
  95.     #[Groups('section.get')]
  96.     private ?\DateTimeInterface $lastUpdateCompliance null;
  97.     public function __construct()
  98.     {
  99.         $this->evaluations = new ArrayCollection();
  100.         $this->compliances = new ArrayCollection();
  101.     }
  102.     public function getId(): ?int
  103.     {
  104.         return $this->id;
  105.     }
  106.     /**
  107.      * @param int $id
  108.      */
  109.     public function setId(int $id): void
  110.     {
  111.         $this->id $id;
  112.     }
  113.     public function getOldId(): ?string
  114.     {
  115.         return $this->oldId;
  116.     }
  117.     public function setOldId(?string $oldId): self
  118.     {
  119.         $this->oldId $oldId;
  120.         return $this;
  121.     }
  122.     public function getTitle(): string
  123.     {
  124.         return $this->title;
  125.     }
  126.     public function setTitle(string $title): self
  127.     {
  128.         $this->title $title;
  129.         return $this;
  130.     }
  131.     public function getRanked(): int
  132.     {
  133.         return $this->ranked;
  134.     }
  135.     public function setRanked(int $ranked): self
  136.     {
  137.         $this->ranked $ranked;
  138.         return $this;
  139.     }
  140.     public function getDocument(): Document
  141.     {
  142.         return $this->document;
  143.     }
  144.     public function setDocument(Document $document): self
  145.     {
  146.         $this->document $document;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return Collection<int, Evaluation>
  151.      */
  152.     public function getEvaluations(): Collection
  153.     {
  154.         return $this->evaluations;
  155.     }
  156.     /**
  157.      * @return Collection<int, Evaluation>
  158.      */
  159.     public function getEvaluationsBySiteId(Site $site): Collection
  160.     {
  161.         $criteria Criteria::create();
  162.         $criteria->where(Criteria::expr()->eq('site'$site));
  163.         return $this->evaluations->matching($criteria);
  164.     }
  165.     public function addEvaluation(Evaluation $evaluation): self
  166.     {
  167.         if (!$this->evaluations->contains($evaluation)) {
  168.             $this->evaluations->add($evaluation);
  169.             $evaluation->setSection($this);
  170.         }
  171.         return $this;
  172.     }
  173.     public function removeEvaluation(Evaluation $evaluation): self
  174.     {
  175.         if ($this->evaluations->removeElement($evaluation)) {
  176.             // set the owning side to null (unless already changed)
  177.             if ($evaluation->getSection() === $this) {
  178.                 $evaluation->setSection(null);
  179.             }
  180.         }
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return Collection
  185.      */
  186.     public function getCompliances(): Collection
  187.     {
  188.         return $this->compliances;
  189.     }
  190.     #[Groups(['section.get''document.get'])]
  191.     public function getCompliancesCount()
  192.     {
  193.         return $this->compliances->count();
  194.     }
  195.     public function getLastUpdateCompliance(): ?\DateTimeInterface
  196.     {
  197.         return $this->lastUpdateCompliance;
  198.     }
  199.     public function setLastUpdateCompliance(?\DateTimeInterface $lastUpdateCompliance): self
  200.     {
  201.         $this->lastUpdateCompliance $lastUpdateCompliance;
  202.         return $this;
  203.     }
  204. }