<?php
namespace App\Entity\Core\Worksheet;
use App\Entity\Core\Classroom\ClassroomType;
use App\Entity\Core\Mathproblem;
use App\Entity\User\User;
use DateTimeImmutable;
use DateTimeZone;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table('worksheet')]
#[ORM\Entity(repositoryClass: WorksheetRepository::class)]
class Worksheet
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
/**
* @var int
*/
#[ORM\Column(type: 'integer', nullable: false, options: ['default' => 0])]
private $duration;
/**
* @var string
*/
#[ORM\Column(name: 'name', type: 'string', length: 255, nullable: true)]
private $name;
/**
* @var Collection
*/
#[ORM\JoinTable(name: 'worksheet_problem')]
#[ORM\JoinColumn(name: 'worksheet_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'mathproblem_id', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: Mathproblem::class)]
private $problems;
/**
* @var array
*/
#[ORM\Column(name: 'problem_order', type: 'simple_array', nullable: true)]
private $problemOrder;
/**
* @var bool
*/
#[ORM\Column(name: 'reusable', type: 'boolean', nullable: false)]
private $reusable;
/**
* @var bool
*/
#[ORM\Column(name: 'abacus', type: 'boolean', nullable: true, options: ['default' => 0])]
private $abacus;
/**
* @var DateTimeImmutable
*/
#[ORM\Column(name: 'created_at', type: 'datetime_immutable', nullable: false)]
private $createdAt;
/**
* @var User
*/
#[ORM\JoinColumn(name: 'created_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: User::class)]
private $createdBy;
/**
* @var User[]
*/
#[ORM\JoinTable(name: 'worksheet_teacher')]
#[ORM\JoinColumn(name: 'worksheet_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'teacher_id', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: User::class)]
private $teachers;
/**
* @var WorksheetSession[]
*/
#[ORM\OneToMany(targetEntity: WorksheetSession::class, mappedBy: 'worksheet', cascade: ['persist'])]
private $worksheetSessions;
/**
* @var ClassroomType
*/
#[ORM\JoinColumn(name: 'level', referencedColumnName: 'id', nullable: true)]
#[ORM\ManyToOne(targetEntity: ClassroomType::class)]
private $level;
/**
* @var array
*/
#[ORM\Column(name: 'mathproblems_for_templates', type: 'simple_array', nullable: true)]
private $mathproblemsForTemplates;
public function __construct()
{
$this->problems = new ArrayCollection();
$this->teachers = new ArrayCollection();
$this->worksheetSessions = new ArrayCollection();
$this->createdAt = new DateTimeImmutable('now', new DateTimeZone('Europe/Copenhagen'));
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Set duration.
*
* @param int $duration
*
* @return $this
*/
public function setDuration($duration)
{
$this->duration = $duration;
return $this;
}
/**
* Get duration.
*
* @return int
*/
public function getDuration()
{
return $this->duration;
}
public function getProblems()
{
return $this->problems;
}
public function getSortedProblems($problemOrder = -1)
{
if ($problemOrder == -1) {
$problemOrder = $this->problemOrder;
}
$problems = $this->problems;
if ($problemOrder && count($problemOrder) == count($problems)) {
$newmathproblems = [];
foreach ($problems as $mp) {
$newkey = array_search($mp->getID(), $problemOrder);
$newmathproblems[$newkey] = $mp;
}
ksort($newmathproblems);
$problems = $newmathproblems;
return $problems;
} else {
return $this->problems->toArray(); // fallback
}
}
/**
* @param Mathproblem[]
*
* @return $this
*/
public function setProblems($problems)
{
$this->problems = $problems;
return $this;
}
/**
* @param Mathproblem
*
* @return $this
*/
public function addProblem($problem)
{
$this->problems->add($problem);
return $this;
}
/**
* @return bool
*/
public function getReusable()
{
return $this->reusable;
}
/**
* @param bool $reusable
*
* @return $this
*/
public function setReusable($reusable)
{
$this->reusable = $reusable;
return $this;
}
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
/**
* @param User $createdBy
*
* @return $this
*/
public function setCreatedBy($createdBy)
{
$this->createdBy = $createdBy;
return $this;
}
public function getTeachers()
{
return $this->teachers;
}
public function addTeacher(User $teacher)
{
$this->teachers->add($teacher);
return $this;
}
public function getWorksheetSessions(): Collection
{
return $this->worksheetSessions;
}
public function addWorksheetSession(WorksheetSession $worksheetSession)
{
$this->worksheetSessions->add($worksheetSession);
$worksheetSession->setWorksheet($this);
return $this;
}
/**
* @return bool
*/
public function isAbacus()
{
return $this->abacus;
}
/**
* @param bool $abacus
*/
public function setAbacus($abacus)
{
$this->abacus = $abacus;
}
public function getLevel(): ?ClassroomType
{
return $this->level;
}
public function setLevel(?ClassroomType $level): void
{
$this->level = $level;
}
public function getProblemOrder(): ?array
{
return $this->problemOrder;
}
public function setProblemOrder(array $problemOrder)
{
$this->problemOrder = $problemOrder;
}
/**
* @return array|null
*/
public function getMathproblemsForTemplates()
{
return $this->mathproblemsForTemplates;
}
/**
* @param $mathproblemsForTemplates
*/
public function setMathproblemsForTemplates($mathproblemsForTemplates): void
{
$this->mathproblemsForTemplates = $mathproblemsForTemplates;
}
}