Je dispose d'une requête SQL imbriquée que je souhaite rajouter à mon QueryBuilder actuel en mettant mes imbrications de requête dans la clause having. Le problème est que, malgré mes différentes recherches sur le net, je ne trouve pas de tutos, d'aide et je ne vois pas non plus comment le mettre en place. Voici la requête SQL en question :
Code SQL : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
SELECT offer_id
FROM OfferMangooappPlatform
WHERE isActive=true
GROUP BY offer_id
having COUNT(DISTINCT mangooapp_id) = (SELECT MAX(nbapps.nbcount) FROM (SELECT COUNT(DISTINCT mangooapp_id) as nbcount FROM OfferMangooappPlatform
WHERE isActive=true
GROUP BY offer_id) AS nbapps)
Concernant mon queryBuilder, voici son état actuel :
Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public function ajaxLiveOffersFinder($app, $country, $platform)
    {
        $this->isWhere = true;
        $qb = $this->_em->createQueryBuilder();
        $qb->select('off.id as id_offer, plt.id as id_platform, mangapp.id as id_mangooapp, omp.nbClick, omp.nbDownload, off.appName, off.appIcon, off.link, off.maxPayout, off.countriesAllowed')
           ->from('MangooGamesGeneralBundle:OfferMangooappPlatform', 'omp')
           ->join('omp.offer', 'off')
           ->join('omp.mangooapp', 'mangapp')
           ->join('omp.platform', 'plt')
           ->groupBy('off.id');
        $this->addWhere($qb, 'omp', 'isActive', true);
        $this->addWhere($qb, 'off', 'isActive', true);
        if ($app != 'all' && $app != "")
            $this->addWhere($qb, 'omp', 'mangooapp', $app);
        else {
            // C'est ici que doit être ajoutée la requête imbriquée $qb->having('');
 
        }
        if ($country)
            $this->addWhere($qb, 'off', 'countriesAllowed', $country, true);
        if ($platform)
            $this->addWhere($qb, 'omp', 'platform', $platform);
 
        return $qb->getQuery()->getResult();
    }
La méthode addWhere me permet de générer le contenu de la clause Where. Voici sa signature :
Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
private function addWhere(&$qb, $table, $column, $value, $like = false, $orand = 'and');

Merci d'avance pour votre aide,
Rémi