<?php
namespace App\Entity;
use App\Repository\AchievementLevelRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Blameable\Traits\BlameableEntity;
use Gedmo\Timestampable\Traits\TimestampableEntity;
#[ORM\Entity(repositoryClass: AchievementLevelRepository::class)]
class AchievementLevel extends BaseKeyValue
{
use BlameableEntity; //Hook blameable behaviour. Updates createdBy, updatedBy fields
use TimestampableEntity; //Hook timestampable behaviour. Updates createdAt, updatedAt fields
const SILVER = 'SILVER';
const GOLD = 'GOLD';
#[ORM\Id]
#[ORM\GeneratedValue(strategy: "IDENTITY")]
#[ORM\Column]
private ?int $id = null;
#[ORM\OneToMany(mappedBy: 'level', targetEntity: Achievement::class)]
private Collection $achievements;
public function __construct()
{
$this->achievements = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, Achievement>
*/
public function getAchievements(): Collection
{
return $this->achievements;
}
public function addAchievement(Achievement $achievement): self
{
if (!$this->achievements->contains($achievement)) {
$this->achievements->add($achievement);
$achievement->setLevel($this);
}
return $this;
}
public function removeAchievement(Achievement $achievement): self
{
if ($this->achievements->removeElement($achievement)) {
// set the owning side to null (unless already changed)
if ($achievement->getLevel() === $this) {
$achievement->setLevel(null);
}
}
return $this;
}
}