<?php
namespace Acme\OffresBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Annonceurs
*
* @ORM\Table(name="annonceurs")
* @ORM\Entity(repositoryClass="Acme\OffresBundle\Repository\AnnonceursRepository")
* @ORM\HasLifecycleCallbacks
*/
class Annonceurs
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=100)
*/
private $nom;
/**
* @var string
*
* @ORM\Column(name="organisme", type="string", length=100, nullable=true)
*/
private $organisme;
/**
* @var string
*
* @ORM\Column(name="telephone", type="string", length=22, nullable=true)
*/
private $telephone;
/**
* @var string
*
* @ORM\Column(name="adresse", type="string", length=255, nullable=true)
*/
private $adresse;
/**
* @var string
*
* @ORM\Column(name="logo", type="string", length=200, nullable=true)
*/
private $logo;
public $file;
private $temp;
public function __toString() {
return $this->nom;
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set nom
*
* @param string $nom
*
* @return annonceurs
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* Set organisme
*
* @param string $organisme
*
* @return annonceurs
*/
public function setOrganisme($organisme)
{
$this->organisme = $organisme;
return $this;
}
/**
* Get organisme
*
* @return string
*/
public function getOrganisme()
{
return $this->organisme;
}
/**
* Set telephone
*
* @param string $telephone
*
* @return annonceurs
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
return $this;
}
/**
* Get telephone
*
* @return string
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* Set adresse
*
* @param string $adresse
*
* @return annonceurs
*/
public function setAdresse($adresse)
{
$this->adresse = $adresse;
return $this;
}
/**
* Get adresse
*
* @return string
*/
public function getAdresse()
{
return $this->adresse;
}
/**
* Set logo
*
* @param string $logo
*
* @return Annonceurs
*/
public function setLogo($logo)
{
$this->logo = $logo;
return $this;
}
/**
* Get logo
*
* @return string
*/
public function getLogo()
{
return $this->logo;
}
/**
* Sets file.
*
* @param UploadedFile $file
*/
public function setFile(UploadedFile $file = null)
{
$this->file = $file;
// check if we have an old image path
if (isset($this->logo)) {
// store the old name to delete after the update
$this->temp = $this->logo;
$this->logo = null;
} else {
$this->logo = 'initial';
}
}
protected function getUploadDir()
{
return 'uploads/media/logos';
}
protected function getUploadRootDir()
{
return __DIR__.'/../../../../public/'.$this->getUploadDir();
}
public function getWebPath()
{
return null === $this->logo ? null : $this->getUploadDir().'/'.$this->logo;
}
public function getAbsolutePath()
{
return null === $this->logo ? null : $this->getUploadRootDir().'/'.$this->logo;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function preUpload()
{
// Add your code here
if (null !== $this->file) {
// do whatever you want to generate a unique name
$this->logo = uniqid().'.'.$this->file->guessExtension();
}
}
/**
* @ORM\PostPersist
* @ORM\PostUpdate
*/
public function upload()
{
// Add your code here
if (null === $this->file) {
return;
}
// if there is an error when moving the file, an exception will
// be automatically thrown by move(). This will properly prevent
// the entity from being persisted to the database on error
$this->file->move($this->getUploadRootDir(), $this->logo);
// check if we have an old image
if (isset($this->temp)) {
// delete the old image
unlink($this->getUploadRootDir().'/'.$this->temp);
// clear the temp image path
$this->temp = null;
}
unset($this->file);
}
/**
* @ORM\PostRemove
*/
public function removeUpload()
{
// Add your code here
if ($file = $this->getAbsolutePath()) {
unlink($file);
}
}
/**
* Return class name of form type used to add & edit users
*
* @return string
*/
public function getFormTypeClass()
{
return 'Acme\OffresBundle\Form\AnnonceursType';
}
public function getAdminListConfigurator()
{
return 'Acme\OffresBundle\AdminList\AnnonceursAdminListConfigurator';
}
}