src/Entity/Location/County.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:17
  6.  */
  7. namespace App\Entity\Location;
  8. use AngelGamez\TranslatableBundle\Entity\TranslatableValue;
  9. use App\Repository\CountyRepository;
  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_counties')]
  17. #[ORM\Entity(repositoryClassCountyRepository::class)]
  18. #[ORM\Cache(usage'NONSTRICT_READ_WRITE'region'geoposition')]
  19. class County
  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'counties')]
  27.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  28.     protected City $city;
  29.     #[ORM\Column(name'name'type'translatable')]
  30.     protected TranslatableValue $name;
  31.     #[ORM\Column(name'uri_identity'type'string'length128)]
  32.     protected string $uriIdentity;
  33.     /** @var District[] */
  34.     #[ORM\OneToMany(targetEntityDistrict::class, mappedBy'county')]
  35.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  36.     protected Collection $districts;
  37.     /** @var Station[] */
  38.     #[ORM\OneToMany(targetEntityStation::class, mappedBy'county')]
  39.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  40.     protected Collection $stations;
  41.     public function __construct(City $cityTranslatableValue $namestring $uriIdentity)
  42.     {
  43.         $this->relocate($city);
  44.         $this->rename($name$uriIdentity);
  45.         $this->districts = new ArrayCollection();
  46.         $this->stations = new ArrayCollection();
  47.     }
  48.     public function rename(TranslatableValue $namestring $uriIdentity): void
  49.     {
  50.         $this->name $name;
  51.         $this->uriIdentity $uriIdentity;
  52.     }
  53.     public function relocate(City $city): void
  54.     {
  55.         $this->city $city;
  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 getName(): TranslatableValue
  66.     {
  67.         return $this->name;
  68.     }
  69.     public function getUriIdentity(): string
  70.     {
  71.         return $this->uriIdentity;
  72.     }
  73.     /**
  74.      * @return District[]
  75.      */
  76.     public function getDistricts(): Collection
  77.     {
  78.         return $this->districts;
  79.     }
  80.     public function hasDistrict(District $district): bool
  81.     {
  82.         return $this->districts->contains($district);
  83.     }
  84.     /**
  85.      * @return Station[]
  86.      */
  87.     public function getStations(): Collection
  88.     {
  89.         return $this->stations;
  90.     }
  91.     /**
  92.      * @inheritDoc
  93.      */
  94.     public function __toString(): string
  95.     {
  96.         return (string) $this->name;
  97.     }
  98. }