src/Entity/Location/District.php line 22

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. /**
  14.  * Район города
  15.  */
  16. #[ORM\Table(name'city_districts')]
  17. #[ORM\Entity(repositoryClassDistrictRepository::class)]
  18. #[ORM\Cache(usage'NONSTRICT_READ_WRITE'region'geoposition')]
  19. class District
  20. {
  21.     #[ORM\Id]
  22.     #[ORM\Column(name'id'type'integer')]
  23.     #[ORM\GeneratedValue(strategy'AUTO')]
  24.     protected int $id;
  25.     #[ORM\JoinColumn(name'city_id'referencedColumnName'id')]
  26.     #[ORM\ManyToOne(targetEntityCity::class, inversedBy'districts')]
  27.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  28.     protected City $city;
  29.     #[ORM\JoinColumn(name'county_id'referencedColumnName'id')]
  30.     #[ORM\ManyToOne(targetEntityCounty::class, inversedBy'districts')]
  31.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  32.     protected ?County $county;
  33.     #[ORM\Column(name'name'type'translatable')]
  34.     protected TranslatableValue $name;
  35.     #[ORM\Column(name'uri_identity'type'string'length128)]
  36.     protected string $uriIdentity;
  37.     /** @var Station[] */
  38.     #[ORM\OneToMany(targetEntityStation::class, mappedBy'district')]
  39.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  40.     protected Collection $stations;
  41.     public function __construct(City $city, ?County $countyTranslatableValue $namestring $uriIdentity)
  42.     {
  43.         $this->relocate($city$county);
  44.         $this->rename($name$uriIdentity);
  45.         $this->stations = new ArrayCollection();
  46.     }
  47.     public function rename(TranslatableValue $namestring $uriIdentity): void
  48.     {
  49.         $this->name $name;
  50.         $this->uriIdentity $uriIdentity;
  51.     }
  52.     public function relocate(City $city, ?County $county): void
  53.     {
  54.         $this->city $city;
  55.         $this->county = (null !== $county && $this->city->hasCounty($county)) ? $county null;
  56.     }
  57.     public function getId(): int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getCity(): City
  62.     {
  63.         return $this->city;
  64.     }
  65.     public function getCounty(): ?County
  66.     {
  67.         return $this->county;
  68.     }
  69.     public function getName(): TranslatableValue
  70.     {
  71.         return $this->name;
  72.     }
  73.     public function getUriIdentity(): string
  74.     {
  75.         return $this->uriIdentity;
  76.     }
  77.     /**
  78.      * @return Station[]
  79.      */
  80.     public function getStations(): Collection
  81.     {
  82.         return $this->stations;
  83.     }
  84.     /**
  85.      * @inheritDoc
  86.      */
  87.     public function __toString(): string
  88.     {
  89.         return (string) $this->name;
  90.     }
  91. }