1: <?php
2: namespace TIC\TownBundle\Entity;
3:
4: use TIC\TownBundle\Repository\CommuneRepository as EntityRepo;
5: use TIC\TownBundle\Traits\InseeTnccable;
6: use TIC\TownBundle\Traits\Geolocatable;
7:
8: use Doctrine\ORM\Mapping as ORM;
9:
10: /**
11: * Commune française.
12: * @ORM\Table(name="tic_town_commune", indexes={
13: * @ORM\Index(name="insee_idx", columns={"insee"}),
14: * @ORM\Index(name="postal_idx", columns={"postal"}),
15: * @ORM\Index(name="nom_idx", columns={"nom"}),
16: * })
17: * @ORM\Entity(repositoryClass=EntityRepo::class)
18: */
19: class Commune
20: {
21: use InseeTnccable, Geolocatable;
22:
23:
24: // --------------------------------------------------------------------- Properties
25:
26: /**
27: * @ORM\Id
28: * @ORM\Column(type="string", length=16)
29: */
30: private $codes;
31:
32: /**
33: * @ORM\Column(type="string", length=5)
34: */
35: private $insee;
36:
37: /**
38: * @ORM\Column(type="string", length=5, nullable=true)
39: */
40: private $postal;
41:
42: /**
43: * @ORM\Column(type="string", length=4)
44: */
45: private $type;
46:
47: /**
48: * @ORM\Column(type="string", length=255)
49: */
50: private $nom_maj;
51:
52: /**
53: * @ORM\Column(type="string", length=255)
54: */
55: private $nom;
56:
57: /**
58: * @ORM\ManyToOne(targetEntity="Departement", inversedBy="communes")
59: * @ORM\JoinColumn(referencedColumnName="insee")
60: */
61: private $departement;
62:
63: /**
64: * @ORM\Column(type="boolean")
65: */
66: private $enabled;
67:
68: /**
69: * @ORM\Column(type="boolean")
70: */
71: private $outre_mer;
72:
73: /**
74: * @ORM\Column(type="string", length=6, nullable=true)
75: */
76: private $version;
77:
78:
79: // --------------------------------------------------------------------- Custom methods
80:
81: public function __construct()
82: {
83: $this->insee = '';
84: $this->postal = '';
85: $this->type = 'COM';
86: $this->enabled = true;
87: $this->outre_mer = true;
88: }
89:
90: public function __toString()
91: {
92: # return $this->postal . " " . $this->getArtNom();
93: return $this->postal . " " . $this->getNomArt();
94: }
95:
96:
97: // --------------------------------------------------------------------- Shortcut methods
98:
99: public function getRegion(): ?Region
100: {
101: if (isset($this->departement)) return $this->departement->getRegion();
102: }
103:
104:
105: // --------------------------------------------------------------------- Tweaked methods
106:
107: public function setInsee(string $insee): self
108: {
109: $this->insee = $insee;
110: $this->codes = $this->insee . ':' . $this->postal;
111: return $this;
112: }
113:
114: public function setPostal(?string $postal): self
115: {
116: $this->postal = $postal;
117: $this->codes = $this->insee . ':' . $this->postal;
118: return $this;
119: }
120:
121:
122: // --------------------------------------------------------------------- Auto-generated
123:
124: public function getCodes(): ?string
125: {
126: return $this->codes;
127: }
128:
129: public function getInsee(): ?string
130: {
131: return $this->insee;
132: }
133:
134: public function getPostal(): ?string
135: {
136: return $this->postal;
137: }
138:
139: public function getType(): ?string
140: {
141: return $this->type;
142: }
143:
144: public function setType(string $type): self
145: {
146: $this->type = $type;
147:
148: return $this;
149: }
150:
151: public function getNomMaj(): ?string
152: {
153: return $this->nom_maj;
154: }
155:
156: public function setNomMaj(string $nom_maj): self
157: {
158: $this->nom_maj = $nom_maj;
159:
160: return $this;
161: }
162:
163: public function getNom(): ?string
164: {
165: return $this->nom;
166: }
167:
168: public function setNom(string $nom): self
169: {
170: $this->nom = $nom;
171:
172: return $this;
173: }
174:
175: public function getEnabled(): ?bool
176: {
177: return $this->enabled;
178: }
179:
180: public function setEnabled(bool $enabled): self
181: {
182: $this->enabled = $enabled;
183:
184: return $this;
185: }
186:
187: public function getOutreMer(): ?bool
188: {
189: return $this->outre_mer;
190: }
191:
192: public function setOutreMer(bool $outre_mer): self
193: {
194: $this->outre_mer = $outre_mer;
195:
196: return $this;
197: }
198:
199: public function getVersion(): ?string
200: {
201: return $this->version;
202: }
203:
204: public function setVersion(?string $version): self
205: {
206: $this->version = $version;
207:
208: return $this;
209: }
210:
211: public function getDepartement(): ?Departement
212: {
213: return $this->departement;
214: }
215:
216: public function setDepartement(?Departement $departement): self
217: {
218: $this->departement = $departement;
219:
220: return $this;
221: }
222: }
223: