<?php
namespace App\Entity;
use App\Model\BitrixSerializeList;
use App\Repository\ServiceSectionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
use App\Entity\ServiceForm;
/**
* @ORM\Entity(repositoryClass=ServiceSectionRepository::class)
*/
class ServiceSection implements \JsonSerializable, BitrixSerializeList
{
public const LABELS = [
'Онлайн оценка движимого имущества' => 'Движимое имущество',
'Онлайн оценка недвижимого имущества' => 'Недвижимое имущество',
'Оценка Активов и аренды' => 'Активы и аренда',
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @JMS\Type("integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
* @JMS\Type("string")
*/
private $name;
/**
* Для вывода названия в шаблоне
* @ORM\Column(type="string", length=255, nullable=false)
*/
private string $label = '';
/**
* @ORM\Column(type="integer")
*
* @JMS\Type("string")
*/
private $sortNumber;
/**
* @ORM\OneToMany(targetEntity=ServiceForm::class, mappedBy="serviceSection")
*
* @JMS\Type("Relation<App\Entity\ServiceForm>")
*/
private $serviceForms;
/**
* @ORM\ManyToOne(targetEntity=ServiceSectionGroup::class, inversedBy="sections")
*/
private $serviceSectionGroup;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $isEnabled = true;
public function __construct()
{
$this->serviceForms = new ArrayCollection();
}
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 getLabel(): string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getSortNumber(): ?int
{
return $this->sortNumber;
}
public function setSortNumber(int $sortNumber): self
{
$this->sortNumber = $sortNumber;
return $this;
}
/**
* @return Collection|ServiceForm[]
*/
public function getServiceForms(): Collection
{
return $this->serviceForms;
}
public function addServiceForm(ServiceForm $serviceForm): self
{
if (!$this->serviceForms->contains($serviceForm)) {
$this->serviceForms[] = $serviceForm;
$serviceForm->setServiceSection($this);
}
return $this;
}
public function removeServiceForm(ServiceForm $serviceForm): self
{
if ($this->serviceForms->contains($serviceForm)) {
$this->serviceForms->removeElement($serviceForm);
// set the owning side to null (unless already changed)
if ($serviceForm->getServiceSection() === $this) {
$serviceForm->setServiceSection(null);
}
}
return $this;
}
public function isEnabled(): bool
{
return (bool)$this->isEnabled;
}
public function setIsEnabled(bool $isEnabled): self
{
$this->isEnabled = $isEnabled;
return $this;
}
public function jsonSerialize(): array
{
return [
'id' => $this->getId(),
'name' => $this->getName(),
'sortNumber' => $this->getSortNumber(),
'serviceForms' => array_map(static function (ServiceForm $form): array {
return $form->jsonSerialize();
}, $this->getServiceForms()->toArray()),
'isEnabled' => $this->isEnabled(),
];
}
public function jsonSerializeWithoutForms(): array
{
return [
'id' => $this->getId(),
'name' => $this->getName(),
'sortNumber' => $this->getSortNumber(),
];
}
public function getServiceSectionGroup(): ?ServiceSectionGroup
{
return $this->serviceSectionGroup;
}
public function setServiceSectionGroup(?ServiceSectionGroup $serviceSectionGroup): self
{
$this->serviceSectionGroup = $serviceSectionGroup;
return $this;
}
public function getIBlockId(): int
{
return 36;
}
public function getElementCode(): string
{
return 'service_section_' . $this->getId();
}
}