src/Entity/ServiceSection.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Model\BitrixSerializeList;
  4. use App\Repository\ServiceSectionRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JMS\Serializer\Annotation as JMS;
  9. use App\Entity\ServiceForm;
  10. /**
  11.  * @ORM\Entity(repositoryClass=ServiceSectionRepository::class)
  12.  */
  13. class ServiceSection implements \JsonSerializableBitrixSerializeList
  14. {
  15.     public const LABELS = [
  16.         'Онлайн оценка движимого имущества'   => 'Движимое имущество',
  17.         'Онлайн оценка недвижимого имущества' => 'Недвижимое имущество',
  18.         'Оценка Активов и аренды'             => 'Активы и аренда',
  19.     ];
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue
  23.      * @ORM\Column(type="integer")
  24.      *
  25.      * @JMS\Type("integer")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      *
  31.      * @JMS\Type("string")
  32.      */
  33.     private $name;
  34.     /**
  35.      * Для вывода названия в шаблоне
  36.      * @ORM\Column(type="string", length=255, nullable=false)
  37.      */
  38.     private string $label '';
  39.     /**
  40.      * @ORM\Column(type="integer")
  41.      *
  42.      * @JMS\Type("string")
  43.      */
  44.     private $sortNumber;
  45.     /**
  46.      * @ORM\OneToMany(targetEntity=ServiceForm::class, mappedBy="serviceSection")
  47.      *
  48.      * @JMS\Type("Relation<App\Entity\ServiceForm>")
  49.      */
  50.     private $serviceForms;
  51.     /**
  52.      * @ORM\ManyToOne(targetEntity=ServiceSectionGroup::class, inversedBy="sections")
  53.      */
  54.     private $serviceSectionGroup;
  55.     /**
  56.      * @ORM\Column(type="boolean", nullable=true)
  57.      */
  58.     private ?bool $isEnabled true;
  59.     public function __construct()
  60.     {
  61.         $this->serviceForms = new ArrayCollection();
  62.     }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     public function getName(): ?string
  68.     {
  69.         return $this->name;
  70.     }
  71.     public function setName(string $name): self
  72.     {
  73.         $this->name $name;
  74.         return $this;
  75.     }
  76.     public function getLabel(): string
  77.     {
  78.         return $this->label;
  79.     }
  80.     public function setLabel(string $label): self
  81.     {
  82.         $this->label $label;
  83.         return $this;
  84.     }
  85.     public function getSortNumber(): ?int
  86.     {
  87.         return $this->sortNumber;
  88.     }
  89.     public function setSortNumber(int $sortNumber): self
  90.     {
  91.         $this->sortNumber $sortNumber;
  92.         return $this;
  93.     }
  94.     /**
  95.      * @return Collection|ServiceForm[]
  96.      */
  97.     public function getServiceForms(): Collection
  98.     {
  99.         return $this->serviceForms;
  100.     }
  101.     public function addServiceForm(ServiceForm $serviceForm): self
  102.     {
  103.         if (!$this->serviceForms->contains($serviceForm)) {
  104.             $this->serviceForms[] = $serviceForm;
  105.             $serviceForm->setServiceSection($this);
  106.         }
  107.         return $this;
  108.     }
  109.     public function removeServiceForm(ServiceForm $serviceForm): self
  110.     {
  111.         if ($this->serviceForms->contains($serviceForm)) {
  112.             $this->serviceForms->removeElement($serviceForm);
  113.             // set the owning side to null (unless already changed)
  114.             if ($serviceForm->getServiceSection() === $this) {
  115.                 $serviceForm->setServiceSection(null);
  116.             }
  117.         }
  118.         return $this;
  119.     }
  120.     public function isEnabled(): bool
  121.     {
  122.         return (bool)$this->isEnabled;
  123.     }
  124.     public function setIsEnabled(bool $isEnabled): self
  125.     {
  126.         $this->isEnabled $isEnabled;
  127.         return $this;
  128.     }
  129.     public function jsonSerialize(): array
  130.     {
  131.         return [
  132.             'id'           => $this->getId(),
  133.             'name'         => $this->getName(),
  134.             'sortNumber'   => $this->getSortNumber(),
  135.             'serviceForms' => array_map(static function (ServiceForm $form): array {
  136.                 return $form->jsonSerialize();
  137.             }, $this->getServiceForms()->toArray()),
  138.             'isEnabled'    => $this->isEnabled(),
  139.         ];
  140.     }
  141.     public function jsonSerializeWithoutForms(): array
  142.     {
  143.         return [
  144.             'id'         => $this->getId(),
  145.             'name'       => $this->getName(),
  146.             'sortNumber' => $this->getSortNumber(),
  147.         ];
  148.     }
  149.     public function getServiceSectionGroup(): ?ServiceSectionGroup
  150.     {
  151.         return $this->serviceSectionGroup;
  152.     }
  153.     public function setServiceSectionGroup(?ServiceSectionGroup $serviceSectionGroup): self
  154.     {
  155.         $this->serviceSectionGroup $serviceSectionGroup;
  156.         return $this;
  157.     }
  158.     public function getIBlockId(): int
  159.     {
  160.         return 36;
  161.     }
  162.     public function getElementCode(): string
  163.     {
  164.         return 'service_section_' $this->getId();
  165.     }
  166. }