<?php
namespace App\Entity\Core\Peer;
use App\Entity\Core\Classroom\ClassroomStudent;
use App\Entity\User\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table('peer_unit')]
#[ORM\Entity(repositoryClass: PeerUnitRepository::class)]
class PeerUnit
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
/**
* @var string
*/
#[ORM\Column(name: 'name', type: 'string', nullable: true)]
private $name;
/**
* @var PeerGroup
*/
#[ORM\JoinColumn(name: 'id_group', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[ORM\ManyToOne(targetEntity: PeerGroup::class, inversedBy: 'peerUnits')]
private $peerGroup;
/**
* @var PeerMathproblem
*/
#[ORM\JoinColumn(name: 'id_mathproblem', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[ORM\ManyToOne(targetEntity: PeerMathproblem::class, inversedBy: 'peerUnits')]
private $peerMathproblem;
/**
* @var ClassroomStudent[]
*/
#[ORM\JoinTable(name: 'peer_rel_unit_student')]
#[ORM\JoinColumn(name: 'peer_unit_id', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: ClassroomStudent::class, inversedBy: 'peerUnits')]
private $students;
#[ORM\OneToMany(targetEntity: PeerStudent::class, mappedBy: 'peerUnit', cascade: ['persist'])]
private Collection $peerStudents;
/**
* @var ArrayCollection PeerFeedback
*/
#[ORM\OneToMany(targetEntity: PeerFeedback::class, mappedBy: 'peerUnit', cascade: ['persist'])]
private $peerFeedbacks;
#[ORM\OneToOne(targetEntity: PeerSolution::class, mappedBy: 'peerUnit', cascade: ['persist'])]
private PeerSolution $peerSolution;
/**
* PeerUnit constructor.
*/
public function __construct()
{
$this->peerFeedbacks = new ArrayCollection();
$this->students = new ArrayCollection();
$this->peerStudents = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName(string $name)
{
$this->name = $name;
}
public function getPeerGroup(): PeerGroup
{
return $this->peerGroup;
}
public function setPeerGroup(PeerGroup $peerGroup)
{
$this->peerGroup = $peerGroup;
}
public function getPeerMathproblem(): PeerMathproblem
{
return $this->peerMathproblem;
}
public function setPeerMathproblem(PeerMathproblem $peerMathproblem)
{
$this->peerMathproblem = $peerMathproblem;
}
/**
* @return ClassroomStudent[]|ArrayCollection
*/
public function getStudents()
{
return $this->students;
}
public function addStudent(ClassroomStudent $student)
{
$this->students->add($student);
}
public function getPeerFeedbacks(): ArrayCollection
{
return $this->peerFeedbacks;
}
public function addPeerFeedback(PeerFeedback $peerFeedback)
{
$peerFeedback->setPeerUnit($this);
$this->peerFeedbacks->add($peerFeedback);
}
public function setPeerSolution(PeerSolution $peerSolution) : PeerUnit
{
$this->peerSolution = $peerSolution;
return $this;
}
public function getPeerSolution(): PeerSolution
{
return $this->peerSolution;
}
public function addPeerStudent(PeerStudent $student)
{
$this->peerStudents->add($student);
}
/**
* @return Collection|ArrayCollection|PeerStudent[]
*/
public function getPeerStudents(): Collection
{
return $this->peerStudents;
}
public function getTeamleader(): ?User
{
foreach ($this->peerStudents as $peerStudent) {
if ($peerStudent->getIsTeamLeader()) {
return $peerStudent->getStudent();
}
}
return null;
}
public function getSiblings()
{
$allUnits = $this->getPeerGroup()->getPeerUnits();
$otherUnits = [];
foreach ($allUnits as $unit) {
if ($unit != $this) {
$otherUnits[] = $unit;
}
}
return $otherUnits;
}
}