<?php
namespace App\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
use App\Validation as ExcAssert;
use App\Validation\Siret;
/**
* Prestataire
*
*
* @ORM\Table(name="Prestataire")
* @ORM\Entity(repositoryClass="App\Entity\PrestataireRepository")
* @ORM\HasLifecycleCallbacks
* @UniqueEntity(
* fields="siret",
* message="Ce numéro SIRET est déjà utilisé."
* )
*/
class Prestataire
{
public static function createWithId($id)
{
$instance = new self();
$instance->id = $id;
return $instance;
}
public const STATUS_NEW = 'new';
public const STATUS_VALIDATED = 'valid';
public const STATUS_DELETED = 'deleted';
private static $statusLabels = array(
self::STATUS_NEW => 'Nouveau',
self::STATUS_VALIDATED => 'Validé',
self::STATUS_DELETED => 'Supprimé',
);
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="status", type="string")
*/
private $status;
/**
* @var DateTime
*
* @ORM\Column(name="register_date", type="datetime")
*/
private $registerDate;
/**
* @var DateTime
*
* @ORM\Column(name="modified_date", type="datetime")
*/
private $modifiedDate;
/**
* @var integer
*
* @ORM\Column(name="credits", type="integer")
*/
private $credits;
/**
* @var string
*
* @ORM\Column(name="entreprise", type="string", length=255)
* @Assert\NotBlank(
* message="Veuillez renseigner ce champ.",
* groups={"registration", "update"}
* )
*/
private $entreprise;
/**
* @var integer
*
* @ORM\Column(name="siret", type="bigint", nullable=true)
* @Assert\NotBlank(
* message="Veuillez renseigner ce champ.",
* groups={"registration", "update"}
* )
* @Siret()
*/
private $siret;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=255)
* @Assert\NotBlank(
* message="Veuillez renseigner ce champ.",
* groups={"registration", "update"}
* )
*/
private $nom;
/**
* @var string
*
* @ORM\Column(name="adresse", type="string", length=255)
* @Assert\NotBlank(
* message="Veuillez renseigner ce champ.",
* groups={"registration", "update"}
* )
*/
private $adresse;
/**
* @var string
*
* @ORM\Column(name="code_postal", type="string", length=20)
* @Assert\NotBlank(
* message="Veuillez renseigner ce champ.",
* groups={"registration", "update"}
* )
*/
private $codePostal;
/**
* @var string
*
* @ORM\Column(name="ville", type="string", length=255)
* @Assert\NotBlank(
* message="Veuillez renseigner ce champ.",
* groups={"registration", "update"}
* )
*/
private $ville;
/**
* @var string
* @ORM\Column(name="coordinates", type="string", length=255, nullable=true)
*/
private $coordinates;
/**
* @var string
*
* @ORM\Column(name="telephone", type="string", length=255)
* @Assert\NotBlank(
* message="Veuillez renseigner ce champ.",
* groups={"registration", "update"}
* )
*/
private $telephone;
/**
* @var string
*
* @ORM\Column(name="fax", type="string", length=255, nullable=true)
*/
private $fax;
/**
* @var string
*
* @ORM\Column(name="website", type="string", length=255, nullable=true)
* @Assert\Url(
* message="Veuillez entrer une adresse valide.",
* groups={"registration", "update"}
* )
*/
private $website;
/**
* @var string
*
* @ORM\Column(name="logo", type="string", length=255, nullable=true)
*/
private $logoPath;
/**
* @Assert\Image(
* maxSize="10M",
* maxSizeMessage="Le poids maximum possible est de 10 Mo.",
* groups={"registration", "update"}
* )
*/
private $logo;
/**
* @var boolean
* @Assert\IsTrue(
* message="Veuillez confirmer votre adhésion aux CGUV.",
* groups={"registration"}
* )
*/
private $declaration;
/**
* @var User
*
* @ORM\OneToOne(targetEntity="User", inversedBy="prestataire", cascade={"persist","remove"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="Departement", inversedBy="prestataires")
* @ORM\JoinTable(name="PrestataireDepartement")
* @Assert\Count(
* min=1,
* minMessage="Veuillez sélectionner au moins un secteur d'intervention.",
* groups={"registration", "update"}
* )
*/
private $departements;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="Categorie", inversedBy="prestataires")
* @ORM\JoinTable(name="PrestataireCategorie")
* @Assert\Count(
* min=1,
* minMessage="Veuillez sélectionner au moins un domaine d'intervention.",
* groups={"registration", "update"}
* )
*/
private $categories;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Transaction", mappedBy="prestataire", cascade={"remove"})
*/
private $transactions;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="RefundRequest", mappedBy="prestataire")
*/
private $refundRequests;
public function __construct()
{
$this->status = self::STATUS_NEW;
$this->registerDate = new DateTime();
$this->modifiedDate = new DateTime();
$this->departements = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->credits = 0;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @param boolean $status
*
* @return Prestataire
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
public function getStatus()
{
return $this->status;
}
/**
* Get validated
*
* @return boolean
*/
public function isValidated()
{
return $this->status === self::STATUS_VALIDATED;
}
public function isNew()
{
return $this->status === self::STATUS_NEW;
}
public function isDeleted()
{
return $this->status === self::STATUS_DELETED;
}
/**
* Set registerDate
*
* @param DateTime $registerDate
*
* @return Prestataire
*/
public function setRegisterDate($registerDate)
{
$this->registerDate = $registerDate;
return $this;
}
/**
* Get registerDate
*
* @return DateTime
*/
public function getRegisterDate()
{
return $this->registerDate;
}
/**
* Set credits
*
* @param integer $credits
*
* @return Prestataire
*/
public function setCredits($credits)
{
$this->credits = $credits;
return $this;
}
public function addCredits($credits)
{
$this->credits += $credits;
}
public function removeCredits($credits)
{
$this->credits -= $credits;
}
/**
* Get credits
*
* @return integer
*/
public function getCredits()
{
return $this->credits;
}
/**
* Set company
*
* @param string $entreprise
*
* @return Prestataire
*/
public function setEntreprise($entreprise)
{
$this->entreprise = $entreprise;
return $this;
}
/**
* Get company
*
* @return string
*/
public function getEntreprise()
{
return $this->entreprise;
}
/**
* Set siret
*
* @param integer $siret
*
* @return Prestataire
*/
public function setSiret($siret)
{
$this->siret = $siret;
return $this;
}
/**
* Get siret
*
* @return integer
*/
public function getSiret()
{
return $this->siret;
}
/**
* Set name
*
* @param string $nom
*
* @return Prestataire
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set address
*
* @param string $adresse
*
* @return Prestataire
*/
public function setAdresse($adresse)
{
$this->adresse = $adresse;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAdresse()
{
return $this->adresse;
}
/**
* Set zipCode
*
* @param string $codePostal
*
* @return Prestataire
*/
public function setCodePostal($codePostal)
{
$this->codePostal = $codePostal;
return $this;
}
/**
* Get zipCode
*
* @return string
*/
public function getCodePostal()
{
return $this->codePostal;
}
/**
* Set ville
*
* @param string $ville
*
* @return Prestataire
*/
public function setVille($ville)
{
$this->ville = $ville;
return $this;
}
/**
* Get ville
*
* @return string
*/
public function getVille()
{
return $this->ville;
}
/**
* Set telephone
*
* @param string $telephone
*
* @return Prestataire
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
return $this;
}
/**
* Get telephone
*
* @return string
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* Set fax
*
* @param string $fax
*
* @return Prestataire
*/
public function setFax($fax)
{
$this->fax = $fax;
return $this;
}
/**
* Get fax
*
* @return string
*/
public function getFax()
{
return $this->fax;
}
/**
* Set website
*
* @param string $website
*
* @return Prestataire
*/
public function setWebsite($website)
{
$this->website = $website;
return $this;
}
/**
* Get website
*
* @return string
*/
public function getWebsite()
{
if ($this->website && !str_starts_with($this->website, 'http://') && !str_starts_with($this->website, 'https://') && !str_starts_with($this->website, '://')):
return 'http://' . $this->website;
else: return $this->website; endif;
}
/**
* Set logo
*
* @param string $logoPath
*
* @return Prestataire
*/
public function setLogoPath($logoPath)
{
$this->logoPath = $logoPath;
return $this;
}
/**
* Get logo
*
* @return string
*/
public function getLogoPath()
{
return sprintf(
$this->logoPath,
$this->getId() ? $this->getId() : '%s'
);
}
/**
*/
public function getLogo()
{
return $this->logo;
}
/**
*
* @return $this
*/
public function setLogo($logo)
{
$this->logo = $logo;
return $this;
}
/**
* Set user
*
* @param User $user
*
* @return Prestataire
*/
public function setUser(User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* Add departement
*
* @param Departement $departement
*
* @return Prestataire
*/
public function addDepartement(Departement $departement)
{
$this->departements[] = $departement;
return $this;
}
/**
* Remove departement
*
* @param Departement $departement
*/
public function removeDepartement(Departement $departement)
{
$this->departements->removeElement($departement);
}
/**
* Get departements
*
* @return Collection
*/
public function getDepartements()
{
return $this->departements;
}
/**
* Add categories
*
* @param Categorie $categorie
*
* @return Prestataire
*/
public function addCategorie(Categorie $categorie)
{
$this->categories[] = $categorie;
return $this;
}
/**
* Remove categories
*
* @param Categorie $categorie
*/
public function removeCategorie(Categorie $categorie)
{
$this->categories->removeElement($categorie);
}
/**
* Get categories
*
* @return Collection
*/
public function getCategories()
{
return $this->categories;
}
/**
* Add categories
*
* @param Categorie $categories
* @return Prestataire
*/
public function addCategory(Categorie $categories)
{
$this->categories[] = $categories;
return $this;
}
/**
* Remove categories
*
* @param Categorie $categories
*/
public function removeCategory(Categorie $categories)
{
$this->categories->removeElement($categories);
}
/**
* Add transactions
*
* @param Transaction $transactions
* @return Prestataire
*/
public function addTransaction(Transaction $transactions)
{
$this->transactions[] = $transactions;
return $this;
}
/**
* Remove transactions
*
* @param Transaction $transactions
*/
public function removeTransaction(Transaction $transactions)
{
$this->transactions->removeElement($transactions);
}
/**
* Get transactions
*
* @return Collection
*/
public function getTransactions()
{
return $this->transactions;
}
/**
* Set modifiedDate
*
* @param \DateTime $modifiedDate
* @return Prestataire
*/
public function setModifiedDate($modifiedDate)
{
$this->modifiedDate = $modifiedDate;
return $this;
}
/**
* Get modifiedDate
*
* @return \DateTime
*/
public function getModifiedDate()
{
return $this->modifiedDate;
}
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preSave()
{
$this->nom = mb_convert_case($this->nom, MB_CASE_TITLE);
}
/**
* @return boolean
*/
public function isDeclaration()
{
return $this->declaration;
}
/**
* @param boolean $declaration
*/
public function setDeclaration($declaration)
{
$this->declaration = $declaration;
}
/**
* @return ArrayCollection
*/
public function getRefundRequests()
{
return $this->refundRequests;
}
/**
* @param ArrayCollection $refundRequests
*/
public function setRefundRequests($refundRequests)
{
$this->refundRequests = $refundRequests;
}
public function getStatusLabel()
{
return self::$statusLabels[$this->status];
}
public function __toString()
{
return $this->entreprise;
}
/**
* @return string
*/
public function getCoordinates()
{
return $this->coordinates;
}
/**
* @param string $coordinates
*/
public function setCoordinates($coordinates)
{
$this->coordinates = $coordinates;
}
public function getLat()
{
if ($this->coordinates) {
return json_decode($this->coordinates)->lat;
}
return null;
}
public function getLng()
{
if ($this->coordinates) {
return json_decode($this->coordinates)->lng;
}
return null;
}
}