<?php
namespace CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use UserBundle\Entity\User;
/**
* @ORM\Table("gamification_profile")
* @ORM\Entity(repositoryClass="CoreBundle\Entity\GamificationProfileRepository")
*/
class GamificationProfile implements JsonSerializable
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private int $id;
/**
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\User")
* @ORM\JoinColumn(name="student", referencedColumnName="id", onDelete="CASCADE")
*/
private User $student;
/**
* @ORM\Column(name="current_points", type="integer", options={"default":0})
*/
private int $currentPoints = 0;
/**
* @ORM\Column(name="spent_points", type="integer", options={"default":0})
*/
private int $spentPoints = 0;
/**
* @ORM\OneToMany(targetEntity="KvikCustomizationBuy", mappedBy="gamificationProfile", cascade={"persist"})
*/
private Collection $kvikCustomizationBuys;
/**
* @ORM\ManyToMany(targetEntity="CoreBundle\Entity\KvikCustomization")
* @ORM\JoinTable(name="kvik_customization_selection",
* joinColumns={@ORM\JoinColumn(name="gamification_profile", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="kvik_customization", referencedColumnName="id")})
*/
private Collection $selectedKvikCustomizations;
public function __construct()
{
$this->selectedKvikCustomizations = new ArrayCollection();
$this->kvikCustomizationBuys = new ArrayCollection();
}
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 getCurrentPoints(): int
{
return $this->currentPoints;
}
public function setCurrentPoints(int $currentPoints): void
{
$this->currentPoints = $currentPoints;
}
public function getSpentPoints(): int
{
return $this->spentPoints;
}
public function setSpentPoints(int $spentPoints): void
{
$this->spentPoints = $spentPoints;
}
public function getKvikCustomizationBuys(): Collection
{
return $this->kvikCustomizationBuys;
}
public function setKvikCustomizationBuys(Collection $kvikCustomizationBuys): void
{
$this->kvikCustomizationBuys = $kvikCustomizationBuys;
}
public function getSelectedKvikCustomizations(): Collection
{
return $this->selectedKvikCustomizations;
}
public function setSelectedKvikCustomizations(Collection $selectedKvikCustomizations): void
{
$this->selectedKvikCustomizations = $selectedKvikCustomizations;
}
public function spendPoints(int $points): void
{
if ($points > $this->currentPoints)
return;
$this->currentPoints -= $points;
$this->spentPoints += $points;
}
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'student' => $this->student,
'currentPoints' => $this->currentPoints,
'spentPoints' => $this->spentPoints,
'selectedKvikCustomizations' => $this->selectedKvikCustomizations->toArray()
];
}
}