Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Site\MonBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Component\HttpFoundation\File\UploadedFile;
- /**
- * @ORM\Entity
- * @ORM\HasLifecycleCallbacks
- */
- class Photo
- {
- /**
- * @ORM\GeneratedValue
- * @ORM\Id
- * @ORM\Column(type="integer")
- */
- private $id;
- /**
- * @ORM\Column(type="string",length="255")
- */
- private $nom;
- /**
- * @Assert\File(maxSize="6000000")
- * @ORM\Column(type="string", length=255, nullable=true)
- */
- public $file;
- /**
- * @ORM\Column(type="string", length=255, nullable=true)
- */
- public $path;
- /**
- * @ORM\Column(type="integer")
- */
- private $ordre;
- /**
- * @ORM\Column(type="string",length="1")
- * @Assert\NotBlank()
- * @Assert\Choice(choices = {"B", "P", "C"})
- */
- // B : Brouillon - P : PubliƩ - C : Corbeille
- private $etat;
- /**
- * @ORM\ManyToOne(targetEntity="Bien")
- */
- private $bien;
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set nom
- *
- * @param string $nom
- */
- public function setNom($nom)
- {
- $this->nom = $nom;
- }
- /**
- * Get nom
- *
- * @return string
- */
- public function getNom()
- {
- return $this->nom;
- }
- /**
- * Set ordre
- *
- * @param integer $ordre
- */
- public function setOrdre($ordre)
- {
- $this->ordre = $ordre;
- }
- /**
- * Get ordre
- *
- * @return integer
- */
- public function getOrdre()
- {
- return $this->ordre;
- }
- /**
- * Set etat
- *
- * @param string $etat
- */
- public function setEtat($etat)
- {
- $this->etat = $etat;
- }
- /**
- * Get etat
- *
- * @return string
- */
- public function getEtat()
- {
- return $this->etat;
- }
- /**
- * Set bien
- *
- * @param Site\DefiscBundle\Entity\Bien $bien
- */
- public function setBien(\Site\DefiscBundle\Entity\Bien $bien)
- {
- $this->bien = $bien;
- }
- /**
- * Get bien
- *
- * @return Site\DefiscBundle\Entity\Bien
- */
- public function getBien()
- {
- return $this->bien;
- }
- /**
- * Set path
- *
- * @param string $path
- */
- public function setPath($path)
- {
- $this->path = $path;
- }
- /**
- * Get path
- *
- * @return string
- */
- public function getPath()
- {
- return $this->path;
- }
- /**
- * Set file
- *
- * @param string $file
- */
- public function setFile($file) {
- $this->file = $file;
- }
- /**
- * Get file
- *
- * @return string
- */
- public function getFile() {
- return $this->file;
- }
- public function getFullFilePath() {
- return null === $this->file ? null : $this->getUploadRootDir(). $this->file;
- }
- protected function getUploadRootDir() {
- // the absolute directory path where uploaded documents should be saved
- return $this->getTmpUploadRootDir().$this->getId()."/";
- }
- protected function getTmpUploadRootDir() {
- // the absolute directory path where uploaded documents should be saved
- return __DIR__ . '/../../../../web/uploads/movies/';
- }
- /**
- * @ORM\PrePersist()
- * @ORM\PreUpdate()
- */
- public function uploadFile() {
- // the file property can be empty if the field is not required
- if (null === $this->file) {
- return;
- }
- if(!$this->id){
- $this->file->move($this->getTmpUploadRootDir(), $this->file->getClientOriginalName());
- }else{
- $this->file->move($this->getUploadRootDir(), $this->file->getClientOriginalName());
- }
- $this->setFile($this->file->getClientOriginalName());
- }
- /**
- * @ORM\PostPersist()
- */
- public function moveFile()
- {
- if (null === $this->file) {
- return;
- }
- if(!is_dir($this->getUploadRootDir())){
- mkdir($this->getUploadRootDir());
- }
- copy($this->getTmpUploadRootDir().$this->file, $this->getFullFilePath());
- unlink($this->getTmpUploadRootDir().$this->file);
- }
- /**
- * @ORM\PreRemove()
- */
- public function removeFile()
- {
- unlink($this->getFullFilePath());
- rmdir($this->getUploadRootDir());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment