* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Rapsys\AirBundle\Entity; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Event\PreUpdateEventArgs; /** * GoogleToken */ class GoogleToken { /** * Primary key */ private ?int $id = null; /** * Create datetime */ private \DateTime $created; /** * Update datetime */ private \DateTime $updated; /** * Google calendars collection */ private Collection $googleCalendars; /** * Constructor * * @param User $user The user instance * @param string The token user mail * @param string The access token identifier * @param \DateTime The access token expires * @param ?string The refresh token identifier */ public function __construct(private User $user, private string $mail, private string $access, private \DateTime $expired, private ?string $refresh = null) { //Set defaults $this->created = new \DateTime('now'); $this->updated = new \DateTime('now'); //Set collections $this->googleCalendars = new ArrayCollection(); } /** * Get id * * @return ?int */ public function getId(): ?int { return $this->id; } /** * Set mail * * @param string $mail * @return GoogleToken */ public function setMail(string $mail): GoogleToken { $this->mail = $mail; return $this; } /** * Get mail * * @return string */ public function getMail(): string { return $this->mail; } /** * Set access * * @param string $access * * @return GoogleToken */ public function setAccess(string $access): GoogleToken { $this->access = $access; return $this; } /** * Get access * * @return string */ public function getAccess(): string { return $this->access; } /** * Set refresh * * @param string $refresh * * @return GoogleToken */ public function setRefresh(?string $refresh): GoogleToken { $this->refresh = $refresh; return $this; } /** * Get refresh * * @return string */ public function getRefresh(): ?string { return $this->refresh; } /** * Set expired * * @param \DateTime $expired * * @return GoogleToken */ public function setExpired(\DateTime $expired): GoogleToken { $this->expired = $expired; return $this; } /** * Get expired * * @return \DateTime */ public function getExpired(): \DateTime { return $this->expired; } /** * Set created * * @param \DateTime $created * * @return GoogleToken */ public function setCreated(\DateTime $created): GoogleToken { $this->created = $created; return $this; } /** * Get created * * @return \DateTime */ public function getCreated(): \DateTime { return $this->created; } /** * Set updated * * @param \DateTime $updated * * @return GoogleToken */ public function setUpdated(\DateTime $updated): GoogleToken { $this->updated = $updated; return $this; } /** * Get updated * * @return \DateTime */ public function getUpdated(): \DateTime { return $this->updated; } /** * Add google calendar * * @param GoogleCalendar $googleCalendar * * @return User */ public function addGoogleCalendar(GoogleCalendar $googleCalendar): User { $this->googleCalendars[] = $googleCalendar; return $this; } /** * Remove google calendar * * @param GoogleCalendar $googleCalendar */ public function removeGoogleCalendar(GoogleCalendar $googleCalendar): bool { return $this->googleCalendars->removeElement($googleCalendar); } /** * Get google calendars * * @return \Doctrine\Common\Collections\Collection */ public function getGoogleCalendars(): Collection { return $this->googleCalendars; } /** * Set user * * @param \Rapsys\AirBundle\Entity\User $user * * @return GoogleToken */ public function setUser(User $user): GoogleToken { $this->user = $user; return $this; } /** * Get user * * @return \Rapsys\AirBundle\Entity\User */ public function getUser(): User { return $this->user; } /** * {@inheritdoc} */ public function preUpdate(PreUpdateEventArgs $eventArgs): ?GoogleToken { //Check that we have an snippet instance if (($entity = $eventArgs->getObject()) instanceof GoogleToken) { //Set updated value return $entity->setUpdated(new \DateTime('now')); } } }