src/Entity/Board.php line 15

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BoardRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Component\Validator\Mapping\ClassMetadata;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. #[ORM\Entity(repositoryClass:BoardRepository::class)]
  11. class Board
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column(type:"integer")]
  16.     private $id;
  17.     #[ORM\Column(type:"string"length:255)]
  18.     private $public_key;
  19.     #[ORM\Column(type:"string"length:255)]
  20.     private $private_key;
  21.     #[ORM\Column(type:"string"length:4)]
  22.     private $sort_order;
  23.     #[ORM\Column(type:"boolean")]
  24.     private $distict;
  25.     #[ORM\OneToMany(targetEntity:Score::class, mappedBy:"board"orphanRemoval:true)]
  26.     private $scores;
  27.     public static function loadValidatorMetadata(ClassMetadata $metadata)
  28.     {
  29.         $metadata->addConstraint(new UniqueEntity([
  30.             'fields' => 'public_key',
  31.             'message' => 'Dieser Name ist leider bereits vergeben',
  32.         ]));
  33.         $metadata->addConstraint(new UniqueEntity([
  34.             'fields' => 'private_key',
  35.             'message' => 'Dieser Schlüssel ist leider bereits vergeben',
  36.         ]));
  37.     }
  38.     public function __construct()
  39.     {
  40.         $this->scores = new ArrayCollection();
  41.     }
  42.     public function __toString()
  43.     {
  44.         return (string) $this->getPublicKey();
  45.     }
  46.     public function getId(): ?int
  47.     {
  48.         return $this->id;
  49.     }
  50.     public function getPublicKey(): ?string
  51.     {
  52.         return $this->public_key;
  53.     }
  54.     public function setPublicKey(string $public_key): self
  55.     {
  56.         $this->public_key $public_key;
  57.         return $this;
  58.     }
  59.     public function getPrivateKey(): ?string
  60.     {
  61.         return $this->private_key;
  62.     }
  63.     public function setPrivateKey(string $private_key): self
  64.     {
  65.         $this->private_key $private_key;
  66.         return $this;
  67.     }
  68.     public function getSortOrder(): ?string
  69.     {
  70.         return $this->sort_order;
  71.     }
  72.     public function setSortOrder(string $sort_order): self
  73.     {
  74.         $this->sort_order $sort_order;
  75.         return $this;
  76.     }
  77.     public function isDistict(): ?bool
  78.     {
  79.         return $this->distict;
  80.     }
  81.     public function setDistict(bool $distict): self
  82.     {
  83.         $this->distict $distict;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, Score>
  88.      */
  89.     public function getScores(): Collection
  90.     {
  91.         return $this->scores;
  92.     }
  93.     public function addScore(Score $score): self
  94.     {
  95.         if (!$this->scores->contains($score)) {
  96.             $this->scores[] = $score;
  97.             $score->setBoard($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removeScore(Score $score): self
  102.     {
  103.         if ($this->scores->removeElement($score)) {
  104.             // set the owning side to null (unless already changed)
  105.             if ($score->getBoard() === $this) {
  106.                 $score->setBoard(null);
  107.             }
  108.         }
  109.         return $this;
  110.     }
  111. }