Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace MundoIdeas\FrontendBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Doctrine\Common\Collections\ArrayCollection;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Component\HttpFoundation\File\UploadedFile;
- use MundoIdeas\FrontendBundle\Util\Util;
- /**
- * Proyecto
- *
- * @ORM\Table(name="proyecto")
- * @ORM\Entity(repositoryClass="MundoIdeas\FrontendBundle\Entity\ProyectoRepository")
- * @ORM\HasLifecycleCallbacks()
- */
- class Proyecto
- {
- /**
- * @var integer
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var integer
- *
- * @ORM\ManyToOne(targetEntity="MundoIdeas\FrontendBundle\Entity\Usuario")
- */
- private $usuario;
- /**
- * @var integer
- *
- * @ORM\ManyToOne(targetEntity="MundoIdeas\FrontendBundle\Entity\Categoria")
- */
- private $categoria;
- /**
- * @var string
- *
- * @ORM\Column(name="nombre", type="string", length=100, unique=true)
- */
- private $nombre;
- /**
- * @var string
- *
- * @ORM\Column(name="slug", type="string", length=255)
- */
- private $slug;
- /**
- * @var string
- *
- * @ORM\Column(name="descripcion_corta", type="string", length=255)
- */
- private $descripcion_corta;
- /**
- * @var string
- *
- * @ORM\Column(name="descripcion", type="text")
- */
- private $descripcion;
- /**
- * @var string
- *
- * @ORM\Column(name="imagen", type="string", length=100)
- */
- private $imagen;
- /**
- * @ORM\OneToMany(targetEntity="MundoIdeas\FrontendBundle\Entity\ProyectoImagen", mappedBy="proyecto", cascade={"persist"})
- */
- private $imagenes;
- /**
- * @var integer
- *
- * @ORM\Column(name="estado", type="smallint")
- */
- private $estado;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="fecha_creacion", type="datetime")
- */
- private $fecha_creacion;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="fecha_autorizacion", type="datetime", nullable=true)
- */
- private $fecha_autorizacion;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="fecha_modificacion", type="datetime", nullable=true)
- */
- private $fecha_modificacion;
- /**
- * @var string
- *
- * @Assert\Image(maxSize="500k")
- */
- private $_file_image;
- /**
- * Si se actualiza la imagen almacena la ruta absoluta de la imagen
- * original para eliminarla.
- *
- * @var string
- */
- private $_pre_imagen;
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->imagenes = new ArrayCollection();
- }
- /**
- * @ORM\PrePersist
- */
- public function setCreatedValue()
- {
- $this->setEstado(3); // pendiente de autorización.
- $this->setFechaCreacion(new \DateTime());
- }
- /**
- * @ORM\PrePersist()
- * @ORM\PreUpdate()
- */
- public function preUpload()
- {
- if (NULL !== $this->_file_image)
- {
- $this->_pre_imagen = $this->getAbsolutePath();
- $this->imagen = $this->getSlug().'.'.$this->_file_image->guessExtension();
- }
- }
- /**
- * @ORM\PostPersist()
- * @ORM\PostUpdate()
- */
- public function upload()
- {
- if (NULL === $this->_file_image)
- {
- return;
- }
- // si hay un error al mover el archivo, move() automáticamente
- // envía una excepción. Esta impedirá que la entidad se persista
- // en la base de datos en caso de error
- $this->_file_image->move($this->getUploadRootDir(), $this->imagen);
- if (is_file($this->_pre_imagen))
- {
- unlink($this->_pre_imagen);
- }
- unset($this->_file_image, $this->_pre_imagen);
- }
- /**
- * @ORM\PostRemove()
- */
- public function removeUpload()
- {
- if ($file = $this->getAbsolutePath())
- {
- unlink($file);
- }
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set usuario
- *
- * @param integer $usuario
- * @return Proyecto
- */
- public function setUsuario(\MundoIdeas\FrontendBundle\Entity\Usuario $usuario)
- {
- $this->usuario = $usuario;
- return $this;
- }
- /**
- * Get usuario
- *
- * @return integer
- */
- public function getUsuario()
- {
- return $this->usuario;
- }
- /**
- * Set categoria
- *
- * @param integer $categoria
- * @return Proyecto
- */
- public function setCategoria(\MundoIdeas\FrontendBundle\Entity\Categoria $categoria)
- {
- $this->categoria = $categoria;
- return $this;
- }
- /**
- * Get categoria
- *
- * @return integer
- */
- public function getCategoria()
- {
- return $this->categoria;
- }
- /**
- * Set nombre
- *
- * @param string $nombre
- * @return Proyecto
- */
- public function setNombre($nombre)
- {
- $this->nombre = $nombre;
- $this->slug = Util::getSlug($nombre);
- return $this;
- }
- /**
- * Get nombre
- *
- * @return string
- */
- public function getNombre()
- {
- return $this->nombre;
- }
- /**
- * Set slug
- *
- * @param string $slug
- * @return Proyecto
- */
- public function setSlug($slug)
- {
- $this->slug = $slug;
- return $this;
- }
- /**
- * Get slug
- *
- * @return string
- */
- public function getSlug()
- {
- return $this->slug;
- }
- /**
- * Set descripcion_corta
- *
- * @param string $descripcionCorta
- * @return Proyecto
- */
- public function setDescripcionCorta($descripcionCorta)
- {
- $this->descripcion_corta = $descripcionCorta;
- return $this;
- }
- /**
- * Get descripcion_corta
- *
- * @return string
- */
- public function getDescripcionCorta()
- {
- return $this->descripcion_corta;
- }
- /**
- * Set descripcion
- *
- * @param string $descripcion
- * @return Proyecto
- */
- public function setDescripcion($descripcion)
- {
- $this->descripcion = $descripcion;
- return $this;
- }
- /**
- * Get descripcion
- *
- * @return string
- */
- public function getDescripcion()
- {
- return $this->descripcion;
- }
- /**
- * Set imagen
- *
- * @param string $imagen
- * @return Proyecto
- */
- public function setImagen($imagen)
- {
- $this->imagen = $imagen;
- return $this;
- }
- /**
- * Get imagen
- *
- * @return string
- */
- public function getImagen()
- {
- return $this->imagen;
- }
- /**
- * Set estado
- *
- * @param integer $estado
- * @return Proyecto
- */
- public function setEstado($estado)
- {
- $this->estado = $estado;
- return $this;
- }
- /**
- * Get estado
- *
- * @return integer
- */
- public function getEstado()
- {
- return $this->estado;
- }
- /**
- * Set fecha_autorizacion
- *
- * @param \DateTime $fechaAutorizacion
- * @return Proyecto
- */
- public function setFechaAutorizacion($fechaAutorizacion)
- {
- $this->fecha_autorizacion = $fechaAutorizacion;
- return $this;
- }
- /**
- * Get fecha_autorizacion
- *
- * @return \DateTime
- */
- public function getFechaAutorizacion()
- {
- return $this->fecha_autorizacion;
- }
- /**
- * Set fecha_creacion
- *
- * @param \DateTime $$fechaCreacion
- * @return Proyecto
- */
- public function setFechaCreacion($fechaCreacion)
- {
- $this->fecha_creacion = $fechaCreacion;
- return $this;
- }
- /**
- * Get fecha_creacion
- *
- * @return \DateTime
- */
- public function getFechaCreacion()
- {
- return $this->fecha_creacion;
- }
- /**
- * Set fecha_modificacion
- *
- * @param \DateTime $fechaModificacion
- * @return Proyecto
- */
- public function setFechaModificacion($fechaModificacion)
- {
- $this->fecha_modificacion = $fechaModificacion;
- return $this;
- }
- /**
- * Get fecha_modificacion
- *
- * @return \DateTime
- */
- public function getFechaModificacion()
- {
- return $this->fecha_modificacion;
- }
- /**
- * Set _file_imagen
- *
- * @param string $_file_image
- * @return Proyecto
- */
- public function set_FileImage($fileImage)
- {
- $this->_file_image = $fileImage;
- return $this;
- }
- /**
- * Get imagen
- *
- * @return string
- */
- public function get_FileImage()
- {
- return $this->_file_image;
- }
- /**
- * Set _file_imagen
- *
- * @param string $_file_image
- * @return Proyecto
- */
- public function set_PreImagen($preImagen)
- {
- $this->_pre_imagen = $preImagen;
- return $this;
- }
- /**
- * Get imagen
- *
- * @return string
- */
- public function get_PreImagen()
- {
- return $this->_pre_imagen;
- }
- public function __toString()
- {
- return $this->getNombre();
- }
- /**
- * Add imagenes
- *
- * @param \MundoIdeas\FrontendBundle\Entity\ProyectoImagen $imagenes
- * @return Proyecto
- */
- public function addImagen(\MundoIdeas\FrontendBundle\Entity\ProyectoImagen $imagenes)
- {
- $imagenes->setProyecto($this);
- $this->imagenes[] = $imagenes;
- return $this;
- }
- /**
- * Remove imagenes
- *
- * @param \MundoIdeas\FrontendBundle\Entity\ProyectoImagen $imagenes
- */
- public function removeImagen(\MundoIdeas\FrontendBundle\Entity\ProyectoImagen $imagenes)
- {
- $this->imagenes->removeElement($imagenes);
- }
- /**
- * Get imagenes
- *
- * @return \Doctrine\Common\Collections\Collection
- */
- public function getImagenes()
- {
- return $this->imagenes;
- }
- /**
- * Obtiene la ruta absoluta de la imagen.
- *
- * @return string
- */
- public function getAbsolutePath()
- {
- return NULL === $this->imagen
- ? NULL
- : $this->getUploadRootDir() . '/' . $this->imagen;
- }
- /**
- * Obtiene la ruta absoluta del directorio donde se
- * deben guardar los archivos cargados.
- *
- * @return string
- */
- protected function getUploadRootDir()
- {
- return __DIR__.'/../../../../web/'.$this->getUploadDir();
- }
- /**
- * Ruta dentro de la carpeta web donde se guardan los
- * archivos cargados.
- *
- * @return string
- */
- protected function getUploadDir()
- {
- return 'uploads/images/projects';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment