<?php
namespace App\Entity;
use App\Repository\TblSocieteRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Table(name="tbl_societe")
* @ORM\Entity(repositoryClass=TblSocieteRepository::class)
* @Gedmo\Loggable()
*/
class TblSociete
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id", type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $raisonSocial;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $adresse;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $codePostal;
/**
* @Gedmo\Versioned
* @ORM\ManyToOne(targetEntity=RefVille::class)
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="ville", referencedColumnName="id")
* })
*/
private $ville;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $pays;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $departement;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $devisePrincipale;
/**
* @ORM\Column(type="string", length=20, nullable=true)
* @Assert\Regex(pattern="/^(\+212||0)[0-9]{9,9}$/", message="Numéro Téléphone invalide !")
*/
private $telephone;
/**
* @ORM\Column(type="string", length=20, nullable=true)
* @Assert\Regex(pattern="/^(\+212||0)[0-9]{9,9}$/", message="Numéro Téléphone invalide !")
*/
private $fax;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Email( message = "L'e-mail '{{ value }}' n'est pas valide." )
*/
private $email;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $web;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $note;
/**
* @ORM\OneToOne(targetEntity=TblFile::class, inversedBy="logoSociete", cascade={"persist", "remove"})
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="logo_societe_id", referencedColumnName="id", onDelete="CASCADE")
* })
*/
private $logo;
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created_at", type="datetime", nullable=true)
*/
private $createdAt;
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @var \DateTime
*
* @ORM\Column(name="deleted_at", type="datetime", nullable=true)
*/
private $deletedAt;
/**
* @var \User
*
* @Gedmo\Blameable(on="create")
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="created_by", referencedColumnName="user_id")
* })
*/
private $createdBy;
/**
* @var \User
*
* @Gedmo\Blameable(on="update")
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="updated_by", referencedColumnName="user_id")
* })
*/
private $updatedBy;
/**
* @var \User
*
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="deleted_by", referencedColumnName="user_id")
* })
*/
private $deletedBy;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getRaisonSocial(): ?string
{
return $this->raisonSocial;
}
public function setRaisonSocial(?string $raisonSocial): self
{
$this->raisonSocial = $raisonSocial;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(?string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getCodePostal(): ?string
{
return $this->codePostal;
}
public function setCodePostal(?string $codePostal): self
{
$this->codePostal = $codePostal;
return $this;
}
public function getVille(): ?RefVille
{
return $this->ville;
}
public function setVille(?RefVille $ville): self
{
$this->ville = $ville;
return $this;
}
public function getPays(): ?string
{
return $this->pays;
}
public function setPays(?string $pays): self
{
$this->pays = $pays;
return $this;
}
public function getDepartement(): ?string
{
return $this->departement;
}
public function setDepartement(?string $departement): self
{
$this->departement = $departement;
return $this;
}
public function getDevisePrincipale(): ?string
{
return $this->devisePrincipale;
}
public function setDevisePrincipale(?string $devisePrincipale): self
{
$this->devisePrincipale = $devisePrincipale;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(?string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
public function getFax(): ?int
{
return $this->fax;
}
public function setFax(?int $fax): self
{
$this->fax = $fax;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getWeb(): ?string
{
return $this->web;
}
public function setWeb(?string $web): self
{
$this->web = $web;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
public function getLogo(): ?TblFile
{
return $this->logo;
}
public function setLogo(?TblFile $logo): self
{
$this->logo = $logo;
return $this;
}
const SERVER_PATH_TO_IMAGE_FOLDER = 'public/sonataAdminImg';
/**
* Unmapped property to handle file uploads
*/
private $file;
/**
* @param UploadedFile $file
*/
public function setFile(UploadedFile $file = null)
{
$this->file = $file;
}
/**
* @return UploadedFile
*/
public function getFile()
{
return $this->file;
}
/**
* Manages the copying of the file to the relevant place on the server/**
*/
public function upload(): void
{
// the file property can be empty if the field is not required
if (null === $this->getFile()) {
return;
}
$typeFile = $this->getFile()->guessExtension();
$pathFolder = self::SERVER_PATH_TO_IMAGE_FOLDER;
$originalName = $this->getFile()->getClientOriginalName();
// move takes the target directory and target filename as params
$this->getFile()->move($pathFolder, $originalName);
$tblFile = $this->getLogo() ? $this->getLogo() : new TblFile();
$this->file = $this->getFile()->getClientOriginalName();
$fileName = $originalName;
$pathFile = '/public/sonataAdminImg-' . $fileName;
$tblFile->setFileName($originalName);
$tblFile->setFilePath($pathFolder.'/'.$fileName);
$tblFile->getFileSize($fileName);
$tblFile->setOriginName($pathFile);
$tblFile->setFileExt($fileName);
try {
$this->setLogo($tblFile);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
/**
* Updates the hash value to force the preUpdate and postUpdate events to fire.
*/
public function refreshUpdated(): void
{
$this->getLogo()->setUpdatedAt(new \DateTime());
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(\DateTimeInterface $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getDeletedBy(): ?User
{
return $this->deletedBy;
}
public function setDeletedBy(?User $deletedBy): self
{
$this->deletedBy = $deletedBy;
return $this;
}
}