<?php
/*
*
* (c) Loïc Haas <loic.haas@outlook.com>
* http://www.haas-info.com/
*
*/
namespace App\Framework\ShopBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Framework\ShopBundle\Repository\ProductRepository")
* @ORM\Table(name="framework_shop_product")
* @ORM\HasLifecycleCallbacks()
*
*/
class Product
{
/**
* @var int
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="\App\Framework\ShopBundle\Entity\Category", fetch="EAGER")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=true)
**/
private $category;
/**
* @ORM\Column(type="integer", length=11, nullable=true)
*/
protected $position;
/**
* @var string
*
* @ORM\Column(type="string")
*/
private $slug;
/**
* @var string
*
* @ORM\Column(type="string")
*/
private $type;
/**
* @var string
*
* @ORM\Column(type="string")
*/
private $tags;
/**
* @var array
*
* @ORM\Column(type="json")
*/
private $name = [];
/**
* @var array
*
* @ORM\Column(type="json")
*/
private $usecase = [];
/**
* @var array
*
* @ORM\Column(type="json")
*/
private $description = [];
/**
* @var array
*
* @ORM\Column(type="json")
*/
private $additional = [];
/**
* @var array
*
* @ORM\Column(type="json")
*/
private $attributes = [];
/**
* @ORM\Column(type="float", nullable=true)
*/
protected $price;
/**
* @ORM\Column(type="float", nullable=true)
*/
protected $amountShow;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
protected $published;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
protected $pinned;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
protected $slider;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
protected $featured;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $stock;
/**
* @ORM\Column(type="integer", length=11, nullable=true)
*/
protected $stockTotal;
/**
* @ORM\Column(type="integer", length=11, nullable=true)
*/
protected $stockLeft;
/**
* @ORM\Column(type="float", nullable=true)
*/
protected $weight;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $packaging;
/**
* @var \DateTime $created
*
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
protected $createdAt;
/**
* @var \DateTime $updated
*
* @ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
protected $updatedAt;
/**
* @var string
*
* @ORM\Column(name="dataform", type="json", nullable=true)
*/
private $dataform;
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updatedTimestamps(): void
{
$dateTimeNow = new \DateTime('now');
$this->setUpdatedAt($dateTimeNow);
if ($this->getCreatedAt() === null) {
$this->setCreatedAt($dateTimeNow);
}
}
public function getCreatedAt() :?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt() :?\DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* Set category
*
* @param \AppBundle\Entity\Category $category
*
* @return Category
*/
public function setCategory(\App\Framework\ShopBundle\Entity\Category $category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* @return \App\Framework\ShopBundle\Entity\Category
*/
public function getCategory()
{
return $this->category;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): void
{
$this->slug = $slug;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): void
{
$this->type = $type;
}
public function getTags(): ?string
{
return $this->tags;
}
public function setTags(string $tags): void
{
$this->tags = $tags;
}
public function getName(): array
{
return $this->name;
}
public function getNameJson()
{
return json_encode($this->name);
}
public function getNameLocale($locale)
{
if( isset($this->name[$locale]) ){
return $this->name[$locale];
} else {
return '';
}
}
public function setName(array $name): void
{
$this->name = $name;
}
public function getDescription(): array
{
return $this->description;
}
public function getDescriptionLocale($locale)
{
if( isset($this->description[$locale]) ){
return $this->description[$locale];
} else {
return '';
}
}
public function setDescription(array $description): void
{
$this->description = $description;
}
public function getUsecase(): array
{
return $this->usecase;
}
public function getUsecaseLocale($locale)
{
if( isset($this->usecase[$locale]) ){
return $this->usecase[$locale];
} else {
return '';
}
}
public function setUsecase(array $usecase): void
{
$this->usecase = $usecase;
}
public function getAdditional(): array
{
return $this->additional;
}
public function getAdditionalLocale($locale)
{
if( isset($this->additional[$locale]) ){
return $this->additional[$locale];
} else {
return '';
}
}
public function setAdditional(array $additional): void
{
$this->additional = $additional;
}
public function getAttributes(): array
{
return $this->attributes;
}
public function setAttributes(array $attributes): void
{
$this->attributes = $attributes;
}
/**
* Set price
*
* @param float $price
* @return Reward
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return float
*/
public function getPrice()
{
return $this->price;
}
/**
* Set amountShow
*
* @param float $amountShow
* @return Reward
*/
public function setAmountShow($amountShow)
{
$this->amountShow = $amountShow;
return $this;
}
/**
* Get amountShow
*
* @return float
*/
public function getAmountShow()
{
return $this->amountShow;
}
/**
* Get price
*
* @return float
*/
public function getPriceFr()
{
setlocale(LC_MONETARY, 'fr_FR');
return money_format('%!i', $this->price);
}
/**
* Set published
*
* @param boolean $published
* @return AppPost
*/
public function setPublished($published)
{
$this->published = $published;
return $this;
}
/**
* Get published
*
* @return boolean
*/
public function getPublished()
{
return $this->published;
}
/**
* Set slider
*
* @param boolean $slider
* @return AppPost
*/
public function setSlider($slider)
{
$this->slider = $slider;
return $this;
}
/**
* Get slider
*
* @return boolean
*/
public function getSlider()
{
return $this->slider;
}
/**
* Set pinned
*
* @param boolean $pinned
* @return AppPost
*/
public function setPinned($pinned)
{
$this->pinned = $pinned;
return $this;
}
/**
* Get pinned
*
* @return boolean
*/
public function getPinned()
{
return $this->pinned;
}
/**
* Set featured
*
* @param boolean $featured
* @return AppPost
*/
public function setFeatured($featured)
{
$this->featured = $featured;
return $this;
}
/**
* Get featured
*
* @return boolean
*/
public function getFeatured()
{
return $this->featured;
}
/**
* Set weight
*
* @param float $weight
* @return Reward
*/
public function setWeight($weight)
{
$this->weight = $weight;
return $this;
}
/**
* Get weight
*
* @return float
*/
public function getWeight()
{
return $this->weight;
}
/**
* Set stock
*
* @param integer $stock
*
* @return Reward
*/
public function setStock($stock)
{
$this->stock = $stock;
return $this;
}
/**
* Get stock
*
* @return integer
*/
public function getStock()
{
return $this->stock;
}
/**
* Set stockTotal
*
* @param integer $stockTotal
*
* @return Reward
*/
public function setStockTotal($stockTotal)
{
$this->stockTotal = $stockTotal;
return $this;
}
/**
* Get stockTotal
*
* @return integer
*/
public function getStockTotal()
{
return $this->stockTotal;
}
/**
* Set stockLeft
*
* @param integer $stockLeft
*
* @return Reward
*/
public function setStockLeft($stockLeft)
{
$this->stockLeft = $stockLeft;
return $this;
}
/**
* Get stockLeft
*
* @return integer
*/
public function getStockLeft()
{
return $this->stockLeft;
}
public function setPackaging($packaging)
{
$this->packaging = $packaging;
return $this;
}
public function getPackaging()
{
return $this->packaging;
}
/**
* Set dataform
*
* @param string $dataform
*
* @return Exp
*/
public function setDataform($dataform)
{
$this->dataform = json_encode($dataform);
return $this;
}
/**
* Get dataform
*
* @return string
*/
public function getDataform()
{
return json_decode($this->dataform, true);
}
/**
* Get dataform
*
* @return string
*/
public function getInfo($index)
{
$dataform = json_decode($this->dataform, true);
$str = '';
if(substr($index, 0, 5) == 'image'){
if(isset($dataform['images'][$index])){
$str = $dataform['images'][$index];
}
}
if(isset($dataform[$index])){
$str = $dataform[$index];
}
$str = str_replace('\n', '<br>', $str);
return $str;
}
/**
* Get dataform
*
* @return string
*/
public function getDataformJson()
{
$json = $this->dataform;
// $json = str_replace('\n', '\\\n', $json);
$json = addslashes($json);
// $json = str_replace('\'', '\\\'', $json);
// $json = str_replace('\'', '\\\'', $json);
return $json;
}
/**
* Get dataform
*
* @return string
*/
public function getMainImage()
{
$dataform = json_decode($this->dataform, true);
$images = '';
if(isset($dataform['images'])){
foreach ($dataform['images'] as $key => $value) {
if( substr($value, 0, 10) == 'image_main' ){
$images = $value;
}
}
}
return $images;
}
/**
* Get dataform
*
* @return string
*/
public function getAllImages()
{
$dataform = json_decode($this->dataform, true);
$images = [];
if(isset($dataform['images'])){
foreach ($dataform['images'] as $key => $value) {
// if( substr($value, 0, 10) == 'image_add_' ){
$images[] = $value;
// }
}
}
return $images;
}
public function getDateStr($locale)
{
$date = strtotime($this->getCreatedAt()->format('d-m-Y'));
switch ($locale) {
case 'en':
setlocale(LC_TIME, 'en_US');
date_default_timezone_set('Europe/Paris');
break;
case 'de':
setlocale(LC_TIME, 'de_DE');
date_default_timezone_set('Europe/Paris');
break;
default:
setlocale(LC_TIME, 'fr_FR');
date_default_timezone_set('Europe/Paris');
break;
}
$date_str = ucwords(utf8_encode(strftime('%d %B %Y', $date)));
return $date_str.'.';
}
}