<?php
// src/Acme/UserBundle/Entity/User.php
namespace App\Entity;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
/**
* @Doctrine\ORM\Mapping\Entity
* @Doctrine\ORM\Mapping\Table(name="product_photo")
* @Doctrine\ORM\Mapping\Entity()
*/
class ProductPhoto implements TranslatableInterface, BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use TranslatableTrait;
use SoftDeletableTrait;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="photos")
*/
private $product;
/**
* @Doctrine\ORM\Mapping\Column(type="boolean", nullable=true)
*/
protected $main = false;
/**
* @Doctrine\ORM\Mapping\Column(type="boolean", nullable=true)
*/
protected $lifestyle = false;
/**
* @Doctrine\ORM\Mapping\Column(type="boolean", nullable=true)
*/
protected $hover = false;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* To which locale photo is associated to
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Language")
*/
protected $languages;
/**
*
* note This is not a mapped field of entity metadata, just a simple property.
*
* @var File $imageFile
*/
protected $imageFile;
/**
* @ORM\Column(type="string", length=255, name="image_name", nullable=true)
* @var string $imageName
*/
protected $imageName;
/**
* @ORM\Column(type="integer", length=12, name="position", nullable=true)
* @var string $imageName
*/
protected $position;
/**
* @var string
*
* @ORM\Column(name="alt", type="string", length=255, nullable=true)
*/
private $alt;
/**
* @var string
*
* @ORM\Column(name="image_custom_name", type="string", length=255, nullable=true)
*/
private $imageCustomName;
/**
* @return string
*/
public function getPosition(): string
{
return $this->position;
}
/**
* @param string $position
*/
public function setPosition(string $position): void
{
$this->position = $position;
}
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
try {
if ($this->getImageCustomName()) {
$fileName = $this->getImageCustomName();
} else {
$fileName = md5(uniqid()).'.'.$image->guessExtension();
}
// Move the file to the directory where brochures are stored
$brochuresDir = getcwd().'/images/product/';
$image->move($brochuresDir, $fileName);
// Update the 'brochure' property to store the PDF file name
// instead of its contents
$this->setImageName($fileName);
$this->updatedAt = new \DateTime('now');
} catch (\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException $e) {
}
}
return $this;
}
/**
* @return File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param string $imageName
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
}
/**
* @return string
*/
public function getImageName()
{
return $this->imageName;
}
/**
* Constructor
*/
public function __construct()
{
$this->languages = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set main
*
* @param boolean $main
*
* @return ProductPhoto
*/
public function setMain($main)
{
$this->main = $main;
return $this;
}
/**
* Get main
*
* @return boolean
*/
public function getMain()
{
return $this->main;
}
/**
* Set name
*
* @param string $name
*
* @return ProductPhoto
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set product
*
* @param \App\Entity\Product $product
*
* @return ProductPhoto
*/
public function setProduct(\App\Entity\Product $product = null)
{
$this->product = $product;
return $this;
}
/**
* Get product
*
* @return \App\Entity\Product
*/
public function getProduct()
{
return $this->product;
}
/**
* Add language
*
* @param \App\Entity\Language $language
*
* @return ProductPhoto
*/
public function addLanguage(\App\Entity\Language $language)
{
$this->languages[] = $language;
return $this;
}
/**
* Remove language
*
* @param \App\Entity\Language $language
*/
public function removeLanguage(\App\Entity\Language $language)
{
$this->languages->removeElement($language);
}
/**
* Get languages
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getLanguages()
{
return $this->languages;
}
/**
* Set hover
*
* @param boolean $hover
*
* @return ProductPhoto
*/
public function setHover($hover)
{
$this->hover = $hover;
return $this;
}
/**
* Get hover
*
* @return boolean
*/
public function getHover()
{
return $this->hover;
}
/**
* Obsługa tłumaczeń
* @param $method
* @param $arguments
* @return mixed
*/
public function __call($method, $arguments)
{
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
public function getDescription(){
return $this->translate()->getDescription();
}
public function getTranslatedDescription($locale) {
if ($this->translate($locale, false)->getDescription()) {
return $this->translate($locale, false)->getDescription();
} else {
return '';
}
}
/**
* @return string
*/
public function getAlt()
{
return $this->alt;
}
/**
* @param string $alt
*/
public function setAlt($alt)
{
$this->alt = $alt;
}
/**
* @return string
*/
public function getImageCustomName()
{
return $this->imageCustomName;
}
/**
* @param string $imageCustomName
*/
public function setImageCustomName($imageCustomName)
{
$this->imageCustomName = $imageCustomName;
}
public function getIsAvailableForLang(Language $language) {
if ($this->getLanguages()->contains($language)) {
return true;
}
return false;
}
/**
* @return bool
*/
public function isLifestyle()
{
return $this->lifestyle;
}
/**
* @param bool $lifestyle
*/
public function setLifestyle(bool $lifestyle)
{
$this->lifestyle = $lifestyle;
}
public function getLifestyle(): ?bool
{
return $this->lifestyle;
}
}