Commit ca00bc0b authored by SpinShare's avatar SpinShare

added badge entities

parent 087b16c9
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\BadgeRepository")
*/
class Badge
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="string", length=255)
*/
private $description;
/**
* @ORM\Column(type="string", length=255)
*/
private $icon;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserBadge", mappedBy="badge")
*/
private $users;
public function __construct()
{
$this->users = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getIcon(): ?string
{
return $this->icon;
}
public function setIcon(string $icon): self
{
$this->icon = $icon;
return $this;
}
/**
* @return Collection|UserBadge[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(UserBadge $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setBadge($this);
}
return $this;
}
public function removeUser(UserBadge $user): self
{
if ($this->users->contains($user)) {
$this->users->removeElement($user);
// set the owning side to null (unless already changed)
if ($user->getBadge() === $this) {
$user->setBadge(null);
}
}
return $this;
}
}
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserBadgeRepository")
*/
class UserBadge
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Badge", inversedBy="users")
* @ORM\JoinColumn(nullable=false)
*/
private $badge;
/**
* @ORM\Column(type="date")
*/
private $givenDate;
public function getId(): ?int
{
return $this->id;
}
public function getBadge(): ?Badge
{
return $this->badge;
}
public function setBadge(?Badge $badge): self
{
$this->badge = $badge;
return $this;
}
public function getGivenDate(): ?\DateTimeInterface
{
return $this->givenDate;
}
public function setGivenDate(\DateTimeInterface $givenDate): self
{
$this->givenDate = $givenDate;
return $this;
}
}
<?php
namespace App\Repository;
use App\Entity\Badge;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Badge|null find($id, $lockMode = null, $lockVersion = null)
* @method Badge|null findOneBy(array $criteria, array $orderBy = null)
* @method Badge[] findAll()
* @method Badge[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class BadgeRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Badge::class);
}
// /**
// * @return Badge[] Returns an array of Badge objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('b')
->andWhere('b.exampleField = :val')
->setParameter('val', $value)
->orderBy('b.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Badge
{
return $this->createQueryBuilder('b')
->andWhere('b.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}
<?php
namespace App\Repository;
use App\Entity\UserBadge;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method UserBadge|null find($id, $lockMode = null, $lockVersion = null)
* @method UserBadge|null findOneBy(array $criteria, array $orderBy = null)
* @method UserBadge[] findAll()
* @method UserBadge[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class UserBadgeRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, UserBadge::class);
}
// /**
// * @return UserBadge[] Returns an array of UserBadge objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('u')
->andWhere('u.exampleField = :val')
->setParameter('val', $value)
->orderBy('u.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?UserBadge
{
return $this->createQueryBuilder('u')
->andWhere('u.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment