Adherent.php 2.86 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 18 19 20 21 22 23
 * ApiResource(
 *     attributes={"security"="is_granted('ROLE_ADMIN_ADHERENT_GERER_VIEW')"},
 *     collectionOperations={
 *         "get"={"security"="is_granted('ROLE_ADMIN_ADHERENT_GERER_LIST')"},
 *         "post"={"security"="is_granted('ROLE_ADMIN_ADHERENT_GERER_EDIT')"}
 *     },
 *     itemOperations={
 *         "get"={"security"="is_granted('ROLE_ADMIN_ADHERENT_GERER_LIST')"},
 *         "put"={"security"="is_granted('ROLE_ADMIN_ADHERENT_GERER_EDIT') or object.user == user"},
 *     },
24 25 26
 *     normalizationContext={"groups"={"read"}},
 *     denormalizationContext={"groups"={"write"}}
 * )
Julien Jorry committed
27
 * @ORM\Entity(repositoryClass="App\Repository\AdherentRepository")
28
 * @ORM\Table(name="adherent")
Julien Jorry committed
29 30 31
 */
class Adherent
{
32
    use EnablableEntityTrait,
33
        TimestampableEntity,
34 35
        GeolocEntityTrait,
        HasEcompteEntity;
36

Julien Jorry committed
37 38 39 40 41 42 43 44 45 46
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var User
     *
47
     * @ORM\OneToOne(targetEntity="User", cascade={"all"}, mappedBy="adherent", fetch="LAZY")
Julien Jorry committed
48 49 50
     */
    protected $user;

51 52 53
    /**
     * @var Groupe $groupe
     *
Julien Jorry committed
54
     * @ORM\ManyToOne(targetEntity="Groupe", inversedBy="adherents")
55 56 57
     */
    private $groupe;

Julien Jorry committed
58 59 60 61 62
    public function getId(): ?int
    {
        return $this->id;
    }

63 64
    public function getCompte(): float
    {
65
        return $this->getEcompte();
66 67 68
    }

    public function setCompte(float $ecompte): self
Julien Jorry committed
69
    {
70
        $this->setEcompte($ecompte);
Julien Jorry committed
71 72 73 74 75 76 77

        return $this;
    }

    /**
     * @return User
     */
78
    public function getUser(): ?User
Julien Jorry committed
79 80 81 82 83 84 85 86 87 88 89 90 91
    {
        return $this->user;
    }

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

93 94 95 96
    /**
     * @param null|Groupe $groupe
     * @return $this
     */
Julien Jorry committed
97
    public function setGroupe(?Groupe $groupe): self
98 99 100 101 102 103 104 105 106 107 108 109 110 111
    {
        $this->groupe = $groupe;
        return $this;
    }

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


Julien Jorry committed
112 113 114 115 116 117 118 119 120 121 122
    public function isEnabled(): bool
    {
        return $this->getUser()->isEnabled();
    }

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

123 124 125 126
    public function __toString(): string
    {
        return (!empty($this->getUser() && $this->getUser()->getUsername())?$this->getUser()->getUsername():'Adherent '.$this->getId());
    }
Julien Jorry committed
127
}