src/Entity/ProductLang.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductLangRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassProductLangRepository::class)]
  9. class ProductLang
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255nullabletrue)]
  16.     private ?string $name null;
  17.     #[ORM\Column(length255nullabletrue)]
  18.     private ?string $sub_title null;
  19.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  20.     private ?string $description null;
  21.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  22.     private ?string $short_description null;
  23.     #[ORM\Column(length255nullabletrue)]
  24.     private ?string $meta_title null;
  25.     #[ORM\Column(length255nullabletrue)]
  26.     private ?string $meta_description null;
  27.     #[ORM\ManyToOne(inversedBy'productLangs')]
  28.     private ?Lang $lang null;
  29.     #[ORM\ManyToOne(inversedBy'productLangs')]
  30.     private ?Product $product null;
  31.     #[ORM\Column]
  32.     private ?int $progression null;
  33.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  34.     private ?string $regulations null;
  35.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  36.     private ?string $advices null;
  37.     public function __construct()
  38.     {
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getProduct(): ?Product
  45.     {
  46.         return $this->product;
  47.     }
  48.     public function setProduct(?Product $product): self
  49.     {
  50.         $this->product $product;
  51.         return $this;
  52.     }
  53.     public function getName(): ?string
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function setName(string $name): self
  58.     {
  59.         $this->name $name;
  60.         return $this;
  61.     }
  62.     public function getDescription(): ?string
  63.     {
  64.         return $this->description;
  65.     }
  66.     public function setDescription(string $description): self
  67.     {
  68.         $this->description $description;
  69.         return $this;
  70.     }
  71.     public function getMetaTitle(): ?string
  72.     {
  73.         return $this->meta_title;
  74.     }
  75.     public function setMetaTitle(string $meta_title): self
  76.     {
  77.         $this->meta_title $meta_title;
  78.         return $this;
  79.     }
  80.     public function getMetaDescription(): ?string
  81.     {
  82.         return $this->meta_description;
  83.     }
  84.     public function setMetaDescription(string $meta_description): self
  85.     {
  86.         $this->meta_description $meta_description;
  87.         return $this;
  88.     }
  89.     public function getLang(): ?Lang
  90.     {
  91.         return $this->lang;
  92.     }
  93.     public function setLang(?Lang $lang): self
  94.     {
  95.         $this->lang $lang;
  96.         return $this;
  97.     }
  98.     public function getProgression(): ?int
  99.     {
  100.         return $this->progression;
  101.     }
  102.     public function setProgression(int $progression): self
  103.     {
  104.         $this->progression $progression;
  105.         return $this;
  106.     }
  107.     public function getRegulations(): ?string
  108.     {
  109.         return $this->regulations;
  110.     }
  111.     public function setRegulations(?string $regulations): self
  112.     {
  113.         $this->regulations $regulations;
  114.         return $this;
  115.     }
  116.     public function getAdvices(): ?string
  117.     {
  118.         return $this->advices;
  119.     }
  120.     public function setAdvices(?string $advices): self
  121.     {
  122.         $this->advices $advices;
  123.         return $this;
  124.     }
  125.     public function calculateProgression(): int
  126.     {
  127.         $progression 0;
  128.         $fields = [
  129.             [
  130.                 'name' => 'name',
  131.                 'completed' => false
  132.             
  133.             ],
  134.             [
  135.                 'name' => 'description',
  136.                 'completed' => false
  137.             
  138.             ],
  139.             [
  140.                 'name' => 'regulations',
  141.                 'completed' => false
  142.             ],
  143.             [
  144.                 'name' => 'advices',
  145.                 'completed' => false
  146.             ],
  147.             
  148.             [
  149.                 'name' => 'meta_title',
  150.                 'completed' => false
  151.             
  152.             ],
  153.             [
  154.                 'name' => 'meta_description',
  155.                 'completed' => false
  156.             
  157.             ],
  158.             [
  159.                 'name' => 'sub_title',
  160.                 'completed' => false
  161.             
  162.             ],
  163.             [
  164.                 'name' => 'short_description',
  165.                 'completed' => false
  166.             
  167.             ],
  168.         ];
  169.         foreach ($fields as $keyField => $field) {
  170.             $jsonField json_decode($this->{$field['name']}, true);
  171.             if($jsonField == null && $this->{$field['name']} != ""){
  172.                 $field['completed'] = true;
  173.             }
  174.             if($jsonField != null && $jsonField['blocks'] != null && count($jsonField['blocks']) > 0){
  175.                 $field['completed'] = true;
  176.             }
  177.             if($field['completed'] == true){
  178.                 $progression $progression 100/count($fields);
  179.             }
  180.             
  181.         }
  182.         return round($progression);
  183.     }
  184.     public function getShortDescription(): ?string
  185.     {
  186.         return $this->short_description;
  187.     }
  188.     public function setShortDescription(?string $short_description): self
  189.     {
  190.         $this->short_description $short_description;
  191.         return $this;
  192.     }
  193.     public function getSubTitle(): ?string
  194.     {
  195.         return $this->sub_title;
  196.     }
  197.     public function setSubTitle(?string $sub_title): self
  198.     {
  199.         $this->sub_title $sub_title;
  200.         return $this;
  201.     }
  202. }