1: <?php
2: namespace TIC\TownBundle\Traits;
3:
4: /**
5: * Gestion du champs TNCC fourni par l'INSEE (Type Nom Clair => article).
6: */
7: trait InseeTnccable
8: {
9:
10: private $tncc_articles = array( "", "", "Le", "La", "Les", "L'", "Aux", "Las", "Los");
11: private $tncc_charnieres = array("de", "d'", "du", "de la", "des", "de l'", "des", "de Las", "de Los");
12:
13:
14: // --------------------------------------------------------------------- Properties
15:
16: /**
17: * @ORM\Column(type="smallint", nullable=true)
18: */
19: private $tncc;
20:
21: /**
22: * @ORM\Column(type="string", length=8, nullable=true)
23: */
24: private $art;
25:
26:
27: // --------------------------------------------------------------------- Mutators/Accessors
28:
29: public function getTncc(): ?int
30: {
31: return $this->tncc;
32: }
33:
34: public function setTncc(?int $tncc): self
35: {
36: $this->tncc = $tncc;
37: $this->art = $this->getArticle();
38: return $this;
39: }
40:
41:
42: public function getArt(): ?string
43: {
44: return $this->art;
45: }
46:
47: public function setArt(?string $art): self
48: {
49: $this->art = $art;
50: return $this;
51: }
52:
53:
54: /**
55: * Alias du getter sur tncc.
56: * @return integer
57: */
58: public function getTypeNomClair(): ?int
59: {
60: return $this->getTncc();
61: }
62:
63: /**
64: * Alias du setter sur tncc.
65: * @param integer $tncc
66: */
67: public function setTypeNomClair(?int $tncc): self
68: {
69: return $this->setTncc($tncc);
70: }
71:
72:
73: // --------------------------------------------------------------------- Static methods
74:
75: /**
76: * Retourne l'article correspondant à un code TNCC.
77: */
78: public static function tnccArticle(int $tncc): string
79: {
80: if (! isset(self::tncc_articles[$tncc])) return "";
81: return self::tncc_articles[$tncc];
82: }
83:
84: /**
85: * Retourne la charnière correspondant à un code TNCC.
86: */
87: public static function tnccCharniere(int $tncc): string
88: {
89: if (! isset(self::tncc_charnieres[$tncc])) return "";
90: return self::tncc_charnieres[$tncc];
91: }
92:
93:
94: // --------------------------------------------------------------------- Custom methods
95:
96: /**
97: * Retourne l'article à employer avec le nom.
98: */
99: public function getArticle(bool $espace = false, bool $parentheses = false): string
100: {
101: $sep = ($espace) ? " " : "";
102: switch ($this->tncc + ($parentheses ? 10 : 0)) {
103: case 0 : return "";
104: case 1 : return "";
105: case 2 : return "Le" . $sep;
106: case 3 : return "La" . $sep;
107: case 4 : return "Les" . $sep;
108: case 5 : return "L'";
109: case 6 : return "Aux" . $sep;
110: case 7 : return "Las" . $sep;
111: case 8 : return "Los" . $sep;
112: case 10 : return "";
113: case 11 : return "";
114: case 12 : return $sep . "(Le)";
115: case 13 : return $sep . "(La)";
116: case 14 : return $sep . "(Les)";
117: case 15 : return $sep . "(L')";
118: case 16 : return $sep . "(Aux)";
119: case 17 : return $sep . "(Las)";
120: case 18 : return $sep . "(Los)";
121: }
122: return "";
123: }
124:
125: /**
126: * Retourne la charnière à employer avec le nom.
127: */
128: public function getCharniere(bool $espace = false): string
129: {
130: $sep = ($espace) ? " " : "";
131: switch ($this->tncc) {
132: case 0 : return "de" . $sep;
133: case 1 : return "d'";
134: case 2 : return "du" . $sep;
135: case 3 : return "de la" . $sep;
136: case 4 : return "des" . $sep;
137: case 5 : return "de l'";
138: case 6 : return "des" . $sep;
139: case 7 : return "de Las" . $sep;
140: case 8 : return "de Los" . $sep;
141: }
142: return "";
143: }
144:
145:
146: // --------------------------------------------------------------------- Shortcut methods
147:
148: /**
149: * Retourne le nom avec son éventuel article en préfixe.
150: */
151: public function getArtNom(): string
152: {
153: if (! isset($this->nom)) return "";
154: return $this->getArticle(true) . $this->nom;
155: }
156:
157: /**
158: * Retourne le nom avec son éventuel article en suffixe (entre parenthèses).
159: */
160: public function getNomArt(): string
161: {
162: if (! isset($this->nom)) return "";
163: return $this->nom . $this->getArticle(true, true);
164: }
165:
166:
167: }
168: