<?php
namespace CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use DateTime;
/**
* @ORM\Table("category")
* @ORM\Entity(repositoryClass="CoreBundle\Entity\CategoryRepository")
*/
class Category implements JsonSerializable
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, unique=true)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="display_name", type="string", length=255, nullable=true)
*/
private $displayName;
/**
* Type of a category;
* 0 - normal
* 1 - screening
*
* @var int
*
* @ORM\Column(name="type", type="integer", nullable=true, options={"default"=0})
*/
private $type = 0;
/**
* @var Topic[]
*
* @ORM\OneToMany(targetEntity="Topic", mappedBy="category", cascade={"persist"})
* @ORM\OrderBy({"sortOrder" = "ASC"})
*/
private $topics;
/**
* @var bool $enabled
*
* @ORM\Column(name="enabled", type="boolean", unique=false, options={"default" : true})
*/
private $enabled = true;
/**
* @var bool $show_in_self_study
*
* @ORM\Column(name="show_in_self_study", type="boolean", unique=false, options={"default" : true})
*/
private $showInSelfStudy = false;
/**
* @var bool $show_in_self_study
*
* @ORM\Column(name="show_in_main_system", type="boolean", unique=false, options={"default" : true})
*/
private $showInMainSystem = true;
/**
* @var bool $show_in_self_study
*
* @ORM\Column(name="show_only_to_demo_user", type="boolean", unique=false, options={"default" : false})
*/
private $showOnlyToDemoUser = false;
/**
* @var int
*
* @ORM\Column(name="sort_order", type="integer", nullable=true, options={"default"=0})
*/
private $sortOrder;
/**
* @var ?DateTime
*
* @ORM\Column(name="deleted_at", type="datetime", nullable=true)
*/
private ?DateTime $deletedAt;
public function __construct()
{
$this->topics = new ArrayCollection();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name.
*
* @param string $name
*
* @return Category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return Topic[]
*/
public function getTopics()
{
return $this->topics;
}
/**
* @return Topic[]
*/
public function getEnabledTopics()
{
return $this->topics->filter(function (Topic $topic) {
return $topic->isEnabled();
});
}
/**
* @param Topic $topic
*
* @return Category
*/
public function addTopic(Topic $topic)
{
$topic->setCategory($this);
$this->topics->add($topic);
return $this;
}
/**
* @param Topic $topic
*
* @return bool
*/
public function removeTopic(Topic $topic)
{
$topic->setCategory(null);
return $this->topics->removeElement($topic);
}
/**
* @return int
*/
public function getType()
{
return $this->type;
}
/**
* @param int $type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* @param bool $enabled
*/
public function setEnabled(bool $enabled): void
{
$this->enabled = $enabled;
}
/**
* @return int
*/
public function getSortOrder()
{
return $this->sortOrder;
}
/**
* @param int $sortOrder
*/
public function setSortOrder($sortOrder)
{
$this->sortOrder = $sortOrder;
}
public function getTopicNames()
{
$topic_obj_array = $this->getTopics()->toArray();
$topics = array_map(fn($e) => $e->getName(), $topic_obj_array);
return implode(', ', $topics);
}
public function isShownInMainSystem(): bool
{
return $this->showInMainSystem;
}
public function setShowInMainSystem(bool $showInMainSystem): void
{
$this->showInMainSystem = $showInMainSystem;
}
public function getDisplayName(): string
{
if ($this->displayName)
{
return $this->displayName;
}
return $this->name;
}
public function setDisplayName(?string $displayName): void
{
$this->displayName = $displayName;
}
/**
* @return DateTime|null
*/
public function getDeletedAt(): ?DateTime
{
return $this->deletedAt;
}
/**
* @param DateTime|null $deletedAt
* @return void
*/
public function setDeletedAt(?DateTime $deletedAt): void
{
$this->deletedAt = $deletedAt;
}
public function JsonSerialize(): mixed
{
return [
"id" => $this->getId(),
"name" => $this->getName(),
"type" => $this->getType(),
];
}
public function __toString(): string
{
return $this->getName();
}
}