Fixed searching short URLs list not querying tag names

This commit is contained in:
Alejandro Celaya 2017-01-22 11:14:25 +01:00
parent b4548f3401
commit 4df1af5fd8

View File

@ -21,15 +21,15 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
$qb->select('s'); $qb->select('s');
// Set limit and offset // Set limit and offset
if (isset($limit)) { if ($limit !== null) {
$qb->setMaxResults($limit); $qb->setMaxResults($limit);
} }
if (isset($offset)) { if ($offset !== null) {
$qb->setFirstResult($offset); $qb->setFirstResult($offset);
} }
// In case the ordering has been specified, the query could be more complex. Process it // In case the ordering has been specified, the query could be more complex. Process it
if (isset($orderBy)) { if ($orderBy !== null) {
return $this->processOrderByForList($qb, $orderBy); return $this->processOrderByForList($qb, $orderBy);
} }
@ -47,7 +47,7 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
'visits', 'visits',
'visitsCount', 'visitsCount',
'visitCount', 'visitCount',
])) { ], true)) {
$qb->addSelect('COUNT(v) AS totalVisits') $qb->addSelect('COUNT(v) AS totalVisits')
->leftJoin('s.visits', 'v') ->leftJoin('s.visits', 'v')
->groupBy('s') ->groupBy('s')
@ -58,7 +58,7 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
'originalUrl', 'originalUrl',
'shortCode', 'shortCode',
'dateCreated', 'dateCreated',
])) { ], true)) {
$qb->orderBy('s.' . $fieldName, $order); $qb->orderBy('s.' . $fieldName, $order);
} }
@ -93,9 +93,12 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
// Apply search term to every searchable field if not empty // Apply search term to every searchable field if not empty
if (! empty($searchTerm)) { if (! empty($searchTerm)) {
$qb->join('s.tags', 't');
$conditions = [ $conditions = [
$qb->expr()->like('s.originalUrl', ':searchPattern'), $qb->expr()->like('s.originalUrl', ':searchPattern'),
$qb->expr()->like('s.shortCode', ':searchPattern'), $qb->expr()->like('s.shortCode', ':searchPattern'),
$qb->expr()->like('t.name', ':searchPattern'),
]; ];
// Unpack and apply search conditions // Unpack and apply search conditions