src/Entity/Section.php line 70

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