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
;
25 private ?int $id = null;
30 private \DateTime
$created;
35 private \DateTime
$updated;
38 * Google calendars collection
40 private Collection
$googleCalendars;
45 * @param User $user The user instance
46 * @param string The token user mail
47 * @param string The access token identifier
48 * @param \DateTime The access token expires
49 * @param ?string The refresh token identifier
51 public function __construct(private User
$user, private string $mail, private string $access, private \DateTime
$expired, private ?string $refresh = null) {
53 $this->created
= new \
DateTime('now');
54 $this->updated
= new \
DateTime('now');
57 $this->googleCalendars
= new ArrayCollection();
65 public function getId(): ?int {
75 public function setMail(string $mail): GoogleToken
{
86 public function getMail(): string {
93 * @param string $access
97 public function setAccess(string $access): GoogleToken
{
98 $this->access
= $access;
108 public function getAccess(): string {
109 return $this->access
;
115 * @param string $refresh
117 * @return GoogleToken
119 public function setRefresh(?string $refresh): GoogleToken
{
120 $this->refresh
= $refresh;
130 public function getRefresh(): ?string {
131 return $this->refresh
;
137 * @param \DateTime $expired
139 * @return GoogleToken
141 public function setExpired(\DateTime
$expired): GoogleToken
{
142 $this->expired
= $expired;
152 public function getExpired(): \DateTime
{
153 return $this->expired
;
159 * @param \DateTime $created
161 * @return GoogleToken
163 public function setCreated(\DateTime
$created): GoogleToken
{
164 $this->created
= $created;
174 public function getCreated(): \DateTime
{
175 return $this->created
;
181 * @param \DateTime $updated
183 * @return GoogleToken
185 public function setUpdated(\DateTime
$updated): GoogleToken
{
186 $this->updated
= $updated;
196 public function getUpdated(): \DateTime
{
197 return $this->updated
;
201 * Add google calendar
203 * @param GoogleCalendar $googleCalendar
207 public function addGoogleCalendar(GoogleCalendar
$googleCalendar): User
{
208 $this->googleCalendars
[] = $googleCalendar;
214 * Remove google calendar
216 * @param GoogleCalendar $googleCalendar
218 public function removeGoogleCalendar(GoogleCalendar
$googleCalendar): bool {
219 return $this->googleCalendars
->removeElement($googleCalendar);
223 * Get google calendars
225 * @return \Doctrine\Common\Collections\Collection
227 public function getGoogleCalendars(): Collection
{
228 return $this->googleCalendars
;
234 * @param \Rapsys\AirBundle\Entity\User $user
236 * @return GoogleToken
238 public function setUser(User
$user): GoogleToken
{
247 * @return \Rapsys\AirBundle\Entity\User
249 public function getUser(): User
{
256 public function preUpdate(PreUpdateEventArgs
$eventArgs): ?GoogleToken
{
257 //Check that we have an snippet instance
258 if (($entity = $eventArgs->getObject()) instanceof GoogleToken
) {
260 return $entity->setUpdated(new \
DateTime('now'));