Source of file InseeTnccable.php

Size: 3,797 Bytes - Last Modified: 2023-11-16T22:56:03+01:00

/home/websites/teicee/packagist/site/phpdoc/conf/../vendor/teicee/town-bundle/src/Traits/InseeTnccable.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
<?php
namespace TIC\TownBundle\Traits;

/**
 * Gestion du champs TNCC fourni par l'INSEE (Type Nom Clair => article).
 */
trait InseeTnccable
{

	private $tncc_articles   = array(  "",   "", "Le",    "La", "Les",    "L'", "Aux",    "Las",    "Los");
	private $tncc_charnieres = array("de", "d'", "du", "de la", "des", "de l'", "des", "de Las", "de Los");


// --------------------------------------------------------------------- Properties

	/**
	 * @ORM\Column(type="smallint", nullable=true)
	 */
	private $tncc;

	/**
	 * @ORM\Column(type="string", length=8, nullable=true)
	 */
	private $art;


// --------------------------------------------------------------------- Mutators/Accessors

	public function getTncc(): ?int
	{
		return $this->tncc;
	}

	public function setTncc(?int $tncc): self
	{
		$this->tncc = $tncc;
		$this->art = $this->getArticle();
		return $this;
	}


	public function getArt(): ?string
	{
		return $this->art;
	}

	public function setArt(?string $art): self
	{
		$this->art = $art;
		return $this;
	}


	/**
	 * Alias du getter sur tncc.
	 * @return integer
	 */
	public function getTypeNomClair(): ?int
	{
		return $this->getTncc();
	}

	/**
	 * Alias du setter sur tncc.
	 * @param integer $tncc
	 */
	public function setTypeNomClair(?int $tncc): self
	{
		return $this->setTncc($tncc);
	}


// --------------------------------------------------------------------- Static methods

	/**
	 * Retourne l'article correspondant à un code TNCC.
	 */
	public static function tnccArticle(int $tncc): string
	{
		if (! isset(self::tncc_articles[$tncc])) return "";
		return self::tncc_articles[$tncc];
	}

	/**
	 * Retourne la charnière correspondant à un code TNCC.
	 */
	public static function tnccCharniere(int $tncc): string
	{
		if (! isset(self::tncc_charnieres[$tncc])) return "";
		return self::tncc_charnieres[$tncc];
	}


// --------------------------------------------------------------------- Custom methods

	/**
	 * Retourne l'article à employer avec le nom.
	 */
	public function getArticle(bool $espace = false, bool $parentheses = false): string
	{
		$sep = ($espace) ? " " : "";
		switch ($this->tncc + ($parentheses ? 10 : 0)) {
			case 0  : return "";
			case 1  : return "";
			case 2  : return "Le"  . $sep;
			case 3  : return "La"  . $sep;
			case 4  : return "Les" . $sep;
			case 5  : return "L'";
			case 6  : return "Aux" . $sep;
			case 7  : return "Las" . $sep;
			case 8  : return "Los" . $sep;
			case 10 : return "";
			case 11 : return "";
			case 12 : return $sep . "(Le)";
			case 13 : return $sep . "(La)";
			case 14 : return $sep . "(Les)";
			case 15 : return $sep . "(L')";
			case 16 : return $sep . "(Aux)";
			case 17 : return $sep . "(Las)";
			case 18 : return $sep . "(Los)";
		}
		return "";
	}

	/**
	 * Retourne la charnière à employer avec le nom.
	 */
	public function getCharniere(bool $espace = false): string
	{
		$sep = ($espace) ? " " : "";
		switch ($this->tncc) {
			case 0 : return "de"     . $sep;
			case 1 : return "d'";
			case 2 : return "du"     . $sep;
			case 3 : return "de la"  . $sep;
			case 4 : return "des"    . $sep;
			case 5 : return "de l'";
			case 6 : return "des"    . $sep;
			case 7 : return "de Las" . $sep;
			case 8 : return "de Los" . $sep;
		}
		return "";
	}


// --------------------------------------------------------------------- Shortcut methods

	/**
	 * Retourne le nom avec son éventuel article en préfixe.
	 */
	public function getArtNom(): string
	{
		if (! isset($this->nom)) return "";
		return $this->getArticle(true) . $this->nom;
	}

	/**
	 * Retourne le nom avec son éventuel article en suffixe (entre parenthèses).
	 */
	public function getNomArt(): string
	{
		if (! isset($this->nom)) return "";
		return $this->nom . $this->getArticle(true, true);
	}


}