src/Entity/Location/Station.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-03-19
  5.  * Time: 17:13
  6.  */
  7. namespace App\Entity\Location;
  8. use AngelGamez\TranslatableBundle\Entity\TranslatableValue;
  9. use ApiPlatform\Core\Annotation\ApiResource;
  10. use App\Entity\Location\Subway\Line;
  11. use App\Repository\StationRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Doctrine\ORM\Mapping as ORM;
  16. #[ORM\Table(name'city_stations')]
  17. #[ORM\Entity(repositoryClassStationRepository::class)]
  18. #[ORM\Cache(usage'NONSTRICT_READ_WRITE'region'geoposition')]
  19. class Station
  20. {
  21.     #[ORM\Id]
  22.     #[ORM\Column(name'id'type'integer')]
  23.     #[ORM\GeneratedValue(strategy'AUTO')]
  24.     #[Groups('profile')]
  25.     protected int $id;
  26.     #[ORM\JoinColumn(name'city_id'referencedColumnName'id')]
  27.     #[ORM\ManyToOne(targetEntityCity::class, inversedBy'stations')]
  28.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  29.     protected City $city;
  30.     #[ORM\JoinColumn(name'county_id'referencedColumnName'id')]
  31.     #[ORM\ManyToOne(targetEntityCounty::class, inversedBy'stations')]
  32.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  33.     protected ?County $county;
  34.     #[ORM\JoinColumn(name'district_id'referencedColumnName'id')]
  35.     #[ORM\ManyToOne(targetEntityDistrict::class, inversedBy'stations')]
  36.     #[ORM\Cache(usage'READ_ONLY'region'geoposition')]
  37.     protected ?District $district;
  38.     #[ORM\JoinTable(name'city_subway_station_lines')]
  39.     #[ORM\JoinColumn(name'station_id'referencedColumnName'id')]
  40.     #[ORM\InverseJoinColumn(name'line_id'referencedColumnName'id')]
  41.     #[ORM\ManyToMany(targetEntityLine::class, fetch'EXTRA_LAZY')]
  42.     protected Collection $lines;
  43.     #[ORM\Column(name'name'type'translatable')]
  44.     #[Groups('profile')]
  45.     protected TranslatableValue $name;
  46.     #[ORM\Column(name'uri_identity'type'string'length128)]
  47.     #[Groups('profile')]
  48.     protected string $uriIdentity;
  49.     public function __construct(City $city, ?County $county, ?District $districtTranslatableValue $namestring $uriIdentity)
  50.     {
  51.         $this->city $city;
  52.         $this->county $county;
  53.         $this->district $district;
  54.         $this->name $name;
  55.         $this->uriIdentity $uriIdentity;
  56.         $this->lines = new ArrayCollection();
  57.     }
  58.     public function rename(TranslatableValue $namestring $uriIdentity): void
  59.     {
  60.         $this->name $name;
  61.         $this->uriIdentity $uriIdentity;
  62.     }
  63.     public function relocate(City $city, ?County $county, ?District $district): void
  64.     {
  65.         $this->city $city;
  66.         $this->county = (null !== $county && $this->city->hasCounty($county)) ? $county null;
  67.         $this->district = (
  68.             null !== $district
  69.             && $this->city->hasDistrict($district)
  70.             && (null === $this->county || $this->county->hasDistrict($district))
  71.         ) ? $district null;
  72.     }
  73.     public function getId(): int
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function getCity(): City
  78.     {
  79.         return $this->city;
  80.     }
  81.     public function getCounty(): ?County
  82.     {
  83.         return $this->county;
  84.     }
  85.     public function getDistrict(): ?District
  86.     {
  87.         return $this->district;
  88.     }
  89.     public function getName(): TranslatableValue
  90.     {
  91.         return $this->name;
  92.     }
  93.     public function getUriIdentity(): string
  94.     {
  95.         return $this->uriIdentity;
  96.     }
  97.     public function setDistrict(?District $district): void
  98.     {
  99.         $this->district $district;
  100.     }
  101.     public function lines(): iterable
  102.     {
  103.         return $this->lines;
  104.     }
  105.     public function specifyLines(Line ...$lines): void
  106.     {
  107.         $this->lines = new ArrayCollection($lines);
  108.     }
  109.     /**
  110.      * @inheritDoc
  111.      */
  112.     public function __toString(): string
  113.     {
  114.         return (string) $this->name;
  115.     }
  116. }