Created
January 15, 2013 00:50
-
-
Save oopsFrogs/4534997 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace MyVendor\ImageBundle\Entity; | |
| use Doctrine\ORM\Mapping as ORM, | |
| Doctrine\Common\Collections\ArrayCollection, | |
| Symfony\Component\HttpFoundation\File\File, | |
| Symfony\Component\Validator\Constraints as Assert, | |
| Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity, | |
| Vich\UploaderBundle\Mapping\Annotation as Vich; | |
| /** | |
| * @ORM\Entity | |
| * @UniqueEntity("imageName") | |
| * @Vich\Uploadable | |
| * | |
| * @author travisyang | |
| */ | |
| class LogoImage extends Image | |
| { | |
| /** | |
| * @Assert\File( | |
| * maxSize="1M", | |
| * mimeTypes={"image/png", "image/jpeg", "image/pjpeg", "image/gif"} | |
| * ) | |
| * @Vich\UploadableField(mapping="oopsfrogs_logo", fileNameProperty="imageName") | |
| * | |
| * @var File $image | |
| */ | |
| protected $image; | |
| /** | |
| * @ORM\Column() | |
| * | |
| * @var string $imageName | |
| */ | |
| protected $imageName; | |
| /** | |
| * @Assert\NotBlank() | |
| * @Assert\MinLength( | |
| * limit=3, | |
| * message="Your name must have at least {{ limit }} characters." | |
| * ) | |
| * @var unknown_type | |
| */ | |
| protected $inputName; | |
| /** | |
| * @ORM\OneToMany(targetEntity="\MyVendor\BranchBundle\Entity\Branch", mappedBy="logoImage") | |
| * | |
| * @var ArrayCollection $branches | |
| */ | |
| protected $branches; | |
| /** | |
| * set image | |
| * | |
| * @param File $image | |
| */ | |
| public function setImage(File $image = null) | |
| { | |
| $this->image = $image; | |
| } | |
| /** | |
| * get image | |
| * | |
| * @return File | |
| */ | |
| public function getImage() | |
| { | |
| return $this->image; | |
| } | |
| /** | |
| * set imageName | |
| * | |
| * @param string $imageName | |
| */ | |
| public function setImageName($imageName) | |
| { | |
| $this->imageName = $imageName; | |
| } | |
| /** | |
| * get imageName | |
| * | |
| * @return string | |
| */ | |
| public function getImageName() | |
| { | |
| return $this->imageName; | |
| } | |
| /** | |
| * set inputName | |
| * | |
| * @param string $inputName | |
| */ | |
| public function setInputName($inputName) | |
| { | |
| $this->inputName = $inputName; | |
| } | |
| /** | |
| * get inputName | |
| * | |
| * @return string | |
| */ | |
| public function getInputName() | |
| { | |
| return $this->inputName; | |
| } | |
| public function addBranch(\MyVendor\BranchBundle\Entity\Branch $branch) | |
| { | |
| if (null !== $branch) { | |
| $this->branches[] = $branch; | |
| //$location->addLogo($this); | |
| } | |
| } | |
| public function removeBranch(\MyVendor\BranchBundle\Entity\Branch $branch) | |
| { | |
| if ($this->branches->contains($branch)) { | |
| $this->branches->removeElement($branch); | |
| } | |
| } | |
| public function getBranches() | |
| { | |
| return $this->branches; | |
| } | |
| public function __construct() | |
| { | |
| parent::__construct(); | |
| $this->branches = new ArrayCollection(); | |
| } | |
| public function getImagePath() | |
| { | |
| return 'uploads/images/logos/' . $this->imageName; // if permanent_image_logo_dir in parameters.ini is changed | |
| } // this should be changed too | |
| public function __toString() | |
| { | |
| return $this->imageName; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment