Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Component\HttpFoundation\File\UploadedFile;
- /**
- * Picture
- *
- * @ORM\Table(name="picture")
- * @ORM\Entity(repositoryClass="AppBundle\Repository\PictureRepository")
- * @ORM\HasLifecycleCallbacks
- */
- class Picture
- {
- /**
- * @var int
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- * @Assert\File( maxSize = "1024k", mimeTypesMessage = "Please upload a valid Image")
- * @ORM\Column(name="image", type="string", length=255, nullable=true, unique=true)
- */
- private $image;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="stamp", type="datetime")
- */
- private $stamp;
- /**
- * @var int
- *
- * @ORM\Column(name="sort", type="integer")
- */
- private $sort;
- /**
- * @var Campground[]
- * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Campground", inversedBy="picture")
- */
- private $campgrounds;
- /**
- * Unmapped property to handle file uploads
- */
- private $file;
- /**
- * Get id
- *
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set image
- *
- * @param string $image
- *
- * @return Picture
- */
- public function setImage($image)
- {
- $this->image = $image;
- return $this;
- }
- /**
- * Get image
- *
- * @return string
- */
- public function getImage()
- {
- return $this->image;
- }
- /**
- * Set stamp
- *
- * @param \DateTime $stamp
- *
- * @return Picture
- */
- public function setStamp($stamp)
- {
- $this->stamp = $stamp;
- return $this;
- }
- /**
- * Get stamp
- *
- * @return \DateTime
- */
- public function getStamp()
- {
- return $this->stamp;
- }
- /**
- * Set sort
- *
- * @param integer $sort
- *
- * @return Picture
- */
- public function setSort($sort)
- {
- $this->sort = $sort;
- return $this;
- }
- /**
- * Get sort
- *
- * @return int
- */
- public function getSort()
- {
- return $this->sort;
- }
- /**
- * Set campground
- *
- * @param \AppBundle\Entity\Campground $campground
- *
- * @return Picture
- */
- public function setCampground(\AppBundle\Entity\Campground $campground = null)
- {
- $this->campground = $campground;
- return $this;
- }
- /**
- * Get campground
- *
- * @return \AppBundle\Entity\Campground
- */
- public function getCampground()
- {
- return $this->campground;
- }
- /**
- * Sets file.
- *
- * @param UploadedFile $file
- */
- public function setFile(UploadedFile $file = null)
- {
- $this->file = $file;
- }
- /**
- * Get file.
- *
- * @return UploadedFile
- */
- public function getFile()
- {
- return $this->file;
- }
- /**
- * Manages the copying of the file to the relevant place on the server
- */
- public function upload()
- {
- // the file property can be empty if the field is not required
- if (null === $this->getFile()) {
- return;
- }
- // we use the original file name here but you should
- // sanitize it at least to avoid any security issues
- // move takes the target directory and target filename as params
- $this->getFile()->move(
- SERVER_PATH_TO_IMAGE_FOLDER,
- $this->getFile()->getClientOriginalName()
- );
- // set the path property to the filename where you've saved the file
- $this->image = $this->getFile()->getClientOriginalName();
- // clean up the file property as you won't need it anymore
- $this->setFile(null);
- }
- /**
- * @ORM\PrePersist
- * @ORM\PreUpdate
- */
- public function lifecycleFileUpload() {
- $this->upload();
- }
- public function refreshUpdated() {
- $this->setStamp(new \DateTime("now"));
- }
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->stamp = new \DateTime();
- $this->sort = 0;
- $this->campgrounds = new \Doctrine\Common\Collections\ArrayCollection();
- }
- /**
- * Add campground
- *
- * @param \AppBundle\Entity\Campground $campground
- *
- * @return Picture
- */
- public function addCampground(\AppBundle\Entity\Campground $campground)
- {
- $this->campgrounds[] = $campground;
- return $this;
- }
- /**
- * Remove campground
- *
- * @param \AppBundle\Entity\Campground $campground
- */
- public function removeCampground(\AppBundle\Entity\Campground $campground)
- {
- $this->campgrounds->removeElement($campground);
- }
- /**
- * Get campgrounds
- *
- * @return \Doctrine\Common\Collections\Collection
- */
- public function getCampgrounds()
- {
- return $this->campgrounds;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement