<?php
namespace App\Entity\Core\Dictate;
use App\Entity\Core\Classroom\ClassroomType;
use App\Services\Core\ActivityTypeMappingService;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
#[ORM\Table('dictate')]
#[ORM\Entity(repositoryClass: DictateRepository::class)]
class Dictate implements JsonSerializable
{
private const int DEFAULT_DURATION = 15;
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
/**
* @var string
*/
#[ORM\Column(name: 'introduction', type: 'string', length: 255, nullable: true)]
private $introduction;
/**
* @var string
*/
#[ORM\Column(name: 'image', type: 'string', length: 128, nullable: true)]
private $image;
/**
* @var string
*/
#[ORM\Column(name: 'text', type: 'string', length: 4000, nullable: false)]
private $text;
/**
* @var string
*/
#[ORM\Column(name: 'sound_path', type: 'string', length: 128, nullable: true)]
private $soundPath;
/**
* @var int
*/
#[ORM\Column(name: 'level', type: 'integer', nullable: false)]
private $level;
/**
* @var ClassroomType
*/
#[ORM\JoinColumn(name: 'classroom_type', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: ClassroomType::class)]
private $classroomType;
/**
* @var array
*/
#[ORM\Column(name: 'color_wrong_count_threshold', type: 'simple_array', nullable: true)]
private $colorWrongCountThreshold;
/**
* @var bool
*/
#[ORM\Column(name: 'is_case_insensitive', type: 'boolean', options: ['default' => false])]
private $isCaseInsensitive = false;
public function getId(): int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getIntroduction(): string
{
return $this->introduction;
}
public function setIntroduction(string $introduction): void
{
$this->introduction = $introduction;
}
public function getImage(): string
{
return $this->image;
}
public function setImage(string $image): void
{
$this->image = $image;
}
public function getText(): string
{
return $this->text;
}
public function setText(string $text): void
{
$this->text = $text;
}
public function getSoundPath(): string
{
return $this->soundPath;
}
public function setSoundPath(string $soundPath): void
{
$this->soundPath = $soundPath;
}
/**
* @return int
*/
public function getLevel()
{
return $this->level;
}
public function setLevel(int $level): void
{
$this->level = $level;
}
/**
* @return ClassroomType
*/
public function getClassroomType()
{
return $this->classroomType;
}
public function setClassroomType(ClassroomType $classroomType): void
{
$this->classroomType = $classroomType;
}
public function getColorWrongCountThreshold(): ?array
{
return $this->colorWrongCountThreshold;
}
public function setColorWrongCountThreshold(?array $colorWrongCountThreshold): self
{
$this->colorWrongCountThreshold = $colorWrongCountThreshold;
return $this;
}
public function isCaseInsensitive(): bool
{
return $this->isCaseInsensitive;
}
public function setIsCaseInsensitive(bool $isCaseInsensitive): void
{
$this->isCaseInsensitive = $isCaseInsensitive;
}
public function toLightweightArray(ActivityTypeMappingService $activityTypeMappingService): array
{
return [
'id' => $this->getId(),
'type' => $activityTypeMappingService->getActivityTypeFromClass(Dictate::class),
'name' => $this->getIntroduction(),
'problemCount' => 1,
'classroomType' => $this->getClassroomType()?->getId(),
];
}
public function jsonSerialize(): array
{
return [
'id' => $this->getId(),
'introduction' => $this->getIntroduction(),
'level' => $this->getLevel(),
'problemCount' => 1,
'duration' => self::DEFAULT_DURATION, // Add this to have a fallback for screening upon request from Sofie, well knowing that the activity does not come with a duration as is. Perhaps it should be added at some point
'classroomType' => $this->getClassroomType()?->getId(),
];
}
}