1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys AirBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\AirBundle\Entity
;
14 use Doctrine\Common\Collections\Collection
;
15 use Doctrine\Common\Collections\ArrayCollection
;
16 use Doctrine\ORM\Event\PreUpdateEventArgs
;
35 private string $access;
40 private ?string $refresh;
45 private \DateTime
$expired;
50 private \DateTime
$created;
55 private \DateTime
$updated;
58 * @var \Doctrine\Common\Collections\Collection
60 private Collection
$googleCalendars;
63 * @var \Rapsys\AirBundle\Entity\User
70 * @param \Rapsys\AirBundle\Entity\User $user The user
71 * @param string The token user mail
72 * @param string The access token identifier
73 * @param \DateTime The access token expires
74 * @param ?string The refresh token identifier
76 public function __construct(User
$user, string $mail, string $access, \DateTime
$expired, ?string $refresh = null) {
80 $this->access
= $access;
81 $this->refresh
= $refresh;
82 $this->expired
= $expired;
83 $this->created
= new \
DateTime('now');
84 $this->updated
= new \
DateTime('now');
85 $this->googleCalendars
= new ArrayCollection();
93 public function getId(): ?int {
100 * @param string $mail
101 * @return GoogleToken
103 public function setMail(string $mail): GoogleToken
{
114 public function getMail(): string {
121 * @param string $access
123 * @return GoogleToken
125 public function setAccess(string $access): GoogleToken
{
126 $this->access
= $access;
136 public function getAccess(): string {
137 return $this->access
;
143 * @param string $refresh
145 * @return GoogleToken
147 public function setRefresh(?string $refresh): GoogleToken
{
148 $this->refresh
= $refresh;
158 public function getRefresh(): ?string {
159 return $this->refresh
;
165 * @param \DateTime $expired
167 * @return GoogleToken
169 public function setExpired(\DateTime
$expired): GoogleToken
{
170 $this->expired
= $expired;
180 public function getExpired(): \DateTime
{
181 return $this->expired
;
187 * @param \DateTime $created
189 * @return GoogleToken
191 public function setCreated(\DateTime
$created): GoogleToken
{
192 $this->created
= $created;
202 public function getCreated(): \DateTime
{
203 return $this->created
;
209 * @param \DateTime $updated
211 * @return GoogleToken
213 public function setUpdated(\DateTime
$updated): GoogleToken
{
214 $this->updated
= $updated;
224 public function getUpdated(): \DateTime
{
225 return $this->updated
;
229 * Add google calendar
231 * @param GoogleCalendar $googleCalendar
235 public function addGoogleCalendar(GoogleCalendar
$googleCalendar): User
{
236 $this->googleCalendars
[] = $googleCalendar;
242 * Remove google calendar
244 * @param GoogleCalendar $googleCalendar
246 public function removeGoogleCalendar(GoogleCalendar
$googleCalendar): bool {
247 return $this->googleCalendars
->removeElement($googleCalendar);
251 * Get google calendars
253 * @return \Doctrine\Common\Collections\Collection
255 public function getGoogleCalendars(): Collection
{
256 return $this->googleCalendars
;
262 * @param \Rapsys\AirBundle\Entity\User $user
264 * @return GoogleToken
266 public function setUser(User
$user): GoogleToken
{
275 * @return \Rapsys\AirBundle\Entity\User
277 public function getUser(): User
{
284 public function preUpdate(PreUpdateEventArgs
$eventArgs): ?GoogleToken
{
285 //Check that we have an snippet instance
286 if (($entity = $eventArgs->getEntity()) instanceof GoogleToken
) {
288 return $entity->setUpdated(new \
DateTime('now'));