<?php
namespace App\Entity;
use App\Repository\SelectionPartRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Serializer\Annotation\SerializedName;
use App\Annotation\DashboardAnnotation as Dashboard;
/**
* @ORM\Entity(repositoryClass=SelectionPartRepository::class)
* @Dashboard(generation=true, name="Данные подбора запчастей")
*/
class SelectionPart
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"collection"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Modification::class, inversedBy="selectionParts")
* @Serializer\Groups({"collection"})
*/
private $modification;
/**
* @ORM\ManyToOne(targetEntity=ProductOem::class, inversedBy="selectionParts")
* @Serializer\Groups({"collection"})
*/
private $productOem;
public function getId(): ?int
{
return $this->id;
}
public function getModification(): ?Modification
{
return $this->modification;
}
public function setModification(?Modification $modification): self
{
$this->modification = $modification;
return $this;
}
public function getProductOem(): ?ProductOem
{
return $this->productOem;
}
public function setProductOem(?ProductOem $productOem): self
{
$this->productOem = $productOem;
return $this;
}
/**
* @Serializer\Groups({"selection/applicable"})
* @SerializedName("title")
*/
public function getApplicableTitle(): string
{
$title = '';
if ($modification = $this->getModification()) {
$title = $modification->getModel()->getMark()->getTitle() . ' ' . $modification->getModel()->getTitle() . ' [' . $modification->getParams() .']';
}
return $title;
}
/**
* @Serializer\Groups({"selection/applicable"})
*/
public function getRef(): array
{
if ($modification = $this->getModification()) {
return [
//'modification' => $modification->getId(),
'mark' => $modification->getModel()->getMark()->getId(),
'model' => $modification->getModel()->getId(),
'body' => $modification->getBody(),
'years' => ($modification->getYearFrom() ?? '') . '|' . ($modification->getYearTo() ?? '')
];
}
return [];
}
}