src/Entity/Location/District.php line 23

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-03-19
  5.  * Time: 20:14
  6.  */
  7. namespace App\Entity\Location;
  8. use AngelGamez\TranslatableBundle\Entity\TranslatableValue;
  9. use App\Repository\DistrictRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. /**
  15.  * Район города
  16.  */
  17. #[ORM\Table(name'city_districts')]
  18. #[ORM\Entity(repositoryClassDistrictRepository::class)]
  19. #[ORM\Cache(usage'NONSTRICT_READ_WRITE'region'geoposition')]
  20. class District
  21. {
  22.     #[ORM\Id]
  23.     #[ORM\Column(name'id'type'integer')]
  24.     #[ORM\GeneratedValue(strategy'AUTO')]
  25.     #[Groups(['preview''listing'])]
  26.     protected int $id;
  27.     #[ORM\JoinColumn(name'city_id'referencedColumnName'id')]
  28.     #[ORM\ManyToOne(targetEntityCity::class, inversedBy'districts')]
  29.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  30.     protected City $city;
  31.     #[ORM\JoinColumn(name'county_id'referencedColumnName'id')]
  32.     #[ORM\ManyToOne(targetEntityCounty::class, inversedBy'districts')]
  33.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  34.     #[Groups(['preview''listing'])]
  35.     protected ?County $county;
  36.     #[ORM\Column(name'name'type'translatable')]
  37.     #[Groups(['preview''listing'])]
  38.     protected TranslatableValue $name;
  39.     #[ORM\Column(name'uri_identity'type'string'length128)]
  40.     #[Groups(['preview''listing'])]
  41.     protected string $uriIdentity;
  42.     /** @var Station[] */
  43.     #[ORM\OneToMany(targetEntityStation::class, mappedBy'district')]
  44.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  45.     protected Collection $stations;
  46.     public function __construct(City $city, ?County $countyTranslatableValue $namestring $uriIdentity)
  47.     {
  48.         $this->relocate($city$county);
  49.         $this->rename($name$uriIdentity);
  50.         $this->stations = new ArrayCollection();
  51.     }
  52.     public function rename(TranslatableValue $namestring $uriIdentity): void
  53.     {
  54.         $this->name $name;
  55.         $this->uriIdentity $uriIdentity;
  56.     }
  57.     public function relocate(City $city, ?County $county): void
  58.     {
  59.         $this->city $city;
  60.         $this->county = (null !== $county && $this->city->hasCounty($county)) ? $county null;
  61.     }
  62.     public function getId(): int
  63.     {
  64.         return $this->id;
  65.     }
  66.     public function getCity(): City
  67.     {
  68.         return $this->city;
  69.     }
  70.     public function getCounty(): ?County
  71.     {
  72.         return $this->county;
  73.     }
  74.     public function getName(): TranslatableValue
  75.     {
  76.         return $this->name;
  77.     }
  78.     public function getUriIdentity(): string
  79.     {
  80.         return $this->uriIdentity;
  81.     }
  82.     /**
  83.      * @return Station[]
  84.      */
  85.     public function getStations(): Collection
  86.     {
  87.         return $this->stations;
  88.     }
  89.     /**
  90.      * @inheritDoc
  91.      */
  92.     public function __toString(): string
  93.     {
  94.         return (string) $this->name;
  95.     }
  96. }