<?php
namespace App\Entity\Core\SelfStudy;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
#[ORM\Table('self_study_category')]
#[ORM\Entity]
class SelfStudyCategory implements JsonSerializable
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
/**
* @var string
*/
#[ORM\Column(name: 'display_name', type: 'string', length: 255)]
private $displayName;
/**
* @var string
*/
#[ORM\Column(name: 'icon', type: 'string', length: 255, nullable: true)]
private $icon;
/**
* @var string
*/
#[ORM\Column(name: 'image', type: 'string', length: 255, nullable: true)]
private $image;
/**
* @var string
*/
#[ORM\Column(name: 'teaser', type: 'string', length: 1000, nullable: true)]
private $teaser;
/**
* @var int
*/
#[ORM\Column(name: 'sort_order', type: 'integer', nullable: true, options: ['default' => 0])]
private $sortOrder;
/**
* @var SelfStudy
*/
#[ORM\JoinColumn(name: 'self_study', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: SelfStudy::class, inversedBy: 'selfStudyCategories')]
private $selfStudy;
/**
* @var SelfStudyTopic[]
*/
#[ORM\OneToMany(targetEntity: SelfStudyTopic::class, mappedBy: 'selfStudyCategory', cascade: ['persist'])]
private $selfStudyTopics;
public function __construct()
{
$this->selfStudyTopics = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function getDisplayName(): string
{
return $this->displayName;
}
public function getSelfStudy(): SelfStudy
{
return $this->selfStudy;
}
public function getIcon(): string
{
return $this->icon;
}
public function getImage(): string
{
return $this->image;
}
public function getTeaser(): ?string
{
return $this->teaser;
}
public function getSelfStudyTopics(): Collection
{
return $this->selfStudyTopics;
}
public function getSortOrder(): int
{
return $this->sortOrder;
}
public function jsonSerialize(): mixed
{
return [
"id" => $this->getId(),
"name" => $this->getDisplayName(),
"icon" => $this->getIcon(),
"topics" => array_map(function ($topic) {
return $topic->jsonSerialize();
}, $this->getSelfStudyTopics()->toArray()),
];
}
}