Skip to content

Commit 7b9b3fa

Browse files
committed
Extend findBy pass data in as an array
1 parent 8ae2908 commit 7b9b3fa

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

src/Provider/DoctrineProvider.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,37 +234,39 @@ public function getById($id)
234234
return $this->repository->find($id);
235235
}
236236

237-
/*
237+
/**
238238
* Returns a query of the message queue
239239
*
240-
* @param string $contains
241-
* @param DateTime $from
242-
* @param DateTime $to
243-
*
240+
* @param array $data ['field'=>'id', 'search'=>'text', 'to'=>date, from=>date]
244241
* @return Query
242+
*
245243
*/
246-
247-
public function findBy($contains = null, $from = null, $to = null, $field = 'message')
244+
public function findBy($data)
248245
{
249-
246+
if(!is_array($data) || empty($data)) {
247+
return;
248+
}
249+
250250
$qb = $this->repository->createQueryBuilder('p');
251251
$qb->select('p');
252252
$qb->where('p.queue = :queue');
253253
$qb->setParameter('queue', $this->name);
254254

255-
if ($contains !== null) {
255+
$field = (isset($data['field']))?$data['field']:'message';
256+
257+
if (isset($data['search']) && $data['search'] !== null) {
256258
$qb->andWhere('p.'.$field.' LIKE :contains');
257-
$qb->setParameter('contains', '%' . $contains . '%');
259+
$qb->setParameter('contains', '%' . $data['search'] . '%');
258260
}
259261

260-
if ($from !== null) {
262+
if (isset($data['from']) && $data['from'] !== null) {
261263
$qb->andWhere('p.created >= :from');
262-
$qb->setParameter('from', $from);
264+
$qb->setParameter('from', $data['from']);
263265
}
264266

265-
if ($to !== null) {
267+
if (isset($data['to']) && $data['to'] !== null) {
266268
$qb->andWhere('p.created <= :to');
267-
$qb->setParameter('to', $to);
269+
$qb->setParameter('to', $data['to']);
268270
}
269271

270272
return $qb->getQuery();

0 commit comments

Comments
 (0)