src/Entity/City.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CityRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. #[ORM\Table(name'city')]
  9. #[ORM\UniqueConstraint(name'city_region_unique'columns: ['name''id_region'])]
  10. #[ORM\Entity(repositoryClassCityRepository::class)]
  11. class City {
  12.     #[ORM\Id]
  13.     #[ORM\Column(name'id'type'integer')]
  14.     #[ORM\GeneratedValue(strategy'AUTO')]
  15.              private ?int $id null;
  16.     #[ORM\Column(name'name'type'string'length255)]
  17.     #[Assert\NotBlank]
  18.     #[Assert\Length(min'4')]
  19.              private ?string $name;
  20.     #[ORM\Column(name'post_code'type'integer'nullabletrue)]
  21.              private ?int $postCode;
  22.     #[ORM\Column(name'is_capital'type'boolean')]
  23.              private ?bool $isCapital;
  24.     #[ORM\Column(name'is_prefecture_capital'type'boolean'nullabletrue)]
  25.         private ?bool $isPrefectureCapital false;
  26.     #[ORM\ManyToOne(targetEntityRegion::class, inversedBy'cities')]
  27.     #[ORM\JoinColumn(name'id_region'referencedColumnName'id')]
  28.     #[Assert\NotNull]
  29.              private ?Region $region null;
  30.     #[ORM\ManyToOne(inversedBy'cities')]
  31.         private ?Prefecture $prefecture null;
  32.     #[ORM\OneToMany(mappedBy'city'targetEntityJobOffer::class, cascade: ['remove'])]
  33.         private Collection $jobOffers;
  34.     public function __construct() {
  35.         $this->jobOffers = new ArrayCollection();
  36.     }
  37.     public function getId(): ?int {
  38.         return $this->id;
  39.     }
  40.     public function setName(?string $name): self {
  41.         $this->name $name;
  42.         return $this;
  43.     }
  44.     public function getName(): ?string {
  45.         return $this->name;
  46.     }
  47.     public function getPostCode(): ?int {
  48.         return $this->postCode;
  49.     }
  50.     public function setPostCode(?int $postCode): self {
  51.         $this->postCode $postCode;
  52.         return $this;
  53.     }
  54.     public function setIsCapital(?bool $isCapital): self {
  55.         $this->isCapital $isCapital;
  56.         return $this;
  57.     }
  58.     public function getIsCapital(): ?bool {
  59.         return $this->isCapital;
  60.     }
  61.     /**
  62.      * @return bool|null
  63.      */
  64.     public function getIsPrefectureCapital(): ?bool {
  65.         return $this->isPrefectureCapital;
  66.     }
  67.     /**
  68.      * @param bool|null $isPrefectureCapital
  69.      */
  70.     public function setIsPrefectureCapital(?bool $isPrefectureCapital): void
  71.     {
  72.         $this->isPrefectureCapital $isPrefectureCapital;
  73.     }
  74.     public function setRegion(Region $region null): self {
  75.         $this->region $region;
  76.         return $this;
  77.     }
  78.     public function getRegion(): ?Region {
  79.         return $this->region;
  80.     }
  81.     public function getCountry(): Country {
  82.         return $this->region->getCountry();
  83.     }
  84.     public function __toString(): string {
  85.         if($this->prefecture) {
  86.             return sprintf('%s - %s - %s',
  87.                 ucfirst($this->region->getCountry()->getName()),
  88.                 ucfirst($this->prefecture->getName()),
  89.                 ucfirst($this->name)
  90.             );
  91.         }
  92.         return sprintf('%s - %s - %s',
  93.             ucfirst($this->region->getCountry()->getName()),
  94.             ucfirst($this->region->getName()),
  95.             ucfirst($this->name)
  96.         );
  97.     }
  98.     public function getPrefecture(): ?Prefecture {
  99.         return $this->prefecture;
  100.     }
  101.     public function setPrefecture(?Prefecture $prefecture): self {
  102.         $this->prefecture $prefecture;
  103.         return $this;
  104.     }
  105. }