From 99ca79d86ec65e8a3d5f0329d653beb6c318ae33 Mon Sep 17 00:00:00 2001 From: Mat Date: Tue, 6 Nov 2018 15:19:02 +0100 Subject: [PATCH] do not display similar search results if null --- Search/SimilarityPersonSearch.php | 39 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/Search/SimilarityPersonSearch.php b/Search/SimilarityPersonSearch.php index 69d9c67ee..9aac92a88 100644 --- a/Search/SimilarityPersonSearch.php +++ b/Search/SimilarityPersonSearch.php @@ -113,21 +113,30 @@ class SimilarityPersonSearch extends AbstractSearch $total = $this->count($terms); $paginator = $this->paginatorFactory->create($total); - if ($format === 'html') { - return $this->container->get('templating')->render('ChillPersonBundle:Person:list.html.twig', - array( - 'persons' => $this->search($terms, $start, $limit, $options), - 'pattern' => $this->recomposePattern($terms, array('nationality', - 'firstname', 'lastname', 'birthdate', 'gender', - 'birthdate-before','birthdate-after'), $terms['_domain']), - 'total' => $total, - 'start' => $start, - 'search_name' => self::NAME, - 'preview' => $options[SearchInterface::SEARCH_PREVIEW_OPTION], - 'paginator' => $paginator, - 'title' => "Similar persons" - )); - } elseif ($format === 'json') { + if ($format === 'html') + { + if ($total !== 0) + { + return $this->container->get('templating')->render('ChillPersonBundle:Person:list.html.twig', + array( + 'persons' => $this->search($terms, $start, $limit, $options), + 'pattern' => $this->recomposePattern($terms, array('nationality', + 'firstname', 'lastname', 'birthdate', 'gender', + 'birthdate-before','birthdate-after'), $terms['_domain']), + 'total' => $total, + 'start' => $start, + 'search_name' => self::NAME, + 'preview' => $options[SearchInterface::SEARCH_PREVIEW_OPTION], + 'paginator' => $paginator, + 'title' => "Similar persons" + )); + } + else { + return null; + } + + } elseif ($format === 'json') + { return [ 'results' => $this->search($terms, $start, $limit, \array_merge($options, [ 'simplify' => true ])), 'pagination' => [