<?php
declare(strict_types=1);
namespace App\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Application\ApiResources\State\Processor\OffmapSizeUpdateProcessor;
use App\Application\Controller\Api\Offmap\GetOffmapImagesZipAction;
use App\Application\Controller\Api\Offmap\GetOffmapLastSizeCheckAction;
use App\Application\Controller\Api\Offmap\GetOffmapRevisionsZipAction;
use App\Application\Controller\Api\Offmap\ZipOffmapPackAction;
use App\Domain\Entity\Behavior\Identifiable;
use App\Domain\Entity\Translation\OffmapTranslation;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
use Gedmo\Timestampable\Traits\Timestampable;
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
#[ApiResource(
operations : [
new Delete(security: "is_granted('ROLE_ADMIN')"),
new GetCollection(filters: ['offmap.search_filter', 'offmap.query_filter', 'soft_delete_filter']),
new Get(),
new Get(
uriTemplate: '/offmaps/{uuid}/pack',
controller : ZipOffmapPackAction::class,
),
new Get(
uriTemplate: '/offmaps/{uuid}/revisions',
controller : GetOffmapRevisionsZipAction::class,
),
new Get(
uriTemplate: '/offmaps/{uuid}/images',
controller : GetOffmapImagesZipAction::class,
),
new Post(normalizationContext: ['groups' => ['translations']], security: "is_granted('ROLE_ADMIN')"),
new Put(normalizationContext: ['groups' => ['translations']], security: "is_granted('ROLE_ADMIN')"),
new Get(
uriTemplate: '/offmaps/{uuid}/lastSizeCheck',
controller: GetOffmapLastSizeCheckAction::class,
),
new Put(
uriTemplate: '/offmaps/{uuid}/size',
processor: OffmapSizeUpdateProcessor::class,
),
],
normalizationContext : ['groups' => ['offmap_read']],
denormalizationContext: ['groups' => ['offmap_write']],
filters : ['translation.groups'],
)]
class Offmap extends AbstractTranslatable
{
use Identifiable;
use SoftDeleteable;
use Timestampable;
private Collection $countries;
private Collection $departments;
public ?DateTime $zhistUpdate = null;
public function __construct(
public OffmapCategory $category,
public float $latSW,
public float $lngSW,
public float $latNE,
public float $lngNE,
public int $zoom,
public int $minZoom,
public int $maxZoom,
public float $size = 0,
public ?Region $region = null,
public ?string $mapboxUrl = null,
public ?string $hash = null,
public ?string $remoteId = null,
public ?DateTime $lastSizeCheck = null
) {
parent::__construct();
$this->countries = new ArrayCollection();
$this->departments = new ArrayCollection();
}
public function createTranslation(): TranslationInterface
{
return new OffmapTranslation();
}
public function getName(): ?string
{
return $this->getTranslationType()->getName();
}
public function getTranslationType(): OffmapTranslation
{
return $this->getTranslation();
}
public function setName(?string $name): void
{
$this->getTranslationType()->setName($name);
}
/**
* @return Collection
*/
public function getCountries(): Collection
{
return $this->countries;
}
/**
* @param Collection $countries
*/
public function setCountries(Collection $countries): void
{
$this->countries = $countries;
}
public function addCountry(Country $country): void
{
if ($this->countries->contains($country)) {
return;
}
$this->countries->add($country);
}
public function removeCountry(Country $country): void
{
if (!$this->countries->contains($country)) {
return;
}
$this->countries->removeElement($country);
}
public function getDepartments(): Collection
{
return $this->departments;
}
public function setDepartments(Collection $departments): void
{
$this->departments = $departments;
}
public function addDepartment(DirectoryDepartment $department): void
{
if ($this->departments->contains($department)) {
return;
}
$this->departments->add($department);
}
public function removeDepartment(DirectoryDepartment $department): void
{
if (!$this->departments->contains($department)) {
return;
}
$this->departments->removeElement($department);
}
public function getLastSizeCheck(): ?DateTime
{
return $this->lastSizeCheck;
}
public function setLastSizeCheck(?DateTime $lastSizeCheck): void
{
$this->lastSizeCheck = $lastSizeCheck;
}
public function setSize(float $size): void
{
$this->size = $size;
}
}