add getRecentTravel method
This commit is contained in:
parent
81ba235b08
commit
781935821b
@ -3,6 +3,9 @@
|
|||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
use App\Entity\CaseItinerary;
|
use App\Entity\CaseItinerary;
|
||||||
|
use App\Entity\MemberCase;
|
||||||
|
use App\Entity\User;
|
||||||
|
use App\Entity\UserCase;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
@ -16,6 +19,36 @@ class CaseItineraryRepository extends ServiceEntityRepository
|
|||||||
parent::__construct($registry, CaseItinerary::class);
|
parent::__construct($registry, CaseItinerary::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRecentTravel(User $user, ?array $params = null): ?array
|
||||||
|
{
|
||||||
|
//dd($params);
|
||||||
|
|
||||||
|
$query = $this->createQueryBuilder('ci')
|
||||||
|
->leftJoin(UserCase::class, 'uc', 'WITH', 'uc.memberCase = ci.memberCase')
|
||||||
|
->andWhere('uc.user = :user')
|
||||||
|
->setParameter('user', $user->getId()->toBinary())
|
||||||
|
;
|
||||||
|
|
||||||
|
if (isset($params['case']) && is_a($params['case'], MemberCase::class)) {
|
||||||
|
$query->andWhere('ci.memberCase = :case')->setParameter('case', $params['case']->getId()->toBinary());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($params['from']) && is_a($params['from'], \DateTime::class)) {
|
||||||
|
$query->andWhere('ci.date >= :from')->setParameter('from', $params['from']->format('Y-m-d'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($params['to']) && is_a($params['to'], \DateTime::class)) {
|
||||||
|
$query->andWhere('ci.date <= :to')->setParameter('to', $params['to']->format('Y-m-d'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->orderBy('ci.date', 'DESC')
|
||||||
|
->addOrderBy('ci.arrival', 'DESC');
|
||||||
|
|
||||||
|
//dd($query->getQuery());
|
||||||
|
|
||||||
|
return $query->getQuery()->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * @return CaseLocation[] Returns an array of CaseLocation objects
|
// * @return CaseLocation[] Returns an array of CaseLocation objects
|
||||||
// */
|
// */
|
||||||
|
Loading…
Reference in New Issue
Block a user