src/Entity/Location/County.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: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. use Symfony\Component\Serializer\Annotation\Groups;
  14. /**
  15.  * Округ города (имеет значение только для Москвы)
  16.  */
  17. #[ORM\Table(name'city_counties')]
  18. #[ORM\Entity(repositoryClassCountyRepository::class)]
  19. #[ORM\Cache(usage'NONSTRICT_READ_WRITE'region'geoposition')]
  20. class County
  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'counties')]
  29.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  30.     protected City $city;
  31.     #[ORM\Column(name'name'type'translatable')]
  32.     #[Groups(['preview''listing'])]
  33.     protected TranslatableValue $name;
  34.     #[ORM\Column(name'uri_identity'type'string'length128)]
  35.     #[Groups(['preview''listing'])]
  36.     protected string $uriIdentity;
  37.     /** @var District[] */
  38.     #[ORM\OneToMany(targetEntityDistrict::class, mappedBy'county')]
  39.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  40.     protected Collection $districts;
  41.     /** @var Station[] */
  42.     #[ORM\OneToMany(targetEntityStation::class, mappedBy'county')]
  43.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  44.     protected Collection $stations;
  45.     public function __construct(City $cityTranslatableValue $namestring $uriIdentity)
  46.     {
  47.         $this->relocate($city);
  48.         $this->rename($name$uriIdentity);
  49.         $this->districts = new ArrayCollection();
  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): void
  58.     {
  59.         $this->city $city;
  60.     }
  61.     public function getId(): int
  62.     {
  63.         return $this->id;
  64.     }
  65.     public function getCity(): City
  66.     {
  67.         return $this->city;
  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 District[]
  79.      */
  80.     public function getDistricts(): Collection
  81.     {
  82.         return $this->districts;
  83.     }
  84.     public function hasDistrict(District $district): bool
  85.     {
  86.         return $this->districts->contains($district);
  87.     }
  88.     /**
  89.      * @return Station[]
  90.      */
  91.     public function getStations(): Collection
  92.     {
  93.         return $this->stations;
  94.     }
  95.     /**
  96.      * @inheritDoc
  97.      */
  98.     public function __toString(): string
  99.     {
  100.         return (string) $this->name;
  101.     }
  102. }