Adherent.php 2.38 KB
Newer Older
Julien Jorry committed
1 2 3 4
<?php

namespace App\Entity;

5 6
use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\EntityTrait\GeolocEntityTrait;
7
use App\Entity\EntityTrait\HasEcompteEntity;
Julien Jorry committed
8
use Doctrine\ORM\Mapping as ORM;
9
use Gedmo\Timestampable\Traits\TimestampableEntity;
10 11
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
Julien Jorry committed
12 13

/**
14 15 16 17
 * @ApiResource(
 *     normalizationContext={"groups"={"read"}},
 *     denormalizationContext={"groups"={"write"}}
 * )
Julien Jorry committed
18
 * @ORM\Entity(repositoryClass="App\Repository\AdherentRepository")
19
 * @ORM\Table(name="adherent")
Julien Jorry committed
20 21 22
 */
class Adherent
{
23
    use EnablableEntityTrait,
24
        TimestampableEntity,
25 26
        GeolocEntityTrait,
        HasEcompteEntity;
27

Julien Jorry committed
28 29 30 31 32 33 34 35 36 37
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var User
     *
38
     * @ORM\OneToOne(targetEntity="User", cascade={"all"}, mappedBy="adherent", fetch="LAZY")
Julien Jorry committed
39 40 41
     */
    protected $user;

42 43 44
    /**
     * @var Groupe $groupe
     *
Julien Jorry committed
45
     * @ORM\ManyToOne(targetEntity="Groupe", inversedBy="adherents")
46 47 48
     */
    private $groupe;

Julien Jorry committed
49 50 51 52 53
    public function getId(): ?int
    {
        return $this->id;
    }

54 55
    public function getCompte(): float
    {
56
        return $this->getEcompte();
57 58 59
    }

    public function setCompte(float $ecompte): self
Julien Jorry committed
60
    {
61
        $this->setEcompte($ecompte);
Julien Jorry committed
62 63 64 65 66 67 68

        return $this;
    }

    /**
     * @return User
     */
69
    public function getUser(): ?User
Julien Jorry committed
70 71 72 73 74 75 76 77 78 79 80 81 82
    {
        return $this->user;
    }

    /**
     * @param User $user
     * @return Prestataire
     */
    public function setUser(User $user): self
    {
        $this->user = $user;
        return $this;
    }
Julien Jorry committed
83

84 85 86 87
    /**
     * @param null|Groupe $groupe
     * @return $this
     */
Julien Jorry committed
88
    public function setGroupe(?Groupe $groupe): self
89 90 91 92 93 94 95 96 97 98 99 100 101 102
    {
        $this->groupe = $groupe;
        return $this;
    }

    /**
     * @return null|Groupe
     */
    public function getGroupe(): ?Groupe
    {
        return $this->groupe;
    }


Julien Jorry committed
103 104 105 106 107 108 109 110 111 112 113
    public function isEnabled(): bool
    {
        return $this->getUser()->isEnabled();
    }

    public function setEnabled($enabled): self
    {
        $this->getUser()->setEnabled($enabled);
        return $this;
    }

114 115 116 117
    public function __toString(): string
    {
        return (!empty($this->getUser() && $this->getUser()->getUsername())?$this->getUser()->getUsername():'Adherent '.$this->getId());
    }
Julien Jorry committed
118
}