WIP: Implement closer BPN integration
This commit is contained in:
1 parent
bea5edd615
commit
25a90b04aa
23 files changed
+628
-224
No files matched your search
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\BpnDate;
|
||||
use App\Repository\Traits\QueryHelperTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<BpnDate>
|
||||
*
|
||||
* @method BpnDate|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method BpnDate|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method BpnDate[] findAll()
|
||||
* @method BpnDate[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class BpnDateRepository extends ServiceEntityRepository
|
||||
{
|
||||
use QueryHelperTrait;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, BpnDate::class);
|
||||
}
|
||||
|
||||
public function getAutocompletionData(string $search): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('bpn_date');
|
||||
|
||||
$dates = $qb
|
||||
->select('bpn_date.id', 'bpn_date.product', 'bpn_date.hotel', 'bpn_date.dateFrom', 'bpn_date.dateTo')
|
||||
->where($qb->expr()->orX(
|
||||
$qb->expr()->like('bpn_date.product', ':product'),
|
||||
$qb->expr()->like('bpn_date.hotel', ':hotel')
|
||||
))
|
||||
->setParameter('product', '%'.$this->escapeLikeWildcards($search).'%')
|
||||
->setParameter('hotel', '%'.$this->escapeLikeWildcards($search).'%')
|
||||
->orderBy('bpn_date.product', 'ASC')
|
||||
->addOrderBy('bpn_date.dateFrom', 'ASC')
|
||||
->getQuery()
|
||||
->getArrayResult()
|
||||
;
|
||||
|
||||
$data = [
|
||||
[
|
||||
'value' => '',
|
||||
'text' => '...',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($dates as $date) {
|
||||
$data[] = [
|
||||
'value' => $date['id'],
|
||||
'text' => sprintf('%s (%s - %s)', $date['product'], $date['dateFrom']->format('d.m.y'), $date['dateTo']->format('d.m.y')),
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository\Traits;
|
||||
|
||||
trait QueryHelperTrait
|
||||
{
|
||||
public function escapeLikeWildcards(string $value): string
|
||||
{
|
||||
return addcslashes($value, '_%');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user