src/Entity/Site.php line 149

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Controller\Action\CloneSiteActionController;
  4. use App\Controller\Action\DeleteSitesController;
  5. use App\Controller\Action\DocumentSiteDeleteActionController;
  6. use App\Controller\Action\GetFilsOfParentEntityAction;
  7. use App\Controller\Action\GetSiteAction;
  8. use App\Controller\Action\ListProcessingTasksController;
  9. use App\Controller\Action\ReportMonthlyEvolutionController;
  10. use App\Controller\Action\SiteAffectationController;
  11. use App\Controller\Action\StatConformiteSiteController;
  12. use App\Controller\Action\StatECRAction;
  13. use App\Controller\Action\StatGlobalConformityRatpController;
  14. use App\Services\SiteService;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Doctrine\Common\Collections\Collection;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use ApiPlatform\Metadata\ApiResource;
  19. use Doctrine\ORM\Mapping\PrePersist;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. use App\Traits\AutoTimestampTrait;
  22. use App\ApiPlatform\CustomerAwareInterface;
  23. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  24. use ApiPlatform\Metadata\ApiFilter;
  25. use ApiPlatform\Metadata\Delete;
  26. use ApiPlatform\Metadata\Get;
  27. use ApiPlatform\Metadata\GetCollection;
  28. use ApiPlatform\Metadata\Post;
  29. use ApiPlatform\Metadata\Put;
  30. use App\Controller\Action\SiteWithEvaluationStatAction;
  31. #[ORM\Table(name'site')]
  32. #[ORM\Index(name'parent_id'columns: ['parent_id'])]
  33. #[ORM\Index(name'customer_id'columns: ['customer_id'])]
  34. #[ORM\Entity]
  35. #[ApiResource(
  36.     operations: [
  37.         new GetCollection(
  38.             order: ['code' => 'ASC'],
  39.             paginationEnabledfalse
  40.         ),
  41.         new GetCollection(
  42.             name'_api_/sites/with_stat',
  43.             uriTemplate'/sites/with_stat',
  44.             controllerSiteWithEvaluationStatAction::class,
  45.             writefalse,
  46.             readfalse
  47.         ),
  48.         new GetCollection(
  49.             name'_api_/site_affectation',
  50.             uriTemplate'/site_affectation',
  51.             controllerSiteAffectationController::class,
  52.             writefalse,
  53.             readfalse
  54.         ),
  55.         new GetCollection(
  56.             name'_api_/report_monthly_evolution',
  57.             uriTemplate'/report_monthly_evolution',
  58.             controllerReportMonthlyEvolutionController::class,
  59.             writefalse,
  60.             readfalse
  61.         ),
  62.         new GetCollection(
  63.             name'_api_/stat_conformite_site',
  64.             uriTemplate'/stat_conformite_site',
  65.             controllerStatConformiteSiteController::class,
  66.             writefalse,
  67.             readfalse
  68.         ),
  69.         new Post(
  70.             uriTemplate'/stat_global_conformity_ratp',
  71.             controllerStatGlobalConformityRatpController::class,
  72.             readfalse,
  73.             writefalse,
  74.             name'_api_/stat_global_conformity_ratp'
  75.         ),
  76.         new Post(
  77.             name'_api_/list_processing_tasks_site',
  78.             uriTemplate'/list_processing_tasks_site',
  79.             controllerListProcessingTasksController::class,
  80.             writefalse,
  81.             readfalse
  82.         ),
  83.         new GetCollection(
  84.             name'_api_/list_site_of_parent',
  85.             uriTemplate'/list_site_of_parent',
  86.             controllerGetFilsOfParentEntityAction::class,
  87.             writefalse,
  88.             readfalse
  89.         ),
  90.         new Post(
  91.             name'_api_/sites/clone',
  92.             uriTemplate'/sites/clone',
  93.             controllerCloneSiteActionController::class,
  94.             writefalse,
  95.             readfalse
  96.             ),
  97.         new Post(
  98.             security'user.isMasterAdmin()',
  99.         ),
  100.         new Get(),
  101.         new Get(
  102.             name'_api_/site/{id}',
  103.             uriTemplate'/site/{id}',
  104.             controllerGetSiteAction::class,
  105.             writefalse,
  106.             readfalse
  107.         ),
  108.         new Post(
  109.             name'_api_/stat_ECR_100',
  110.             uriTemplate'/stat_ECR_100',
  111.             controllerStatECRAction::class,
  112.             writefalse,
  113.             readfalse
  114.         ),
  115.         new Post(
  116.             name'_api_/delete_site',
  117.             uriTemplate'/delete_site',
  118.             controllerDeleteSitesController::class,
  119.             writefalse,
  120.             readfalse
  121.         ),
  122.         new Put(
  123.             security'user.isMasterAdmin()',
  124.         ),
  125.         new Delete(
  126.             // Duplicate de l'operation delete , il y a deja une POST pour supprimer un site
  127.             security'user.isMasterAdmin()',
  128.         )
  129.     ],
  130.     normalizationContext: ['groups' => ['site.get''document.get''user.get''customer.get''discussion.get']],
  131.     denormalizationContext: ['groups' => ['site.write']]
  132. )]
  133. #[ORM\HasLifecycleCallbacks]
  134. #[ApiFilter(
  135.     SearchFilter::class,
  136.     properties: [
  137.         'id' => 'exact',
  138.         'type' => 'exact',
  139.         'customer' => 'exact',
  140.         'userSites.user' => 'exact',
  141.         'affectations.document' => 'exact'
  142.     ]
  143. )]
  144. class Site implements CustomerAwareInterface
  145. {
  146.     use AutoTimestampTrait;
  147.     const SITE_TYPE 'site';
  148.     const ENTITY_TYPE 'entity';
  149.     #[ORM\Column(name'id'type'integer'nullablefalse)]
  150.     #[ORM\Id]
  151.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  152.     #[Groups(['site.get''document.get''user.get''customer.get''plan.get'])]
  153.     private int $id;
  154.     #[ORM\Column(name'old_id'type'string'length255nullabletrue)]
  155.     private ?string $oldId null;
  156.     #[ORM\Column(name'code'type'string'length255nullabletrue)]
  157.     #[Groups(['site.get''site.write''customer.get''user.get''plan.get'])]
  158.     private ?string $code null;
  159.     #[ORM\Column(name'name'type'string'length255nullabletrue)]
  160.     #[Groups(['site.get''site.write''document.get''user.get''customer.get''plan.get'])]
  161.     private ?string $name null;
  162.     #[ORM\Column(name'kind'type'string'length255nullabletrue)]
  163.     #[Groups(['site.get''site.write'])]
  164.     private ?string $kind null;
  165.     #[ORM\Column(name'address'type'string'length255nullabletrue)]
  166.     #[Groups(['site.get''site.write'])]
  167.     private ?string $address null;
  168.     #[ORM\Column(name'additional_address'type'string'length255nullabletrue)]
  169.     #[Groups(['site.get''site.write'])]
  170.     private ?string $additionalAddress null;
  171.     #[ORM\Column(name'zipcode'type'string'length255nullabletrue)]
  172.     #[Groups(['site.get''site.write''document.get'])]
  173.     private ?string $zipcode null;
  174.     #[ORM\Column(name'phone'type'string'length255nullabletrue)]
  175.     #[Groups(['site.get''site.write''document.get'])]
  176.     private ?string $phone null;
  177.     #[ORM\Column(name'naf'type'string'length255nullabletrue)]
  178.     #[Groups(['site.get''site.write'])]
  179.     private ?string $naf null;
  180.     #[ORM\Column(name'adr'type'string'length255nullabletrue)]
  181.     #[Groups(['site.get''site.write'])]
  182.     private ?string $adr null;
  183.     #[ORM\Column(name'fax'type'string'length255nullabletrue)]
  184.     #[Groups(['site.get''site.write'])]
  185.     private ?string $fax null;
  186.     #[ORM\Column(name'groupe'type'string'length255nullabletrue)]
  187.     #[Groups(['site.get''site.write'])]
  188.     private ?string $groupe null;
  189.     #[ORM\Column(name'coordinates_lambert'type'string'length255nullabletrue)]
  190.     #[Groups(['site.get''site.write'])]
  191.     private ?string $coordinatesLambert null;
  192.     #[ORM\Column(name'is_active'type'boolean'nullabletrue)]
  193.     #[Groups(['site.get''site.write'])]
  194.     private ?bool $isActive null;
  195.     #[ORM\Column(name'type'type'string'length255)]
  196.     #[Groups(['site.get''site.write''document.get''customer.get'])]
  197.     private ?string $type self::ENTITY_TYPE;
  198.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'sites')]
  199.     #[Groups(['site.write'])]
  200.     private ?self $parent null;
  201.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  202.     #[Groups(['site.get','customer.get''site.write'])]
  203.     private Collection $sites;
  204.     #[ORM\OneToMany(mappedBy'site'targetEntityAffectation::class, cascade: ['persist'], orphanRemovaltrue)]
  205.     #[Groups(['site.write'])]
  206.     private Collection $affectations;
  207.     #[ORM\OneToMany(mappedBy'site'targetEntityUserSite::class)]
  208.     #[Groups(['site.write''plan.get'])]
  209.     private Collection $userSites;
  210.     #[ORM\Column(length255nullabletrue)]
  211.     #[Groups(['site.get''site.write'])]
  212.     private ?string $city null;
  213.     #[ORM\Column(name'reference'type'string'length255nullabletrue)]
  214.     #[Groups(['site.get''site.write'])]
  215.     private ?string $reference null;
  216.     #[ORM\ManyToMany(targetEntityCountry::class)]
  217.     #[Groups(['site.write''site.get'])]
  218.     private Collection $documentCountries;
  219.     #[ORM\ManyToMany(targetEntityCategory::class)]
  220.     #[Groups(['site.write''site.get'])]
  221.     private Collection $documentThemes;
  222.     #[ORM\ManyToOne]
  223.     private ?Country $country null;
  224.     #[ORM\OneToMany(mappedBy'site'targetEntityEvaluation::class)]
  225.     private Collection $evaluations;
  226.     #[ORM\ManyToOne(cascade: ['persist'])]
  227.     #[ORM\JoinColumn(name'customer_id'referencedColumnName'id')]
  228.     #[Groups(['site.get','site.write'])]
  229.     private ?Customer $customer null;
  230.     #[ORM\Column(name'init_site'type'boolean'nullabletrueoptions: ['default' => false])]
  231.     #[Groups(['site.get','site.write'])]
  232.     private ?bool $initStatus false;
  233.     #[ORM\OneToMany(mappedBy'site'targetEntitySiteQuestions::class)]
  234.     private Collection $siteQuestions;
  235.     #[ORM\Column(nullabletrue)]
  236.     #[Groups(['site.get','site.write''discussion.get'])]
  237.     private ?array $path = [];
  238.     #[ORM\Column(nullabletrue)]
  239.     #[Groups(['site.get''site.write'])]
  240.     private ?int $year null;
  241.     public function __construct()
  242.     {
  243.         $this->sites = new ArrayCollection();
  244.         $this->affectations = new ArrayCollection();
  245.         $this->users = new ArrayCollection();
  246.         $this->userSites = new ArrayCollection();
  247.         $this->countries = new ArrayCollection();
  248.         $this->categories = new ArrayCollection();
  249.         $this->documentCountries = new ArrayCollection();
  250.         $this->documentThemes = new ArrayCollection();
  251.         $this->evaluations = new ArrayCollection();
  252.         $this->initStatus true;
  253.         $this->siteQuestions = new ArrayCollection();
  254.     }
  255.     public function getId(): ?int
  256.     {
  257.         return $this->id;
  258.     }
  259.     public function setId(int $id): void
  260.     {
  261.         $this->id $id;
  262.     }
  263.     public function getOldId(): ?string
  264.     {
  265.         return $this->oldId;
  266.     }
  267.     public function setOldId(?string $oldId): self
  268.     {
  269.         $this->oldId $oldId;
  270.         return $this;
  271.     }
  272.     public function getCode(): ?string
  273.     {
  274.         return $this->code;
  275.     }
  276.     public function setCode(?string $code): self
  277.     {
  278.         $this->code $code;
  279.         return $this;
  280.     }
  281.     public function getName(): ?string
  282.     {
  283.         return $this->name;
  284.     }
  285.     public function setName(?string $name): self
  286.     {
  287.         $this->name $name;
  288.         return $this;
  289.     }
  290.     public function getKind(): ?string
  291.     {
  292.         return $this->kind;
  293.     }
  294.     public function setKind(?string $kind): self
  295.     {
  296.         $this->kind $kind;
  297.         return $this;
  298.     }
  299.     public function getAddress(): ?string
  300.     {
  301.         return $this->address;
  302.     }
  303.     public function setAddress(?string $address): self
  304.     {
  305.         $this->address $address;
  306.         return $this;
  307.     }
  308.     public function getAdditionalAddress(): ?string
  309.     {
  310.         return $this->additionalAddress;
  311.     }
  312.     public function setAdditionalAddress(?string $additionalAddress): self
  313.     {
  314.         $this->additionalAddress $additionalAddress;
  315.         return $this;
  316.     }
  317.     public function getZipcode(): ?string
  318.     {
  319.         return $this->zipcode;
  320.     }
  321.     public function setZipcode(?string $zipcode): self
  322.     {
  323.         $this->zipcode $zipcode;
  324.         return $this;
  325.     }
  326.     public function getPhone(): ?string
  327.     {
  328.         return $this->phone;
  329.     }
  330.     public function setPhone(?string $phone): self
  331.     {
  332.         $this->phone $phone;
  333.         return $this;
  334.     }
  335.     public function getNaf(): ?string
  336.     {
  337.         return $this->naf;
  338.     }
  339.     public function setNaf(?string $naf): self
  340.     {
  341.         $this->naf $naf;
  342.         return $this;
  343.     }
  344.     public function getAdr(): ?string
  345.     {
  346.         return $this->adr;
  347.     }
  348.     public function setAdr(?string $adr): self
  349.     {
  350.         $this->adr $adr;
  351.         return $this;
  352.     }
  353.     public function getFax(): ?string
  354.     {
  355.         return $this->fax;
  356.     }
  357.     public function setFax(?string $fax): self
  358.     {
  359.         $this->fax $fax;
  360.         return $this;
  361.     }
  362.     public function getGroupe(): ?string
  363.     {
  364.         return $this->groupe;
  365.     }
  366.     public function setGroupe(?string $groupe): self
  367.     {
  368.         $this->groupe $groupe;
  369.         return $this;
  370.     }
  371.     public function getCoordinatesLambert(): ?string
  372.     {
  373.         return $this->coordinatesLambert;
  374.     }
  375.     public function setCoordinatesLambert(?string $coordinatesLambert): self
  376.     {
  377.         $this->coordinatesLambert $coordinatesLambert;
  378.         return $this;
  379.     }
  380.     public function isIsActive(): ?bool
  381.     {
  382.         return $this->isActive;
  383.     }
  384.     public function setIsActive(?bool $isActive): self
  385.     {
  386.         $this->isActive $isActive;
  387.         return $this;
  388.     }
  389.     public function getType(): ?string
  390.     {
  391.         return $this->type;
  392.     }
  393.     public function setType(?string $type): self
  394.     {
  395.         $this->type $type;
  396.         return $this;
  397.     }
  398.     public function getParent(): ?self
  399.     {
  400.         return $this->parent;
  401.     }
  402.     public function setParent(?self $parent): self
  403.     {
  404.         $this->parent $parent;
  405.         return $this;
  406.     }
  407.     /**
  408.      * @return Collection<int, self>
  409.      */
  410.     public function getSites(): Collection
  411.     {
  412.         return $this->sites;
  413.     }
  414.     public function setSites($sites): self
  415.     {
  416.         $this->sites $sites;
  417.         return $this;
  418.     }
  419.     public function addSite(self $site): self
  420.     {
  421.         if (!$this->sites->contains($site)) {
  422.             $this->sites->add($site);
  423.             $site->setParent($this);
  424.         }
  425.         return $this;
  426.     }
  427.     public function removeSite(self $site): self
  428.     {
  429.         if ($this->sites->removeElement($site)) {
  430.             // set the owning side to null (unless already changed)
  431.             if ($site->getParent() === $this) {
  432.                 $site->setParent(null);
  433.             }
  434.         }
  435.         return $this;
  436.     }
  437.     /**
  438.      * @return Collection<int, Affectation>
  439.      */
  440.     public function getAffectations(): Collection
  441.     {
  442.         return $this->affectations;
  443.     }
  444.     public function addAffectation(Affectation $affectation): self
  445.     {
  446.         if (!$this->affectations->contains($affectation)) {
  447.             $this->affectations->add($affectation);
  448.             $affectation->setSite($this);
  449.         }
  450.         return $this;
  451.     }
  452.     public function removeAffectation(Affectation $affectation): self
  453.     {
  454.         if ($this->affectations->removeElement($affectation)) {
  455.             // set the owning side to null (unless already changed)
  456.             if ($affectation->getSite() === $this) {
  457.                 $affectation->setSite(null);
  458.             }
  459.         }
  460.         return $this;
  461.     }
  462.     /**
  463.      * @return Collection<int, UserSite>
  464.      */
  465.     public function getUserSites(): Collection
  466.     {
  467.         return $this->userSites;
  468.     }
  469.     public function addUserSite(UserSite $userSite): self
  470.     {
  471.         if (!$this->userSites->contains($userSite)) {
  472.             $this->userSites->add($userSite);
  473.             $userSite->setSite($this);
  474.         }
  475.         return $this;
  476.     }
  477.     public function removeUserSite(UserSite $userSite): self
  478.     {
  479.         if ($this->userSites->removeElement($userSite)) {
  480.             if ($userSite->getSite() === $this) {
  481.                 $userSite->setSite(null);
  482.             }
  483.         }
  484.         return $this;
  485.     }
  486.     public function getCity(): ?string
  487.     {
  488.         return $this->city;
  489.     }
  490.     public function setCity(?string $city): self
  491.     {
  492.         $this->city $city;
  493.         return $this;
  494.     }
  495.     /**
  496.      * @return Collection<int, Country>
  497.      */
  498.     public function getDocumentCountries(): Collection
  499.     {
  500.         return $this->documentCountries;
  501.     }
  502.     public function addDocumentCountry(Country $documentCountry): self
  503.     {
  504.         if (!$this->documentCountries->contains($documentCountry)) {
  505.             $this->documentCountries->add($documentCountry);
  506.         }
  507.         return $this;
  508.     }
  509.     public function removeDocumentCountry(Country $documentCountry): self
  510.     {
  511.         $this->documentCountries->removeElement($documentCountry);
  512.         return $this;
  513.     }
  514.     /**
  515.      * @return Collection<int, Category>
  516.      */
  517.     public function getDocumentThemes(): Collection
  518.     {
  519.         return $this->documentThemes;
  520.     }
  521.     public function addDocumentTheme(Category $documentTheme): self
  522.     {
  523.         if (!$this->documentThemes->contains($documentTheme)) {
  524.             $this->documentThemes->add($documentTheme);
  525.         }
  526.         return $this;
  527.     }
  528.     public function removeDocumentTheme(Category $documentTheme): self
  529.     {
  530.         $this->documentThemes->removeElement($documentTheme);
  531.         return $this;
  532.     }
  533.     public function getCountry(): ?Country
  534.     {
  535.         return $this->country;
  536.     }
  537.     public function setCountry(?Country $country): self
  538.     {
  539.         $this->country $country;
  540.         return $this;
  541.     }
  542.     public function getEvaluations(): Collection
  543.     {
  544.         return $this->evaluations;
  545.     }
  546.     public function addEvaluation(Evaluation $evaluation): self
  547.     {
  548.         if (!$this->evaluations->contains($evaluation)) {
  549.             $this->evaluations->add($evaluation);
  550.             $evaluation->setSite($this);
  551.         }
  552.         return $this;
  553.     }
  554.     public function removeEvaluation(Evaluation $evaluation): self
  555.     {
  556.         if ($this->evaluations->removeElement($evaluation)) {
  557.             // set the owning side to null (unless already changed)
  558.             if ($evaluation->getDocument() === $this) {
  559.                 $evaluation->setSite(null);
  560.             }
  561.         }
  562.         return $this;
  563.     }
  564.     public function isSite()
  565.     {
  566.         return self::SITE_TYPE === $this->type;
  567.     }
  568.     public function isEntity()
  569.     {
  570.         return self::ENTITY_TYPE === $this->type;
  571.     }
  572.     public static function getCustomerColumnName(): string
  573.     {
  574.         return 'customer';
  575.     }
  576.     public function getCustomer(): ?Customer
  577.     {
  578.         return $this->customer;
  579.     }
  580.     public function setCustomer(?Customer $customer): self
  581.     {
  582.         $this->customer $customer;
  583.         return $this;
  584.     }
  585.     public function isInitStatus(): ?bool
  586.     {
  587.         return $this->initStatus;
  588.     }
  589.     public function setInitStatus(bool $initStatus): self
  590.     {
  591.         $this->initStatus $initStatus;
  592.         return $this;
  593.     }
  594.     /**
  595.      * @return Collection<int, SiteQuestions>
  596.      */
  597.     public function getSiteQuestions(): Collection
  598.     {
  599.         return $this->siteQuestions;
  600.     }
  601.     public function addSiteQuestion(SiteQuestions $siteQuestion): self
  602.     {
  603.         if (!$this->siteQuestions->contains($siteQuestion)) {
  604.             $this->siteQuestions->add($siteQuestion);
  605.             $siteQuestion->setSite($this);
  606.         }
  607.         return $this;
  608.     }
  609.     public function removeSiteQuestion(SiteQuestions $siteQuestion): self
  610.     {
  611.         if ($this->siteQuestions->removeElement($siteQuestion)) {
  612.             // set the owning side to null (unless already changed)
  613.             if ($siteQuestion->getSite() === $this) {
  614.                 $siteQuestion->setSite(null);
  615.             }
  616.         }
  617.         return $this;
  618.     }
  619.     public function getPath(): ?array
  620.     {
  621.         return $this->path;
  622.     }
  623.     public function setPath(?array $path): self
  624.     {
  625.         $this->path $path;
  626.         return $this;
  627.     }
  628.     #[PrePersist]
  629.     public function setPathNotNull(): self
  630.     {
  631.         if (empty($this->path))
  632.             return SiteService::generateFullPath($this);
  633.         else return $this;
  634.     }
  635.     public function getYear(): ?int
  636.     {
  637.         return $this->year;
  638.     }
  639.     public function setYear(?int $year): self
  640.     {
  641.         $this->year $year;
  642.         return $this;
  643.     }
  644. }