src/Acme/OffresBundle/Entity/Annonceurs.php line 14

Open in your IDE?
  1. <?php
  2. namespace Acme\OffresBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\HttpFoundation\File\UploadedFile;
  5. /**
  6.  * Annonceurs
  7.  *
  8.  * @ORM\Table(name="annonceurs")
  9.  * @ORM\Entity(repositoryClass="Acme\OffresBundle\Repository\AnnonceursRepository")
  10.  * @ORM\HasLifecycleCallbacks
  11.  */
  12. class Annonceurs
  13. {
  14.     /**
  15.      * @var int
  16.      *
  17.      * @ORM\Column(name="id", type="integer")
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue(strategy="AUTO")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @var string
  24.      *
  25.      * @ORM\Column(name="nom", type="string", length=100)
  26.      */
  27.     private $nom;
  28.     /**
  29.      * @var string
  30.      *
  31.      * @ORM\Column(name="organisme", type="string", length=100, nullable=true)
  32.      */
  33.     private $organisme;
  34.     /**
  35.      * @var string
  36.      *
  37.      * @ORM\Column(name="telephone", type="string", length=22, nullable=true)
  38.      */
  39.     private $telephone;
  40.     /**
  41.      * @var string
  42.      *
  43.      * @ORM\Column(name="adresse", type="string", length=255, nullable=true)
  44.      */
  45.     private $adresse;
  46.     
  47.     /**
  48.      * @var string
  49.      *
  50.      * @ORM\Column(name="logo", type="string", length=200, nullable=true)
  51.      */
  52.     private $logo;
  53.     public $file;
  54.     private $temp;
  55.     public function __toString() {
  56.         return $this->nom;
  57.     }   
  58.     
  59.     /**
  60.      * Get id
  61.      *
  62.      * @return int
  63.      */
  64.     public function getId()
  65.     {
  66.         return $this->id;
  67.     }
  68.     /**
  69.      * Set nom
  70.      *
  71.      * @param string $nom
  72.      *
  73.      * @return annonceurs
  74.      */
  75.     public function setNom($nom)
  76.     {
  77.         $this->nom $nom;
  78.         return $this;
  79.     }
  80.     /**
  81.      * Get nom
  82.      *
  83.      * @return string
  84.      */
  85.     public function getNom()
  86.     {
  87.         return $this->nom;
  88.     }
  89.     /**
  90.      * Set organisme
  91.      *
  92.      * @param string $organisme
  93.      *
  94.      * @return annonceurs
  95.      */
  96.     public function setOrganisme($organisme)
  97.     {
  98.         $this->organisme $organisme;
  99.         return $this;
  100.     }
  101.     /**
  102.      * Get organisme
  103.      *
  104.      * @return string
  105.      */
  106.     public function getOrganisme()
  107.     {
  108.         return $this->organisme;
  109.     }
  110.     
  111.     /**
  112.      * Set telephone
  113.      *
  114.      * @param string $telephone
  115.      *
  116.      * @return annonceurs
  117.      */
  118.     public function setTelephone($telephone)
  119.     {
  120.         $this->telephone $telephone;
  121.         return $this;
  122.     }
  123.     /**
  124.      * Get telephone
  125.      *
  126.      * @return string
  127.      */
  128.     public function getTelephone()
  129.     {
  130.         return $this->telephone;
  131.     }
  132.     /**
  133.      * Set adresse
  134.      *
  135.      * @param string $adresse
  136.      *
  137.      * @return annonceurs
  138.      */
  139.     public function setAdresse($adresse)
  140.     {
  141.         $this->adresse $adresse;
  142.         return $this;
  143.     }
  144.     /**
  145.      * Get adresse
  146.      *
  147.      * @return string
  148.      */
  149.     public function getAdresse()
  150.     {
  151.         return $this->adresse;
  152.     }
  153.     
  154.     /**
  155.      * Set logo
  156.      *
  157.      * @param string $logo
  158.      *
  159.      * @return Annonceurs
  160.      */
  161.     public function setLogo($logo)
  162.     {
  163.         $this->logo $logo;
  164.         return $this;
  165.     }
  166.     /**
  167.      * Get logo
  168.      *
  169.      * @return string
  170.      */
  171.     public function getLogo()
  172.     {
  173.         return $this->logo;
  174.     }
  175.     
  176.      /**
  177.      * Sets file.
  178.      *
  179.      * @param UploadedFile $file
  180.      */
  181.     public function setFile(UploadedFile $file null)
  182.     {
  183.         $this->file $file;
  184.         // check if we have an old image path
  185.         if (isset($this->logo)) {
  186.             // store the old name to delete after the update
  187.             $this->temp $this->logo;
  188.             $this->logo null;
  189.         } else {
  190.             $this->logo 'initial';
  191.         }
  192.     }
  193.     protected function getUploadDir()
  194.     {
  195.         return 'uploads/media/logos';
  196.     }
  197.      
  198.     protected function getUploadRootDir()
  199.     {
  200.         return __DIR__.'/../../../../public/'.$this->getUploadDir();
  201.     }
  202.      
  203.     public function getWebPath()
  204.     {
  205.         return null === $this->logo null $this->getUploadDir().'/'.$this->logo;
  206.     }
  207.      
  208.     public function getAbsolutePath()
  209.     {
  210.         return null === $this->logo null $this->getUploadRootDir().'/'.$this->logo;
  211.     }
  212.     /**
  213.      * @ORM\PrePersist
  214.      * @ORM\PreUpdate
  215.      */
  216.     public function preUpload()
  217.     {
  218.         // Add your code here
  219.          if (null !== $this->file) {
  220.              // do whatever you want to generate a unique name
  221.              $this->logo uniqid().'.'.$this->file->guessExtension();
  222.              }
  223.     }
  224.     /**
  225.      * @ORM\PostPersist
  226.      * @ORM\PostUpdate
  227.      */
  228.     public function upload()
  229.     {
  230.         // Add your code here
  231.         if (null === $this->file) {
  232.             return;
  233.         }
  234.         
  235.         
  236.       // if there is an error when moving the file, an exception will
  237.       // be automatically thrown by move(). This will properly prevent
  238.       // the entity from being persisted to the database on error
  239.       $this->file->move($this->getUploadRootDir(), $this->logo);
  240.       // check if we have an old image
  241.         if (isset($this->temp)) {
  242.             // delete the old image
  243.             unlink($this->getUploadRootDir().'/'.$this->temp);
  244.             // clear the temp image path
  245.             $this->temp null;
  246.         }
  247.       unset($this->file);
  248.     }
  249.     /**
  250.      * @ORM\PostRemove
  251.      */
  252.     public function removeUpload()
  253.     {
  254.         // Add your code here
  255.         if ($file $this->getAbsolutePath()) {
  256.             unlink($file);
  257.         }
  258.     }
  259.     /**
  260.      * Return class name of form type used to add & edit users
  261.      *
  262.      * @return string
  263.      */
  264.     public function getFormTypeClass()
  265.     {
  266.         return 'Acme\OffresBundle\Form\AnnonceursType';
  267.     }
  268.     public function getAdminListConfigurator()
  269.     {
  270.         return 'Acme\OffresBundle\AdminList\AnnonceursAdminListConfigurator';
  271.     }
  272. }