<?php
namespace App\Entity;
use App\Repository\CustomerProductRepository;
use App\Traits\DateTrait;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=CustomerProductRepository::class)
* @ORM\HasLifecycleCallbacks()
*
* @Vich\Uploadable
* @Serializer\ExclusionPolicy("ALL")
*/
class CustomerProduct
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Expose()
* @Groups({"id"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Expose()
* @Groups({"name"})
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Expose()
* @Serializer\Groups({"image"})
*/
private $image;
// Vich Uploader
/**
* @Vich\UploadableField(mapping="customer_product_images", fileNameProperty="image")
* @var File
*/
private $imageFile;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $price;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $categoryValues;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*
* @Expose()
* @Serializer\Groups({"category"})
*/
private $category;
/**
* @ORM\Column(type="boolean")
*
* @Expose()
* @Serializer\Groups({"enabled"})
*/
private $enabled;
use DateTrait;
/**
* @Serializer\VirtualProperty()
* @Serializer\SerializedName("array_category_values")
*
* @Expose()
* @Groups({"array_category_values"})
* @return mixed
*/
public function getArrayCategoryValues()
{
return json_decode($this->categoryValues, TRUE) ?? [];
}
/**
* @param string $slug
* @param int $value
* @return $this
*/
public function modifyValueToCategory(string $slug, int $value): self
{
$newArray = $this->getArrayCategoryValues();
$newArray[$slug] = $value;
$this->categoryValues = json_encode($newArray);
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param File|UploadedFile|null $imageFile
*/
public function setImageFile( File $imageFile ): void
{
$this->imageFile = $imageFile;
if ( NULL !== $imageFile ) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTime();
}
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(?float $price): self
{
$this->price = $price;
return $this;
}
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(?string $category): self
{
$this->category = $category;
return $this;
}
public function getCategoryValues()
{
return $this->categoryValues;
}
public function setCategoryValues($categoryValues)
{
$this->categoryValues = $categoryValues;
return $this;
}
/**
* @return mixed
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* @param mixed $enabled
* @return CustomerProduct
*/
public function setEnabled($enabled)
{
$this->enabled = $enabled;
return $this;
}
}