<?php
declare(strict_types=1);
namespace App\Entity\Core\Classroom;
use App\Entity\User\User;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use JsonSerializable;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Table('classroom_student')]
#[ORM\Entity(repositoryClass: \App\Entity\Core\Classroom\ClassroomStudentRepository::class)]
#[UniqueEntity(fields: ['student', 'classroom'], errorPath: 'classroom', message: 'Student is already in the classroom')]
class ClassroomStudent implements JsonSerializable
{
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private int $id;
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: \App\Entity\User\User::class, fetch: 'EAGER', cascade: ['persist'])]
private User $student;
#[ORM\JoinColumn(name: 'classroom_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[ORM\ManyToOne(targetEntity: \App\Entity\Core\Classroom\Classroom::class, inversedBy: 'members')]
private Classroom $classroom;
#[ORM\ManyToMany(targetEntity: \App\Entity\Core\Peer\PeerUnit::class, mappedBy: 'students')]
private PersistentCollection $peerUnits;
public function getId(): int
{
return $this->id;
}
public function setStudent(User $student): ClassroomStudent
{
$this->student = $student;
return $this;
}
public function getStudent(): User
{
return $this->student;
}
public function setClassroom(Classroom $classroom): ClassroomStudent
{
$this->classroom = $classroom;
return $this;
}
public function getPeerUnits(): PersistentCollection
{
return $this->peerUnits;
}
public function getClassroom(): Classroom
{
return $this->classroom;
}
public function jsonSerialize(): mixed
{
return [
"id" => $this->getId(),
"student" => $this->getStudent(),
"peerUnits" => $this->getPeerUnits()
];
}
}