<?php
namespace App\Entity;
use App\Repository\ProductLangRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProductLangRepository::class)]
class ProductLang
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $sub_title = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $short_description = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $meta_title = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $meta_description = null;
#[ORM\ManyToOne(inversedBy: 'productLangs')]
private ?Lang $lang = null;
#[ORM\ManyToOne(inversedBy: 'productLangs')]
private ?Product $product = null;
#[ORM\Column]
private ?int $progression = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $regulations = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $advices = null;
public function __construct()
{
}
public function getId(): ?int
{
return $this->id;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
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 getMetaTitle(): ?string
{
return $this->meta_title;
}
public function setMetaTitle(string $meta_title): self
{
$this->meta_title = $meta_title;
return $this;
}
public function getMetaDescription(): ?string
{
return $this->meta_description;
}
public function setMetaDescription(string $meta_description): self
{
$this->meta_description = $meta_description;
return $this;
}
public function getLang(): ?Lang
{
return $this->lang;
}
public function setLang(?Lang $lang): self
{
$this->lang = $lang;
return $this;
}
public function getProgression(): ?int
{
return $this->progression;
}
public function setProgression(int $progression): self
{
$this->progression = $progression;
return $this;
}
public function getRegulations(): ?string
{
return $this->regulations;
}
public function setRegulations(?string $regulations): self
{
$this->regulations = $regulations;
return $this;
}
public function getAdvices(): ?string
{
return $this->advices;
}
public function setAdvices(?string $advices): self
{
$this->advices = $advices;
return $this;
}
public function calculateProgression(): int
{
$progression = 0;
$fields = [
[
'name' => 'name',
'completed' => false
],
[
'name' => 'description',
'completed' => false
],
[
'name' => 'regulations',
'completed' => false
],
[
'name' => 'advices',
'completed' => false
],
[
'name' => 'meta_title',
'completed' => false
],
[
'name' => 'meta_description',
'completed' => false
],
[
'name' => 'sub_title',
'completed' => false
],
[
'name' => 'short_description',
'completed' => false
],
];
foreach ($fields as $keyField => $field) {
$jsonField = json_decode($this->{$field['name']}, true);
if($jsonField == null && $this->{$field['name']} != ""){
$field['completed'] = true;
}
if($jsonField != null && $jsonField['blocks'] != null && count($jsonField['blocks']) > 0){
$field['completed'] = true;
}
if($field['completed'] == true){
$progression = $progression + 100/count($fields);
}
}
return round($progression);
}
public function getShortDescription(): ?string
{
return $this->short_description;
}
public function setShortDescription(?string $short_description): self
{
$this->short_description = $short_description;
return $this;
}
public function getSubTitle(): ?string
{
return $this->sub_title;
}
public function setSubTitle(?string $sub_title): self
{
$this->sub_title = $sub_title;
return $this;
}
}