Skip to content
Snippets Groups Projects
Commit 2bc67477 authored by Moreau Elise's avatar Moreau Elise
Browse files

add controler to get near contaminated users

parent c2a83cfa
No related branches found
No related tags found
No related merge requests found
<?php
declare(strict_types=1);
namespace App\Application\Actions\User;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use App\Domain\User\UserNotFoundException;
use Doctrine\ORM\EntityManager;
use Psr\Log\LoggerInterface;
use Slim\Views\Twig;
use Slim\Flash\Messages;
/**
* Class ListUsersAction
*
* @author : moreau96u
*/
class NearContaminatedUsers extends UserAction
{
public function __construct(LoggerInterface $logger, EntityManager $em, Twig $twig, Messages $flash){
parent::__construct($logger, $em, $twig, $flash);
$this->em = $em;
$this->userRepository = $em->getRepository('App\Domain\User\User');
$this->groupRepository = $em->getRepository('App\Domain\Group\Group');
$this->locationRepository = $em->getRepository('App\Domain\Location\Location');
}
protected function action(): Response
{
if(!isset($_SESSION['userId'])){
$this->flash->addMessage('login', 'Please log in or sign up.');
return $this->response
->withHeader('Location', '/login')
->withStatus(302);
}
$currentUser = $this->userRepository->find($_SESSION['userId']);
$location = $this->locationRepository->find($currentUser->getLocationId());
$userLatitude = $location->getLatitude();
$userLongitude = $location->getLongitude();
$latitude_min = $userLatitude - 1 ;
$latitude_max = $userLatitude + 1 ;
$longitude_min = $userLongitude - 1 ;
$longitude_max = $userLongitude + 1 ;
$qb = $this->em->createQueryBuilder()
->select('u')
->from('App\Domain\User\User', 'u')
->where('u.contaminated = 1')
->andWhere('u.location.latitude >= :latitude_min')
->andWhere('u.location.latitude <= :latitude_max')
->andWhere('u.location.longitude >= :longitude_min')
->andWhere('u.location.longitude <= :longitude_max')
->setParameter('latitude_min', $latitude_min)
->setParameter('latitude_max', $latitude_max)
->setParameter('longitude_min', $longitude_min)
->setParameter('longitude_max', $longitude_max)
->getQuery()
->getResult();
return $this->respondWithData($qb);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment