src/Entity/Region.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RegionRepository;
  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'region')]
  9. #[ORM\UniqueConstraint(name'region_name_unique'columns: ['name''id_country'])]
  10. #[ORM\Entity(repositoryClassRegionRepository::class)]
  11. class Region {
  12.     #[ORM\Id]
  13.                    #[ORM\GeneratedValue]
  14.                    #[ORM\Column(type'integer')]
  15.                    private ?int $id null;
  16.     #[ORM\Column(name'name'type'string'length255)]
  17.                    #[Assert\NotBlank]
  18.                    #[Assert\Length(min'3')]
  19.                    private string $name;
  20.     #[ORM\Column(name'valid'type'boolean')]
  21.     private bool $valid;
  22.     #[ORM\Column(name'iso_code'type'string'length3uniquefalsenullabletrue)]
  23.     private ?string $isoCode null;
  24.     #[ORM\Column(name'phone_code'type'integer')]
  25.     private int $phoneCode 0;
  26.     #[ORM\Column(name'phone_digit'type'integer')]
  27.     private int $phoneDigit 0;
  28.     #[ORM\ManyToOne(targetEntityCountry::class, inversedBy'regions')]
  29.                    #[ORM\JoinColumn(name'id_country'referencedColumnName'id')]
  30.                    #[Assert\NotBlank]
  31.                    private Country $country;
  32.     #[ORM\OneToMany(mappedBy'region'targetEntityCity::class, cascade: ['persist''remove'])]
  33.                    private Collection $cities;
  34.     #[ORM\OneToMany(mappedBy'region'targetEntitySchool::class, cascade: ['persist'])]
  35.                    private Collection $schools;
  36.     #[ORM\ManyToOne(targetEntityCurrency::class, inversedBy'regions')]
  37.     #[ORM\JoinColumn(name'id_currency'referencedColumnName'id')]
  38.     private Currency $currency;
  39.     #[ORM\OneToMany(mappedBy'regions'targetEntityPrefecture::class, cascade: ['persist'])]
  40.                 private Collection $prefectures;
  41.     public function __construct() {
  42.                        $this->cities = new ArrayCollection();
  43.                        $this->schools = new ArrayCollection();
  44.                  $this->prefectures = new ArrayCollection();
  45.                    }
  46.     public function getId(): ?int {
  47.                        return $this->id;
  48.                    }
  49.     public function getName(): string {
  50.                        return $this->name;
  51.                    }
  52.     public function setName(string $name): static {
  53.                        $this->name $name;
  54.                
  55.                        return $this;
  56.                    }
  57.     /**
  58.      * @return bool
  59.      */
  60.     public function isValid(): bool
  61.     {
  62.         return $this->valid;
  63.     }
  64.     /**
  65.      * @param bool $valid
  66.      * @return Region
  67.      */
  68.     public function setValid(bool $valid): Region
  69.     {
  70.         $this->valid $valid;
  71.         return $this;
  72.     }
  73.     /**
  74.      * @return string|null
  75.      */
  76.     public function getIsoCode(): ?string
  77.     {
  78.         return $this->isoCode;
  79.     }
  80.     /**
  81.      * @param string|null $isoCode
  82.      * @return Region
  83.      */
  84.     public function setIsoCode(?string $isoCode): Region
  85.     {
  86.         $this->isoCode $isoCode;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return int
  91.      */
  92.     public function getPhoneCode(): int
  93.     {
  94.         return $this->phoneCode;
  95.     }
  96.     /**
  97.      * @param int $phoneCode
  98.      * @return Region
  99.      */
  100.     public function setPhoneCode(int $phoneCode): Region
  101.     {
  102.         $this->phoneCode $phoneCode;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return int
  107.      */
  108.     public function getPhoneDigit(): int
  109.     {
  110.         return $this->phoneDigit;
  111.     }
  112.     /**
  113.      * @param int $phoneDigit
  114.      * @return Region
  115.      */
  116.     public function setPhoneDigit(int $phoneDigit): Region
  117.     {
  118.         $this->phoneDigit $phoneDigit;
  119.         return $this;
  120.     }
  121.     public function getCountry(): Country {
  122.                        return $this->country;
  123.                    }
  124.     public function setCountry(Country $country null): static {
  125.                        $this->country $country;
  126.                
  127.                        return $this;
  128.                    }
  129.     public function addCity(City $city): static {
  130.                        $this->cities->add($city);
  131.                
  132.                        return $this;
  133.                    }
  134.     public function removeCity(City $city): void {
  135.                        $this->cities->removeElement($city);
  136.                    }
  137.     public function getCities(): Collection {
  138.                        return $this->cities;
  139.                    }
  140.     public function __toString() {
  141.                        return $this->name;
  142.                    }
  143.     public function addSchool(School $school): static {
  144.                        $this->schools->add($school);
  145.                
  146.                        return $this;
  147.                    }
  148.     public function removeSchool(School $school): void {
  149.                        $this->schools->removeElement($school);
  150.                    }
  151.     public function getSchools(): Collection {
  152.                        return $this->schools;
  153.                    }
  154.     public static function fromFixture(string $name): static {
  155.                        return (new static())
  156.                            ->setName($name);
  157.                    }
  158.     /**
  159.      * @return Currency
  160.      */
  161.     public function getCurrency(): Currency
  162.     {
  163.         return $this->currency;
  164.     }
  165.     /**
  166.      * @param Currency $currency
  167.      * @return Region
  168.      */
  169.     public function setCurrency(Currency $currency): Region
  170.     {
  171.         $this->currency $currency;
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return Collection<int, Prefecture>
  176.      */
  177.     public function getPrefectures(): Collection
  178.     {
  179.         return $this->prefectures;
  180.     }
  181.     public function addPrefecture(Prefecture $prefecture): self
  182.     {
  183.         if (!$this->prefectures->contains($prefecture)) {
  184.             $this->prefectures->add($prefecture);
  185.             $prefecture->setRegions($this);
  186.         }
  187.         return $this;
  188.     }
  189.     public function removePrefecture(Prefecture $prefecture): self
  190.     {
  191.         if ($this->prefectures->removeElement($prefecture)) {
  192.             // set the owning side to null (unless already changed)
  193.             if ($prefecture->getRegions() === $this) {
  194.                 $prefecture->setRegions(null);
  195.             }
  196.         }
  197.         return $this;
  198.     }
  199. }