src/Domain/Entity/Offmap.php line 60

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\Entity;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Post;
  9. use ApiPlatform\Metadata\Put;
  10. use App\Application\ApiResources\State\Processor\OffmapSizeUpdateProcessor;
  11. use App\Application\Controller\Api\Offmap\GetOffmapImagesZipAction;
  12. use App\Application\Controller\Api\Offmap\GetOffmapLastSizeCheckAction;
  13. use App\Application\Controller\Api\Offmap\GetOffmapRevisionsZipAction;
  14. use App\Application\Controller\Api\Offmap\ZipOffmapPackAction;
  15. use App\Domain\Entity\Behavior\Identifiable;
  16. use App\Domain\Entity\Translation\OffmapTranslation;
  17. use DateTime;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Doctrine\Common\Collections\Collection;
  20. use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
  21. use Gedmo\Timestampable\Traits\Timestampable;
  22. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  23. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  24. #[ApiResource(
  25.     operations            : [
  26.         new Delete(security"is_granted('ROLE_ADMIN')"),
  27.         new GetCollection(filters: ['offmap.search_filter''offmap.query_filter''soft_delete_filter']),
  28.         new Get(),
  29.         new Get(
  30.             uriTemplate'/offmaps/{uuid}/pack',
  31.             controller ZipOffmapPackAction::class,
  32.         ),
  33.         new Get(
  34.             uriTemplate'/offmaps/{uuid}/revisions',
  35.             controller GetOffmapRevisionsZipAction::class,
  36.         ),
  37.         new Get(
  38.             uriTemplate'/offmaps/{uuid}/images',
  39.             controller GetOffmapImagesZipAction::class,
  40.         ),
  41.         new Post(normalizationContext: ['groups' => ['translations']], security"is_granted('ROLE_ADMIN')"),
  42.         new Put(normalizationContext: ['groups' => ['translations']], security"is_granted('ROLE_ADMIN')"),
  43.         new Get(
  44.             uriTemplate'/offmaps/{uuid}/lastSizeCheck',
  45.             controllerGetOffmapLastSizeCheckAction::class,
  46.         ),
  47.         new Put(
  48.             uriTemplate'/offmaps/{uuid}/size',
  49.             processorOffmapSizeUpdateProcessor::class,
  50.         ),
  51.     ],
  52.     normalizationContext  : ['groups' => ['offmap_read']],
  53.     denormalizationContext: ['groups' => ['offmap_write']],
  54.     filters               : ['translation.groups'],
  55. )]
  56. class Offmap extends AbstractTranslatable
  57. {
  58.     use Identifiable;
  59.     use SoftDeleteable;
  60.     use Timestampable;
  61.     private Collection $countries;
  62.     private Collection $departments;
  63.     public ?DateTime   $zhistUpdate null;
  64.     public function __construct(
  65.         public OffmapCategory $category,
  66.         public float $latSW,
  67.         public float $lngSW,
  68.         public float $latNE,
  69.         public float $lngNE,
  70.         public int $zoom,
  71.         public int $minZoom,
  72.         public int $maxZoom,
  73.         public float $size 0,
  74.         public ?Region $region null,
  75.         public ?string $mapboxUrl null,
  76.         public ?string $hash null,
  77.         public ?string $remoteId null,
  78.         public ?DateTime $lastSizeCheck null
  79.     ) {
  80.         parent::__construct();
  81.         $this->countries = new ArrayCollection();
  82.         $this->departments = new ArrayCollection();
  83.     }
  84.     public function createTranslation(): TranslationInterface
  85.     {
  86.         return new OffmapTranslation();
  87.     }
  88.     public function getName(): ?string
  89.     {
  90.         return $this->getTranslationType()->getName();
  91.     }
  92.     public function getTranslationType(): OffmapTranslation
  93.     {
  94.         return $this->getTranslation();
  95.     }
  96.     public function setName(?string $name): void
  97.     {
  98.         $this->getTranslationType()->setName($name);
  99.     }
  100.     /**
  101.      * @return Collection
  102.      */
  103.     public function getCountries(): Collection
  104.     {
  105.         return $this->countries;
  106.     }
  107.     /**
  108.      * @param Collection $countries
  109.      */
  110.     public function setCountries(Collection $countries): void
  111.     {
  112.         $this->countries $countries;
  113.     }
  114.     public function addCountry(Country $country): void
  115.     {
  116.         if ($this->countries->contains($country)) {
  117.             return;
  118.         }
  119.         $this->countries->add($country);
  120.     }
  121.     public function removeCountry(Country $country): void
  122.     {
  123.         if (!$this->countries->contains($country)) {
  124.             return;
  125.         }
  126.         $this->countries->removeElement($country);
  127.     }
  128.     public function getDepartments(): Collection
  129.     {
  130.         return $this->departments;
  131.     }
  132.     public function setDepartments(Collection $departments): void
  133.     {
  134.         $this->departments $departments;
  135.     }
  136.     public function addDepartment(DirectoryDepartment $department): void
  137.     {
  138.         if ($this->departments->contains($department)) {
  139.             return;
  140.         }
  141.         $this->departments->add($department);
  142.     }
  143.     public function removeDepartment(DirectoryDepartment $department): void
  144.     {
  145.         if (!$this->departments->contains($department)) {
  146.             return;
  147.         }
  148.         $this->departments->removeElement($department);
  149.     }
  150.     public function getLastSizeCheck(): ?DateTime
  151.     {
  152.         return $this->lastSizeCheck;
  153.     }
  154.     public function setLastSizeCheck(?DateTime $lastSizeCheck): void
  155.     {
  156.         $this->lastSizeCheck $lastSizeCheck;
  157.     }
  158.     public function setSize(float $size): void
  159.     {
  160.         $this->size $size;
  161.     }
  162. }