<?php namespace App\Entity; use App\Repository\GodChildRepository; use App\Traits\DateTrait; use Doctrine\ORM\Mapping as ORM; use ReflectionClass; /** * @ORM\Entity(repositoryClass=GodChildRepository::class) */ class GodChild { const STATUS_PENDING = 'pending'; const STATUS_VALID = 'valid'; const STATUS_CANCELED = 'canceled'; /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=10) */ private $civility; /** * @ORM\Column(type="string", length=255) */ private $lastName; /** * @ORM\Column(type="string", length=255) */ private $firstName; /** * @ORM\Column(type="string", length=255, nullable=true) */ private $company; /** * @ORM\Column(type="string", length=255, nullable=true) */ private $email; /** * @ORM\Column(type="string", length=255) */ private $address1; /** * @ORM\Column(type="string", length=255, nullable=true) */ private $address2; /** * @ORM\Column(type="string", length=30) */ private $zipcode; /** * @ORM\Column(type="string", length=255) */ private $city; /** * @ORM\Column(type="string", length=3) */ private $country; /** * @ORM\Column(type="string", length=20) */ private $phone; /** * @ORM\Column(type="integer", options={"default":0}) */ private $points = 0; /** * @ORM\Column(type="string", length=64, options={"default":self::STATUS_PENDING}) */ private $status = self::STATUS_PENDING; /** * @ORM\ManyToOne(targetEntity=User::class, inversedBy="godchilds") * @ORM\JoinColumn(nullable=false) */ private $user; /** * @ORM\Column(type="text", nullable=true) */ private $reason; /** * @ORM\Column(type="text", nullable=true) */ private $identifier; use DateTrait; /* * ============================================================================================ * =============================== FONCTIONS CUSTOM =========================================== * ============================================================================================ */ /** * @return array */ static function getStatuses(): array { $oClass = new ReflectionClass( __CLASS__ ); $constantType = []; foreach ( $oClass->getConstants() as $c ) { $constantType[ $c ] = $c; } return $constantType; } /** * @return string */ public function getNameCiv(): string { return trim( strtoupper( $this->civility ) . ' ' . trim( $this->firstName . " " . $this->lastName ) ); } /** * @return mixed */ public function getUsernameFromName() { $username = $this->getName(); $username = str_replace( [ 'Á', 'À', 'Â', 'Ä', 'Ã', 'Å', 'Ç', 'É', 'È', 'Ê', 'Ë', 'Í', 'Ï', 'Î', 'Ì', 'Ñ', 'Ó', 'Ò', 'Ô', 'Ö', 'Õ', 'Ú', 'Ù', 'Û', 'Ü', 'Ý' ], [ 'A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'N', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y' ], $username ); $username = str_replace( [ 'á', 'à', 'â', 'ä', 'ã', 'å', 'ç', 'é', 'è', 'ê', 'ë', 'í', 'ì', 'î', 'ï', 'ñ', 'ó', 'ò', 'ô', 'ö', 'õ', 'ú', 'ù', 'û', 'ü', 'ý', 'ÿ' ], [ 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y' ], $username ); $username = str_replace( [ ' ', '' ], '', $username ); return filter_var( strtolower( $username ), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW ); } public function getName(): string { return trim( $this->firstName . " " . $this->lastName ); } /* * ============================================================================================ * ============================== FIN FONCTIONS CUSTOM ======================================== * ============================================================================================ */ public function getId(): ?int { return $this->id; } public function getCivility(): ?string { return $this->civility; } public function setCivility( string $civility ): self { $this->civility = $civility; return $this; } public function getLastName(): ?string { return $this->lastName; } public function setLastName( string $lastName ): self { $this->lastName = $lastName; return $this; } public function getFirstName(): ?string { return $this->firstName; } public function setFirstName( string $firstName ): self { $this->firstName = $firstName; return $this; } public function getCompany(): ?string { return $this->company; } public function setCompany( ?string $company ): self { $this->company = $company; return $this; } public function getEmail(): ?string { return $this->email; } public function setEmail( ?string $email ): self { $this->email = $email; return $this; } public function getAddress1(): ?string { return $this->address1; } public function setAddress1( string $address1 ): self { $this->address1 = $address1; return $this; } public function getAddress2(): ?string { return $this->address2; } public function setAddress2( ?string $address2 ): self { $this->address2 = $address2; return $this; } public function getZipcode(): ?string { return $this->zipcode; } public function setZipcode( string $zipcode ): self { $this->zipcode = $zipcode; return $this; } public function getCity(): ?string { return $this->city; } public function setCity( string $city ): self { $this->city = $city; return $this; } public function getCountry(): ?string { return $this->country; } public function setCountry( string $country ): self { $this->country = $country; return $this; } public function getPhone(): ?string { return $this->phone; } public function setPhone( string $phone ): self { $this->phone = $phone; return $this; } public function getPoints(): ?int { return $this->points; } public function setPoints( int $points ): self { $this->points = $points; return $this; } public function getStatus(): ?string { return $this->status; } public function setStatus( string $status ): self { $this->status = $status; return $this; } public function getUser(): ?User { return $this->user; } public function setUser( ?User $user ): self { $this->user = $user; return $this; } public function getReason(): ?string { return $this->reason; } public function setReason( ?string $reason ): self { $this->reason = $reason; return $this; } public function getIdentifier(): ?string { return $this->identifier; } public function setIdentifier( ?string $identifier ): self { $this->identifier = $identifier; return $this; } }