Repository URL to install this package:
|
Version:
6.2.3 ▾
|
<?php
/**
* Created by PhpStorm.
* User: eduarddezacastellano
* Date: 12/09/2018
* Time: 16:36
*/
namespace DigitalAscetic\GoogleApiClientBundle\Service;
use DigitalAscetic\GoogleApiClientBundle\Entity\GoogleApiNotificationsChannel;
use DigitalAscetic\GoogleApiClientBundle\Entity\IGoogleApiUser;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
class GoogleNotificationsService
{
const SERVICE_NAME = 'ascetic_google_api_client.notifications';
/** @var ContainerInterface $container */
private $container;
/** @var EntityManagerInterface $em */
private $em;
/** @var RouterInterface $router */
private $router;
/** @var string */
private $requestProtocol;
/**
* GoogleNotificationsService constructor.
* @param ContainerInterface $container
* @param EntityManagerInterface $em
* @param RouterInterface $router
* @param string $requestProtocol
*/
public function __construct(ContainerInterface $container, EntityManagerInterface $em, RouterInterface $router, $requestProtocol)
{
$this->container = $container;
$this->em = $em;
$this->router = $router;
$this->requestProtocol = $requestProtocol;
}
/**
* @param string|null $host
* @return string|null
*/
public function getDeliveryAddress(string $host = null): ?string
{
if (!empty($host)) {
$path = $this->router->generate('da.google_api.calendar.notifications');
$deliveryAddress = $this->requestProtocol . '://' . $host . $path;
} else {
$path = $this->router->generate('da.google_api.calendar.notifications', array(), UrlGeneratorInterface::NETWORK_PATH);
$deliveryAddress = $this->requestProtocol . ':' . $path;
}
return $deliveryAddress;
}
/**
* @param IGoogleApiUser $user
* @return GoogleApiNotificationsChannel[]
*/
public function getChannelsByUser(IGoogleApiUser $user)
{
/** @var GoogleApiNotificationsChannel[] $channels */
$channels = $this->em->getRepository(GoogleApiNotificationsChannel::class)->findBy(array('user' => $user));
return $channels;
}
/**
* @param IGoogleApiUser $user
* @return GoogleApiNotificationsChannel
*/
public function getLastChannelByUser(IGoogleApiUser $user)
{
/** @var GoogleApiNotificationsChannel $channel */
$channel = $this->em->getRepository(GoogleApiNotificationsChannel::class)->findOneBy(array('user' => $user), array('id' => 'DESC'));
return $channel;
}
/**
* @param string $channelId
* @return GoogleApiNotificationsChannel
*/
public function getChannelByChannelId(string $channelId)
{
/** @var GoogleApiNotificationsChannel $channel */
$channel = $this->em->getRepository(GoogleApiNotificationsChannel::class)->findOneBy(array('channelId' => $channelId));
return $channel;
}
}