src/Entity/TblSociete.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TblSocieteRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  7. use Symfony\Component\HttpFoundation\File\UploadedFile;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Table(name="tbl_societe")
  11.  * @ORM\Entity(repositoryClass=TblSocieteRepository::class)
  12.  * @Gedmo\Loggable()
  13.  */ 
  14. class TblSociete
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(name="id", type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, nullable=true)
  24.      */
  25.     private $raisonSocial;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private $adresse;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $codePostal;
  34.     /**
  35.      * @Gedmo\Versioned
  36.      * @ORM\ManyToOne(targetEntity=RefVille::class)
  37.      * @ORM\JoinColumns({
  38.      *   @ORM\JoinColumn(name="ville", referencedColumnName="id")
  39.      * })
  40.      */
  41.     private $ville;
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      */
  45.     private $pays;
  46.     /**
  47.      * @ORM\Column(type="string", length=255, nullable=true)
  48.      */
  49.     private $departement;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      */
  53.     private $devisePrincipale;
  54.     /**
  55.      * @ORM\Column(type="string", length=20, nullable=true)
  56.      * @Assert\Regex(pattern="/^(\+212||0)[0-9]{9,9}$/", message="Numéro Téléphone invalide !")
  57.      */
  58.     private $telephone;
  59.     /**
  60.      * @ORM\Column(type="string", length=20, nullable=true)
  61.      * @Assert\Regex(pattern="/^(\+212||0)[0-9]{9,9}$/", message="Numéro Téléphone invalide !")
  62.      */
  63.     private $fax;
  64.     /**
  65.      * @ORM\Column(type="string", length=255, nullable=true)
  66.      * @Assert\Email( message = "L'e-mail '{{ value }}' n'est pas valide." )
  67.      */
  68.     private $email;
  69.     /**
  70.      * @ORM\Column(type="string", length=255, nullable=true)
  71.      */
  72.     private $web;
  73.     /**
  74.      * @ORM\Column(type="string", length=255, nullable=true)
  75.      */
  76.     private $note;
  77.     /**
  78.      * @ORM\OneToOne(targetEntity=TblFile::class, inversedBy="logoSociete", cascade={"persist", "remove"})
  79.      * @ORM\JoinColumns({
  80.      *   @ORM\JoinColumn(name="logo_societe_id", referencedColumnName="id", onDelete="CASCADE")
  81.      * })
  82.      */
  83.     private $logo;
  84.     /**
  85.      * @var \DateTime
  86.      *
  87.      * @Gedmo\Timestampable(on="create")
  88.      * @ORM\Column(name="created_at", type="datetime", nullable=true)
  89.      */
  90.     private $createdAt;
  91.     /**
  92.      * @var \DateTime
  93.      *
  94.      * @Gedmo\Timestampable(on="update")
  95.      * @ORM\Column(name="updated_at", type="datetime", nullable=true)
  96.      */
  97.     private $updatedAt;
  98.     /**
  99.      * @var \DateTime
  100.      *
  101.      * @ORM\Column(name="deleted_at", type="datetime", nullable=true)
  102.      */
  103.     private $deletedAt;
  104.     /**
  105.      * @var \User
  106.      *
  107.      * @Gedmo\Blameable(on="create")
  108.      * @ORM\ManyToOne(targetEntity="User")
  109.      * @ORM\JoinColumns({
  110.      *   @ORM\JoinColumn(name="created_by", referencedColumnName="user_id")
  111.      * })
  112.      */
  113.     private $createdBy;
  114.     /**
  115.      * @var \User
  116.      *
  117.      * @Gedmo\Blameable(on="update")
  118.      * @ORM\ManyToOne(targetEntity="User")
  119.      * @ORM\JoinColumns({
  120.      *   @ORM\JoinColumn(name="updated_by", referencedColumnName="user_id")
  121.      * })
  122.      */
  123.     private $updatedBy;
  124.     /**
  125.      * @var \User
  126.      *
  127.      * @ORM\ManyToOne(targetEntity="User")
  128.      * @ORM\JoinColumns({
  129.      *   @ORM\JoinColumn(name="deleted_by", referencedColumnName="user_id")
  130.      * })
  131.      */
  132.     private $deletedBy;
  133.     public function __construct()
  134.     {
  135.         $this->createdAt = new \DateTime();
  136.         $this->updatedAt = new \DateTime();
  137.     }
  138.     public function getId(): ?int
  139.     {
  140.         return $this->id;
  141.     }
  142.     public function getRaisonSocial(): ?string
  143.     {
  144.         return $this->raisonSocial;
  145.     }
  146.     public function setRaisonSocial(?string $raisonSocial): self
  147.     {
  148.         $this->raisonSocial $raisonSocial;
  149.         return $this;
  150.     }
  151.     public function getAdresse(): ?string
  152.     {
  153.         return $this->adresse;
  154.     }
  155.     public function setAdresse(?string $adresse): self
  156.     {
  157.         $this->adresse $adresse;
  158.         return $this;
  159.     }
  160.     public function getCodePostal(): ?string
  161.     {
  162.         return $this->codePostal;
  163.     }
  164.     public function setCodePostal(?string $codePostal): self
  165.     {
  166.         $this->codePostal $codePostal;
  167.         return $this;
  168.     }
  169.     public function getVille(): ?RefVille
  170.     {
  171.         return $this->ville;
  172.     }
  173.     public function setVille(?RefVille $ville): self
  174.     {
  175.         $this->ville $ville;
  176.         return $this;
  177.     }
  178.     public function getPays(): ?string
  179.     {
  180.         return $this->pays;
  181.     }
  182.     public function setPays(?string $pays): self
  183.     {
  184.         $this->pays $pays;
  185.         return $this;
  186.     }
  187.     public function getDepartement(): ?string
  188.     {
  189.         return $this->departement;
  190.     }
  191.     public function setDepartement(?string $departement): self
  192.     {
  193.         $this->departement $departement;
  194.         return $this;
  195.     }
  196.     public function getDevisePrincipale(): ?string
  197.     {
  198.         return $this->devisePrincipale;
  199.     }
  200.     public function setDevisePrincipale(?string $devisePrincipale): self
  201.     {
  202.         $this->devisePrincipale $devisePrincipale;
  203.         return $this;
  204.     }
  205.     public function getTelephone(): ?string
  206.     {
  207.         return $this->telephone;
  208.     }
  209.     public function setTelephone(?string $telephone): self
  210.     {
  211.         $this->telephone $telephone;
  212.         return $this;
  213.     }
  214.     public function getFax(): ?int
  215.     {
  216.         return $this->fax;
  217.     }
  218.     public function setFax(?int $fax): self
  219.     {
  220.         $this->fax $fax;
  221.         return $this;
  222.     }
  223.     public function getEmail(): ?string
  224.     {
  225.         return $this->email;
  226.     }
  227.     public function setEmail(?string $email): self
  228.     {
  229.         $this->email $email;
  230.         return $this;
  231.     }
  232.     public function getWeb(): ?string
  233.     {
  234.         return $this->web;
  235.     }
  236.     public function setWeb(?string $web): self
  237.     {
  238.         $this->web $web;
  239.         return $this;
  240.     }
  241.     public function getNote(): ?string
  242.     {
  243.         return $this->note;
  244.     }
  245.     public function setNote(?string $note): self
  246.     {
  247.         $this->note $note;
  248.         return $this;
  249.     }
  250.     public function getLogo(): ?TblFile
  251.     {
  252.         
  253.         return $this->logo;
  254.     }
  255.     public function setLogo(?TblFile $logo): self
  256.     {
  257.         $this->logo $logo;
  258.         return $this;
  259.     }
  260.     const SERVER_PATH_TO_IMAGE_FOLDER 'public/sonataAdminImg';
  261.     /**
  262.     * Unmapped property to handle file uploads
  263.     */
  264.     private $file;
  265.     /**
  266.     * @param UploadedFile $file
  267.     */
  268.     public function setFile(UploadedFile $file null)
  269.     {
  270.         $this->file $file;
  271.     }
  272.     /**
  273.     * @return UploadedFile
  274.     */
  275.     public function getFile()
  276.     {
  277.         return $this->file;
  278.     }
  279.     /**
  280.      * Manages the copying of the file to the relevant place on the server/**
  281.      */
  282.     public function upload(): void
  283.     {
  284.         // the file property can be empty if the field is not required
  285.         if (null === $this->getFile()) {
  286.             return;
  287.         }
  288.         $typeFile $this->getFile()->guessExtension();
  289.         $pathFolder self::SERVER_PATH_TO_IMAGE_FOLDER;
  290.         $originalName $this->getFile()->getClientOriginalName();
  291.         // move takes the target directory and target filename as params
  292.         $this->getFile()->move($pathFolder$originalName);
  293.         
  294.         $tblFile $this->getLogo() ? $this->getLogo() : new TblFile();
  295.         $this->file $this->getFile()->getClientOriginalName();
  296.         
  297.         $fileName $originalName;
  298.         $pathFile '/public/sonataAdminImg-' $fileName;
  299.         $tblFile->setFileName($originalName);
  300.         $tblFile->setFilePath($pathFolder.'/'.$fileName);
  301.         $tblFile->getFileSize($fileName);
  302.         $tblFile->setOriginName($pathFile);
  303.         $tblFile->setFileExt($fileName);
  304.         try {
  305.             $this->setLogo($tblFile);
  306.         } catch (FileException $e) {
  307.             // ... handle exception if something happens during file upload
  308.         }
  309.    }
  310.    /**
  311.     * Updates the hash value to force the preUpdate and postUpdate events to fire.
  312.     */
  313.    public function refreshUpdated(): void
  314.    {
  315.         $this->getLogo()->setUpdatedAt(new \DateTime());
  316.    }
  317.    public function getCreatedAt(): ?\DateTimeInterface
  318.    {
  319.        return $this->createdAt;
  320.    }
  321.    public function setCreatedAt(\DateTimeInterface $createdAt): self
  322.    {
  323.        $this->createdAt $createdAt;
  324.        return $this;
  325.    }
  326.    public function getUpdatedAt(): ?\DateTimeInterface
  327.    {
  328.        return $this->updatedAt;
  329.    }
  330.    public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  331.    {
  332.        $this->updatedAt $updatedAt;
  333.        return $this;
  334.    }
  335.    public function getDeletedAt(): ?\DateTimeInterface
  336.    {
  337.        return $this->deletedAt;
  338.    }
  339.    public function setDeletedAt(\DateTimeInterface $deletedAt): self
  340.    {
  341.        $this->deletedAt $deletedAt;
  342.        return $this;
  343.    }
  344.    public function getCreatedBy(): ?User
  345.    {
  346.        return $this->createdBy;
  347.    }
  348.    public function setCreatedBy(?User $createdBy): self
  349.    {
  350.        $this->createdBy $createdBy;
  351.        return $this;
  352.    }
  353.     public function getUpdatedBy(): ?User
  354.     {
  355.         return $this->updatedBy;
  356.     }
  357.     public function setUpdatedBy(?User $updatedBy): self
  358.     {
  359.         $this->updatedBy $updatedBy;
  360.         return $this;
  361.     }
  362.     public function getDeletedBy(): ?User
  363.     {
  364.         return $this->deletedBy;
  365.     }
  366.     public function setDeletedBy(?User $deletedBy): self
  367.     {
  368.         $this->deletedBy $deletedBy;
  369.         return $this;
  370.     }
  371. }