Closed jra83 closed 4 years ago
So I think I have the right way to implemetn it now but I am sturggling with syntax. So the SQL query could look like this in the repository finqueryBuilder : And I would add a "andwhere" clause on the allcat in the searchmanager with the $categories from the request originally in an array implode in a string. I think it should work but I can't find how to write it. Could you indicate me how to add the group_concat in the select, and to build a new andwhre condition ?
Much appriciated. JR
Hi everyone, I ended with a solution (not the best but still) so I give it here if it can help some lost soul. I used a having clause + a group_concat function. In the listingsearchmanager.php I added :
$categories = $listingSearchRequest->getCategories(); asort($categories); $strgcategories = implode(',',$categories); if (count($categories)) { $queryBuilder ->andWhere('llcat.category IN (:categories)') ->having("group_concat(llcat.listingcategoryid order by llcat.listingcategoryid asc) = :strgcategories") ->setParameter('categories', $categories) ->setParameter('strgcategories',$strgcategories);
And in the listingRepository.php I added :
$queryBuilder ->addGroupBy('l.id');
I also added the DQL class GroupConcat and updated the config.yml
This is not perfect, I would have prefered to modify the entities in order to add a field in the listinglistingcategory containing the concatenation and then be able to use a where clause on this field, but too complicated for me...
Now the behavoir is as wished. Only the listing with all the categories requested are showed.
Hope It will spare time for people wanting the same results ;)
Hi everyone, I have been working on a cocorico for several day only, so big newby here. Sorry if my question has been answered but i couldn't find any clue... For my project I would like to make a search that takes into account the categories selected with a AND style condition. Ex: I have the following listings :
list1 ClassA / ClassB list2 ClassA list3 Class B
If I search ClassA I want 1 and 2 but if I search A&B i just want just and today it's coded so that I have 1/2/3 as results.
I did my best to dig into the code but I m stuck. So far I have understood that it begins in listingsearchcontrol.php
I have watched in the listingsearchmanage.php with the function search ` public function search(ListingSearchRequest $listingSearchRequest, $locale) { //Select $queryBuilder = $this->getRepository()->getFindQueryBuilder();
And finally the listingrepository.php that gives the initial construction of the sql query :
But from all of this I cannot find a way to execute the way I want the research. I have watched in a lot of other files but I might have missed a step in the process. Could you please help me with this ?
thanks very much, JR