src/Entity/AchievementLevel.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AchievementLevelRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Blameable\Traits\BlameableEntity;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. #[ORM\Entity(repositoryClassAchievementLevelRepository::class)]
  10. class AchievementLevel extends BaseKeyValue
  11. {
  12.     use BlameableEntity//Hook blameable behaviour. Updates createdBy, updatedBy fields
  13.     use TimestampableEntity//Hook timestampable behaviour. Updates createdAt, updatedAt fields 
  14.     
  15.     
  16.     const SILVER 'SILVER';
  17.     const GOLD 'GOLD';
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue(strategy"IDENTITY")]
  20.     #[ORM\Column]
  21.     private ?int $id null;
  22.     #[ORM\OneToMany(mappedBy'level'targetEntityAchievement::class)]
  23.     private Collection $achievements;
  24.     public function __construct()
  25.     {
  26.         $this->achievements = new ArrayCollection();
  27.     }
  28.     public function getId(): ?int
  29.     {
  30.         return $this->id;
  31.     }
  32.     /**
  33.      * @return Collection<int, Achievement>
  34.      */
  35.     public function getAchievements(): Collection
  36.     {
  37.         return $this->achievements;
  38.     }
  39.     public function addAchievement(Achievement $achievement): self
  40.     {
  41.         if (!$this->achievements->contains($achievement)) {
  42.             $this->achievements->add($achievement);
  43.             $achievement->setLevel($this);
  44.         }
  45.         return $this;
  46.     }
  47.     public function removeAchievement(Achievement $achievement): self
  48.     {
  49.         if ($this->achievements->removeElement($achievement)) {
  50.             // set the owning side to null (unless already changed)
  51.             if ($achievement->getLevel() === $this) {
  52.                 $achievement->setLevel(null);
  53.             }
  54.         }
  55.         return $this;
  56.     }
  57. }