<?php
namespace CoreBundle\Entity;
use JsonSerializable;
use UserBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table("self_study_point_pool")
* @ORM\Entity(repositoryClass="SelfStudyPointPoolRepository")
*/
class SelfStudyPointPool implements JsonSerializable
{
private const POINT_GOAL = 450;
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private int $id;
/**
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
*/
private User $student;
/**
* @ORM\ManyToOne(targetEntity="Topic")
* @ORM\JoinColumn(name="topic_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
*/
private Topic $topic;
/**
* @ORM\Column(name="current_points")
*/
private int $currentPoints;
public function getId(): int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getStudent(): User
{
return $this->student;
}
public function setStudent(User $student): void
{
$this->student = $student;
}
public function getTopic(): Topic
{
return $this->topic;
}
public function setTopic(Topic $topic): void
{
$this->topic = $topic;
}
public function getCurrentPoints(): int
{
return $this->currentPoints;
}
public function setCurrentPoints(int $currentPoints): void
{
$this->currentPoints = $currentPoints;
}
public function getProgressPercentage(): float
{
if (self::POINT_GOAL === 0)
return 0.0;
$progress = $this->currentPoints / self::POINT_GOAL * 100;
return round($progress, 1);
}
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'student' => $this->student,
'topic' => $this->topic,
'currentPoints' => $this->currentPoints,
'progressPercentage' => $this->getProgressPercentage()
];
}
}